From 1f7f20530c8c3642264ea420cfd24c9a7d0e90c4 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Fri, 27 Jan 2023 15:59:37 -0500 Subject: [PATCH] logictest: frontport test from #96124 This testing is worth having. It does pass. Epic: None Release note: None --- .../testdata/logic_test/schema_change_in_txn | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn b/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn index 6bada7ca76eb..c2037b0e683a 100644 --- a/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn +++ b/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn @@ -1950,3 +1950,50 @@ DROP SCHEMA sc; # Prior to fixing this bug, this commit would hang indefinitely. statement ok COMMIT; + +# This is a regression test to handle the case where a newly created table or +# a previously unleased table are referenced in a transaction involving +# transactional constraint validation. +subtest validate_constraint_referencing_modified_table + +statement ok +CREATE TABLE t1 (id STRING PRIMARY KEY, other_id STRING NOT NULL); +CREATE TABLE t2 (id STRING PRIMARY KEY); +ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (other_id) REFERENCES t2(id) NOT VALID; + +statement ok +BEGIN; +SET TRANSACTION PRIORITY HIGH; +ALTER TABLE t2 RENAME TO t3; +ALTER TABLE t1 VALIDATE CONSTRAINT fk; +COMMIT; + +statement ok +DROP TABLE t1, t3 CASCADE + +statement ok +CREATE TABLE t1 (id STRING PRIMARY KEY, other_id STRING NOT NULL); +CREATE TABLE t2 (id STRING PRIMARY KEY); +ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (other_id) REFERENCES t2(id) NOT VALID; + +statement ok +BEGIN; +SET TRANSACTION PRIORITY HIGH; +ALTER TABLE t1 RENAME TO t3; +ALTER TABLE t3 VALIDATE CONSTRAINT fk; +COMMIT; + +statement ok +DROP TABLE t2, t3 CASCADE + +statement ok +BEGIN; +SET TRANSACTION PRIORITY HIGH; +CREATE TABLE t1 (id STRING PRIMARY KEY, other_id STRING NOT NULL); +CREATE TABLE t2 (id STRING PRIMARY KEY); +ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (other_id) REFERENCES t2(id); +ALTER TABLE t1 VALIDATE CONSTRAINT fk; +COMMIT; + +statement ok +DROP TABLE t1, t2 CASCADE