Skip to content

Commit 89c834d

Browse files
a.pervushinadanolivo
authored andcommitted
[PGPRO-6755] Refactor machine dependent tests
Tags: aqo
1 parent 6411fee commit 89c834d

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

expected/forced_stat_collection.out

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@ SELECT * FROM aqo_data;
4040
-------------+--------------+-----------+----------+---------+------
4141
(0 rows)
4242

43-
SELECT learn_aqo,use_aqo,auto_tuning,cardinality_error_without_aqo ce,executions_without_aqo nex
43+
CREATE OR REPLACE FUNCTION round_array (double precision[])
44+
RETURNS double precision[]
45+
LANGUAGE SQL
46+
AS $$
47+
SELECT array_agg(round(elem::numeric, 3))
48+
FROM unnest($1) as arr(elem);
49+
$$;
50+
SELECT learn_aqo,use_aqo,auto_tuning,round_array(cardinality_error_without_aqo) ce,executions_without_aqo nex
4451
FROM aqo_queries JOIN aqo_query_stat USING (query_hash);
45-
learn_aqo | use_aqo | auto_tuning | ce | nex
46-
-----------+---------+-------------+----------------------+-----
47-
f | f | f | {0.8637762840285226} | 1
48-
f | f | f | {2.9634630129852053} | 1
52+
learn_aqo | use_aqo | auto_tuning | ce | nex
53+
-----------+---------+-------------+---------+-----
54+
f | f | f | {0.864} | 1
55+
f | f | f | {2.963} | 1
4956
(2 rows)
5057

5158
SELECT query_text FROM aqo_query_texts ORDER BY (md5(query_text));
@@ -54,6 +61,10 @@ SELECT query_text FROM aqo_query_texts ORDER BY (md5(query_text));
5461
SELECT count(*) FROM person WHERE age<18;
5562
COMMON feature space (do not delete!)
5663
SELECT count(*) FROM person WHERE age<18 AND passport IS NOT NULL;
57-
(3 rows)
64+
+
65+
SELECT array_agg(round(elem::numeric, 3)) +
66+
FROM unnest($1) as arr(elem); +
67+
68+
(4 rows)
5869

5970
DROP EXTENSION aqo;

expected/unsupported.out

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,17 @@ SELECT * FROM
470470
-- any prediction on number of fetched tuples.
471471
-- So, if selectivity was wrong we could make bad choice of Scan operation.
472472
-- For example, we could choose suboptimal index.
473+
--
474+
-- Returns string-by-string explain of a query. Made for removing some strings
475+
-- from the explain output.
476+
--
477+
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
478+
BEGIN
479+
RETURN QUERY
480+
EXECUTE format('EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF) %s', query_string);
481+
RETURN;
482+
END;
483+
$$ LANGUAGE PLPGSQL;
473484
-- Turn off statistics gathering for simple demonstration of filtering problem.
474485
ALTER TABLE t SET (autovacuum_enabled = 'false');
475486
CREATE INDEX ind1 ON t(x);
@@ -505,21 +516,22 @@ SELECT count(*) FROM t WHERE x < 3 AND mod(x,3) = 1;
505516
50
506517
(1 row)
507518

508-
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF)
509-
SELECT count(*) FROM t WHERE x < 3 AND mod(x,3) = 1;
510-
QUERY PLAN
519+
SELECT str AS result
520+
FROM expln('SELECT count(*) FROM t WHERE x < 3 AND mod(x,3) = 1') AS str
521+
WHERE str NOT LIKE '%Heap Blocks%';
522+
result
511523
-----------------------------------------------------------------
512524
Aggregate (actual rows=1 loops=1)
513525
AQO not used
514-
-> Bitmap Heap Scan on t (actual rows=50 loops=1)
526+
Output: count(*)
527+
-> Bitmap Heap Scan on public.t (actual rows=50 loops=1)
515528
AQO: rows=50, error=0%
516-
Recheck Cond: (mod(x, 3) = 1)
517-
Filter: (x < 3)
529+
Recheck Cond: (mod(t.x, 3) = 1)
530+
Filter: (t.x < 3)
518531
Rows Removed by Filter: 300
519-
Heap Blocks: exact=5
520532
-> Bitmap Index Scan on ind2 (actual rows=350 loops=1)
521533
AQO not used
522-
Index Cond: (mod(x, 3) = 1)
534+
Index Cond: (mod(t.x, 3) = 1)
523535
Using aqo: true
524536
AQO mode: LEARN
525537
JOINS: 0

sql/forced_stat_collection.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ SELECT count(*) FROM person WHERE age<18;
3333
SELECT count(*) FROM person WHERE age<18 AND passport IS NOT NULL;
3434
SELECT * FROM aqo_data;
3535

36-
SELECT learn_aqo,use_aqo,auto_tuning,cardinality_error_without_aqo ce,executions_without_aqo nex
36+
CREATE OR REPLACE FUNCTION round_array (double precision[])
37+
RETURNS double precision[]
38+
LANGUAGE SQL
39+
AS $$
40+
SELECT array_agg(round(elem::numeric, 3))
41+
FROM unnest($1) as arr(elem);
42+
$$;
43+
44+
SELECT learn_aqo,use_aqo,auto_tuning,round_array(cardinality_error_without_aqo) ce,executions_without_aqo nex
3745
FROM aqo_queries JOIN aqo_query_stat USING (query_hash);
3846

3947
SELECT query_text FROM aqo_query_texts ORDER BY (md5(query_text));

sql/unsupported.sql

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ SELECT * FROM
139139
-- So, if selectivity was wrong we could make bad choice of Scan operation.
140140
-- For example, we could choose suboptimal index.
141141

142+
--
143+
-- Returns string-by-string explain of a query. Made for removing some strings
144+
-- from the explain output.
145+
--
146+
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
147+
BEGIN
148+
RETURN QUERY
149+
EXECUTE format('EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF) %s', query_string);
150+
RETURN;
151+
END;
152+
$$ LANGUAGE PLPGSQL;
153+
142154
-- Turn off statistics gathering for simple demonstration of filtering problem.
143155
ALTER TABLE t SET (autovacuum_enabled = 'false');
144156
CREATE INDEX ind1 ON t(x);
@@ -151,8 +163,9 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF)
151163
-- Here we filter more tuples than with the ind1 index.
152164
CREATE INDEX ind2 ON t(mod(x,3));
153165
SELECT count(*) FROM t WHERE x < 3 AND mod(x,3) = 1;
154-
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF)
155-
SELECT count(*) FROM t WHERE x < 3 AND mod(x,3) = 1;
166+
SELECT str AS result
167+
FROM expln('SELECT count(*) FROM t WHERE x < 3 AND mod(x,3) = 1') AS str
168+
WHERE str NOT LIKE '%Heap Blocks%';
156169

157170
-- Best choice is ...
158171
ANALYZE t;

0 commit comments

Comments
 (0)