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

Commit 5793965

Browse files
author
Daniil Anisimov
committed
Introduction to AQO Basic mode.
Add the aqo.use GUC to determine how AQO should learn. Reduce the aqo.mode GUC to determine AQO learning procedures.
1 parent 656ec07 commit 5793965

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+389
-192
lines changed

aqo.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void _PG_init(void);
3030
#define AQO_MODULE_MAGIC (1234)
3131

3232
/* Strategy of determining feature space for new queries. */
33+
int aqo_use = AQO_USE_OFF;
3334
int aqo_mode = AQO_MODE_CONTROLLED;
3435
bool force_collect_stat;
3536
bool aqo_predict_with_few_neighbors;
@@ -50,15 +51,18 @@ bool aqo_show_details;
5051
bool change_flex_timeout;
5152

5253
/* GUC variables */
53-
static const struct config_enum_entry format_options[] = {
54+
static const struct config_enum_entry use_options[] = {
55+
{"off", AQO_USE_OFF, false},
56+
{"on", AQO_USE_ON, false},
57+
{"advanced", AQO_USE_ADVANCED, false},
58+
{NULL, 0, false}
59+
};
60+
61+
static const struct config_enum_entry mode_options[] = {
5462
{"intelligent", AQO_MODE_INTELLIGENT, false},
55-
{"forced", AQO_MODE_FORCED, false},
56-
{"forced_controlled", AQO_MODE_FORCED_CONTROLLED, false},
57-
{"forced_frozen", AQO_MODE_FORCED_FROZEN, false},
5863
{"controlled", AQO_MODE_CONTROLLED, false},
5964
{"learn", AQO_MODE_LEARN, false},
6065
{"frozen", AQO_MODE_FROZEN, false},
61-
{"disabled", AQO_MODE_DISABLED, false},
6266
{NULL, 0, false}
6367
};
6468

@@ -138,12 +142,25 @@ _PG_init(void)
138142
*/
139143
EnableQueryId();
140144

145+
DefineCustomEnumVariable("aqo.use",
146+
"State of aqo",
147+
NULL,
148+
&aqo_use,
149+
AQO_USE_OFF,
150+
use_options,
151+
PGC_USERSET,
152+
0,
153+
NULL,
154+
NULL,
155+
NULL
156+
);
157+
141158
DefineCustomEnumVariable("aqo.mode",
142159
"Mode of aqo usage.",
143160
NULL,
144161
&aqo_mode,
145162
AQO_MODE_CONTROLLED,
146-
format_options,
163+
mode_options,
147164
PGC_USERSET,
148165
0,
149166
NULL,

aqo.h

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,46 @@
148148
#error "Cannot build aqo with PostgreSQL version lower than 9.6.0"
149149
#endif
150150

151-
/* Strategy of determining feature space for new queries. */
151+
/* Strategy of determining feature space for queries. */
152152
typedef enum
153153
{
154-
/* Creates new feature space for each query type with auto-tuning enabled */
154+
/* Aqo is disabled for all queries */
155+
AQO_USE_OFF,
156+
157+
/* Treats query types as linked to the common feature space (FORCED) */
158+
AQO_USE_ON,
159+
160+
/* Creates new feature space for each query type (LEARN) */
161+
AQO_USE_ADVANCED,
162+
} AQO_USE;
163+
164+
/* Strategy of determining learn/predict routines. */
165+
typedef enum
166+
{
167+
/*
168+
* When AQO_USE_ADVANCED, creates new feature space for each query type
169+
* with auto-tuning enabled.
170+
* When AQO_USE_ON, it works as LEARN mode.
171+
*/
155172
AQO_MODE_INTELLIGENT,
156-
/* Treats new query types as linked to the common feature space */
157-
AQO_MODE_FORCED,
158-
/* Like FORCED, but learn only on old feature sub spaces */
159-
AQO_MODE_FORCED_CONTROLLED,
160-
/* Like FORCED, but use old knowledge without learning */
161-
AQO_MODE_FORCED_FROZEN,
162-
/* New query types are not linked with any feature space */
173+
174+
/*
175+
* Learn only on old feature sub space for AQO_USE_ON or
176+
* only on old feature space for AQO_USE_ADVANCED
177+
*/
163178
AQO_MODE_CONTROLLED,
164-
/* Creates new feature space for each query type without auto-tuning */
179+
180+
/*
181+
* Creates new feature sub space and if AQO_USE_ON feature space too
182+
* for each query type without auto-tuning
183+
*/
165184
AQO_MODE_LEARN,
185+
166186
/* Use only current AQO estimations, without learning or tuning */
167-
AQO_MODE_FROZEN,
168-
/* Aqo is disabled for all queries */
169-
AQO_MODE_DISABLED,
187+
AQO_MODE_FROZEN
170188
} AQO_MODE;
171189

190+
extern int aqo_use;
172191
extern int aqo_mode;
173192
extern bool force_collect_stat;
174193
extern bool aqo_show_hash;
@@ -177,6 +196,10 @@ extern int aqo_join_threshold;
177196
extern bool use_wide_search;
178197
extern bool aqo_learn_statement_timeout;
179198

199+
#define AQO_MODE() \
200+
(aqo_mode == AQO_MODE_INTELLIGENT && aqo_use != AQO_USE_ADVANCED ? \
201+
AQO_MODE_LEARN : aqo_mode)
202+
180203
/* Parameters for current query */
181204
typedef struct QueryContextData
182205
{

expected/aqo_controlled.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ AS (
3232
) INSERT INTO aqo_test2 (SELECT * FROM t);
3333
CREATE INDEX aqo_test2_idx_a ON aqo_test2 (a);
3434
ANALYZE aqo_test2;
35+
SET aqo.use = 'advanced';
3536
SET aqo.mode = 'controlled';
3637
EXPLAIN (COSTS FALSE)
3738
SELECT * FROM aqo_test0

expected/aqo_disabled.out

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ AS (
2525
) INSERT INTO aqo_test1 (SELECT * FROM t);
2626
CREATE INDEX aqo_test1_idx_a ON aqo_test1 (a);
2727
ANALYZE aqo_test1;
28+
SET aqo.use = 'advanced';
2829
SET aqo.mode = 'controlled';
2930
CREATE TABLE tmp1 AS SELECT * FROM aqo_test0
3031
WHERE a < 3 AND b < 3 AND c < 3 AND d < 3;
@@ -77,7 +78,7 @@ SELECT count(*) FROM aqo_queries WHERE queryid <> fs; -- Should be zero
7778
0
7879
(1 row)
7980

80-
SET aqo.mode = 'disabled';
81+
SET aqo.use = 'off';
8182
CREATE TABLE tmp1 AS SELECT * FROM aqo_test0
8283
WHERE a < 3 AND b < 3 AND c < 3 AND d < 3;
8384
SELECT count(*) FROM tmp1;
@@ -129,6 +130,7 @@ SELECT count(*) FROM aqo_queries WHERE queryid <> fs; -- Should be zero
129130
0
130131
(1 row)
131132

133+
SET aqo.use = 'advanced';
132134
SET aqo.mode = 'intelligent';
133135
CREATE TABLE tmp1 AS SELECT * FROM aqo_test0
134136
WHERE a < 3 AND b < 3 AND c < 3 AND d < 3;
@@ -198,7 +200,7 @@ SELECT count(*) FROM aqo_queries WHERE queryid <> fs; -- Should be zero
198200
0
199201
(1 row)
200202

201-
SET aqo.mode = 'disabled';
203+
SET aqo.use = 'off';
202204
EXPLAIN SELECT * FROM aqo_test0
203205
WHERE a < 3 AND b < 3 AND c < 3 AND d < 3;
204206
QUERY PLAN

expected/aqo_fdw.out

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SELECT true AS success FROM aqo_reset();
1111
t
1212
(1 row)
1313

14+
SET aqo.use = 'advanced';
1415
SET aqo.mode = 'learn';
1516
SET aqo.show_details = 'true'; -- show AQO info for each node and entire query.
1617
SET aqo.show_hash = 'false'; -- a hash value is system-depended. Ignore it.
@@ -43,9 +44,10 @@ SELECT x FROM frgn;
4344
Foreign Scan on frgn (actual rows=1 loops=1)
4445
AQO not used
4546
Using aqo: true
47+
AQO use: ADVANCED
4648
AQO mode: LEARN
4749
JOINS: 0
48-
(5 rows)
50+
(6 rows)
4951

5052
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
5153
SELECT x FROM frgn;
@@ -54,9 +56,10 @@ SELECT x FROM frgn;
5456
Foreign Scan on frgn (actual rows=1 loops=1)
5557
AQO: rows=1, error=0%
5658
Using aqo: true
59+
AQO use: ADVANCED
5760
AQO mode: LEARN
5861
JOINS: 0
59-
(5 rows)
62+
(6 rows)
6063

6164
-- Push down base filters. Use verbose mode to see filters.
6265
SELECT str FROM expln('
@@ -70,9 +73,10 @@ SELECT str FROM expln('
7073
Output: x
7174
Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
7275
Using aqo: true
76+
AQO use: ADVANCED
7377
AQO mode: LEARN
7478
JOINS: 0
75-
(7 rows)
79+
(8 rows)
7680

7781
SELECT str FROM expln('
7882
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
@@ -85,9 +89,10 @@ SELECT str FROM expln('
8589
Output: x
8690
Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
8791
Using aqo: true
92+
AQO use: ADVANCED
8893
AQO mode: LEARN
8994
JOINS: 0
90-
(7 rows)
95+
(8 rows)
9196

9297
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
9398
SELECT x FROM frgn WHERE x < -10; -- AQO ignores constants
@@ -96,9 +101,10 @@ SELECT x FROM frgn WHERE x < -10; -- AQO ignores constants
96101
Foreign Scan on frgn (actual rows=0 loops=1)
97102
AQO: rows=1, error=100%
98103
Using aqo: true
104+
AQO use: ADVANCED
99105
AQO mode: LEARN
100106
JOINS: 0
101-
(5 rows)
107+
(6 rows)
102108

103109
-- Trivial JOIN push-down.
104110
SELECT str FROM expln('
@@ -119,9 +125,10 @@ SELECT str FROM expln('
119125
-> Foreign Scan on frgn b (actual rows=1 loops=1)
120126
AQO not used
121127
Using aqo: true
128+
AQO use: ADVANCED
122129
AQO mode: LEARN
123130
JOINS: 1
124-
(14 rows)
131+
(15 rows)
125132

126133
-- Should learn on postgres_fdw nodes
127134
SELECT str FROM expln('
@@ -136,9 +143,10 @@ SELECT str FROM expln('
136143
Relations: (public.frgn a) INNER JOIN (public.frgn b)
137144
Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x = r2.x))))
138145
Using aqo: true
146+
AQO use: ADVANCED
139147
AQO mode: LEARN
140148
JOINS: 0
141-
(8 rows)
149+
(9 rows)
142150

143151
CREATE TABLE local_a(aid int primary key, aval text);
144152
CREATE TABLE local_b(bid int primary key, aid int references local_a(aid), bval text);
@@ -156,9 +164,10 @@ WHERE a.aid = b.aid AND b.bval like 'val%';
156164
AQO not used
157165
Relations: (frgn_a a) INNER JOIN (frgn_b b)
158166
Using aqo: true
167+
AQO use: ADVANCED
159168
AQO mode: LEARN
160169
JOINS: 0
161-
(6 rows)
170+
(7 rows)
162171

163172
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
164173
SELECT * from frgn_a AS a, frgn_b AS b
@@ -169,9 +178,10 @@ WHERE a.aid = b.aid AND b.bval like 'val%';
169178
AQO: rows=1000, error=0%
170179
Relations: (frgn_a a) INNER JOIN (frgn_b b)
171180
Using aqo: true
181+
AQO use: ADVANCED
172182
AQO mode: LEARN
173183
JOINS: 0
174-
(6 rows)
184+
(7 rows)
175185

176186
-- Partitioned join over foreign tables
177187
set enable_partitionwise_join = on;
@@ -222,9 +232,10 @@ WHERE str NOT LIKE '%Memory%';
222232
-> Seq Scan on main_p2 a_3 (actual rows=38 loops=1)
223233
AQO not used
224234
Using aqo: true
235+
AQO use: ADVANCED
225236
AQO mode: LEARN
226237
JOINS: 1
227-
(20 rows)
238+
(21 rows)
228239

229240
SELECT str AS result
230241
FROM expln('
@@ -252,9 +263,10 @@ WHERE str NOT LIKE '%Memory%';
252263
-> Seq Scan on main_p2 a_3 (actual rows=38 loops=1)
253264
AQO: rows=38, error=0%
254265
Using aqo: true
266+
AQO use: ADVANCED
255267
AQO mode: LEARN
256268
JOINS: 1
257-
(20 rows)
269+
(21 rows)
258270

259271
DROP TABLE main, local_main_p0, local_main_p1;
260272
DROP TABLE ref, local_ref_p0, local_ref_p1;
@@ -269,9 +281,10 @@ SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
269281
AQO not used
270282
Relations: (frgn a) INNER JOIN (frgn b)
271283
Using aqo: true
284+
AQO use: ADVANCED
272285
AQO mode: LEARN
273286
JOINS: 0
274-
(6 rows)
287+
(7 rows)
275288

276289
SELECT str FROM expln('
277290
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
@@ -285,9 +298,10 @@ SELECT str FROM expln('
285298
Relations: (public.frgn a) INNER JOIN (public.frgn b)
286299
Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x < r2.x))))
287300
Using aqo: true
301+
AQO use: ADVANCED
288302
AQO mode: LEARN
289303
JOINS: 0
290-
(8 rows)
304+
(9 rows)
291305

292306
DROP EXTENSION aqo CASCADE;
293307
DROP EXTENSION postgres_fdw CASCADE;

0 commit comments

Comments
 (0)