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

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix the name collision detection in MERGE/SPLIT partition operat
Date: 2024-05-22 23:35:03
Message-ID: E1s9vU7-001OLj-8J@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2024-05-23 03:25:12 pgsql: Fix a couple of outdated comments now that we have MERGE RETURNI
Previous Message Alexander Korotkov 2024-05-22 23:19:55 pgsql: amcheck: Report an error when the next page to a leaf is not a l