pgsql: Fix inconsistent RestrictInfo serial numbers - Mailing list pgsql-committers

From Richard Guo
Subject pgsql: Fix inconsistent RestrictInfo serial numbers
Date
Msg-id E1t9Egz-000j76-Br@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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(-)


pgsql-committers by date:

Previous
From: Andrew Dunstan
Date:
Subject: pgsql: Provide lstat() for Windows.
Next
From: Richard Guo
Date:
Subject: pgsql: Fix inconsistent RestrictInfo serial numbers