Skip to content

sql: drop check/FK/non-null constraints in the schema changer #39648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2019

Conversation

thoszhang
Copy link
Contributor

@thoszhang thoszhang commented Aug 14, 2019

Previously, DROP CONSTRAINT for check, foreign key, and non-null constraints
would cause those constraints to be immediately removed from the table
descriptor in a single transaction, which causes inconsistencies if the
constraint was validated and the optimizer was relying on those constraints to
hold. In this PR, constraints are now dropped in the schema changer if they
were previously validated. The existing code path is preserved for clusters not
fully upgraded to 19.2.

This PR slightly changes the behavior of DROP CONSTRAINT statements within
transactions: Since constraints are not removed immediately, they are still
enforced for writes within the same transaction, in the same way that
constraints are not enforced within the same transaction in which they are
added. (The difference is that when adding constraints in a transaction that
also contains writes, a validation query is run before any results are returned
to the client, and the schema change is rolled back if necessary.)

Release note (sql change): When DROP CONSTRAINT is executed in a transaction
on a validated constraint, subsequent writes in that constraint will now fail
if they violate that constraint. This is to enforce consistency when dropping
constraints asynchronously in the schema changer.

@thoszhang thoszhang requested a review from a team as a code owner August 14, 2019 00:40
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@thoszhang thoszhang force-pushed the drop-constraint-schema-changer branch 2 times, most recently from 1a09e81 to 6fccda7 Compare August 14, 2019 02:40
@thoszhang thoszhang changed the title [wip] sql: drop check/FK/non-null constraints in the schema changer sql: drop check/FK/non-null constraints in the schema changer Aug 14, 2019
@thoszhang
Copy link
Contributor Author

The first and second commits are #39383 and the third commit is #39614.

@thoszhang thoszhang force-pushed the drop-constraint-schema-changer branch 2 times, most recently from a011984 to 9d12837 Compare August 14, 2019 17:23
@thoszhang thoszhang requested a review from dt August 14, 2019 17:27
@thoszhang thoszhang force-pushed the drop-constraint-schema-changer branch 2 times, most recently from 985e38c to 43e77c0 Compare August 14, 2019 19:43
@thoszhang thoszhang force-pushed the drop-constraint-schema-changer branch 2 times, most recently from a3e393e to 5fe96d2 Compare August 20, 2019 20:07
Previously, `DROP CONSTRAINT` for check, foreign key, and non-null constraints
would cause those constraints to be immediately removed from the table
descriptor in a single transaction, which causes inconsistencies if the
constraint was validated and the optimizer was relying on those constraints to
hold. In this PR, constraints are now dropped in the schema changer if they
were previously validated. The existing code path is preserved for clusters not
fully upgraded to 19.2.

This PR slightly changes the behavior of `DROP CONSTRAINT` statements within
transactions: Since constraints are not removed immediately, they are still
enforced for writes within the same transaction, in the same way that
constraints are _not_ enforced within the same transaction in which they are
added. (The difference is that when adding constraints in a transaction that
also contains writes, a validation query is run before any results are returned
to the client, and the schema change is rolled back if necessary.)

Release note (sql change): When `DROP CONSTRAINT` is executed in a transaction
on a validated constraint, it no longer takes effect immediately, and
subsequent writes in that constraint will now fail if they violate that
constraint. This is to enforce consistency when dropping constraints
asynchronously in the schema changer.
@thoszhang thoszhang force-pushed the drop-constraint-schema-changer branch from 5fe96d2 to 183acd7 Compare August 20, 2019 22:08
@thoszhang
Copy link
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request Aug 20, 2019
39648: sql: drop check/FK/non-null constraints in the schema changer r=lucy-zhang a=lucy-zhang

Previously, `DROP CONSTRAINT` for check, foreign key, and non-null constraints
would cause those constraints to be immediately removed from the table
descriptor in a single transaction, which causes inconsistencies if the
constraint was validated and the optimizer was relying on those constraints to
hold. In this PR, constraints are now dropped in the schema changer if they
were previously validated. The existing code path is preserved for clusters not
fully upgraded to 19.2.

This PR slightly changes the behavior of `DROP CONSTRAINT` statements within
transactions: Since constraints are not removed immediately, they are still
enforced for writes within the same transaction, in the same way that
constraints are _not_ enforced within the same transaction in which they are
added. (The difference is that when adding constraints in a transaction that
also contains writes, a validation query is run before any results are returned
to the client, and the schema change is rolled back if necessary.)

Release note (sql change): When `DROP CONSTRAINT` is executed in a transaction
on a validated constraint, subsequent writes in that constraint will now fail
if they violate that constraint. This is to enforce consistency when dropping
constraints asynchronously in the schema changer.

Co-authored-by: Lucy Zhang <[email protected]>
@craig
Copy link
Contributor

craig bot commented Aug 20, 2019

Build succeeded

@craig craig bot merged commit 183acd7 into cockroachdb:master Aug 20, 2019
@thoszhang thoszhang deleted the drop-constraint-schema-changer branch August 20, 2019 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants