-
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: support adding a column with a check constraint in same txn #33593
Labels
Comments
thoszhang
pushed a commit
to eriktrinh/cockroach
that referenced
this issue
Jan 9, 2019
This change moves check constraint adds and drops through the schema changer when the transaction commits, moving the constraint through the same intermediate states as when index/columns are added or dropped. The only small differences are: - Constraint adds can start in write-only and immediately start being enforced if all used columns are in write-only or public. - Constraint drops can move immediately from public to absent if they have not yet been validated. Therefore, the check constraint is no longer immediately public when it is added, but allows data validation of the constraint to be performed when the constraint is added (and is now the default behaviour). Constraints can now also be added on columns in the process of being added. This change also ensures that there are no data anomalies in either versions of the schema when dropping a validated check constraint, as previously the transition moved the constraint from public -> absent. Writes on the new version were not being checked even though nodes on an older version expect all rows to conform to the constraint. Fixes cockroachdb#33593. See also cockroachdb#33550. Release note (sql change): Check constraint adds by default will validate table data with the added constraint asynchronously after the transaction commits.
thoszhang
pushed a commit
to eriktrinh/cockroach
that referenced
this issue
Jan 10, 2019
This change moves check constraint adds and drops through the schema changer when the transaction commits, moving the constraint through the same intermediate states as when index/columns are added or dropped. The only small differences are: - Constraint adds can start in write-only and immediately start being enforced if all used columns are in write-only or public. - Constraint drops can move immediately from public to absent if they have not yet been validated. Therefore, the check constraint is no longer immediately public when it is added, but allows data validation of the constraint to be performed when the constraint is added (and is now the default behaviour). Constraints can now also be added on columns in the process of being added. This change also ensures that there are no data anomalies in either versions of the schema when dropping a validated check constraint, as previously the transition moved the constraint from public -> absent. Writes on the new version were not being checked even though nodes on an older version expect all rows to conform to the constraint. Fixes cockroachdb#33593. See also cockroachdb#33550. Release note (sql change): Check constraint adds by default will validate table data with the added constraint asynchronously after the transaction commits.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, adding a column and adding a check constraint on that column within the same transaction is not supported:
We should support adding a constraint on the column that's being added. Additionally, we should validate the new constraint on the new column's default values, if applicable (as in the example above), and fail the transaction if validation fails.
This issue is being filed to track progress on #32504 (see the new logic tests for more examples). #33550 is a related issue.
The text was updated successfully, but these errors were encountered: