Adjust EXPLAIN's output for disabled nodes
authorDavid Rowley <[email protected]>
Fri, 11 Oct 2024 04:19:59 +0000 (17:19 +1300)
committerDavid Rowley <[email protected]>
Fri, 11 Oct 2024 04:19:59 +0000 (17:19 +1300)
commit161320b4b960ee4fe918959be6529ae9b106ea5a
tree35fceff1c373c3e505d2d1180429fb1571e8bb73
parentc75c6f8d280a3364643fc51f9c9fdf2dee0213c2
Adjust EXPLAIN's output for disabled nodes

c01743aa4 added EXPLAIN output to display the plan node's disabled_node
count whenever that count is above 0.  Seemingly, there weren't many
people who liked that output as each parent of a disabled node would
also have a "Disabled Nodes" output due to the way disabled_nodes is
accumulated towards the root plan node.  It was often hard and sometimes
impossible to figure out which nodes were disabled from looking at
EXPLAIN.  You might think it would be possible to manually add up the
numbers from the "Disabled Nodes" output of a given node's children to
figure out if that node has a higher disabled_nodes count than its
children, but that wouldn't have worked for Append and Merge Append nodes
if some disabled child nodes were run-time pruned during init plan.  Those
children are not displayed in EXPLAIN.

Here we attempt to improve this output by only showing "Disabled: true"
against only the nodes which are explicitly disabled themselves.  That
seems to be the output that's desired by the most people who voiced
their opinion.  This is done by summing up the disabled_nodes of the
given node's children and checking if that number is less than the
disabled_nodes of the current node.

This commit also fixes a bug in make_sort() which was neglecting to set
the Sort's disabled_nodes field.  This should have copied what was done
in cost_sort(), but it hadn't been updated.  With the new output, the
choice to not maintain that field properly was clearly wrong as the
disabled-ness of the node was attributed to the Sort's parent instead.

Reviewed-by: Laurenz Albe, Alena Rybakina
Discussion: https://postgr.es/m/9e4ad616bebb103ec2084bf6f724cfc739e7fabb[email protected]
17 files changed:
src/backend/commands/explain.c
src/backend/optimizer/plan/createplan.c
src/test/regress/expected/aggregates.out
src/test/regress/expected/btree_index.out
src/test/regress/expected/collate.icu.utf8.out
src/test/regress/expected/explain.out
src/test/regress/expected/incremental_sort.out
src/test/regress/expected/inherit.out
src/test/regress/expected/insert_conflict.out
src/test/regress/expected/join.out
src/test/regress/expected/memoize.out
src/test/regress/expected/select_parallel.out
src/test/regress/expected/sqljson_jsontable.out
src/test/regress/expected/union.out
src/test/regress/expected/xml.out
src/test/regress/expected/xml_1.out
src/test/regress/expected/xml_2.out