Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3416ef5

Browse files
danolivoAndrey Lepikhov
authored and
Andrey Lepikhov
committed
Make the explain of AQO more readable.
1 parent da59897 commit 3416ef5

File tree

4 files changed

+73
-60
lines changed

4 files changed

+73
-60
lines changed

‎expected/aqo_fdw.out‎

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ ANALYZE local;
2424
-- Trivial foreign scan.s
2525
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
2626
SELECT x FROM frgn;
27-
QUERY PLAN
28-
-------------------------------------------------------------
29-
Foreign Scan on frgn (actual rows=1 loops=1) (AQO not used)
27+
QUERY PLAN
28+
----------------------------------------------
29+
Foreign Scan on frgn (actual rows=1 loops=1)
30+
AQO not used
3031
Using aqo: true
3132
AQO mode: LEARN
3233
JOINS: 0
33-
(4 rows)
34+
(5 rows)
3435

3536
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
3637
SELECT x FROM frgn;
37-
QUERY PLAN
38-
-----------------------------------------------------------------------------
39-
Foreign Scan on frgn (actual rows=1 loops=1) (AQO: cardinality=1, error=0%)
38+
QUERY PLAN
39+
----------------------------------------------
40+
Foreign Scan on frgn (actual rows=1 loops=1)
41+
AQO: rows=1, error=0%
4042
Using aqo: true
4143
AQO mode: LEARN
4244
JOINS: 0
43-
(4 rows)
45+
(5 rows)
4446

4547
-- Push down base filters. Use verbose mode to see filters.
4648
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE))
@@ -50,83 +52,93 @@ LINE 1: ...LAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE))
5052
^
5153
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
5254
SELECT x FROM frgn WHERE x < 10;
53-
QUERY PLAN
54-
--------------------------------------------------------------------
55-
Foreign Scan on public.frgn (actual rows=1 loops=1) (AQO not used)
55+
QUERY PLAN
56+
-----------------------------------------------------------
57+
Foreign Scan on public.frgn (actual rows=1 loops=1)
58+
AQO not used
5659
Output: x
5760
Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
5861
Using aqo: true
5962
AQO mode: LEARN
6063
JOINS: 0
61-
(6 rows)
64+
(7 rows)
6265

6366
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
6467
SELECT x FROM frgn WHERE x < -10; -- AQO ignores constants
65-
QUERY PLAN
66-
-------------------------------------------------------------------------------
67-
Foreign Scan on frgn (actual rows=0 loops=1) (AQO: cardinality=1, error=100%)
68+
QUERY PLAN
69+
----------------------------------------------
70+
Foreign Scan on frgn (actual rows=0 loops=1)
71+
AQO: rows=1, error=100%
6872
Using aqo: true
6973
AQO mode: LEARN
7074
JOINS: 0
71-
(4 rows)
75+
(5 rows)
7276

7377
-- Trivial JOIN push-down.
7478
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
7579
SELECT * FROM frgn AS a, frgn AS b WHERE a.x=b.x;
76-
QUERY PLAN
77-
---------------------------------------------------------------------------
78-
Merge Join (actual rows=1 loops=1) (AQO not used)
80+
QUERY PLAN
81+
------------------------------------------------------------
82+
Merge Join (actual rows=1 loops=1)
83+
AQO not used
7984
Merge Cond: (a.x = b.x)
80-
-> Sort (actual rows=1 loops=1) (AQO not used)
85+
-> Sort (actual rows=1 loops=1)
86+
AQO not used
8187
Sort Key: a.x
8288
Sort Method: quicksort Memory: 25kB
83-
-> Foreign Scan on frgn a (actual rows=1 loops=1) (AQO not used)
84-
-> Sort (actual rows=1 loops=1) (AQO not used)
89+
-> Foreign Scan on frgn a (actual rows=1 loops=1)
90+
AQO not used
91+
-> Sort (actual rows=1 loops=1)
92+
AQO not used
8593
Sort Key: b.x
8694
Sort Method: quicksort Memory: 25kB
87-
-> Foreign Scan on frgn b (actual rows=1 loops=1) (AQO not used)
95+
-> Foreign Scan on frgn b (actual rows=1 loops=1)
96+
AQO not used
8897
Using aqo: true
8998
AQO mode: LEARN
9099
JOINS: 0
91-
(13 rows)
100+
(18 rows)
92101

93102
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
94103
SELECT * FROM frgn AS a, frgn AS b WHERE a.x=b.x;
95104
QUERY PLAN
96105
--------------------------------------------------------------------------------------------------------
97-
Foreign Scan (actual rows=1 loops=1) (AQO: cardinality=1, error=0%)
106+
Foreign Scan (actual rows=1 loops=1)
107+
AQO: rows=1, error=0%
98108
Output: a.x, b.x
99109
Relations: (public.frgn a) INNER JOIN (public.frgn b)
100110
Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x = r2.x))))
101111
Using aqo: true
102112
AQO mode: LEARN
103113
JOINS: 0
104-
(7 rows)
114+
(8 rows)
105115

106116
-- TODO: Non-mergejoinable join condition.
107117
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
108118
SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
109-
QUERY PLAN
110-
-----------------------------------------------------
111-
Foreign Scan (actual rows=0 loops=1) (AQO not used)
119+
QUERY PLAN
120+
-------------------------------------------
121+
Foreign Scan (actual rows=0 loops=1)
122+
AQO not used
112123
Relations: (frgn a) INNER JOIN (frgn b)
113124
Using aqo: true
114125
AQO mode: LEARN
115126
JOINS: 0
116-
(5 rows)
127+
(6 rows)
117128

118129
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
119130
SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
120131
QUERY PLAN
121132
--------------------------------------------------------------------------------------------------------
122-
Foreign Scan (actual rows=0 loops=1) (AQO not used)
133+
Foreign Scan (actual rows=0 loops=1)
134+
AQO not used
123135
Output: a.x, b.x
124136
Relations: (public.frgn a) INNER JOIN (public.frgn b)
125137
Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x < r2.x))))
126138
Using aqo: true
127139
AQO mode: LEARN
128140
JOINS: 0
129-
(7 rows)
141+
(8 rows)
130142

131143
DROP EXTENSION aqo CASCADE;
132144
DROP EXTENSION postgres_fdw CASCADE;

‎expected/gucs.out‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,33 @@ INSERT INTO t (x) (SELECT * FROM generate_series(1, 100) AS gs);
66
ANALYZE t;
77
EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF)
88
SELECT x FROM t;
9-
QUERY PLAN
10-
---------------------------------------------------------------
11-
Seq Scan on public.t (actual rows=100 loops=1) (AQO not used)
9+
QUERY PLAN
10+
------------------------------------------------
11+
Seq Scan on public.t (actual rows=100 loops=1)
12+
AQO not used
1213
Output: x
1314
Using aqo: true
1415
AQO mode: LEARN
1516
JOINS: 0
16-
(5 rows)
17+
(6 rows)
1718

1819
EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF)
1920
SELECT x FROM t;
20-
QUERY PLAN
21-
---------------------------------------------------------------------------------
22-
Seq Scan on public.t (actual rows=100 loops=1) (AQO: cardinality=100, error=0%)
21+
QUERY PLAN
22+
------------------------------------------------
23+
Seq Scan on public.t (actual rows=100 loops=1)
24+
AQO: rows=100, error=0%
2325
Output: x
2426
Using aqo: true
2527
AQO mode: LEARN
2628
JOINS: 0
27-
(5 rows)
29+
(6 rows)
2830

2931
DROP EXTENSION aqo;
3032
SET aqo.log_ignorance = 'on';
3133
SET aqo.log_ignorance = 'off';
3234
SET aqo.log_ignorance = 'off';
3335
SET aqo.log_ignorance = 'on';
34-
\d
35-
List of relations
36-
Schema | Name | Type | Owner
37-
--------+------+-------+--------
38-
public | t | table | andrey
39-
(1 row)
40-
4136
CREATE EXTENSION aqo;
4237
SET aqo.log_ignorance = 'off';
4338
SET aqo.log_ignorance = 'on';
@@ -56,13 +51,14 @@ Indexes:
5651

5752
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF)
5853
SELECT * FROM t;
59-
QUERY PLAN
60-
--------------------------------------------------------
61-
Seq Scan on t (actual rows=100 loops=1) (AQO not used)
54+
QUERY PLAN
55+
-----------------------------------------
56+
Seq Scan on t (actual rows=100 loops=1)
57+
AQO not used
6258
Using aqo: true
6359
AQO mode: LEARN
6460
JOINS: 0
65-
(4 rows)
61+
(5 rows)
6662

6763
SELECT node_type FROM aqo_ignorance; -- SeqScan on t must be existed in ignorance table
6864
node_type
@@ -71,13 +67,14 @@ SELECT node_type FROM aqo_ignorance; -- SeqScan on t must be existed in ignoranc
7167
(1 row)
7268

7369
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT * FROM t;
74-
QUERY PLAN
75-
--------------------------------------------------------------------------
76-
Seq Scan on t (actual rows=100 loops=1) (AQO: cardinality=100, error=0%)
70+
QUERY PLAN
71+
-----------------------------------------
72+
Seq Scan on t (actual rows=100 loops=1)
73+
AQO: rows=100, error=0%
7774
Using aqo: true
7875
AQO mode: LEARN
7976
JOINS: 0
80-
(4 rows)
77+
(5 rows)
8178

8279
SELECT node_type FROM aqo_ignorance; -- SeqScan on t must be excluded from ignorance table
8380
node_type

‎postprocessing.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,20 +794,24 @@ print_node_explain(ExplainState *es, PlanState *ps, Plan *plan, double rows)
794794
}
795795
}
796796

797+
appendStringInfoChar(es->str, '\n');
798+
Assert(es->format == EXPLAIN_FORMAT_TEXT);
799+
if (es->str->len == 0 || es->str->data[es->str->len - 1] == '\n')
800+
appendStringInfoSpaces(es->str, es->indent * 2);
801+
797802
if (plan->predicted_cardinality > 0.)
798803
{
799804
error = 100. * (plan->predicted_cardinality - (rows*wrkrs))
800805
/ plan->predicted_cardinality;
801806
appendStringInfo(es->str,
802-
" (AQO: cardinality=%.0lf, error=%.0lf%%",
807+
"AQO: rows=%.0lf, error=%.0lf%%",
803808
plan->predicted_cardinality, error);
804809
}
805810
else
806-
appendStringInfo(es->str, " (AQO not used");
811+
appendStringInfo(es->str, "AQO not used");
807812

808813
if (aqo_show_hash)
809-
appendStringInfo(es->str, ", fss hash = %d", plan->fss_hash);
810-
appendStringInfoChar(es->str, ')');
814+
appendStringInfo(es->str, ", fss=%d", plan->fss_hash);
811815

812816
if (prev_ExplainOneNode_hook)
813817
prev_ExplainOneNode_hook(es, ps, plan, rows);

‎sql/gucs.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SET aqo.log_ignorance = 'on';
1717
SET aqo.log_ignorance = 'off';
1818
SET aqo.log_ignorance = 'off';
1919
SET aqo.log_ignorance = 'on';
20-
\d
20+
2121
CREATE EXTENSION aqo;
2222
SET aqo.log_ignorance = 'off';
2323
SET aqo.log_ignorance = 'on';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /