Skip to content
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

sql: don't exclude unvalidated check constraints #37366

Merged
merged 1 commit into from
May 10, 2019

Conversation

thoszhang
Copy link
Contributor

@thoszhang thoszhang commented May 7, 2019

Previously, as of 19.1, AllActiveAndInactiveChecks(), which gets check
constraints for ALTER TABLE as well as SHOW CONSTRAINT, etc., excluded
unvalidated checks on the table descriptor, under the assumption that all
checks would be validated once they'd been added to the table descriptor. This
was to avoid double-counting constraints that were both on the table descriptor
and in the list of mutations. This caused unvalidated checks added in earlier
versions to disappear (though they are still on the table descriptor itself,
and are still enforced for writes). This PR fixes the issue by only excluding
Validating checks on the table descriptor to avoid double-counting.

Fixes #37285.

Release note (bug fix): Fixes bug where unvalidated check constraints disappear
from the output of SHOW CONSTRAINT and cannot be referenced in ALTER TABLE
after upgrading to 19.1.

@thoszhang thoszhang requested review from dt and a team May 7, 2019 20:12
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Previously, as of 19.1, AllActiveAndInactiveChecks(), which gets check
constraints for ALTER TABLE as well as SHOW CONSTRAINT, etc., excluded
unvalidated checks on the table descriptor, under the assumption that all
checks would be validated once they'd been added to the table descriptor. This
was to avoid double-counting constraints that were both on the table descriptor
and in the list of mutations. This caused unvalidated checks added in earlier
versions to disappear (though they are still on the table descriptor itself,
and are still enforced for writes). This PR fixes the issue by only excluding
`Validating` checks on the table descriptor to avoid double-counting.

Release note (bug fix): Fixes bug where unvalidated check constraints disappear
from the output of SHOW CONSTRAINT and cannot be referenced in ALTER TABLE
after upgrading to 19.1.
@thoszhang
Copy link
Contributor Author

I updated the PR. I realized the previous approach (deduplicating by name, or even name and expression) doesn't work, since this function gets called in validating the uniqueness of constraint names before they're added.

What will work is just filtering out Validating constraints that are on the table descriptor to prevent them from being double-counted (and this should be a reasonable invariant to maintain even if we allow unvalidated constraints in the future, since unvalidated constraints can just be added to the descriptor and removed from the mutations list in a single version change).

@thoszhang
Copy link
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request May 10, 2019
37366: sql: don't exclude unvalidated check constraints r=lucy-zhang a=lucy-zhang

Previously, as of 19.1, AllActiveAndInactiveChecks(), which gets check
constraints for ALTER TABLE as well as SHOW CONSTRAINT, etc., excluded
unvalidated checks on the table descriptor, under the assumption that all
checks would be validated once they'd been added to the table descriptor. This
was to avoid double-counting constraints that were both on the table descriptor
and in the list of mutations. This caused unvalidated checks added in earlier
versions to disappear (though they are still on the table descriptor itself,
and are still enforced for writes). This PR fixes the issue by only excluding
`Validating` checks on the table descriptor to avoid double-counting.

Fixes #37285.

Release note (bug fix): Fixes bug where unvalidated check constraints disappear
from the output of SHOW CONSTRAINT and cannot be referenced in ALTER TABLE
after upgrading to 19.1.

37450: parser: Add IMPORT INTO prototype syntax r=dt a=dt

Breaking this out of the implementation PR.
Release note: None

Co-authored-by: Lucy Zhang <lucy-zhang@users.noreply.github.com>
Co-authored-by: David Taylor <tinystatemachine@gmail.com>
@craig
Copy link
Contributor

craig bot commented May 10, 2019

Build succeeded

@craig craig bot merged commit 4a4e189 into cockroachdb:master May 10, 2019
@thoszhang thoszhang deleted the fix-checks branch May 10, 2019 22:00
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.

CHECK constraint lost during upgrade to v19.1.0
4 participants