@@ -6,56 +6,68 @@ SET aqo.show_details = 'on';
66CREATE TABLE a AS (SELECT gs AS x FROM generate_series(1,10) AS gs);
77CREATE TABLE b AS (SELECT gs AS x FROM generate_series(1,100) AS gs);
88--
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+ --
920-- A LEFT JOIN B isn't equal B LEFT JOIN A.
1021--
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
1427-----------------------------------------------------
1528 Merge Left Join (actual rows=10 loops=1)
1629 AQO not used
1730 Merge Cond: (a.x = b.x)
1831 -> Sort (actual rows=10 loops=1)
1932 AQO not used
2033 Sort Key: a.x
21- Sort Method: quicksort Memory: 25kB
2234 -> Seq Scan on a (actual rows=10 loops=1)
2335 AQO not used
2436 -> Sort (actual rows=11 loops=1)
2537 AQO not used
2638 Sort Key: b.x
27- Sort Method: quicksort Memory: 30kB
2839 -> Seq Scan on b (actual rows=100 loops=1)
2940 AQO not used
3041 Using aqo: true
3142 AQO mode: LEARN
3243 JOINS: 0
33- (18 rows)
44+ (16 rows)
3445
3546-- TODO: Using method of other classes neighbours 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+ ----------------------------------------------------
4053 Hash Left Join (actual rows=100 loops=1)
4154 AQO: rows=10, error=-900%
4255 Hash Cond: (b.x = a.x)
4356 -> Seq Scan on b (actual rows=100 loops=1)
4457 AQO: rows=100, error=0%
4558 -> Hash (actual rows=10 loops=1)
4659 AQO not used
47- Buckets: 1024 Batches: 1 Memory Usage: 9kB
4860 -> Seq Scan on a (actual rows=10 loops=1)
4961 AQO: rows=10, error=0%
5062 Using aqo: true
5163 AQO mode: LEARN
5264 JOINS: 0
53- (13 rows)
65+ (12 rows)
5466
5567-- Look into the reason: two JOINs from different classes have the same FSS.
5668SELECT to_char(d1.targets[1], 'FM999.00') AS target FROM aqo_data d1
5769JOIN 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 ;
5971 target
6072--------
6173 2.30