Fix the name collision detection in MERGE/SPLIT partition operations
authorAlexander Korotkov <akorotkov@postgresql.org>
Wed, 22 May 2024 23:21:00 +0000 (02:21 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Wed, 22 May 2024 23:21:00 +0000 (02:21 +0300)
commit3a82c689fd1be9bdf9d60135e5db7d352c051269
tree02ae38c5f7f13a7bf143b35813eeadda0f6161d3
parent97e5b0026fc276ab1bcde58ae98ae1fcd9c3acc3
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
src/backend/commands/tablecmds.c
src/test/regress/expected/partition_merge.out
src/test/regress/expected/partition_split.out
src/test/regress/sql/partition_merge.sql
src/test/regress/sql/partition_split.sql