Don't add a redundant constraint when detaching a partition
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 21 Apr 2021 22:12:05 +0000 (18:12 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 21 Apr 2021 22:12:05 +0000 (18:12 -0400)
commit7b357cc6ae553c0ecacdc11b2e5278b7bf477dba
tree8223bd010a5f1f0d1ef49bae67ebd7566e645b07
parente014d25deade08df082d2b37de45adb0c984f563
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
src/backend/commands/tablecmds.c
src/test/regress/expected/alter_table.out
src/test/regress/sql/alter_table.sql