aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/analyzejoins.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-02-13 13:35:38 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-02-13 13:35:38 -0500
commite9a20e451f3aa0b64da807338012c65d8664d0ac (patch)
treeed030524aca96c5c13e3d3cd3bef3260dbf6310c /src/backend/optimizer/plan/analyzejoins.c
parentc7468c73f7b6e842a53c12eaee5578a76a8fa7a6 (diff)
downloadpostgresql-e9a20e451f3aa0b64da807338012c65d8664d0ac.tar.gz
postgresql-e9a20e451f3aa0b64da807338012c65d8664d0ac.zip
When removing a relation from the query, drop its RelOptInfo.
In commit b78f6264e I opined that it was "too risky" to delete a relation's RelOptInfo from the planner's data structures when we have realized that we don't need to join to it; so instead we just marked it as a dead relation. In hindsight that judgment seems flawed: any subsequent access to such a dead relation is arguably a bug in itself, so leaving the RelOptInfo present just helps to mask bugs. Let's delete it instead, allowing removal of the whole notion of a "dead relation". So far as the regression tests can find, this requires no other code changes, except for one Assert in equivclass.c that was very dubiously not complaining about access to a dead rel. Discussion: https://postgr.es/m/229905.1676062220@sss.pgh.pa.us
Diffstat (limited to 'src/backend/optimizer/plan/analyzejoins.c')
-rw-r--r--src/backend/optimizer/plan/analyzejoins.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c
index 7fd11df9afb..0dfefd71f21 100644
--- a/src/backend/optimizer/plan/analyzejoins.c
+++ b/src/backend/optimizer/plan/analyzejoins.c
@@ -332,12 +332,6 @@ remove_rel_from_query(PlannerInfo *root, int relid, int ojrelid,
ListCell *l;
/*
- * Mark the rel as "dead" to show it is no longer part of the join tree.
- * (Removing it from the baserel array altogether seems too risky.)
- */
- rel->reloptkind = RELOPT_DEADREL;
-
- /*
* Remove references to the rel from other baserels' attr_needed arrays.
*/
for (rti = 1; rti < root->simple_rel_array_size; rti++)
@@ -487,6 +481,16 @@ remove_rel_from_query(PlannerInfo *root, int relid, int ojrelid,
* There may be references to the rel in root->fkey_list, but if so,
* match_foreign_keys_to_quals() will get rid of them.
*/
+
+ /*
+ * Finally, remove the rel from the baserel array to prevent it from being
+ * referenced again. (We can't do this earlier because
+ * remove_join_clause_from_rels will touch it.)
+ */
+ root->simple_rel_array[relid] = NULL;
+
+ /* And nuke the RelOptInfo, just in case there's another access path */
+ pfree(rel);
}
/*