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

Commit aae577b

Browse files
author
Alexandra Pervushina
committed
Fix tests; fix bugs in storage.c
1 parent 69ead79 commit aae577b

7 files changed

+227
-39
lines changed

expected/aqo_learn.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ SELECT true AS success FROM aqo_cleanup();
251251
-- Result of the query below should be empty
252252
SELECT * FROM aqo_query_texts aqt1, aqo_query_texts aqt2
253253
WHERE aqt1.query_text = aqt2.query_text AND aqt1.queryid <> aqt2.queryid;
254-
queryid | query_text | queryid | query_text
255-
---------+------------+---------+------------
254+
queryid | query_text | dbid | queryid | query_text | dbid
255+
---------+------------+------+---------+------------+------
256256
(0 rows)
257257

258258
-- Fix the state of the AQO data

expected/forced_stat_collection.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ SELECT count(*) FROM person WHERE age<18 AND passport IS NOT NULL;
3939
(1 row)
4040

4141
SELECT * FROM aqo_data;
42-
fs | fss | nfeatures | features | targets | reliability | oids
43-
----+-----+-----------+----------+---------+-------------+------
42+
fs | fss | nfeatures | features | targets | reliability | oids | dbid
43+
----+-----+-----------+----------+---------+-------------+------+------
4444
(0 rows)
4545

4646
CREATE OR REPLACE FUNCTION round_array (double precision[])

expected/gucs.out

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,16 @@ SELECT obj_description('aqo_cleanup'::regproc::oid);
8888
Remove unneeded rows from the AQO ML storage
8989
(1 row)
9090

91-
SELECT obj_description('aqo_reset'::regproc::oid);
92-
obj_description
93-
--------------------------------
94-
Reset all data gathered by AQO
91+
SELECT obj_description('aqo_reset()'::regprocedure::oid);
92+
obj_description
93+
---------------------------------------------------------
94+
Reset all data gathered by AQO for the current database
95+
(1 row)
96+
97+
SELECT obj_description('aqo_reset(oid)'::regprocedure::oid);
98+
obj_description
99+
-----------------------------------------------------------
100+
Reset all data gathered by AQO for the specified database
95101
(1 row)
96102

97103
\df aqo_cardinality_error
@@ -127,7 +133,8 @@ SELECT obj_description('aqo_reset'::regproc::oid);
127133
Schema | Name | Result data type | Argument data types | Type
128134
--------+-----------+------------------+---------------------+------
129135
public | aqo_reset | bigint | | func
130-
(1 row)
136+
public | aqo_reset | bigint | dbid oid | func
137+
(2 rows)
131138

132139
-- Check stat reset
133140
SELECT count(*) FROM aqo_query_stat;

expected/multiple_databases.out

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,180 @@
1+
-- Tests on cross-databases interference.
2+
create extension aqo;
3+
set aqo.join_threshold = 0;
4+
set aqo.show_details = on;
5+
set aqo.mode = learn;
6+
set aqo.use = on;
7+
select * from aqo_reset(NULL);
8+
aqo_reset
9+
-----------
10+
12
11+
(1 row)
112

13+
CREATE DATABASE aqo_crossdb_test;
14+
-- Save current database and port.
15+
SELECT current_database() AS old_db \gset
16+
SELECT oid AS old_dbid FROM pg_database WHERE datname = current_database() \gset
17+
SELECT setting AS old_port FROM pg_settings WHERE name = 'port' \gset
18+
CREATE TABLE a (x1 int, x2 int, x3 int);
19+
INSERT INTO a (x1, x2, x3) SELECT mod(ival,10), mod(ival,10), mod(ival,10) FROM generate_series(1,100) As ival;
20+
CREATE TABLE b (y1 int, y2 int, y3 int);
21+
INSERT INTO b (y1, y2, y3) SELECT mod(ival + 1,10), mod(ival + 1,10), mod(ival + 1,10) FROM generate_series(1,1000) As ival;
22+
--
23+
-- Returns string-by-string explain of a query. Made for removing some strings
24+
-- from the explain output.
25+
--
26+
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
27+
BEGIN
28+
RETURN QUERY
29+
EXECUTE format('EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF) %s', query_string);
30+
RETURN;
31+
END;
32+
$$ LANGUAGE PLPGSQL;
33+
SELECT str AS result
34+
FROM expln('
35+
SELECT x1,y1 FROM A LEFT JOIN b ON A.x1 = B.y1 WHERE x1 = 5 AND x2 = 5;') AS str
36+
WHERE str NOT LIKE 'Query Identifier%' and str NOT LIKE '%Memory%' and str NOT LIKE '%Sort Method%';
37+
result
38+
-------------------------------------------------------
39+
Nested Loop Left Join (actual rows=1000 loops=1)
40+
AQO not used
41+
Output: a.x1, b.y1
42+
Join Filter: (a.x1 = b.y1)
43+
-> Seq Scan on public.a (actual rows=10 loops=1)
44+
AQO not used
45+
Output: a.x1, a.x2, a.x3
46+
Filter: ((a.x1 = 5) AND (a.x2 = 5))
47+
Rows Removed by Filter: 90
48+
-> Seq Scan on public.b (actual rows=100 loops=10)
49+
AQO not used
50+
Output: b.y1, b.y2, b.y3
51+
Filter: (b.y1 = 5)
52+
Rows Removed by Filter: 900
53+
Using aqo: true
54+
AQO use: ON
55+
AQO mode: LEARN
56+
JOINS: 1
57+
(18 rows)
58+
59+
SELECT count(*) FROM aqo_data();
60+
count
61+
-------
62+
3
63+
(1 row)
64+
65+
SELECT count(*) FROM aqo_queries();
66+
count
67+
-------
68+
1
69+
(1 row)
70+
71+
SELECT count(*) FROM aqo_query_texts();
72+
count
73+
-------
74+
1
75+
(1 row)
76+
77+
SELECT count(*) FROM aqo_query_stat();
78+
count
79+
-------
80+
4
81+
(1 row)
82+
83+
-- Connect to other DB
84+
\c aqo_crossdb_test - - :old_port
85+
create extension aqo;
86+
set aqo.join_threshold = 0;
87+
set aqo.show_details = on;
88+
set aqo.mode = learn;
89+
set aqo.use = on;
90+
CREATE TABLE a (x1 int, x2 int, x3 int);
91+
INSERT INTO a (x1, x2, x3) SELECT mod(ival,10), mod(ival,10), mod(ival,10) FROM generate_series(1,100) As ival;
92+
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
93+
BEGIN
94+
RETURN QUERY
95+
EXECUTE format('EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF) %s', query_string);
96+
RETURN;
97+
END;
98+
$$ LANGUAGE PLPGSQL;
99+
SELECT str AS result
100+
FROM expln('
101+
SELECT * FROM a WHERE x1 > 1;') AS str
102+
WHERE str NOT LIKE 'Query Identifier%' and str NOT LIKE '%Memory%' and str NOT LIKE '%Sort Method%';
103+
result
104+
-----------------------------------------------
105+
Seq Scan on public.a (actual rows=80 loops=1)
106+
AQO not used
107+
Output: x1, x2, x3
108+
Filter: (a.x1 > 1)
109+
Rows Removed by Filter: 20
110+
Using aqo: true
111+
AQO use: ON
112+
AQO mode: LEARN
113+
JOINS: 0
114+
(9 rows)
115+
116+
SELECT count(*) FROM aqo_data();
117+
count
118+
-------
119+
4
120+
(1 row)
121+
122+
SELECT count(*) FROM aqo_queries();
123+
count
124+
-------
125+
1
126+
(1 row)
127+
128+
SELECT count(*) FROM aqo_query_texts();
129+
count
130+
-------
131+
1
132+
(1 row)
133+
134+
SELECT count(*) FROM aqo_query_stat();
135+
count
136+
-------
137+
6
138+
(1 row)
139+
140+
-- Remove aqo info from other DB.
141+
SELECT aqo_reset(:old_dbid);
142+
aqo_reset
143+
-----------
144+
7
145+
(1 row)
146+
147+
-- Reconnect to old DB.
148+
\c :old_db - - :old_port
149+
SELECT count(*) FROM aqo_data();
150+
count
151+
-------
152+
1
153+
(1 row)
154+
155+
SELECT count(*) FROM aqo_queries();
156+
count
157+
-------
158+
1
159+
(1 row)
160+
161+
SELECT count(*) FROM aqo_query_texts();
162+
count
163+
-------
164+
1
165+
(1 row)
166+
167+
SELECT count(*) FROM aqo_query_stat();
168+
count
169+
-------
170+
2
171+
(1 row)
172+
173+
SELECT aqo_reset(NULL);
174+
aqo_reset
175+
-----------
176+
3
177+
(1 row)
178+
179+
DROP DATABASE aqo_crossdb_test;
180+
DROP EXTENSION aqo;

expected/update_functions.out

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ ORDER BY res;
169169
(TABLE aqo_query_texts EXCEPT TABLE aqo_query_texts_dump)
170170
UNION ALL
171171
(TABLE aqo_query_texts_dump EXCEPT TABLE aqo_query_texts);
172-
queryid | query_text
173-
---------+------------
172+
queryid | query_text | dbid
173+
---------+------------+------
174174
(0 rows)
175175

176176
-- Update aqo_query_texts with dump data.
@@ -192,8 +192,8 @@ ORDER BY res;
192192
(TABLE aqo_query_texts EXCEPT TABLE aqo_query_texts_dump)
193193
UNION ALL
194194
(TABLE aqo_query_texts_dump EXCEPT TABLE aqo_query_texts);
195-
queryid | query_text
196-
---------+------------
195+
queryid | query_text | dbid
196+
---------+------------+------
197197
(0 rows)
198198

199199
--
@@ -218,8 +218,8 @@ ORDER BY res;
218218
(TABLE aqo_queries_dump EXCEPT TABLE aqo_queries)
219219
UNION ALL
220220
(TABLE aqo_queries EXCEPT TABLE aqo_queries_dump);
221-
queryid | fs | learn_aqo | use_aqo | auto_tuning | smart_timeout | count_increase_timeout
222-
---------+----+-----------+---------+-------------+---------------+------------------------
221+
queryid | fs | learn_aqo | use_aqo | auto_tuning | smart_timeout | count_increase_timeout | dbid
222+
---------+----+-----------+---------+-------------+---------------+------------------------+------
223223
(0 rows)
224224

225225
-- Update aqo_queries with dump data.
@@ -241,8 +241,8 @@ ORDER BY res;
241241
(TABLE aqo_queries_dump EXCEPT TABLE aqo_queries)
242242
UNION ALL
243243
(TABLE aqo_queries EXCEPT TABLE aqo_queries_dump);
244-
queryid | fs | learn_aqo | use_aqo | auto_tuning | smart_timeout | count_increase_timeout
245-
---------+----+-----------+---------+-------------+---------------+------------------------
244+
queryid | fs | learn_aqo | use_aqo | auto_tuning | smart_timeout | count_increase_timeout | dbid
245+
---------+----+-----------+---------+-------------+---------------+------------------------+------
246246
(0 rows)
247247

248248
--
@@ -269,8 +269,8 @@ ORDER BY res;
269269
(TABLE aqo_query_stat_dump EXCEPT TABLE aqo_query_stat)
270270
UNION ALL
271271
(TABLE aqo_query_stat EXCEPT TABLE aqo_query_stat_dump);
272-
queryid | execution_time_with_aqo | execution_time_without_aqo | planning_time_with_aqo | planning_time_without_aqo | cardinality_error_with_aqo | cardinality_error_without_aqo | executions_with_aqo | executions_without_aqo
273-
---------+-------------------------+----------------------------+------------------------+---------------------------+----------------------------+-------------------------------+---------------------+------------------------
272+
queryid | execution_time_with_aqo | execution_time_without_aqo | planning_time_with_aqo | planning_time_without_aqo | cardinality_error_with_aqo | cardinality_error_without_aqo | executions_with_aqo | executions_without_aqo | dbid
273+
---------+-------------------------+----------------------------+------------------------+---------------------------+----------------------------+-------------------------------+---------------------+------------------------+------
274274
(0 rows)
275275

276276
-- Update aqo_query_stat with dump data.
@@ -294,8 +294,8 @@ ORDER BY res;
294294
(TABLE aqo_query_stat_dump EXCEPT TABLE aqo_query_stat)
295295
UNION ALL
296296
(TABLE aqo_query_stat EXCEPT TABLE aqo_query_stat_dump);
297-
queryid | execution_time_with_aqo | execution_time_without_aqo | planning_time_with_aqo | planning_time_without_aqo | cardinality_error_with_aqo | cardinality_error_without_aqo | executions_with_aqo | executions_without_aqo
298-
---------+-------------------------+----------------------------+------------------------+---------------------------+----------------------------+-------------------------------+---------------------+------------------------
297+
queryid | execution_time_with_aqo | execution_time_without_aqo | planning_time_with_aqo | planning_time_without_aqo | cardinality_error_with_aqo | cardinality_error_without_aqo | executions_with_aqo | executions_without_aqo | dbid
298+
---------+-------------------------+----------------------------+------------------------+---------------------------+----------------------------+-------------------------------+---------------------+------------------------+------
299299
(0 rows)
300300

301301
--
@@ -310,8 +310,8 @@ WHERE ret \gset
310310
(TABLE aqo_data_dump EXCEPT TABLE aqo_data)
311311
UNION ALL
312312
(TABLE aqo_data EXCEPT TABLE aqo_data_dump);
313-
fs | fss | nfeatures | features | targets | reliability | oids
314-
----+-----+-----------+----------+---------+-------------+------
313+
fs | fss | nfeatures | features | targets | reliability | oids | dbid
314+
----+-----+-----------+----------+---------+-------------+------+------
315315
(0 rows)
316316

317317
-- Update aqo_data with dump data.
@@ -329,8 +329,8 @@ SELECT :res1 = :res2 AS ml_sizes_are_equal;
329329
(TABLE aqo_data_dump EXCEPT TABLE aqo_data)
330330
UNION ALL
331331
(TABLE aqo_data EXCEPT TABLE aqo_data_dump);
332-
fs | fss | nfeatures | features | targets | reliability | oids
333-
----+-----+-----------+----------+---------+-------------+------
332+
fs | fss | nfeatures | features | targets | reliability | oids | dbid
333+
----+-----+-----------+----------+---------+-------------+------+------
334334
(0 rows)
335335

336336
-- Reject aqo_query_stat_update if there is NULL elements in array arg.

sql/gucs.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ SELECT obj_description('aqo_cardinality_error'::regproc::oid);
4040
SELECT obj_description('aqo_execution_time'::regproc::oid);
4141
SELECT obj_description('aqo_drop_class'::regproc::oid);
4242
SELECT obj_description('aqo_cleanup'::regproc::oid);
43-
SELECT obj_description('aqo_reset'::regproc::oid);
43+
SELECT obj_description('aqo_reset()'::regprocedure::oid);
44+
SELECT obj_description('aqo_reset(oid)'::regprocedure::oid);
4445

4546
\df aqo_cardinality_error
4647
\df aqo_execution_time

0 commit comments

Comments
 (0)