yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
9.04k stars 1.08k forks source link

[YSQL] Schema mismatch error after failed ALTER TABLE command #24981

Open arpang opened 6 days ago

arpang commented 6 days ago

Jira Link: DB-14126

Description

With revision D37933, FK referencing partitioned tables will be supported for YB. Consider the following example which is expected to work with that.

CREATE TABLE droppk (a int PRIMARY KEY) PARTITION BY RANGE (a);
CREATE TABLE droppk2 PARTITION OF droppk FOR VALUES FROM (1000) TO (2000)
  PARTITION BY RANGE (a);
CREATE TABLE droppk2_d PARTITION OF droppk2 DEFAULT;
INSERT into droppk VALUES (1000);
CREATE TABLE dropfk (a int REFERENCES droppk);
INSERT into dropfk VALUES (1000);
ALTER TABLE droppk2 DETACH PARTITION droppk2_d;
ALTER TABLE droppk DETACH PARTITION droppk2;

The last two alters are expected to throw "removing partition violates foreign key constraint". But the last alter throws "schema version mismatch" error.

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

arpang commented 4 days ago

Simpler repro:

CREATE TABLE pk(a int primary key);
INSERT INTO pk values (1);
CREATE TABLE fk(a int);
INSERT INTO fk values (2);
ALTER TABLE fk ADD FOREIGN KEY (a) REFERENCES pk; -- fails due to FK constraint violation
BEGIN;
SELECT * from pk; -- throws schema mismatch error
COMMIT;