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

sqlbase: add support for ON DELETE/UPDATE SET DEFAULT actions for FK references #22220

Merged
merged 1 commit into from Jan 31, 2018

Conversation

BramGruneir
Copy link
Member

This change follows the two that added ON DELETE SET NULL and ON UPDATE SET
NULL and reuses the same code paths in the cascader. In this case, instead of
creating a collection of NULLs for Column IDs, the default values are evaluated
and use when creating the updated row.

Again, most of the work was in adding in new tests to ensure that all strange
edge cases were covered.

The addition of SET NULL added the complication of possibly cascading a NULL
value into NOT NULL column. For the addition of SET DEFAULT, a new complication
arose, it is now possible to inadvertently break a UNIQUE constraint. Luckily,
this was being handled correctly and failing the transaction's run batch, but
the errors were left unconverted so by adding in the ConvertBatchError this
edge case was correctly handled.

Similar to with SET NULL, a restriction had to be added to prevent adding a SET
DEFAULT action to a column that doesn't have a default value. While there I
also updated the error produced by the similar SET NULL on a NOT NULL column's
error message to use the tree.ErrString.

Release note (sql change): ON DELETE SET DEFAULT and ON UPDATE SET DEFAULT
foreign key constraints actions are now fully supported

@BramGruneir BramGruneir added this to the 2.0 milestone Jan 30, 2018
@BramGruneir BramGruneir requested review from justinj, knz and a team January 30, 2018 19:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

…references

This change follows the two that added ON DELETE SET NULL and ON UPDATE SET
NULL and reuses the same code paths in the cascader. In this case, instead of
creating a collection of NULLs for Column IDs, the default values are evaluated
and use when creating the updated row.

Again, most of the work was in adding in new tests to ensure that all strange
edge cases were covered.

The addition of SET NULL added the complication of possibly cascading a NULL
value into NOT NULL column. For the addition of SET DEFAULT, a new complication
arose, it is now possible to inadvertently break a UNIQUE constraint. Luckily,
this was being handled correctly and failing the transaction's run batch, but
the errors were left unconverted so by adding in the ConvertBatchError this
edge case was correctly handled.

Similar to with SET NULL, a restriction had to be added to prevent adding a SET
DEFAULT action to a column that doesn't have a default value. While there I
also updated the error produced by the similar SET NULL on a NOT NULL column's
error message to use the tree.ErrString.

Release note (sql change): ON DELETE SET DEFAULT and ON UPDATE SET DEFAULT
foreign key constraints actions are now fully supported
@justinj
Copy link
Contributor

justinj commented Jan 31, 2018

:lgtm: nice!


Review status: 0 of 4 files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

@BramGruneir
Copy link
Member Author

TFTR!

@BramGruneir BramGruneir merged commit 432f0ce into cockroachdb:master Jan 31, 2018
@BramGruneir BramGruneir deleted the cascade-default branch January 31, 2018 14: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.

None yet

3 participants