[COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. - Mailing list pgsql-committers

From Robert Haas
Subject [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
Date
Msg-id E1cS7Bm-0005BQ-CE@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix a bug in how we generate partition constraints.

Move the code for doing parent attnos to child attnos mapping for Vars
in partition constraint expressions to a separate function
map_partition_varattnos() and call it from the appropriate places.
Doing it in get_qual_from_partbound(), as is now, would produce wrong
result in certain multi-level partitioning cases, because it only
considers the current pair of parent-child relations.  In certain
multi-level partitioning cases, attnums for the same key attribute(s)
might differ between various levels causing the same attribute to be
numbered differently in different instances of the Var corresponding
to a given attribute.

With this commit, in generate_partition_qual(), we first generate the
the whole partition constraint (considering all levels of partitioning)
and then do the mapping, so that Vars in the final expression are
numbered according the leaf relation (to which it is supposed to apply).

Amit Langote, reviewed by me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/0563a3a8b59150bf3cc8b2b7077f684e0eaf8aff

Modified Files
--------------
src/backend/catalog/partition.c           | 99 +++++++++++++++----------------
src/backend/commands/tablecmds.c          |  7 ++-
src/include/catalog/partition.h           |  1 +
src/test/regress/expected/alter_table.out | 30 ++++++++++
src/test/regress/sql/alter_table.sql      | 25 ++++++++
5 files changed, 110 insertions(+), 52 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: [COMMITTERS] pgsql: Fix cardinality estimates for parallel joins.
Next
From: Peter Eisentraut
Date:
Subject: [COMMITTERS] pgsql: pg_upgrade: Fix for changed pg_ctl default stop mode