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)

0 commit comments

Comments
 (0)