From 5a017c684c2dd95752f78ab833075ecdabf4bc8c Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 3 Apr 2019 12:27:42 -0600 Subject: [PATCH] Add repro case for #2484 --- .../sql/multi_alter_table_add_constraints.sql | 7 +++++++ .../sql/multi_create_table_constraints.sql | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/test/regress/sql/multi_alter_table_add_constraints.sql b/src/test/regress/sql/multi_alter_table_add_constraints.sql index 15dfe53b6..bea04596b 100644 --- a/src/test/regress/sql/multi_alter_table_add_constraints.sql +++ b/src/test/regress/sql/multi_alter_table_add_constraints.sql @@ -367,6 +367,13 @@ ALTER TABLE products ADD PRIMARY KEY(product_no); ALTER TABLE products ADD CHECK(product_no <> 0); ALTER TABLE products ADD EXCLUDE USING btree (product_no with =); +-- ... with names, we can add/drop the constraints just fine +ALTER TABLE products ADD CONSTRAINT nonzero_product_no CHECK(product_no <> 0); +ALTER TABLE products ADD CONSTRAINT uniq_product_no EXCLUDE USING btree (product_no with =); + +ALTER TABLE products DROP CONSTRAINT nonzero_product_no; +ALTER TABLE products DROP CONSTRAINT uniq_product_no; + DROP TABLE products; diff --git a/src/test/regress/sql/multi_create_table_constraints.sql b/src/test/regress/sql/multi_create_table_constraints.sql index e04024348..2eb70e756 100644 --- a/src/test/regress/sql/multi_create_table_constraints.sql +++ b/src/test/regress/sql/multi_create_table_constraints.sql @@ -230,6 +230,22 @@ SELECT "Column", "Type", "Definition" FROM index_attrs WHERE SELECT "Constraint", "Definition" FROM table_checks WHERE relid='public.check_example_365056'::regclass; \c - - - :master_port +-- Index-based constraints are created with shard-extended names, but others +-- (e.g. expression-based table CHECK constraints) do _not_ have shardids in +-- their object names, _at least originally as designed_. At some point, we +-- mistakenly started extending _all_ constraint names, but _only_ for ALTER +-- TABLE ... ADD CONSTRAINT commands (yes, even non-index constraints). So now +-- the _same_ constraint definition could result in a non-extended name if made +-- using CREATE TABLE and another name if made using AT ... ADD CONSTRAINT. So +-- DROP CONSTRAINT started erroring because _it_ was also changed to always do +-- shard-id extension. We've fixed that by looking for the non-extended name +-- first and using it for DROP or VALIDATE commands that could be targeting it. + +-- As for the actual test: drop a constraint created by CREATE TABLE ... CHECK, +-- which per the above description would have been created with a non-extended +-- object name, but previously would have failed DROP as DROP does extension. +ALTER TABLE check_example DROP CONSTRAINT check_example_other_col_check; + -- drop unnecessary tables DROP TABLE pk_on_non_part_col, uq_on_non_part_col CASCADE; DROP TABLE pk_on_part_col, uq_part_col, uq_two_columns CASCADE;