pgsql: Fix a bug in how we generate partition constraints.
Robert Haas <rhaas@postgresql.org>
From: Robert Haas <rhaas@postgresql.org>
To: pgsql-committers@postgresql.org
Date: 2017-01-13T19:07:02Z
Lists: pgsql-hackers
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(-)
Commits
-
Avoid some code duplication in map_partition_varattnos().
- cc144155f7cd 10.0 landed
-
Fix a bug in how we generate partition constraints.
- 0563a3a8b591 10.0 cited
-
Fix ALTER TABLE / SET TYPE for irregular inheritance
- 3957b58b8885 10.0 cited