Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78b1c55

Browse files
author
Richard Guo
committed
Fix inconsistent RestrictInfo serial numbers
When we generate multiple clones of the same qual condition to copewith outer join identity 3, we need to ensure that all the clones getthe same serial number. To achieve this, we reset theroot->last_rinfo_serial counter each time we produce RestrictInfo(s)from the qual list (see deconstruct_distribute_oj_quals). Thisapproach works only if we ensure that we are not changing the quallist in any way that'd affect the number of RestrictInfos built fromit.However, withb262ad4, an IS NULL qual on a NOT NULL column mightresult in an additional constant-FALSE RestrictInfo. And differentversions of the same qual clause can lead to different conclusionsabout whether it can be reduced to constant-FALSE. This would affectthe number of RestrictInfos built from the qual list for differentversions, causing inconsistent RestrictInfo serial numbers acrossmultiple clones of the same qual. This inconsistency can confuseusers of these serial numbers, such as rebuild_joinclause_attr_needed,and lead to planner errors such as "ERROR: variable not found insubplan target lists".To fix, reset the root->last_rinfo_serial counter after generating theadditional constant-FALSE RestrictInfo.Back-patch to v17 where the issue crept in. In v17, I failed to makea test case that would expose this bug, so no test case for v17.Author: Richard GuoDiscussion:https://postgr.es/m/CAMbWs4-B6kafn+LmPuh-TYFwFyEm-vVj3Qqv7Yo-69CEv14rRg@mail.gmail.com
1 parente2b5693 commit78b1c55

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

‎src/backend/optimizer/plan/initsplan.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2657,11 +2657,18 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
26572657

26582658
/*
26592659
* Substitute the origin qual with constant-FALSE if it is provably
2660-
* always false. Note that we keep the same rinfo_serial.
2660+
* always false.
2661+
*
2662+
* Note that we need to keep the same rinfo_serial, since it is in
2663+
* practice the same condition. We also need to reset the
2664+
* last_rinfo_serial counter, which is essential to ensure that the
2665+
* RestrictInfos for the "same" qual condition get identical serial
2666+
* numbers (see deconstruct_distribute_oj_quals).
26612667
*/
26622668
if (restriction_is_always_false(root,restrictinfo))
26632669
{
26642670
intsave_rinfo_serial=restrictinfo->rinfo_serial;
2671+
intsave_last_rinfo_serial=root->last_rinfo_serial;
26652672

26662673
restrictinfo=make_restrictinfo(root,
26672674
(Expr*)makeBoolConst(false, false),
@@ -2674,6 +2681,7 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid,
26742681
restrictinfo->incompatible_relids,
26752682
restrictinfo->outer_relids);
26762683
restrictinfo->rinfo_serial=save_rinfo_serial;
2684+
root->last_rinfo_serial=save_last_rinfo_serial;
26772685
}
26782686
}
26792687

‎src/backend/optimizer/util/joininfo.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,19 @@ add_join_clause_to_rels(PlannerInfo *root,
106106
return;
107107

108108
/*
109-
* Substitute constant-FALSE for the origin qual if it is always false.
110-
* Note that we keep the same rinfo_serial.
109+
* Substitute the origin qual with constant-FALSE if it is provably always
110+
* false.
111+
*
112+
* Note that we need to keep the same rinfo_serial, since it is in
113+
* practice the same condition. We also need to reset the
114+
* last_rinfo_serial counter, which is essential to ensure that the
115+
* RestrictInfos for the "same" qual condition get identical serial
116+
* numbers (see deconstruct_distribute_oj_quals).
111117
*/
112118
if (restriction_is_always_false(root,restrictinfo))
113119
{
114120
intsave_rinfo_serial=restrictinfo->rinfo_serial;
121+
intsave_last_rinfo_serial=root->last_rinfo_serial;
115122

116123
restrictinfo=make_restrictinfo(root,
117124
(Expr*)makeBoolConst(false, false),
@@ -124,6 +131,7 @@ add_join_clause_to_rels(PlannerInfo *root,
124131
restrictinfo->incompatible_relids,
125132
restrictinfo->outer_relids);
126133
restrictinfo->rinfo_serial=save_rinfo_serial;
134+
root->last_rinfo_serial=save_last_rinfo_serial;
127135
}
128136

129137
cur_relid=-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp