summaryrefslogtreecommitdiff
path: root/contrib/pg_overexplain
diff options
context:
space:
mode:
authorRobert Haas2025-09-23 13:07:55 +0000
committerRobert Haas2025-09-23 13:07:55 +0000
commitf2bae51dfd5b2edc460c86071c577a45a1acbfd7 (patch)
tree5ec981ac88314052d5fdf1485b0ba33f18971013 /contrib/pg_overexplain
parenta48d1ef58652229521ba4b5070e19f857608b22e (diff)
Keep track of what RTIs a Result node is scanning.
Result nodes now include an RTI set, which is only non-NULL when they have no subplan, and is taken from the relid set of the RelOptInfo that the Result is generating. ExplainPreScanNode now takes notice of these RTIs, which means that a few things get schema-qualified in the regression tests that previously did not. This makes the output more consistent between cases where some part of the plan tree is replaced by a Result node and those where this does not happen. Likewise, pg_overexplain's EXPLAIN (RANGE_TABLE) now displays the RTIs stored in a Result node just as it already does for other RTI-bearing node types. Result nodes also now include a result_reason, which tells us something about why the Result node was inserted. Using that information, EXPLAIN now emits, where relevant, a "Replaces" line describing the origin of a Result node. The purpose of these changes is to allow code that inspects a Plan tree to understand the origin of Result nodes that appear therein. Discussion: http://postgr.es/m/CA+TgmoYeUZePZWLsSO+1FAN7UPePT_RMEZBKkqYBJVCF1s60=w@mail.gmail.com Reviewed-by: Alexandra Wang <alexandra.wang.oss@gmail.com> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Diffstat (limited to 'contrib/pg_overexplain')
-rw-r--r--contrib/pg_overexplain/expected/pg_overexplain.out6
-rw-r--r--contrib/pg_overexplain/pg_overexplain.c12
2 files changed, 16 insertions, 2 deletions
diff --git a/contrib/pg_overexplain/expected/pg_overexplain.out b/contrib/pg_overexplain/expected/pg_overexplain.out
index 6de02323d7c..55d34666d87 100644
--- a/contrib/pg_overexplain/expected/pg_overexplain.out
+++ b/contrib/pg_overexplain/expected/pg_overexplain.out
@@ -44,9 +44,10 @@ EXPLAIN (RANGE_TABLE) SELECT 1;
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.01 rows=1 width=4)
+ RTIs: 1
RTI 1 (result):
Eref: "*RESULT*" ()
-(3 rows)
+(4 rows)
-- Create a partitioned table.
CREATE TABLE vegetables (id serial, name text, genus text)
@@ -475,6 +476,7 @@ INSERT INTO vegetables (name, genus) VALUES ('broccoflower', 'brassica');
Nominal RTI: 1
Exclude Relation RTI: 0
-> Result
+ RTIs: 2
RTI 1 (relation):
Eref: vegetables (id, name, genus)
Relation: vegetables
@@ -485,5 +487,5 @@ INSERT INTO vegetables (name, genus) VALUES ('broccoflower', 'brassica');
Eref: "*RESULT*" ()
Unprunable RTIs: 1
Result RTIs: 1
-(14 rows)
+(15 rows)
diff --git a/contrib/pg_overexplain/pg_overexplain.c b/contrib/pg_overexplain/pg_overexplain.c
index de824566f8c..bd70b6d9d5e 100644
--- a/contrib/pg_overexplain/pg_overexplain.c
+++ b/contrib/pg_overexplain/pg_overexplain.c
@@ -236,6 +236,18 @@ overexplain_per_node_hook(PlanState *planstate, List *ancestors,
((MergeAppend *) plan)->apprelids,
es);
break;
+ case T_Result:
+
+ /*
+ * 'relids' is only meaningful when plan->lefttree is NULL,
+ * but if somehow it ends up set when plan->lefttree is not
+ * NULL, print it anyway.
+ */
+ if (plan->lefttree == NULL ||
+ ((Result *) plan)->relids != NULL)
+ overexplain_bitmapset("RTIs",
+ ((Result *) plan)->relids,
+ es);
default:
break;
}