aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/plan/initsplan.c10
-rw-r--r--src/backend/optimizer/util/joininfo.c12
2 files changed, 19 insertions, 3 deletions
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index e2c68fe6f99..cd0ce25bd86 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -2657,11 +2657,18 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
/*
* Substitute the origin qual with constant-FALSE if it is provably
- * always false. Note that we keep the same rinfo_serial.
+ * always false.
+ *
+ * Note that we need to keep the same rinfo_serial, since it is in
+ * practice the same condition. We also need to reset the
+ * last_rinfo_serial counter, which is essential to ensure that the
+ * RestrictInfos for the "same" qual condition get identical serial
+ * numbers (see deconstruct_distribute_oj_quals).
*/
if (restriction_is_always_false(root, restrictinfo))
{
int save_rinfo_serial = restrictinfo->rinfo_serial;
+ int save_last_rinfo_serial = root->last_rinfo_serial;
restrictinfo = make_restrictinfo(root,
(Expr *) makeBoolConst(false, false),
@@ -2674,6 +2681,7 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
restrictinfo->incompatible_relids,
restrictinfo->outer_relids);
restrictinfo->rinfo_serial = save_rinfo_serial;
+ root->last_rinfo_serial = save_last_rinfo_serial;
}
}
diff --git a/src/backend/optimizer/util/joininfo.c b/src/backend/optimizer/util/joininfo.c
index 5fb0c17630a..65993bd6599 100644
--- a/src/backend/optimizer/util/joininfo.c
+++ b/src/backend/optimizer/util/joininfo.c
@@ -106,12 +106,19 @@ add_join_clause_to_rels(PlannerInfo *root,
return;
/*
- * Substitute constant-FALSE for the origin qual if it is always false.
- * Note that we keep the same rinfo_serial.
+ * Substitute the origin qual with constant-FALSE if it is provably always
+ * false.
+ *
+ * Note that we need to keep the same rinfo_serial, since it is in
+ * practice the same condition. We also need to reset the
+ * last_rinfo_serial counter, which is essential to ensure that the
+ * RestrictInfos for the "same" qual condition get identical serial
+ * numbers (see deconstruct_distribute_oj_quals).
*/
if (restriction_is_always_false(root, restrictinfo))
{
int save_rinfo_serial = restrictinfo->rinfo_serial;
+ int save_last_rinfo_serial = root->last_rinfo_serial;
restrictinfo = make_restrictinfo(root,
(Expr *) makeBoolConst(false, false),
@@ -124,6 +131,7 @@ add_join_clause_to_rels(PlannerInfo *root,
restrictinfo->incompatible_relids,
restrictinfo->outer_relids);
restrictinfo->rinfo_serial = save_rinfo_serial;
+ root->last_rinfo_serial = save_last_rinfo_serial;
}
cur_relid = -1;