Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e7cd9cd

Browse files
author
Alexandra Pervushina
committed
Add aqo.debug_print variable
1 parent 2a3c84a commit e7cd9cd

24 files changed

+84
-22
lines changed

aqo.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int aqo_statement_timeout;
4848
bool aqo_show_hash;
4949
bool aqo_show_details;
5050
bool change_flex_timeout;
51+
bool aqo_debug_print;
5152

5253
/* GUC variables */
5354
static const struct config_enum_entry format_options[] = {
@@ -313,6 +314,17 @@ _PG_init(void)
313314
NULL,
314315
NULL);
315316

317+
DefineCustomBoolVariable("aqo.debug_print",
318+
"Print NOTICE level warnings to logfile",
319+
NULL,
320+
&aqo_debug_print,
321+
false,
322+
PGC_USERSET,
323+
0,
324+
NULL,
325+
NULL,
326+
NULL);
327+
316328
aqo_shmem_init();
317329
aqo_preprocessing_init();
318330
aqo_postprocessing_init();

aqo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ extern bool aqo_show_details;
172172
extern int aqo_join_threshold;
173173
extern bool use_wide_search;
174174
extern bool aqo_learn_statement_timeout;
175+
extern bool aqo_debug_print;
175176

176177
/* Parameters for current query */
177178
typedef struct QueryContextData

postprocessing.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ should_learn(PlanState *ps, AQOPlanNode *node, aqo_obj_stat *ctx,
314314
if (ctx->learn && nrows > predicted * 1.2)
315315
{
316316
/* This node s*/
317-
if (aqo_show_details && compute_query_id != COMPUTE_QUERY_ID_REGRESS)
317+
if (aqo_show_details && aqo_debug_print)
318318
elog(NOTICE,
319319
"[AQO] Learn on a plan node ("UINT64_FORMAT", %d), "
320320
"predicted rows: %.0lf, updated prediction: %.0lf",
@@ -331,7 +331,7 @@ should_learn(PlanState *ps, AQOPlanNode *node, aqo_obj_stat *ctx,
331331
/* This is much more reliable data. So we can correct our prediction. */
332332
if (ctx->learn && aqo_show_details &&
333333
fabs(nrows - predicted) / predicted > 0.2 &&
334-
compute_query_id != COMPUTE_QUERY_ID_REGRESS)
334+
aqo_debug_print)
335335
elog(NOTICE,
336336
"[AQO] Learn on a finished plan node ("UINT64_FORMAT", %d), "
337337
"predicted rows: %.0lf, updated prediction: %.0lf",
@@ -631,11 +631,13 @@ aqo_timeout_handler(void)
631631
ctx.learn = query_context.learn_aqo;
632632
ctx.isTimedOut = true;
633633

634-
if (aqo_statement_timeout == 0)
635-
elog(NOTICE, "[AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.");
636-
else
637-
elog(NOTICE, "[AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data. Timeout is "INT64_FORMAT, max_timeout_value);
638-
634+
if(aqo_debug_print)
635+
{
636+
if (aqo_statement_timeout == 0)
637+
elog(NOTICE, "[AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.");
638+
else
639+
elog(NOTICE, "[AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data. Timeout is "INT64_FORMAT, max_timeout_value);
640+
}
639641
learnOnPlanState(timeoutCtl.queryDesc->planstate, (void *) &ctx);
640642
MemoryContextSwitchTo(oldctx);
641643
}
@@ -648,7 +650,7 @@ increase_smart_timeout()
648650
{
649651
int64 smart_timeout_fin_time = (query_context.smart_timeout + 1) * pow(growth_rate, query_context.count_increase_timeout);
650652

651-
if (query_context.smart_timeout == max_timeout_value && !update_query_timeout(query_context.query_hash, smart_timeout_fin_time))
653+
if (query_context.smart_timeout == max_timeout_value && !update_query_timeout(query_context.query_hash, smart_timeout_fin_time) && aqo_debug_print)
652654
elog(NOTICE, "[AQO] Timeout is not updated!");
653655

654656
return smart_timeout_fin_time;
@@ -827,7 +829,8 @@ aqo_ExecutorEnd(QueryDesc *queryDesc)
827829
if ( aqo_learn_statement_timeout && aqo_statement_timeout > 0 && error >= 0.1)
828830
{
829831
int64 fintime = increase_smart_timeout();
830-
elog(NOTICE, "[AQO] Time limit for execution of the statement was increased. Current timeout is "UINT64_FORMAT, fintime);
832+
if (aqo_debug_print)
833+
elog(NOTICE, "[AQO] Time limit for execution of the statement was increased. Current timeout is "UINT64_FORMAT, fintime);
831834
}
832835

833836
pfree(stat);

sql/aqo_CVE-2020-14350.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
SET client_min_messages = 'warning';
77
DROP ROLE IF EXISTS regress_hacker;
88
SET client_min_messages = 'notice';
9-
SET compute_query_id = on;
9+
SET compute_query_id = auto;
10+
SET aqo.show_hash = 'off';
11+
SET aqo.show_details = 'off';
1012

1113
CREATE ROLE regress_hacker LOGIN;
1214

sql/aqo_controlled.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
CREATE EXTENSION IF NOT EXISTS aqo;
22
SELECT true AS success FROM aqo_reset();
3-
SET compute_query_id = on;
3+
SET compute_query_id = auto;
4+
SET aqo.show_hash = 'off';
5+
SET aqo.show_details = 'off';
46

57
CREATE TABLE aqo_test0(a int, b int, c int, d int);
68
WITH RECURSIVE t(a, b, c, d)

sql/aqo_disabled.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
-- previous pass (repeated installcheck as an example).
33
CREATE EXTENSION IF NOT EXISTS aqo;
44
SELECT true AS success FROM aqo_reset();
5-
SET compute_query_id = on;
5+
SET compute_query_id = auto;
6+
SET aqo.show_hash = 'off';
7+
SET aqo.show_details = 'off';
68

79
CREATE TABLE aqo_test0(a int, b int, c int, d int);
810
WITH RECURSIVE t(a, b, c, d)

sql/aqo_fdw.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
CREATE EXTENSION IF NOT EXISTS aqo;
88
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
99
SELECT true AS success FROM aqo_reset();
10-
SET compute_query_id = on;
10+
SET compute_query_id = auto;
1111

1212
SET aqo.mode = 'learn';
13-
SET aqo.show_details = 'true'; -- show AQO info for each node and entire query.
1413
SET aqo.show_hash = 'false'; -- a hash value is system-depended. Ignore it.
1514

1615
DO $d$

sql/aqo_forced.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-- Preliminaries
22
CREATE EXTENSION IF NOT EXISTS aqo;
33
SELECT true AS success FROM aqo_reset();
4+
SET compute_query_id = auto;
5+
SET aqo.show_hash = 'off';
6+
SET aqo.show_details = 'off';
47

58
CREATE TABLE aqo_test0(a int, b int, c int, d int);
69
WITH RECURSIVE t(a, b, c, d)

sql/aqo_intelligent.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CREATE EXTENSION IF NOT EXISTS aqo;
22
SELECT true AS success FROM aqo_reset();
3+
SET compute_query_id = auto;
4+
SET aqo.show_hash = 'off';
5+
SET aqo.show_details = 'off';
36

47
CREATE TABLE aqo_test0(a int, b int, c int, d int);
58
WITH RECURSIVE t(a, b, c, d)

sql/aqo_learn.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CREATE EXTENSION IF NOT EXISTS aqo;
22
SELECT true AS success FROM aqo_reset();
3+
SET compute_query_id = auto;
4+
SET aqo.show_hash = 'off';
5+
SET aqo.show_details = 'off';
36

47
-- The function just copied from stats_ext.sql
58
create function check_estimated_rows(text) returns table (estimated int, actual int)

sql/clean_aqo_data.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CREATE EXTENSION IF NOT EXISTS aqo;
22
SELECT true AS success FROM aqo_reset();
3+
SET compute_query_id = auto;
4+
SET aqo.show_hash = 'off';
5+
SET aqo.show_details = 'off';
36

47
SET aqo.mode = 'learn';
58

sql/feature_subspace.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
CREATE EXTENSION IF NOT EXISTS aqo;
44
SELECT true AS success FROM aqo_reset();
5+
SET compute_query_id = auto;
6+
SET aqo.show_hash = 'off';
7+
SET aqo.show_details = 'off';
58

69
SET aqo.mode = 'learn';
7-
SET aqo.show_details = 'on';
810

911
CREATE TABLE a AS (SELECT gs AS x FROM generate_series(1,10) AS gs);
1012
CREATE TABLE b AS (SELECT gs AS x FROM generate_series(1,100) AS gs);

sql/forced_stat_collection.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CREATE EXTENSION IF NOT EXISTS aqo;
22
SELECT true AS success FROM aqo_reset();
3+
SET compute_query_id = auto;
4+
SET aqo.show_hash = 'off';
5+
SET aqo.show_details = 'off';
36

47
\set citizens 1000
58

sql/gucs.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
CREATE EXTENSION IF NOT EXISTS aqo;
33
SELECT true AS success FROM aqo_reset();
44

5+
56
-- Utility tool. Allow to filter system-dependent strings from an explain output.
67
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
78
BEGIN
@@ -12,8 +13,8 @@ END;
1213
$$ LANGUAGE PLPGSQL;
1314

1415
SET aqo.mode = 'learn';
15-
SET aqo.show_details = true;
1616
SET compute_query_id = 'auto';
17+
SET aqo.show_details = 'off';
1718

1819
CREATE TABLE t(x int);
1920
INSERT INTO t (x) (SELECT * FROM generate_series(1, 100) AS gs);

sql/look_a_like.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
-- Preliminaries
22
CREATE EXTENSION IF NOT EXISTS aqo;
33
SELECT true AS success FROM aqo_reset();
4+
SET compute_query_id = auto;
5+
SET aqo.show_hash = 'off';
6+
SET aqo.show_details = 'off';
47

58
SET aqo.wide_search = 'on';
69

710
SET aqo.mode = 'learn';
8-
SET aqo.show_details = 'on';
9-
set aqo.show_hash = 'off';
1011
SET aqo.min_neighbors_for_predicting = 1;
1112
SET enable_nestloop = 'off';
1213
SET enable_mergejoin = 'off';

sql/parallel_workers.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
CREATE EXTENSION IF NOT EXISTS aqo;
55
SELECT true AS success FROM aqo_reset();
6+
SET compute_query_id = auto;
7+
SET aqo.show_hash = 'off';
8+
SET aqo.show_details = 'off';
69

710
-- Utility tool. Allow to filter system-dependent strings from explain output.
811
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
@@ -14,7 +17,6 @@ END;
1417
$$ LANGUAGE PLPGSQL;
1518

1619
SET aqo.mode = 'learn';
17-
SET aqo.show_details = true;
1820

1921
-- Be generous with a number parallel workers to test the machinery
2022
SET max_parallel_workers = 64;

sql/plancache.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
CREATE EXTENSION IF NOT EXISTS aqo;
44
SELECT true AS success FROM aqo_reset();
5+
SET compute_query_id = auto;
6+
SET aqo.show_hash = 'off';
7+
SET aqo.show_details = 'off';
58

69
SET aqo.mode = 'intelligent';
7-
SET aqo.show_details = 'on';
8-
SET aqo.show_hash = 'off';
910

1011
CREATE TABLE test AS SELECT x FROM generate_series(1,10) AS x;
1112
ANALYZE test;

sql/relocatable.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CREATE EXTENSION IF NOT EXISTS aqo;
22
SELECT true AS success FROM aqo_reset();
3+
SET compute_query_id = auto;
4+
SET aqo.show_hash = 'off';
5+
SET aqo.show_details = 'off';
36

47
SET aqo.mode = 'learn'; -- use this mode for unconditional learning
58

sql/schema.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ SET search_path TO test1, public;
1212
CREATE EXTENSION aqo;
1313
SELECT true AS success FROM aqo_reset();
1414
SET aqo.mode = 'intelligent';
15+
SET compute_query_id = auto;
16+
SET aqo.show_hash = 'off';
17+
SET aqo.show_details = 'off';
1518

1619
CREATE TABLE test (id SERIAL, data TEXT);
1720
INSERT INTO test (data) VALUES ('string');

sql/statement_timeout.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ END; $$;
2121
-- Preliminaries
2222
CREATE EXTENSION IF NOT EXISTS aqo;
2323
SELECT true AS success FROM aqo_reset();
24+
SET compute_query_id = auto;
25+
SET aqo.show_hash = 'off';
2426

2527
CREATE TABLE t AS SELECT * FROM generate_series(1,50) AS x;
2628
ANALYZE t;
2729
DELETE FROM t WHERE x > 5; -- Force optimizer to make overestimated prediction.
2830

2931
SET aqo.mode = 'learn';
3032
SET aqo.show_details = 'off';
33+
SET aqo.show_details = 'off';
3134
SET aqo.learn_statement_timeout = 'on';
3235

3336
SET statement_timeout = 80; -- [0.1s]

sql/temp_tables.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-- Preliminaries
22
CREATE EXTENSION IF NOT EXISTS aqo;
33
SELECT true AS success FROM aqo_reset();
4+
SET compute_query_id = auto;
5+
SET aqo.show_hash = 'off';
6+
SET aqo.show_details = 'off';
47

58
SET aqo.wide_search = 'on';
69
SET aqo.mode = 'learn';

sql/top_queries.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-- Preliminaries
22
CREATE EXTENSION IF NOT EXISTS aqo;
33
SELECT true AS success FROM aqo_reset();
4+
SET compute_query_id = auto;
5+
SET aqo.show_hash = 'off';
6+
SET aqo.show_details = 'off';
47

58
SET aqo.mode = 'disabled';
69
SET aqo.force_collect_stat = 'on';

sql/unsupported.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
CREATE EXTENSION IF NOT EXISTS aqo;
22
SELECT true AS success FROM aqo_reset();
3+
SET compute_query_id = auto;
4+
SET aqo.show_hash = 'off';
35

46
-- Utility tool. Allow to filter system-dependent strings from an explain output.
57
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
@@ -11,7 +13,6 @@ END;
1113
$$ LANGUAGE PLPGSQL;
1214

1315
SET aqo.mode = 'learn';
14-
SET aqo.show_details = 'on';
1516

1617
DROP TABLE IF EXISTS t;
1718
CREATE TABLE t AS SELECT (gs.* / 50) AS x FROM generate_series(1,1000) AS gs;

sql/update_functions.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-- Preliminaries
22
CREATE EXTENSION IF NOT EXISTS aqo;
33
SELECT true AS success FROM aqo_reset();
4+
SET compute_query_id = auto;
5+
SET aqo.show_hash = 'off';
6+
SET aqo.show_details = 'off';
47

58
CREATE TABLE aqo_test1(a int, b int);
69
WITH RECURSIVE t(a, b)

0 commit comments

Comments
 (0)