Thread: pgsql: Fix the name collision detection in MERGE/SPLIT partition operat

pgsql: Fix the name collision detection in MERGE/SPLIT partition operat

From
Alexander Korotkov
Date:
Fix the name collision detection in MERGE/SPLIT partition operations

Both MERGE and SPLIT partition operations support the case when the name of the
new partition matches the name of the existing partition to be merged/split.
But the name collision detection doesn't always work as intended.  The SPLIT
partition operation finds the namespace to search for an existing partition
without taking into account the parent's persistence.  The MERGE partition
operation checks for the name collision with simple equal() on RangeVar's
simply ignoring the search_path.

This commit fixes this behavior as follows.
 1. The SPLIT partition operation now finds the namespace to search for
    an existing partition according to the parent's persistence.
 2. The MERGE partition operation now checks for the name collision similarly
    to the SPLIT partition operation using
    RangeVarGetAndCheckCreationNamespace() and get_relname_relid().

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/86b4f1e3-0b5d-315c-9225-19860d64d685%40gmail.com
Author: Dmitry Koval, Alexander Korotkov

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3a82c689fd1be9bdf9d60135e5db7d352c051269

Modified Files
--------------
src/backend/commands/tablecmds.c              | 62 ++++++++++++++++++++++-----
src/test/regress/expected/partition_merge.out |  3 +-
src/test/regress/expected/partition_split.out |  8 ++++
src/test/regress/sql/partition_merge.sql      |  3 +-
src/test/regress/sql/partition_split.sql      |  9 ++++
5 files changed, 72 insertions(+), 13 deletions(-)