@@ -6,56 +6,68 @@ SET aqo.show_details = 'on';
6
6
CREATE TABLE a AS (SELECT gs AS x FROM generate_series(1,10) AS gs);
7
7
CREATE TABLE b AS (SELECT gs AS x FROM generate_series(1,100) AS gs);
8
8
--
9
+ -- Returns string-by-string explain of a query. Made for removing some strings
10
+ -- from the explain output.
11
+ --
12
+ CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
13
+ BEGIN
14
+ RETURN QUERY
15
+ EXECUTE format('EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) %s', query_string);
16
+ RETURN;
17
+ END;
18
+ $$ LANGUAGE PLPGSQL;
19
+ --
9
20
-- A LEFT JOIN B isn't equal B LEFT JOIN A.
10
21
--
11
- EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF)
12
- SELECT * FROM a LEFT JOIN b USING (x);
13
- QUERY PLAN
22
+ SELECT str AS result
23
+ FROM expln('
24
+ SELECT * FROM a LEFT JOIN b USING (x);') AS str
25
+ WHERE str NOT LIKE '%Memory%';
26
+ result
14
27
-----------------------------------------------------
15
28
Merge Left Join (actual rows=10 loops=1)
16
29
AQO not used
17
30
Merge Cond: (a.x = b.x)
18
31
-> Sort (actual rows=10 loops=1)
19
32
AQO not used
20
33
Sort Key: a.x
21
- Sort Method: quicksort Memory: 25kB
22
34
-> Seq Scan on a (actual rows=10 loops=1)
23
35
AQO not used
24
36
-> Sort (actual rows=11 loops=1)
25
37
AQO not used
26
38
Sort Key: b.x
27
- Sort Method: quicksort Memory: 30kB
28
39
-> Seq Scan on b (actual rows=100 loops=1)
29
40
AQO not used
30
41
Using aqo: true
31
42
AQO mode: LEARN
32
43
JOINS: 0
33
- (18 rows)
44
+ (16 rows)
34
45
35
46
-- TODO: Using method of other classes neigurs we get a bad estimation.
36
- EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF)
37
- SELECT * FROM b LEFT JOIN a USING (x);
38
- QUERY PLAN
39
- ------------------------------------------------------
47
+ SELECT str AS result
48
+ FROM expln('
49
+ SELECT * FROM b LEFT JOIN a USING (x);') AS str
50
+ WHERE str NOT LIKE '%Memory%';
51
+ result
52
+ ----------------------------------------------------
40
53
Hash Left Join (actual rows=100 loops=1)
41
54
AQO: rows=10, error=-900%
42
55
Hash Cond: (b.x = a.x)
43
56
-> Seq Scan on b (actual rows=100 loops=1)
44
57
AQO: rows=100, error=0%
45
58
-> Hash (actual rows=10 loops=1)
46
59
AQO not used
47
- Buckets: 1024 Batches: 1 Memory Usage: 9kB
48
60
-> Seq Scan on a (actual rows=10 loops=1)
49
61
AQO: rows=10, error=0%
50
62
Using aqo: true
51
63
AQO mode: LEARN
52
64
JOINS: 0
53
- (13 rows)
65
+ (12 rows)
54
66
55
67
-- Look into the reason: two JOINs from different classes have the same FSS.
56
68
SELECT to_char(d1.targets[1], 'FM999.00') AS target FROM aqo_data d1
57
69
JOIN aqo_data d2 ON (d1.fs <> d2.fs AND d1.fss = d2.fss)
58
- WHERE 'a'::regclass = ANY (d1.oids) AND 'b'::regclass = ANY (d1.oids);
70
+ WHERE 'a'::regclass = ANY (d1.oids) AND 'b'::regclass = ANY (d1.oids) order by target ;
59
71
target
60
72
--------
61
73
2.30
0 commit comments