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

Commit c01743a

Browse files
committed
Show number of disabled nodes in EXPLAIN ANALYZE output.
Now that disable_cost is not included in the cost estimate, there's no visible sign in EXPLAIN output of which plan nodes are disabled. Fix that by propagating the number of disabled nodes from Path to Plan, and then showing it in the EXPLAIN output. There is some question about whether this is a desirable change. While I personally believe that it is, it seems best to make it a separate commit, in case we decide to back out just this part, or rework it. Reviewed by Andres Freund, Heikki Linnakangas, and David Rowley. Discussion: http://postgr.es/m/CA+TgmoZ_+MS+o6NeGK2xyBv-xM+w1AfFVuHE4f_aq6ekHv7YSQ@mail.gmail.com
1 parent e222534 commit c01743a

File tree

12 files changed

+59
-15
lines changed

12 files changed

+59
-15
lines changed

src/backend/commands/explain.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,10 @@ ExplainNode(PlanState *planstate, List *ancestors,
18941894
if (es->format == EXPLAIN_FORMAT_TEXT)
18951895
appendStringInfoChar(es->str, '\n');
18961896

1897+
if (plan->disabled_nodes != 0)
1898+
ExplainPropertyInteger("Disabled Nodes", NULL, plan->disabled_nodes,
1899+
es);
1900+
18971901
/* prepare per-worker general execution details */
18981902
if (es->workers_state && es->verbose)
18991903
{

src/backend/optimizer/plan/createplan.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,7 @@ create_minmaxagg_plan(PlannerInfo *root, MinMaxAggPath *best_path)
25722572
0, NULL, NULL, NULL);
25732573

25742574
/* Must apply correct cost/width data to Limit node */
2575+
plan->disabled_nodes = mminfo->path->disabled_nodes;
25752576
plan->startup_cost = mminfo->path->startup_cost;
25762577
plan->total_cost = mminfo->pathcost;
25772578
plan->plan_rows = 1;
@@ -5404,6 +5405,7 @@ order_qual_clauses(PlannerInfo *root, List *clauses)
54045405
static void
54055406
copy_generic_path_info(Plan *dest, Path *src)
54065407
{
5408+
dest->disabled_nodes = src->disabled_nodes;
54075409
dest->startup_cost = src->startup_cost;
54085410
dest->total_cost = src->total_cost;
54095411
dest->plan_rows = src->rows;
@@ -5419,6 +5421,7 @@ copy_generic_path_info(Plan *dest, Path *src)
54195421
static void
54205422
copy_plan_costsize(Plan *dest, Plan *src)
54215423
{
5424+
dest->disabled_nodes = src->disabled_nodes;
54225425
dest->startup_cost = src->startup_cost;
54235426
dest->total_cost = src->total_cost;
54245427
dest->plan_rows = src->plan_rows;
@@ -5452,7 +5455,7 @@ label_sort_with_costsize(PlannerInfo *root, Sort *plan, double limit_tuples)
54525455

54535456
cost_sort(&sort_path, root, NIL,
54545457
lefttree->total_cost,
5455-
0, /* a Plan contains no count of disabled nodes */
5458+
plan->plan.disabled_nodes,
54565459
lefttree->plan_rows,
54575460
lefttree->plan_width,
54585461
0.0,
@@ -6547,11 +6550,12 @@ materialize_finished_plan(Plan *subplan)
65476550

65486551
/* Set cost data */
65496552
cost_material(&matpath,
6550-
0, /* a Plan contains no count of disabled nodes */
6553+
subplan->disabled_nodes,
65516554
subplan->startup_cost,
65526555
subplan->total_cost,
65536556
subplan->plan_rows,
65546557
subplan->plan_width);
6558+
matplan->disabled_nodes = subplan->disabled_nodes;
65556559
matplan->startup_cost = matpath.startup_cost + initplan_cost;
65566560
matplan->total_cost = matpath.total_cost + initplan_cost;
65576561
matplan->plan_rows = subplan->plan_rows;

src/include/nodes/plannodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ typedef struct Plan
125125
/*
126126
* estimated execution costs for plan (see costsize.c for more info)
127127
*/
128+
int disabled_nodes; /* count of disabled nodes */
128129
Cost startup_cost; /* cost expended before fetching any tuples */
129130
Cost total_cost; /* total cost (assuming all tuples fetched) */
130131

src/test/regress/expected/aggregates.out

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,18 +2920,23 @@ GROUP BY c1.w, c1.z;
29202920
QUERY PLAN
29212921
-----------------------------------------------------
29222922
GroupAggregate
2923+
Disabled Nodes: 2
29232924
Group Key: c1.w, c1.z
29242925
-> Sort
2926+
Disabled Nodes: 2
29252927
Sort Key: c1.w, c1.z, c1.x, c1.y
29262928
-> Merge Join
2929+
Disabled Nodes: 2
29272930
Merge Cond: (c1.x = c2.x)
29282931
-> Sort
29292932
Sort Key: c1.x
29302933
-> Seq Scan on group_agg_pk c1
2934+
Disabled Nodes: 1
29312935
-> Sort
29322936
Sort Key: c2.x
29332937
-> Seq Scan on group_agg_pk c2
2934-
(12 rows)
2938+
Disabled Nodes: 1
2939+
(17 rows)
29352940

29362941
SELECT avg(c1.f ORDER BY c1.x, c1.y)
29372942
FROM group_agg_pk c1 JOIN group_agg_pk c2 ON c1.x = c2.x
@@ -2953,19 +2958,24 @@ GROUP BY c1.y,c1.x,c2.x;
29532958
QUERY PLAN
29542959
-----------------------------------------------------
29552960
Group
2961+
Disabled Nodes: 2
29562962
Group Key: c1.x, c1.y
29572963
-> Incremental Sort
2964+
Disabled Nodes: 2
29582965
Sort Key: c1.x, c1.y
29592966
Presorted Key: c1.x
29602967
-> Merge Join
2968+
Disabled Nodes: 2
29612969
Merge Cond: (c1.x = c2.x)
29622970
-> Sort
29632971
Sort Key: c1.x
29642972
-> Seq Scan on group_agg_pk c1
2973+
Disabled Nodes: 1
29652974
-> Sort
29662975
Sort Key: c2.x
29672976
-> Seq Scan on group_agg_pk c2
2968-
(13 rows)
2977+
Disabled Nodes: 1
2978+
(18 rows)
29692979

29702980
EXPLAIN (COSTS OFF)
29712981
SELECT c1.y,c1.x FROM group_agg_pk c1
@@ -2975,19 +2985,24 @@ GROUP BY c1.y,c2.x,c1.x;
29752985
QUERY PLAN
29762986
-----------------------------------------------------
29772987
Group
2988+
Disabled Nodes: 2
29782989
Group Key: c2.x, c1.y
29792990
-> Incremental Sort
2991+
Disabled Nodes: 2
29802992
Sort Key: c2.x, c1.y
29812993
Presorted Key: c2.x
29822994
-> Merge Join
2995+
Disabled Nodes: 2
29832996
Merge Cond: (c1.x = c2.x)
29842997
-> Sort
29852998
Sort Key: c1.x
29862999
-> Seq Scan on group_agg_pk c1
3000+
Disabled Nodes: 1
29873001
-> Sort
29883002
Sort Key: c2.x
29893003
-> Seq Scan on group_agg_pk c2
2990-
(13 rows)
3004+
Disabled Nodes: 1
3005+
(18 rows)
29913006

29923007
RESET enable_nestloop;
29933008
RESET enable_hashjoin;

src/test/regress/expected/btree_index.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,12 @@ select proname from pg_proc where proname ilike 'ri%foo' order by 1;
335335
QUERY PLAN
336336
----------------------------------------------
337337
Sort
338+
Disabled Nodes: 1
338339
Sort Key: proname
339340
-> Seq Scan on pg_proc
341+
Disabled Nodes: 1
340342
Filter: (proname ~~* 'ri%foo'::text)
341-
(4 rows)
343+
(6 rows)
342344

343345
reset enable_seqscan;
344346
reset enable_indexscan;

src/test/regress/expected/collate.icu.utf8.out

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,9 @@ select * from collate_test1 where b ilike 'abc';
989989
QUERY PLAN
990990
-------------------------------
991991
Seq Scan on collate_test1
992+
Disabled Nodes: 1
992993
Filter: (b ~~* 'abc'::text)
993-
(2 rows)
994+
(3 rows)
994995

995996
select * from collate_test1 where b ilike 'abc';
996997
a | b
@@ -1004,8 +1005,9 @@ select * from collate_test1 where b ilike 'ABC';
10041005
QUERY PLAN
10051006
-------------------------------
10061007
Seq Scan on collate_test1
1008+
Disabled Nodes: 1
10071009
Filter: (b ~~* 'ABC'::text)
1008-
(2 rows)
1010+
(3 rows)
10091011

10101012
select * from collate_test1 where b ilike 'ABC';
10111013
a | b

src/test/regress/expected/incremental_sort.out

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,16 +701,19 @@ explain (costs off) select * from t left join (select * from (select * from t or
701701
QUERY PLAN
702702
------------------------------------------------
703703
Nested Loop Left Join
704+
Disabled Nodes: 1
704705
Join Filter: (t_1.a = t.a)
705706
-> Seq Scan on t
706707
Filter: (a = ANY ('{1,2}'::integer[]))
707708
-> Incremental Sort
709+
Disabled Nodes: 1
708710
Sort Key: t_1.a, t_1.b
709711
Presorted Key: t_1.a
710712
-> Sort
713+
Disabled Nodes: 1
711714
Sort Key: t_1.a
712715
-> Seq Scan on t t_1
713-
(10 rows)
716+
(13 rows)
714717

715718
select * from t left join (select * from (select * from t order by a) v order by a, b) s on s.a = t.a where t.a in (1, 2);
716719
a | b | a | b

src/test/regress/expected/inherit.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,7 @@ explain (verbose, costs off) select * from matest0 order by 1-id;
16141614
QUERY PLAN
16151615
------------------------------------------------------------------------
16161616
Merge Append
1617+
Disabled Nodes: 1
16171618
Sort Key: ((1 - matest0.id))
16181619
-> Index Scan using matest0i on public.matest0 matest0_1
16191620
Output: matest0_1.id, matest0_1.name, (1 - matest0_1.id)
@@ -1623,10 +1624,11 @@ explain (verbose, costs off) select * from matest0 order by 1-id;
16231624
Output: matest0_3.id, matest0_3.name, ((1 - matest0_3.id))
16241625
Sort Key: ((1 - matest0_3.id))
16251626
-> Seq Scan on public.matest2 matest0_3
1627+
Disabled Nodes: 1
16261628
Output: matest0_3.id, matest0_3.name, (1 - matest0_3.id)
16271629
-> Index Scan using matest3i on public.matest3 matest0_4
16281630
Output: matest0_4.id, matest0_4.name, (1 - matest0_4.id)
1629-
(13 rows)
1631+
(15 rows)
16301632

16311633
select * from matest0 order by 1-id;
16321634
id | name

src/test/regress/expected/join.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8000,13 +8000,15 @@ SELECT t1.a FROM skip_fetch t1 LEFT JOIN skip_fetch t2 ON t2.a = 1 WHERE t2.a IS
80008000
QUERY PLAN
80018001
---------------------------------------------------------
80028002
Nested Loop Anti Join
8003+
Disabled Nodes: 1
80038004
-> Seq Scan on skip_fetch t1
8005+
Disabled Nodes: 1
80048006
-> Materialize
80058007
-> Bitmap Heap Scan on skip_fetch t2
80068008
Recheck Cond: (a = 1)
80078009
-> Bitmap Index Scan on skip_fetch_a_idx
80088010
Index Cond: (a = 1)
8009-
(7 rows)
8011+
(9 rows)
80108012

80118013
SELECT t1.a FROM skip_fetch t1 LEFT JOIN skip_fetch t2 ON t2.a = 1 WHERE t2.a IS NULL;
80128014
a

src/test/regress/expected/memoize.out

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,29 +333,33 @@ SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.n >= s2.n;', false);
333333
explain_memoize
334334
----------------------------------------------------------------------------------
335335
Nested Loop (actual rows=24 loops=N)
336+
Disabled Nodes: 1
336337
-> Seq Scan on strtest s1 (actual rows=6 loops=N)
338+
Disabled Nodes: 1
337339
-> Memoize (actual rows=4 loops=N)
338340
Cache Key: s1.n
339341
Cache Mode: binary
340342
Hits: 3 Misses: 3 Evictions: Zero Overflows: 0 Memory Usage: NkB
341343
-> Index Scan using strtest_n_idx on strtest s2 (actual rows=4 loops=N)
342344
Index Cond: (n <= s1.n)
343-
(8 rows)
345+
(10 rows)
344346

345347
-- Ensure we get 3 hits and 3 misses
346348
SELECT explain_memoize('
347349
SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.t >= s2.t;', false);
348350
explain_memoize
349351
----------------------------------------------------------------------------------
350352
Nested Loop (actual rows=24 loops=N)
353+
Disabled Nodes: 1
351354
-> Seq Scan on strtest s1 (actual rows=6 loops=N)
355+
Disabled Nodes: 1
352356
-> Memoize (actual rows=4 loops=N)
353357
Cache Key: s1.t
354358
Cache Mode: binary
355359
Hits: 3 Misses: 3 Evictions: Zero Overflows: 0 Memory Usage: NkB
356360
-> Index Scan using strtest_t_idx on strtest s2 (actual rows=4 loops=N)
357361
Index Cond: (t <= s1.t)
358-
(8 rows)
362+
(10 rows)
359363

360364
DROP TABLE strtest;
361365
-- Ensure memoize works with partitionwise join

src/test/regress/expected/select_parallel.out

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,18 +537,22 @@ explain (costs off)
537537
QUERY PLAN
538538
------------------------------------------------------------
539539
Aggregate
540+
Disabled Nodes: 1
540541
-> Nested Loop
542+
Disabled Nodes: 1
541543
-> Gather
544+
Disabled Nodes: 1
542545
Workers Planned: 4
543546
-> Parallel Seq Scan on tenk2
547+
Disabled Nodes: 1
544548
Filter: (thousand = 0)
545549
-> Gather
546550
Workers Planned: 4
547551
-> Parallel Bitmap Heap Scan on tenk1
548552
Recheck Cond: (hundred > 1)
549553
-> Bitmap Index Scan on tenk1_hundred
550554
Index Cond: (hundred > 1)
551-
(12 rows)
555+
(16 rows)
552556

553557
select count(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand=0;
554558
count

src/test/regress/expected/union.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,12 @@ explain (costs off) select '123'::xid union select '123'::xid;
822822
QUERY PLAN
823823
---------------------------
824824
HashAggregate
825+
Disabled Nodes: 1
825826
Group Key: ('123'::xid)
826827
-> Append
827828
-> Result
828829
-> Result
829-
(5 rows)
830+
(6 rows)
830831

831832
reset enable_hashagg;
832833
--

0 commit comments

Comments
 (0)