mirror of
https://github.com/postgres/postgres.git
synced 2025-11-03 09:13:20 +03:00
Don't add a redundant constraint when detaching a partition
On ALTER TABLE .. DETACH CONCURRENTLY, we add a new table constraint that duplicates the partition constraint. But if the partition already has another constraint that implies that one, then that's unnecessary. We were already avoiding the addition of a duplicate constraint if there was an exact 'equal' match -- this just improves the quality of the check. Author: Justin Pryzby <pryzby@telsasoft.com> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/20210410184226.GY6592@telsasoft.com
This commit is contained in:
@@ -2696,6 +2696,12 @@ DROP TABLE part_rpd;
|
||||
-- works fine
|
||||
ALTER TABLE range_parted2 DETACH PARTITION part_rp CONCURRENTLY;
|
||||
\d+ range_parted2
|
||||
-- constraint should be created
|
||||
\d part_rp
|
||||
CREATE TABLE part_rp100 PARTITION OF range_parted2 (CHECK (a>=123 AND a<133 AND a IS NOT NULL)) FOR VALUES FROM (100) to (200);
|
||||
ALTER TABLE range_parted2 DETACH PARTITION part_rp100 CONCURRENTLY;
|
||||
-- redundant constraint should not be created
|
||||
\d part_rp100
|
||||
DROP TABLE range_parted2;
|
||||
|
||||
-- Check ALTER TABLE commands for partitioned tables and partitions
|
||||
|
||||
Reference in New Issue
Block a user