DB-12363: fix drop column and constraints #5703
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Short Description
Fix a regression from DB-12306.
Long Description
If a constraint is defined on a column, the constraint should be dropped when the column is being dropped. The column reference stored in constraint is storage position, so we should get storage position of the dropped column to check whether a constraint is defined on the column.
DB-12306 tried to fix a similar issue for triggers, which store relative column position. We need to check triggers using relative position, and check constraints using storage position
How to test
CREATE TABLE PLAIN_ALTER_SQL.float_alter2 ( VAL1 FLOAT);
ALTER TABLE PLAIN_ALTER_SQL.float_alter2 ADD COLUMN VAL5 FLOAT;
ALTER TABLE PLAIN_ALTER_SQL.float_alter2 DROP COLUMN VAL5;
ALTER TABLE PLAIN_ALTER_SQL.float_alter2 ADD COLUMN VAL6 FLOAT NOT NULL DEFAULT 111 CONSTRAINT float_VAL6 PRIMARY KEY;
ALTER TABLE PLAIN_ALTER_SQL.float_alter2 DROP VAL6; -- this should drop the PK constraint
SELECT * FROM SYS.SYSCONSTRAINTS;