-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: add support for NOT VALID check constraints #38382
Conversation
feda258
to
df20d1d
Compare
393a6c7
to
df20d1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @lucy-zhang and @tyler314)
.gitignore, line 19 at r1 (raw file):
/cockroach* /certs .idea/*
This shouldn't be here
pkg/sql/backfill.go, line 165 at r1 (raw file):
constraintsToValidate = append(constraintsToValidate, *t.Constraint) } case sqlbase.ConstraintToUpdate_FOREIGN_KEY:
Can you add a TODO comment either here or in alter_table.go indicating that we don't yet support adding NOT VALID foreign keys, because we don't add those FK mutations?
pkg/sql/backfill.go, line 169 at r1 (raw file):
constraintsToAddBeforeValidation = append(constraintsToAddBeforeValidation, *t.Constraint) constraintsToValidate = append(constraintsToValidate, *t.Constraint) }
The SET NOT NULL
bug is due to the fact that we're not handling NOT NULL constraints here. This needs an extra case:
case sqlbase.ConstraintToUpdate_NOT_NULL:
// NOT NULL constraints are always validated before they can be added
constraintsToAddBeforeValidation = append(constraintsToAddBeforeValidation, *t.Constraint)
constraintsToValidate = append(constraintsToValidate, *t.Constraint)
pkg/sql/logictest/testdata/logic_test/alter_table, line 925 at r1 (raw file):
INSERT INTO t VALUES (1), (NULL) # Error no longer occurs, EXPECTED?
This is a real failure, related to the fact that SET NOT NULL
goes through much of the same path as check constraints. (See the comment in backfill.go)
pkg/sql/logictest/testdata/logic_test/alter_table, line 985 at r1 (raw file):
query I SELECT * FROM t
The select statement isn't really necessary here.
pkg/sql/logictest/testdata/logic_test/alter_table, line 1003 at r1 (raw file):
SHOW CONSTRAINTS FROM t ---- t check_a CHECK CHECK (a < 100) true
These tests are failing because we recently changed the formatting for check constraints in the output of SHOW CONSTRAINTS
. They should have two sets of parentheses (see #38318 or earlier in this file for examples).
pkg/sql/sqlbase/structured.go, line 2388 at r1 (raw file):
} default: return errors.AssertionFailedf("impossible constraint validity state: %d", t.Constraint.Check.Validity)
nit: this should probably say "invalid" instead of "impossible"
pkg/sql/sqlbase/structured.go, line 2424 at r1 (raw file):
} // AddCheckMutation adds a check constraint validation mutation to desc.Mutations.
The word validation
shouldn't be here anymore
df20d1d
to
96dcc88
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @lucy-zhang)
.gitignore, line 19 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
This shouldn't be here
Done.
pkg/sql/backfill.go, line 165 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
Can you add a TODO comment either here or in alter_table.go indicating that we don't yet support adding NOT VALID foreign keys, because we don't add those FK mutations?
Done.
pkg/sql/backfill.go, line 169 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
The
SET NOT NULL
bug is due to the fact that we're not handling NOT NULL constraints here. This needs an extra case:case sqlbase.ConstraintToUpdate_NOT_NULL: // NOT NULL constraints are always validated before they can be added constraintsToAddBeforeValidation = append(constraintsToAddBeforeValidation, *t.Constraint) constraintsToValidate = append(constraintsToValidate, *t.Constraint)
Done.
pkg/sql/logictest/testdata/logic_test/alter_table, line 925 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
This is a real failure, related to the fact that
SET NOT NULL
goes through much of the same path as check constraints. (See the comment in backfill.go)
Done.
pkg/sql/logictest/testdata/logic_test/alter_table, line 985 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
The select statement isn't really necessary here.
Done.
pkg/sql/logictest/testdata/logic_test/alter_table, line 1003 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
These tests are failing because we recently changed the formatting for check constraints in the output of
SHOW CONSTRAINTS
. They should have two sets of parentheses (see #38318 or earlier in this file for examples).
Done.
pkg/sql/sqlbase/structured.go, line 2424 at r1 (raw file):
Previously, lucy-zhang (Lucy Zhang) wrote…
The word
validation
shouldn't be here anymore
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one typo
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @lucy-zhang and @tyler314)
pkg/sql/backfill.go, line 165 at r2 (raw file):
constraintsToValidate = append(constraintsToValidate, *t.Constraint) } // TODO (tyler): we do not yet support teh NOT VALID foreign keys,
s/teh/the
96dcc88
to
a5317d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @lucy-zhang and @tyler314)
bors r+ |
38377: sql: fix double-adding FK backreferences when retrying r=lucy-zhang a=lucy-zhang Currently, `PublishMultiple()` on the lease manager, which updates multiple table descriptors in a single transaction as part of a schema change, updates each table descriptor independently of the others. There was a bug where if the call to `PublishMultiple()` to add FKs and backreferences was retried (e.g., if there was a crash after this step but before the finalization of the schema change), we would correctly avoid re-adding the reference to the table, but the backreferences would be incorrectly added a second time. This change updates the interface of `PublishMultiple()`: There's now a single update closure which has access to a map of all table descriptors being modified. Backreferences are now only installed if the forward reference was also installed. Release note: None 38382: sql: add support for NOT VALID check constraints r=Tyler314 a=Tyler314 Mark constraint as unvalidated if user specifies NOT VALID in their check constraint. Within backfill, do not add the unvalidated constraints to the queues for validating. Release note (sql change): Support NOT VALID for check constraints, which supports not checking constraints for existing rows. Co-authored-by: Lucy Zhang <[email protected]> Co-authored-by: Tyler314 <[email protected]>
Build failed (retrying...) |
Build failed |
Mark constraint as unvalidated if user specifies NOT VALID in their check constraint. Within backfill, do not add the unvalidated constraints to the queues for validating. Release note (sql change): Support NOT VALID for check constraints, which supports not checking constraints for existing rows.
a5317d3
to
716f0fd
Compare
bors r+ |
38382: sql: add support for NOT VALID check constraints r=Tyler314 a=Tyler314 Mark constraint as unvalidated if user specifies NOT VALID in their check constraint. Within backfill, do not add the unvalidated constraints to the queues for validating. Release note (sql change): Support NOT VALID for check constraints, which supports not checking constraints for existing rows. Co-authored-by: Tyler314 <[email protected]>
Build succeeded |
Mark constraint as unvalidated if user specifies NOT VALID in their
check constraint. Within backfill, do not add the unvalidated constraints
to the queues for validating.
Release note (sql change): Support NOT VALID for check constraints,
which supports not checking constraints for existing rows.