Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7d07684

Browse files
committedMar 18, 2025
Changes needed to use core hooks proposed.
1 parent 9dcc7b3 commit 7d07684

File tree

9 files changed

+191
-171
lines changed

9 files changed

+191
-171
lines changed
 

‎aqo.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ set_baserel_rows_estimate_hook_type prev_set_baserel_rows_estimate_hook;
115115
get_parameterized_baserel_size_hook_type prev_get_parameterized_baserel_size_hook;
116116
set_joinrel_size_estimates_hook_type prev_set_joinrel_size_estimates_hook;
117117
get_parameterized_joinrel_size_hook_type prev_get_parameterized_joinrel_size_hook;
118-
ExplainOnePlan_hook_type prev_ExplainOnePlan_hook;
119-
ExplainOneNode_hook_type prev_ExplainOneNode_hook;
118+
explain_per_plan_hook_type prev_explain_per_plan_hook = NULL;
119+
explain_per_node_hook_type prev_explain_per_node_hook = NULL;
120120
static shmem_request_hook_type prev_shmem_request_hook = NULL;
121121
static object_access_hook_type prev_object_access_hook;
122122

@@ -480,10 +480,10 @@ _PG_init(void)
480480
create_plan_hook = aqo_create_plan_hook;
481481

482482
/* Service hooks. */
483-
prev_ExplainOnePlan_hook = ExplainOnePlan_hook;
484-
ExplainOnePlan_hook = print_into_explain;
485-
prev_ExplainOneNode_hook = ExplainOneNode_hook;
486-
ExplainOneNode_hook = print_node_explain;
483+
prev_explain_per_plan_hook = explain_per_plan_hook;
484+
explain_per_plan_hook = print_into_explain;
485+
prev_explain_per_node_hook = explain_per_node_hook;
486+
explain_per_node_hook = print_node_explain;
487487

488488
prev_create_upper_paths_hook = create_upper_paths_hook;
489489
create_upper_paths_hook = aqo_store_upper_signature_hook;

‎aqo.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ extern set_joinrel_size_estimates_hook_type
252252
prev_set_joinrel_size_estimates_hook;
253253
extern get_parameterized_joinrel_size_hook_type
254254
prev_get_parameterized_joinrel_size_hook;
255-
extern ExplainOnePlan_hook_type prev_ExplainOnePlan_hook;
256-
extern ExplainOneNode_hook_type prev_ExplainOneNode_hook;
255+
extern explain_per_plan_hook_type prev_explain_per_plan_hook;
256+
extern explain_per_node_hook_type prev_explain_per_node_hook;
257257

258258
extern void ppi_hook(ParamPathInfo *ppi);
259259
extern int aqo_statement_timeout;
@@ -269,12 +269,15 @@ extern bool load_fss_ext(uint64 fs, int fss, OkNNrdata *data, List **reloids);
269269
extern bool update_fss_ext(uint64 fs, int fss, OkNNrdata *data, List *reloids);
270270

271271
/* Query preprocessing hooks */
272-
extern void print_into_explain(PlannedStmt *plannedstmt, IntoClause *into,
273-
struct ExplainState *es, const char *queryString,
272+
extern void print_into_explain(PlannedStmt *ps,
273+
IntoClause *into,
274+
struct ExplainState *es,
275+
const char *queryString,
274276
ParamListInfo params,
275-
const instr_time *planduration,
276277
QueryEnvironment *queryEnv);
277-
extern void print_node_explain(struct ExplainState *es, PlanState *ps, Plan *plan);
278+
extern void print_node_explain(PlanState *ps, List *ancestors,
279+
const char *relationship, const char *plan_name,
280+
struct ExplainState *es);
278281

279282
/* Cardinality estimation */
280283
extern double predict_for_relation(List *restrict_clauses, List *selectivities,

‎expected/aqo_fdw.out

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ SELECT str FROM expln('
6666
str
6767
-----------------------------------------------------------
6868
Foreign Scan on public.frgn (actual rows=1.00 loops=1)
69-
AQO not used
7069
Output: x
7170
Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
71+
AQO not used
7272
Using aqo: true
7373
AQO mode: LEARN
7474
JOINS: 0
@@ -81,9 +81,9 @@ SELECT str FROM expln('
8181
str
8282
-----------------------------------------------------------
8383
Foreign Scan on public.frgn (actual rows=1.00 loops=1)
84-
AQO: rows=1, error=0%
8584
Output: x
8685
Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
86+
AQO: rows=1, error=0%
8787
Using aqo: true
8888
AQO mode: LEARN
8989
JOINS: 0
@@ -108,8 +108,8 @@ SELECT str FROM expln('
108108
str
109109
---------------------------------------------------------------
110110
Merge Join (actual rows=1.00 loops=1)
111-
AQO not used
112111
Merge Cond: (a.x = b.x)
112+
AQO not used
113113
-> Sort (actual rows=1.00 loops=1)
114114
Sort Key: a.x
115115
-> Foreign Scan on frgn a (actual rows=1.00 loops=1)
@@ -131,10 +131,10 @@ SELECT str FROM expln('
131131
str
132132
--------------------------------------------------------------------------------------------------------
133133
Foreign Scan (actual rows=1.00 loops=1)
134-
AQO: rows=1, error=0%
135134
Output: a.x, b.x
136135
Relations: (public.frgn a) INNER JOIN (public.frgn b)
137136
Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x = r2.x))))
137+
AQO: rows=1, error=0%
138138
Using aqo: true
139139
AQO mode: LEARN
140140
JOINS: 0
@@ -153,8 +153,8 @@ WHERE a.aid = b.aid AND b.bval like 'val%';
153153
QUERY PLAN
154154
-----------------------------------------------
155155
Foreign Scan (actual rows=1000.00 loops=1)
156-
AQO not used
157156
Relations: (frgn_a a) INNER JOIN (frgn_b b)
157+
AQO not used
158158
Using aqo: true
159159
AQO mode: LEARN
160160
JOINS: 0
@@ -166,8 +166,8 @@ WHERE a.aid = b.aid AND b.bval like 'val%';
166166
QUERY PLAN
167167
-----------------------------------------------
168168
Foreign Scan (actual rows=1000.00 loops=1)
169-
AQO: rows=1000, error=0%
170169
Relations: (frgn_a a) INNER JOIN (frgn_b b)
170+
AQO: rows=1000, error=0%
171171
Using aqo: true
172172
AQO mode: LEARN
173173
JOINS: 0
@@ -207,17 +207,17 @@ WHERE str NOT LIKE '%Memory%';
207207
Append (actual rows=1000.00 loops=1)
208208
AQO not used
209209
-> Foreign Scan (actual rows=400.00 loops=1)
210-
AQO not used
211210
Relations: (main_p0 a_1) INNER JOIN (ref_p0 b_1)
212-
-> Foreign Scan (actual rows=300.00 loops=1)
213211
AQO not used
212+
-> Foreign Scan (actual rows=300.00 loops=1)
214213
Relations: (main_p1 a_2) INNER JOIN (ref_p1 b_2)
215-
-> Hash Join (actual rows=300.00 loops=1)
216214
AQO not used
215+
-> Hash Join (actual rows=300.00 loops=1)
217216
Hash Cond: (b_3.aid = a_3.aid)
217+
AQO not used
218218
-> Seq Scan on ref_p2 b_3 (actual rows=300.00 loops=1)
219-
AQO not used
220219
Filter: (bval ~~ 'val%'::text)
220+
AQO not used
221221
-> Hash (actual rows=38.00 loops=1)
222222
-> Seq Scan on main_p2 a_3 (actual rows=38.00 loops=1)
223223
AQO not used
@@ -237,17 +237,17 @@ WHERE str NOT LIKE '%Memory%';
237237
Append (actual rows=1000.00 loops=1)
238238
AQO not used
239239
-> Foreign Scan (actual rows=400.00 loops=1)
240-
AQO: rows=400, error=0%
241240
Relations: (main_p0 a_1) INNER JOIN (ref_p0 b_1)
241+
AQO: rows=400, error=0%
242242
-> Foreign Scan (actual rows=300.00 loops=1)
243-
AQO: rows=300, error=0%
244243
Relations: (main_p1 a_2) INNER JOIN (ref_p1 b_2)
245-
-> Hash Join (actual rows=300.00 loops=1)
246244
AQO: rows=300, error=0%
245+
-> Hash Join (actual rows=300.00 loops=1)
247246
Hash Cond: (b_3.aid = a_3.aid)
247+
AQO: rows=300, error=0%
248248
-> Seq Scan on ref_p2 b_3 (actual rows=300.00 loops=1)
249-
AQO: rows=300, error=0%
250249
Filter: (bval ~~ 'val%'::text)
250+
AQO: rows=300, error=0%
251251
-> Hash (actual rows=38.00 loops=1)
252252
-> Seq Scan on main_p2 a_3 (actual rows=38.00 loops=1)
253253
AQO: rows=38, error=0%
@@ -266,14 +266,14 @@ SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
266266
QUERY PLAN
267267
---------------------------------------------------------------
268268
Nested Loop (actual rows=0.00 loops=1)
269-
AQO not used
270269
Join Filter: (a.x < b.x)
271270
Rows Removed by Join Filter: 1
271+
AQO not used
272272
-> Foreign Scan on frgn a (actual rows=1.00 loops=1)
273273
AQO not used
274274
-> Materialize (actual rows=1.00 loops=1)
275-
AQO not used
276275
Storage: Memory Maximum Storage: 17kB
276+
AQO not used
277277
-> Foreign Scan on frgn b (actual rows=1.00 loops=1)
278278
AQO not used
279279
Using aqo: true
@@ -288,10 +288,10 @@ SELECT str FROM expln('
288288
str
289289
--------------------------------------------------------------------------------------------------------
290290
Foreign Scan (actual rows=0.00 loops=1)
291-
AQO: rows=1, error=100%
292291
Output: a.x, b.x
293292
Relations: (public.frgn a) INNER JOIN (public.frgn b)
294293
Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x < r2.x))))
294+
AQO: rows=1, error=100%
295295
Using aqo: true
296296
AQO mode: LEARN
297297
JOINS: 0

‎expected/feature_subspace.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ WHERE str NOT LIKE '%Memory%';
3131
result
3232
--------------------------------------------------------
3333
Merge Left Join (actual rows=10.00 loops=1)
34-
AQO not used
3534
Merge Cond: (a.x = b.x)
35+
AQO not used
3636
-> Sort (actual rows=10.00 loops=1)
3737
Sort Key: a.x
3838
-> Seq Scan on a (actual rows=10.00 loops=1)
@@ -54,8 +54,8 @@ WHERE str NOT LIKE '%Memory%';
5454
result
5555
--------------------------------------------------------
5656
Merge Left Join (actual rows=100.00 loops=1)
57-
AQO not used
5857
Merge Cond: (b.x = a.x)
58+
AQO not used
5959
-> Sort (actual rows=100.00 loops=1)
6060
Sort Key: b.x
6161
-> Seq Scan on b (actual rows=100.00 loops=1)

‎expected/gucs.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ SELECT regexp_replace(
3535
str
3636
---------------------------------------------------
3737
Seq Scan on public.t (actual rows=100.00 loops=1)
38-
AQO not used
3938
Output: x
39+
AQO not used
4040
Query Identifier: N
4141
Using aqo: true
4242
AQO mode: LEARN
@@ -51,8 +51,8 @@ SELECT regexp_replace(
5151
str
5252
---------------------------------------------------
5353
Seq Scan on public.t (actual rows=100.00 loops=1)
54-
AQO: rows=100, error=0%
5554
Output: x
55+
AQO: rows=100, error=0%
5656
Query Identifier: N
5757
Using aqo: true
5858
AQO mode: LEARN

‎expected/look_a_like.out

Lines changed: 66 additions & 66 deletions
Large diffs are not rendered by default.

‎expected/parallel_workers.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ WHERE str NOT LIKE '%Worker%';
4747
-> Partial Aggregate (actual rows=1.00 loops=3)
4848
AQO not used
4949
-> Parallel Seq Scan on t (actual rows=333.33 loops=3)
50-
AQO: rows=1000, error=0%
5150
Filter: ((id % '100'::numeric) = '0'::numeric)
5251
Rows Removed by Filter: 33000
52+
AQO: rows=1000, error=0%
5353
Using aqo: true
5454
AQO mode: LEARN
5555
JOINS: 0
@@ -81,37 +81,37 @@ WHERE str NOT LIKE '%Workers%' AND str NOT LIKE '%Sort Method%'
8181
Aggregate (actual rows=1.00 loops=1)
8282
AQO not used
8383
-> Merge Join (actual rows=0.00 loops=1)
84-
AQO not used
8584
Merge Cond: (t.id = q2.id)
85+
AQO not used
8686
-> Group (actual rows=1000.00 loops=1)
87-
AQO not used
8887
Group Key: t.id
88+
AQO not used
8989
AQO: rows=914, error=-9%
9090
-> Sort (actual rows=333.33 loops=3)
91-
AQO: rows=914, error=64%
9291
Sort Key: t.id
92+
AQO: rows=914, error=64%
9393
-> Parallel Seq Scan on t (actual rows=333.33 loops=3)
94-
AQO: rows=914, error=-9%
9594
Filter: ((id % '100'::numeric) = '0'::numeric)
9695
Rows Removed by Filter: 33000
96+
AQO: rows=914, error=-9%
9797
-> Sort (actual rows=1.00 loops=1)
9898
Sort Key: q2.id
9999
-> Subquery Scan on q2 (actual rows=1.00 loops=1)
100100
AQO not used
101101
-> Finalize GroupAggregate (actual rows=1.00 loops=1)
102-
AQO not used
103102
Group Key: t_1.payload
103+
AQO not used
104104
AQO not used
105105
-> Partial GroupAggregate (actual rows=1.00 loops=3)
106-
AQO not used
107106
Group Key: t_1.payload
107+
AQO not used
108108
-> Sort (actual rows=330.00 loops=3)
109-
AQO not used
110109
Sort Key: t_1.payload
110+
AQO not used
111111
-> Parallel Seq Scan on t t_1 (actual rows=330.00 loops=3)
112-
AQO: rows=914, error=-8%
113112
Filter: ((id % '101'::numeric) = '0'::numeric)
114113
Rows Removed by Filter: 33003
114+
AQO: rows=914, error=-8%
115115
Using aqo: true
116116
AQO mode: LEARN
117117
JOINS: 1

‎expected/unsupported.out

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ EXPLAIN (COSTS OFF)
3737
Aggregate
3838
AQO not used
3939
-> HashAggregate
40-
AQO: rows=17
4140
Group Key: t.x
41+
AQO: rows=17
4242
-> Seq Scan on t
43-
AQO: rows=801
4443
Filter: (x > 3)
44+
AQO: rows=801
4545
Using aqo: true
4646
AQO mode: LEARN
4747
JOINS: 0
@@ -54,12 +54,12 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
5454
str
5555
--------------------------------------------------
5656
HashAggregate (actual rows=17.00 loops=1)
57-
AQO not used
5857
Group Key: x
58+
AQO not used
5959
-> Seq Scan on t (actual rows=801.00 loops=1)
60-
AQO not used
6160
Filter: (x > 3)
6261
Rows Removed by Filter: 199
62+
AQO not used
6363
Using aqo: true
6464
AQO mode: LEARN
6565
JOINS: 0
@@ -81,8 +81,8 @@ EXPLAIN (COSTS OFF)
8181
Aggregate
8282
AQO not used
8383
-> HashAggregate
84-
AQO: rows=10
8584
Group Key: t1.x, t1.y
85+
AQO: rows=10
8686
-> Seq Scan on t1
8787
AQO: rows=1000
8888
Using aqo: true
@@ -103,8 +103,8 @@ EXPLAIN (COSTS OFF)
103103
Aggregate
104104
AQO not used
105105
-> HashAggregate
106-
AQO: rows=10
107106
Group Key: t1.x, (t1.x * t1.y)
107+
AQO: rows=10
108108
-> Seq Scan on t1
109109
AQO: rows=1000
110110
Using aqo: true
@@ -146,11 +146,11 @@ WHERE q2.x > 1;
146146
Aggregate
147147
AQO not used
148148
-> Aggregate
149-
AQO not used
150149
Filter: (count(*) > 1)
150+
AQO not used
151151
-> HashAggregate
152-
AQO: rows=10
153152
Group Key: t1.x, t1.y
153+
AQO: rows=10
154154
-> Seq Scan on t1
155155
AQO: rows=1000
156156
Using aqo: true
@@ -174,11 +174,11 @@ EXPLAIN (COSTS OFF)
174174
Aggregate
175175
AQO not used
176176
-> MixedAggregate
177-
AQO not used
178177
Hash Key: t1.x, t1.y
179178
Hash Key: t1.x
180179
Hash Key: t1.y
181180
Group Key: ()
181+
AQO not used
182182
-> Seq Scan on t1
183183
AQO: rows=1000
184184
Using aqo: true
@@ -207,13 +207,13 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
207207
-> Aggregate (actual rows=1.00 loops=1)
208208
AQO not used
209209
-> Seq Scan on t t_1 (actual rows=50.00 loops=1)
210-
AQO: rows=50, error=0%
211210
Filter: (x = 1)
212211
Rows Removed by Filter: 950
212+
AQO: rows=50, error=0%
213213
-> Seq Scan on t (actual rows=50.00 loops=1)
214-
AQO: rows=50, error=0%
215214
Filter: ((x)::numeric = (InitPlan 1).col1)
216215
Rows Removed by Filter: 950
216+
AQO: rows=50, error=0%
217217
Using aqo: true
218218
AQO mode: LEARN
219219
JOINS: 0
@@ -234,15 +234,15 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
234234
Aggregate (actual rows=1.00 loops=1)
235235
AQO not used
236236
-> Seq Scan on t (actual rows=1000.00 loops=1)
237-
AQO: rows=1000, error=0%
238237
Filter: ((x)::numeric = (SubPlan 1))
238+
AQO: rows=1000, error=0%
239239
SubPlan 1
240240
-> Aggregate (actual rows=1.00 loops=1000)
241241
AQO not used
242242
-> Seq Scan on t t0 (actual rows=49.90 loops=1000)
243-
AQO: rows=50, error=0%
244243
Filter: (x = t.x)
245244
Rows Removed by Filter: 950
245+
AQO: rows=50, error=0%
246246
Using aqo: true
247247
AQO mode: LEARN
248248
JOINS: 0
@@ -258,23 +258,23 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
258258
Aggregate (actual rows=1.00 loops=1)
259259
AQO not used
260260
-> Seq Scan on t (actual rows=0.00 loops=1)
261-
AQO not used
262261
Filter: (((x)::numeric = (SubPlan 1)) OR (ANY ((x)::numeric = (SubPlan 2).col1)))
263262
Rows Removed by Filter: 1000
263+
AQO not used
264264
SubPlan 1
265265
-> Aggregate (actual rows=1.00 loops=1000)
266266
AQO not used
267267
-> Seq Scan on t t0 (actual rows=0.00 loops=1000)
268-
AQO not used
269268
Filter: (x = (t.x + 21))
270269
Rows Removed by Filter: 1000
270+
AQO not used
271271
SubPlan 2
272272
-> Aggregate (actual rows=1.00 loops=1000)
273273
AQO not used
274274
-> Seq Scan on t t0_1 (actual rows=0.00 loops=1000)
275-
AQO not used
276275
Filter: (x = (t.x + 21))
277276
Rows Removed by Filter: 1000
277+
AQO not used
278278
Using aqo: true
279279
AQO mode: LEARN
280280
JOINS: 0
@@ -289,23 +289,23 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
289289
Aggregate (actual rows=1.00 loops=1)
290290
AQO not used
291291
-> Seq Scan on t (actual rows=0.00 loops=1)
292-
AQO: rows=1, error=100%
293292
Filter: (((x)::numeric = (SubPlan 1)) OR (ANY ((x)::numeric = (SubPlan 2).col1)))
294293
Rows Removed by Filter: 1000
294+
AQO: rows=1, error=100%
295295
SubPlan 1
296296
-> Aggregate (actual rows=1.00 loops=1000)
297297
AQO not used
298298
-> Seq Scan on t t0 (actual rows=0.00 loops=1000)
299-
AQO: rows=1, error=100%
300299
Filter: (x = (t.x + 21))
301300
Rows Removed by Filter: 1000
301+
AQO: rows=1, error=100%
302302
SubPlan 2
303303
-> Aggregate (actual rows=1.00 loops=1000)
304304
AQO not used
305305
-> Seq Scan on t t0_1 (actual rows=0.00 loops=1000)
306-
AQO: rows=1, error=100%
307306
Filter: (x = (t.x + 21))
308307
Rows Removed by Filter: 1000
308+
AQO: rows=1, error=100%
309309
Using aqo: true
310310
AQO mode: LEARN
311311
JOINS: 0
@@ -321,23 +321,23 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
321321
Aggregate (actual rows=1.00 loops=1)
322322
AQO not used
323323
-> Seq Scan on t (actual rows=0.00 loops=1)
324-
AQO: rows=1, error=100%
325324
Filter: (((x)::numeric = (SubPlan 1)) OR (ANY ((x)::numeric = (SubPlan 2).col1)))
326325
Rows Removed by Filter: 1000
326+
AQO: rows=1, error=100%
327327
SubPlan 1
328328
-> Aggregate (actual rows=1.00 loops=1000)
329329
AQO not used
330330
-> Seq Scan on t t0 (actual rows=0.00 loops=1000)
331-
AQO: rows=1, error=100%
332331
Filter: (x = (t.x + 22))
333332
Rows Removed by Filter: 1000
333+
AQO: rows=1, error=100%
334334
SubPlan 2
335335
-> Aggregate (actual rows=1.00 loops=1000)
336336
AQO not used
337337
-> Seq Scan on t t0_1 (actual rows=0.00 loops=1000)
338-
AQO: rows=1, error=100%
339338
Filter: (x = (t.x + 23))
340339
Rows Removed by Filter: 1000
340+
AQO: rows=1, error=100%
341341
Using aqo: true
342342
AQO mode: LEARN
343343
JOINS: 0
@@ -367,30 +367,30 @@ SELECT count(*) FROM
367367
Aggregate (actual rows=1.00 loops=1)
368368
AQO not used
369369
-> Hash Join (actual rows=42550.00 loops=1)
370-
AQO: rows=42550, error=0%
371370
Hash Cond: ((t_1.x + 1) = t.x)
371+
AQO: rows=42550, error=0%
372372
-> Seq Scan on t t_1 (actual rows=1000.00 loops=1)
373-
AQO: rows=1000, error=0%
374373
Filter: (((x % 3))::numeric < (SubPlan 2))
374+
AQO: rows=1000, error=0%
375375
SubPlan 2
376376
-> Aggregate (actual rows=1.00 loops=1000)
377377
AQO not used
378378
-> Seq Scan on t t0_1 (actual rows=950.10 loops=1000)
379-
AQO: rows=950, error=-0%
380379
Filter: (x <> t_1.x)
381380
Rows Removed by Filter: 50
381+
AQO: rows=950, error=-0%
382382
-> Hash (actual rows=851.00 loops=1)
383383
-> Seq Scan on t (actual rows=851.00 loops=1)
384-
AQO: rows=851, error=0%
385384
Filter: (((x % 3))::numeric < (SubPlan 1))
386385
Rows Removed by Filter: 149
386+
AQO: rows=851, error=0%
387387
SubPlan 1
388388
-> Aggregate (actual rows=1.00 loops=1000)
389389
AQO not used
390390
-> Seq Scan on t t0 (actual rows=49.90 loops=1000)
391-
AQO: rows=50, error=0%
392391
Filter: (x = t.x)
393392
Rows Removed by Filter: 950
393+
AQO: rows=50, error=0%
394394
Using aqo: true
395395
AQO mode: LEARN
396396
JOINS: 1
@@ -405,22 +405,22 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
405405
Aggregate (actual rows=1.00 loops=1)
406406
AQO not used
407407
-> Seq Scan on t (actual rows=1000.00 loops=1)
408-
AQO not used
409408
Filter: ((SubPlan 1) = (SubPlan 2))
409+
AQO not used
410410
SubPlan 1
411411
-> Aggregate (actual rows=1.00 loops=1000)
412412
AQO not used
413413
-> Seq Scan on t t0 (actual rows=49.90 loops=1000)
414-
AQO not used
415414
Filter: (x = t.x)
416415
Rows Removed by Filter: 950
416+
AQO not used
417417
SubPlan 2
418418
-> Aggregate (actual rows=1.00 loops=1000)
419419
AQO not used
420420
-> Seq Scan on t t0_1 (actual rows=49.90 loops=1000)
421-
AQO not used
422421
Filter: (x = t.x)
423422
Rows Removed by Filter: 950
423+
AQO not used
424424
Using aqo: true
425425
AQO mode: LEARN
426426
JOINS: 0
@@ -434,22 +434,22 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
434434
Aggregate (actual rows=1.00 loops=1)
435435
AQO not used
436436
-> Seq Scan on t (actual rows=1000.00 loops=1)
437-
AQO: rows=1000, error=0%
438437
Filter: ((SubPlan 1) = (SubPlan 2))
438+
AQO: rows=1000, error=0%
439439
SubPlan 1
440440
-> Aggregate (actual rows=1.00 loops=1000)
441441
AQO not used
442442
-> Seq Scan on t t0 (actual rows=49.90 loops=1000)
443-
AQO: rows=50, error=0%
444443
Filter: (x = t.x)
445444
Rows Removed by Filter: 950
445+
AQO: rows=50, error=0%
446446
SubPlan 2
447447
-> Aggregate (actual rows=1.00 loops=1000)
448448
AQO not used
449449
-> Seq Scan on t t0_1 (actual rows=49.90 loops=1000)
450-
AQO: rows=50, error=0%
451450
Filter: (x = t.x)
452451
Rows Removed by Filter: 950
452+
AQO: rows=50, error=0%
453453
Using aqo: true
454454
AQO mode: LEARN
455455
JOINS: 0
@@ -476,15 +476,15 @@ SELECT * FROM
476476
QUERY PLAN
477477
------------------------------------------------
478478
Nested Loop (actual rows=0.00 loops=1)
479-
AQO: rows=1, error=100%
480479
Join Filter: (t.x = t_1.x)
480+
AQO: rows=1, error=100%
481481
-> Seq Scan on t (actual rows=0.00 loops=1)
482-
AQO: rows=1, error=100%
483482
Filter: (x < 0)
484483
Rows Removed by Filter: 1000
484+
AQO: rows=1, error=100%
485485
-> Seq Scan on t t_1 (never executed)
486-
AQO: rows=1
487486
Filter: (x > 20)
487+
AQO: rows=1
488488
Using aqo: true
489489
AQO mode: LEARN
490490
JOINS: 0
@@ -513,12 +513,12 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF, BUFFERS OFF)
513513
Aggregate (actual rows=1.00 loops=1)
514514
AQO not used
515515
-> Index Only Scan using ind1 on t (actual rows=50.00 loops=1)
516-
AQO: rows=50, error=0%
517516
Index Cond: (x < 3)
518517
Filter: (mod(x, 3) = 1)
519518
Rows Removed by Filter: 99
520519
Heap Fetches: 149
521520
Index Searches: 1
521+
AQO: rows=50, error=0%
522522
Using aqo: true
523523
AQO mode: LEARN
524524
JOINS: 0
@@ -540,13 +540,13 @@ WHERE str NOT LIKE '%Heap Blocks%';
540540
str
541541
--------------------------------------------------------------------
542542
Aggregate (actual rows=1.00 loops=1)
543-
AQO not used
544543
Output: count(*)
544+
AQO not used
545545
-> Bitmap Heap Scan on public.t (actual rows=50.00 loops=1)
546-
AQO: rows=50, error=0%
547546
Recheck Cond: (mod(t.x, 3) = 1)
548547
Filter: (t.x < 3)
549548
Rows Removed by Filter: 300
549+
AQO: rows=50, error=0%
550550
-> Bitmap Index Scan on ind2 (actual rows=350.00 loops=1)
551551
Index Cond: (mod(t.x, 3) = 1)
552552
Index Searches: 1
@@ -564,9 +564,9 @@ EXPLAIN (COSTS OFF)
564564
Aggregate
565565
AQO not used
566566
-> Index Only Scan using ind1 on t
567-
AQO: rows=50
568567
Index Cond: (x < 3)
569568
Filter: (mod(x, 3) = 1)
569+
AQO: rows=50
570570
Using aqo: true
571571
AQO mode: LEARN
572572
JOINS: 0

‎postprocessing.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -979,15 +979,18 @@ ExtractFromQueryEnv(QueryDesc *queryDesc)
979979
}
980980

981981
void
982-
print_node_explain(ExplainState *es, PlanState *ps, Plan *plan)
982+
print_node_explain(PlanState *ps, List *ancestors,
983+
const char *relationship, const char *plan_name,
984+
struct ExplainState *es)
983985
{
986+
Plan *plan = ps->plan;
984987
int wrkrs = 1;
985988
double error = -1.;
986989
AQOPlanNode *aqo_node;
987990

988991
/* Extension, which took a hook early can be executed early too. */
989-
if (prev_ExplainOneNode_hook)
990-
prev_ExplainOneNode_hook(es, ps, plan);
992+
if (prev_explain_per_node_hook)
993+
prev_explain_per_node_hook(ps, ancestors, relationship, plan_name, es);
991994

992995
if (IsQueryDisabled() || !plan || es->format != EXPLAIN_FORMAT_TEXT)
993996
return;
@@ -1019,44 +1022,58 @@ print_node_explain(ExplainState *es, PlanState *ps, Plan *plan)
10191022
}
10201023

10211024
explain_print:
1022-
appendStringInfoChar(es->str, '\n');
1023-
if (es->str->len == 0 || es->str->data[es->str->len - 1] == '\n')
1024-
appendStringInfoSpaces(es->str, es->indent * 2);
1025-
1026-
if (aqo_node->prediction > 0.)
1025+
if (es->format == EXPLAIN_FORMAT_TEXT)
10271026
{
1028-
appendStringInfo(es->str, "AQO: rows=%.0lf", aqo_node->prediction);
1027+
ExplainIndentText(es);
10291028

1030-
if (ps->instrument && ps->instrument->nloops > 0.)
1029+
if (aqo_node->prediction > 0.)
10311030
{
1032-
double rows = ps->instrument->ntuples / ps->instrument->nloops;
1031+
appendStringInfo(es->str, "AQO: rows=%.0lf", aqo_node->prediction);
1032+
1033+
if (ps->instrument && ps->instrument->nloops > 0.)
1034+
{
1035+
double rows = ps->instrument->ntuples / ps->instrument->nloops;
10331036

1034-
error = 100. * (aqo_node->prediction - (rows*wrkrs))
1035-
/ aqo_node->prediction;
1036-
appendStringInfo(es->str, ", error=%.0lf%%", error);
1037+
error = 100. * (aqo_node->prediction - (rows*wrkrs))
1038+
/ aqo_node->prediction;
1039+
appendStringInfo(es->str, ", error=%.0lf%%", error);
1040+
}
1041+
appendStringInfoChar(es->str, '\n');
10371042
}
1043+
else
1044+
appendStringInfo(es->str, "AQO not used\n");
10381045
}
10391046
else
1040-
appendStringInfo(es->str, "AQO not used");
1047+
{
1048+
/* TODO */
1049+
}
10411050

10421051
explain_end:
10431052
/* XXX: Do we really have situations when the plan is a NULL pointer? */
1044-
if (plan && aqo_show_hash)
1045-
appendStringInfo(es->str, ", fss=%d", aqo_node->fss);
1053+
if (es->format == EXPLAIN_FORMAT_TEXT)
1054+
{
1055+
if (plan && aqo_show_hash)
1056+
{
1057+
ExplainIndentText(es);
1058+
appendStringInfo(es->str, ", fss=%d\n", aqo_node->fss);
1059+
}
1060+
}
1061+
else
1062+
{
1063+
/* TODO */
1064+
}
10461065
}
10471066

10481067
/*
10491068
* Prints if the plan was constructed with AQO.
10501069
*/
10511070
void
1052-
print_into_explain(PlannedStmt *plannedstmt, IntoClause *into,
1071+
print_into_explain(PlannedStmt *ps, IntoClause *into,
10531072
ExplainState *es, const char *queryString,
1054-
ParamListInfo params, const instr_time *planduration,
1055-
QueryEnvironment *queryEnv)
1073+
ParamListInfo params, QueryEnvironment *queryEnv)
10561074
{
1057-
if (prev_ExplainOnePlan_hook)
1058-
prev_ExplainOnePlan_hook(plannedstmt, into, es, queryString,
1059-
params, planduration, queryEnv);
1075+
if (prev_explain_per_plan_hook)
1076+
prev_explain_per_plan_hook(ps, into, es, queryString, params, queryEnv);
10601077

10611078
if (IsQueryDisabled() || !aqo_show_details)
10621079
return;

0 commit comments

Comments
 (0)
Please sign in to comment.