pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix inconsistent RestrictInfo serial numbers
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix inconsistent RestrictInfo serial numbers
@ 2024-11-08 02:25 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Guo @ 2024-11-08 02:25 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix inconsistent RestrictInfo serial numbers

When we generate multiple clones of the same qual condition to cope
with outer join identity 3, we need to ensure that all the clones get
the same serial number.  To achieve this, we reset the
root->last_rinfo_serial counter each time we produce RestrictInfo(s)
from the qual list (see deconstruct_distribute_oj_quals).  This
approach works only if we ensure that we are not changing the qual
list in any way that'd affect the number of RestrictInfos built from
it.

However, with b262ad440, an IS NULL qual on a NOT NULL column might
result in an additional constant-FALSE RestrictInfo.  And different
versions of the same qual clause can lead to different conclusions
about whether it can be reduced to constant-FALSE.  This would affect
the number of RestrictInfos built from the qual list for different
versions, causing inconsistent RestrictInfo serial numbers across
multiple clones of the same qual.  This inconsistency can confuse
users of these serial numbers, such as rebuild_joinclause_attr_needed,
and lead to planner errors such as "ERROR:  variable not found in
subplan target lists".

To fix, reset the root->last_rinfo_serial counter after generating the
additional constant-FALSE RestrictInfo.

Back-patch to v17 where the issue crept in.  In v17, I failed to make
a test case that would expose this bug, so no test case for v17.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4-B6kafn+LmPuh-TYFwFyEm-vVj3Qqv7Yo-69CEv14rRg@mail.gmail.com

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/78b1c553bb1c1f334d0b7f3365070ba27a2fcc41

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c | 10 +++++++++-
src/backend/optimizer/util/joininfo.c  | 12 ++++++++++--
2 files changed, 19 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix inconsistent RestrictInfo serial numbers
@ 2024-11-08 02:28 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Guo @ 2024-11-08 02:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix inconsistent RestrictInfo serial numbers

When we generate multiple clones of the same qual condition to cope
with outer join identity 3, we need to ensure that all the clones get
the same serial number.  To achieve this, we reset the
root->last_rinfo_serial counter each time we produce RestrictInfo(s)
from the qual list (see deconstruct_distribute_oj_quals).  This
approach works only if we ensure that we are not changing the qual
list in any way that'd affect the number of RestrictInfos built from
it.

However, with b262ad440, an IS NULL qual on a NOT NULL column might
result in an additional constant-FALSE RestrictInfo.  And different
versions of the same qual clause can lead to different conclusions
about whether it can be reduced to constant-FALSE.  This would affect
the number of RestrictInfos built from the qual list for different
versions, causing inconsistent RestrictInfo serial numbers across
multiple clones of the same qual.  This inconsistency can confuse
users of these serial numbers, such as rebuild_joinclause_attr_needed,
and lead to planner errors such as "ERROR:  variable not found in
subplan target lists".

To fix, reset the root->last_rinfo_serial counter after generating the
additional constant-FALSE RestrictInfo.

Back-patch to v17 where the issue crept in.  In v17, I failed to make
a test case that would expose this bug, so no test case for v17.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4-B6kafn+LmPuh-TYFwFyEm-vVj3Qqv7Yo-69CEv14rRg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f00ab1fd156ea9c6283ffa0be5cddaafecfb0a35

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c  | 10 +++++++++-
src/backend/optimizer/util/joininfo.c   | 12 ++++++++++--
src/test/regress/expected/predicate.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/predicate.sql      | 15 +++++++++++++++
4 files changed, 62 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-11-08 02:28 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-11-08 02:25 pgsql: Fix inconsistent RestrictInfo serial numbers Richard Guo <rguo@postgresql.org>
2024-11-08 02:28 pgsql: Fix inconsistent RestrictInfo serial numbers Richard Guo <rguo@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox