Skip to content

Commit c6de386

Browse files
committed
Arrange the code with current PG master - 2
1 parent 2a99c02 commit c6de386

17 files changed

+530
-473
lines changed

Diff for: aqo.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ extern double predict_for_relation(List *restrict_clauses, List *selectivities,
282282
List *relsigns, int *fss);
283283

284284
/* Query execution statistics collecting hooks */
285-
void aqo_ExecutorStart(QueryDesc *queryDesc, int eflags);
286-
void aqo_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
287-
uint64 count, bool execute_once);
285+
bool aqo_ExecutorStart(QueryDesc *queryDesc, int eflags);
286+
void aqo_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count);
288287
void aqo_ExecutorEnd(QueryDesc *queryDesc);
289288

290289
/* Automatic query tuning */

Diff for: expected/aqo_CVE-2020-14350.out

+67
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,41 @@ RESET ROLE;
7070
-- Test result (error expected)
7171
CREATE EXTENSION aqo;
7272
ERROR: function "aqo_status" already exists with same argument types
73+
CONTEXT: SQL statement "CREATE FUNCTION public.aqo_status(hash bigint)
74+
RETURNS TABLE (
75+
"learn" BOOL,
76+
"use aqo" BOOL,
77+
"auto tune" BOOL,
78+
"fspace hash" bigINT,
79+
"t_naqo" TEXT,
80+
"err_naqo" TEXT,
81+
"iters" BIGINT,
82+
"t_aqo" TEXT,
83+
"err_aqo" TEXT,
84+
"iters_aqo" BIGINT
85+
)
86+
AS $func$
87+
SELECT learn_aqo,use_aqo,auto_tuning,fspace_hash,
88+
to_char(execution_time_without_aqo[n4],'9.99EEEE'),
89+
to_char(cardinality_error_without_aqo[n2],'9.99EEEE'),
90+
executions_without_aqo,
91+
to_char(execution_time_with_aqo[n3],'9.99EEEE'),
92+
to_char(cardinality_error_with_aqo[n1],'9.99EEEE'),
93+
executions_with_aqo
94+
FROM public.aqo_queries aq, public.aqo_query_stat aqs,
95+
(SELECT array_length(n1,1) AS n1, array_length(n2,1) AS n2,
96+
array_length(n3,1) AS n3, array_length(n4,1) AS n4
97+
FROM
98+
(SELECT cardinality_error_with_aqo AS n1,
99+
cardinality_error_without_aqo AS n2,
100+
execution_time_with_aqo AS n3,
101+
execution_time_without_aqo AS n4
102+
FROM public.aqo_query_stat aqs WHERE
103+
aqs.query_hash = $1) AS al) AS q
104+
WHERE (aqs.query_hash = aq.query_hash) AND
105+
aqs.query_hash = $1;
106+
$func$ LANGUAGE SQL"
107+
extension script file "aqo--1.2.sql", near line 55
73108
SET ROLE regress_hacker;
74109
CREATE OR REPLACE FUNCTION aqo_status(hash bigint)
75110
RETURNS TABLE (
@@ -126,6 +161,11 @@ RESET ROLE;
126161
-- Test result (error expected)
127162
CREATE EXTENSION aqo;
128163
ERROR: function "aqo_enable_class" already exists with same argument types
164+
CONTEXT: SQL statement "CREATE FUNCTION aqo_enable_class(queryid bigint)
165+
RETURNS void
166+
AS '$libdir/aqo', 'aqo_enable_query'
167+
LANGUAGE C STRICT VOLATILE"
168+
extension script file "aqo--1.5--1.6.sql", near line 13
129169
SET ROLE regress_hacker;
130170
CREATE OR REPLACE FUNCTION aqo_enable_class(hash bigint)
131171
RETURNS VOID
@@ -172,6 +212,11 @@ RESET ROLE;
172212
-- Test result (error expected)
173213
CREATE EXTENSION aqo;
174214
ERROR: function "aqo_disable_class" already exists with same argument types
215+
CONTEXT: SQL statement "CREATE FUNCTION aqo_disable_class(queryid bigint)
216+
RETURNS void
217+
AS '$libdir/aqo', 'aqo_disable_query'
218+
LANGUAGE C STRICT VOLATILE"
219+
extension script file "aqo--1.5--1.6.sql", near line 18
175220
SET ROLE regress_hacker;
176221
CREATE OR REPLACE FUNCTION aqo_disable_class(hash bigint)
177222
RETURNS VOID
@@ -218,6 +263,12 @@ RESET ROLE;
218263
-- Test result (error expected)
219264
CREATE EXTENSION aqo;
220265
ERROR: function "aqo_clear_hist" already exists with same argument types
266+
CONTEXT: SQL statement "CREATE FUNCTION public.aqo_clear_hist(hash bigint)
267+
RETURNS VOID
268+
AS $func$
269+
DELETE FROM public.aqo_data WHERE fspace_hash=$1;
270+
$func$ LANGUAGE SQL"
271+
extension script file "aqo--1.2.sql", near line 109
221272
SET ROLE regress_hacker;
222273
CREATE OR REPLACE FUNCTION aqo_clear_hist(hash bigint)
223274
RETURNS VOID
@@ -264,6 +315,15 @@ RESET ROLE;
264315
-- Test result (error expected)
265316
CREATE EXTENSION aqo;
266317
ERROR: function "aqo_drop" already exists with same argument types
318+
CONTEXT: SQL statement "CREATE FUNCTION public.aqo_drop(hash bigint)
319+
RETURNS VOID
320+
AS $func$
321+
DELETE FROM public.aqo_queries aq WHERE (aq.query_hash = $1);
322+
DELETE FROM public.aqo_data ad WHERE (ad.fspace_hash = $1);
323+
DELETE FROM public.aqo_query_stat aq WHERE (aq.query_hash = $1);
324+
DELETE FROM public.aqo_query_texts aq WHERE (aq.query_hash = $1);
325+
$func$ LANGUAGE SQL"
326+
extension script file "aqo--1.2.sql", near line 123
267327
SET ROLE regress_hacker;
268328
CREATE OR REPLACE FUNCTION aqo_drop(hash bigint)
269329
RETURNS VOID
@@ -310,6 +370,13 @@ RESET ROLE;
310370
-- Test result (error expected)
311371
CREATE EXTENSION aqo;
312372
ERROR: function "aqo_ne_queries" already exists with same argument types
373+
CONTEXT: SQL statement "CREATE FUNCTION public.aqo_ne_queries()
374+
RETURNS SETOF int
375+
AS $func$
376+
SELECT query_hash FROM public.aqo_query_stat aqs
377+
WHERE -1 = ANY (cardinality_error_with_aqo::double precision[]);
378+
$func$ LANGUAGE SQL"
379+
extension script file "aqo--1.2.sql", near line 116
313380
SET ROLE regress_hacker;
314381
CREATE OR REPLACE FUNCTION aqo_ne_queries()
315382
RETURNS SETOF int

Diff for: expected/aqo_fdw.out

+64-56
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ BEGIN
3636
END;
3737
$$ LANGUAGE PLPGSQL;
3838
-- Trivial foreign scan.
39-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
39+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
4040
SELECT x FROM frgn;
41-
QUERY PLAN
42-
----------------------------------------------
43-
Foreign Scan on frgn (actual rows=1 loops=1)
41+
QUERY PLAN
42+
-------------------------------------------------
43+
Foreign Scan on frgn (actual rows=1.00 loops=1)
4444
AQO not used
4545
Using aqo: true
4646
AQO mode: LEARN
4747
JOINS: 0
4848
(5 rows)
4949

50-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
50+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
5151
SELECT x FROM frgn;
52-
QUERY PLAN
53-
----------------------------------------------
54-
Foreign Scan on frgn (actual rows=1 loops=1)
52+
QUERY PLAN
53+
-------------------------------------------------
54+
Foreign Scan on frgn (actual rows=1.00 loops=1)
5555
AQO: rows=1, error=0%
5656
Using aqo: true
5757
AQO mode: LEARN
@@ -65,7 +65,7 @@ SELECT str FROM expln('
6565
') AS str;
6666
str
6767
-----------------------------------------------------------
68-
Foreign Scan on public.frgn (actual rows=1 loops=1)
68+
Foreign Scan on public.frgn (actual rows=1.00 loops=1)
6969
AQO not used
7070
Output: x
7171
Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
@@ -80,7 +80,7 @@ SELECT str FROM expln('
8080
') AS str;
8181
str
8282
-----------------------------------------------------------
83-
Foreign Scan on public.frgn (actual rows=1 loops=1)
83+
Foreign Scan on public.frgn (actual rows=1.00 loops=1)
8484
AQO: rows=1, error=0%
8585
Output: x
8686
Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
@@ -89,11 +89,11 @@ SELECT str FROM expln('
8989
JOINS: 0
9090
(7 rows)
9191

92-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
92+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
9393
SELECT x FROM frgn WHERE x < -10; -- AQO ignores constants
94-
QUERY PLAN
95-
----------------------------------------------
96-
Foreign Scan on frgn (actual rows=0 loops=1)
94+
QUERY PLAN
95+
-------------------------------------------------
96+
Foreign Scan on frgn (actual rows=0.00 loops=1)
9797
AQO: rows=1, error=100%
9898
Using aqo: true
9999
AQO mode: LEARN
@@ -102,21 +102,21 @@ SELECT x FROM frgn WHERE x < -10; -- AQO ignores constants
102102

103103
-- Trivial JOIN push-down.
104104
SELECT str FROM expln('
105-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
105+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
106106
SELECT * FROM frgn AS a, frgn AS b WHERE a.x=b.x;
107107
') AS str WHERE str NOT LIKE '%Sort Method%';
108-
str
109-
------------------------------------------------------------
110-
Merge Join (actual rows=1 loops=1)
108+
str
109+
---------------------------------------------------------------
110+
Merge Join (actual rows=1.00 loops=1)
111111
AQO not used
112112
Merge Cond: (a.x = b.x)
113-
-> Sort (actual rows=1 loops=1)
113+
-> Sort (actual rows=1.00 loops=1)
114114
Sort Key: a.x
115-
-> Foreign Scan on frgn a (actual rows=1 loops=1)
115+
-> Foreign Scan on frgn a (actual rows=1.00 loops=1)
116116
AQO not used
117-
-> Sort (actual rows=1 loops=1)
117+
-> Sort (actual rows=1.00 loops=1)
118118
Sort Key: b.x
119-
-> Foreign Scan on frgn b (actual rows=1 loops=1)
119+
-> Foreign Scan on frgn b (actual rows=1.00 loops=1)
120120
AQO not used
121121
Using aqo: true
122122
AQO mode: LEARN
@@ -125,12 +125,12 @@ SELECT str FROM expln('
125125

126126
-- Should learn on postgres_fdw nodes
127127
SELECT str FROM expln('
128-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
128+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE, BUFFERS OFF)
129129
SELECT * FROM frgn AS a, frgn AS b WHERE a.x=b.x;
130130
') AS str;
131131
str
132132
--------------------------------------------------------------------------------------------------------
133-
Foreign Scan (actual rows=1 loops=1)
133+
Foreign Scan (actual rows=1.00 loops=1)
134134
AQO: rows=1, error=0%
135135
Output: a.x, b.x
136136
Relations: (public.frgn a) INNER JOIN (public.frgn b)
@@ -147,25 +147,25 @@ INSERT INTO local_b SELECT i, mod((i+random()*10)::numeric, 10) + 1, 'val_' || i
147147
ANALYZE local_a, local_b;
148148
CREATE FOREIGN TABLE frgn_a(aid int, aval text) SERVER loopback OPTIONS (table_name 'local_a');
149149
CREATE FOREIGN TABLE frgn_b(bid int, aid int, bval text) SERVER loopback OPTIONS (table_name 'local_b');
150-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
150+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
151151
SELECT * from frgn_a AS a, frgn_b AS b
152152
WHERE a.aid = b.aid AND b.bval like 'val%';
153153
QUERY PLAN
154154
-----------------------------------------------
155-
Foreign Scan (actual rows=1000 loops=1)
155+
Foreign Scan (actual rows=1000.00 loops=1)
156156
AQO not used
157157
Relations: (frgn_a a) INNER JOIN (frgn_b b)
158158
Using aqo: true
159159
AQO mode: LEARN
160160
JOINS: 0
161161
(6 rows)
162162

163-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
163+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
164164
SELECT * from frgn_a AS a, frgn_b AS b
165165
WHERE a.aid = b.aid AND b.bval like 'val%';
166166
QUERY PLAN
167167
-----------------------------------------------
168-
Foreign Scan (actual rows=1000 loops=1)
168+
Foreign Scan (actual rows=1000.00 loops=1)
169169
AQO: rows=1000, error=0%
170170
Relations: (frgn_a a) INNER JOIN (frgn_b b)
171171
Using aqo: true
@@ -198,28 +198,28 @@ ANALYZE local_main_p0, local_main_p1, main_p2;
198198
ANALYZE local_ref_p0, local_ref_p1, ref_p2;
199199
SELECT str AS result
200200
FROM expln('
201-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
201+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
202202
SELECT * from main AS a, ref AS b
203203
WHERE a.aid = b.aid AND b.bval like ''val%''') AS str
204204
WHERE str NOT LIKE '%Memory%';
205-
result
206-
--------------------------------------------------------------------
207-
Append (actual rows=1000 loops=1)
205+
result
206+
-----------------------------------------------------------------------
207+
Append (actual rows=1000.00 loops=1)
208208
AQO not used
209-
-> Foreign Scan (actual rows=400 loops=1)
209+
-> Foreign Scan (actual rows=400.00 loops=1)
210210
AQO not used
211211
Relations: (main_p0 a_1) INNER JOIN (ref_p0 b_1)
212-
-> Foreign Scan (actual rows=300 loops=1)
212+
-> Foreign Scan (actual rows=300.00 loops=1)
213213
AQO not used
214214
Relations: (main_p1 a_2) INNER JOIN (ref_p1 b_2)
215-
-> Hash Join (actual rows=300 loops=1)
215+
-> Hash Join (actual rows=300.00 loops=1)
216216
AQO not used
217217
Hash Cond: (b_3.aid = a_3.aid)
218-
-> Seq Scan on ref_p2 b_3 (actual rows=300 loops=1)
218+
-> Seq Scan on ref_p2 b_3 (actual rows=300.00 loops=1)
219219
AQO not used
220220
Filter: (bval ~~ 'val%'::text)
221-
-> Hash (actual rows=38 loops=1)
222-
-> Seq Scan on main_p2 a_3 (actual rows=38 loops=1)
221+
-> Hash (actual rows=38.00 loops=1)
222+
-> Seq Scan on main_p2 a_3 (actual rows=38.00 loops=1)
223223
AQO not used
224224
Using aqo: true
225225
AQO mode: LEARN
@@ -228,28 +228,28 @@ WHERE str NOT LIKE '%Memory%';
228228

229229
SELECT str AS result
230230
FROM expln('
231-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
231+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
232232
SELECT * from main AS a, ref AS b
233233
WHERE a.aid = b.aid AND b.bval like ''val%''') AS str
234234
WHERE str NOT LIKE '%Memory%';
235-
result
236-
--------------------------------------------------------------------
237-
Append (actual rows=1000 loops=1)
235+
result
236+
-----------------------------------------------------------------------
237+
Append (actual rows=1000.00 loops=1)
238238
AQO not used
239-
-> Foreign Scan (actual rows=400 loops=1)
239+
-> Foreign Scan (actual rows=400.00 loops=1)
240240
AQO: rows=400, error=0%
241241
Relations: (main_p0 a_1) INNER JOIN (ref_p0 b_1)
242-
-> Foreign Scan (actual rows=300 loops=1)
242+
-> Foreign Scan (actual rows=300.00 loops=1)
243243
AQO: rows=300, error=0%
244244
Relations: (main_p1 a_2) INNER JOIN (ref_p1 b_2)
245-
-> Hash Join (actual rows=300 loops=1)
245+
-> Hash Join (actual rows=300.00 loops=1)
246246
AQO: rows=300, error=0%
247247
Hash Cond: (b_3.aid = a_3.aid)
248-
-> Seq Scan on ref_p2 b_3 (actual rows=300 loops=1)
248+
-> Seq Scan on ref_p2 b_3 (actual rows=300.00 loops=1)
249249
AQO: rows=300, error=0%
250250
Filter: (bval ~~ 'val%'::text)
251-
-> Hash (actual rows=38 loops=1)
252-
-> Seq Scan on main_p2 a_3 (actual rows=38 loops=1)
251+
-> Hash (actual rows=38.00 loops=1)
252+
-> Seq Scan on main_p2 a_3 (actual rows=38.00 loops=1)
253253
AQO: rows=38, error=0%
254254
Using aqo: true
255255
AQO mode: LEARN
@@ -261,25 +261,33 @@ DROP TABLE ref, local_ref_p0, local_ref_p1;
261261
ALTER SERVER loopback OPTIONS (DROP fdw_tuple_cost);
262262
reset enable_partitionwise_join;
263263
-- TODO: Non-mergejoinable join condition.
264-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
264+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
265265
SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
266-
QUERY PLAN
267-
-------------------------------------------
268-
Foreign Scan (actual rows=0 loops=1)
266+
QUERY PLAN
267+
---------------------------------------------------------------
268+
Nested Loop (actual rows=0.00 loops=1)
269269
AQO not used
270-
Relations: (frgn a) INNER JOIN (frgn b)
270+
Join Filter: (a.x < b.x)
271+
Rows Removed by Join Filter: 1
272+
-> Foreign Scan on frgn a (actual rows=1.00 loops=1)
273+
AQO not used
274+
-> Materialize (actual rows=1.00 loops=1)
275+
AQO not used
276+
Storage: Memory Maximum Storage: 17kB
277+
-> Foreign Scan on frgn b (actual rows=1.00 loops=1)
278+
AQO not used
271279
Using aqo: true
272280
AQO mode: LEARN
273281
JOINS: 0
274-
(6 rows)
282+
(14 rows)
275283

276284
SELECT str FROM expln('
277-
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
285+
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE, BUFFERS OFF)
278286
SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
279287
') AS str;
280288
str
281289
--------------------------------------------------------------------------------------------------------
282-
Foreign Scan (actual rows=0 loops=1)
290+
Foreign Scan (actual rows=0.00 loops=1)
283291
AQO: rows=1, error=100%
284292
Output: a.x, b.x
285293
Relations: (public.frgn a) INNER JOIN (public.frgn b)

0 commit comments

Comments
 (0)