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

Document auto-validation of foreign keys #5690

Closed
wants to merge 1 commit into from

Conversation

jseldess
Copy link
Contributor

@jseldess jseldess commented Oct 25, 2019

Fixes #4891.
Fixes #5187.

@jseldess jseldess requested a review from thoszhang October 25, 2019 03:16
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link

@thoszhang thoszhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jseldess and @lucy-zhang)


v19.2/validate-constraint.md, line 9 at r1 (raw file):

The `VALIDATE CONSTRAINT` [statement](sql-statements.html) is part of `ALTER TABLE` and checks whether values in a column match a [constraint](constraints.html) on the column. This statement is especially useful after applying a constraint to an existing column via [`ADD CONSTRAINT`](add-constraint.html). In this case, `VALIDATE CONSTRAINT` can be used to find values already in the column that do not match the constraint.

<span class="version-tag">New in v19.2:</span> Applying a foreign key constraint via `ADD CONSTRANT` now validates existing rows in addition to enforcing conformance for new rows. As such, it is no longer necessary to use [`VALIDATE CONSTRAINT`](validate-constraint.html) for foreign keys.

CONSTRAINT


v19.2/validate-constraint.md, line 40 at r1 (raw file):

{% include copy-clipboard.html %}
~~~ sql
> ALTER TABLE orders ADD CONSTRAINT check_id_non_zero CHECK (id > 0);

Check constraints are also validated when added. As of 19.2, the only reason to use VALIDATE CONSTRAINT is to validate check/FK constraints that were added as NOT VALID (or were added in an earlier version of Cockroach). The example as it existed before could still work with NOT VALID.

(We didn't add full support for NOT VALID until 19.2, so as far as I know there's no existing documentation for that.)

Copy link
Contributor Author

@jseldess jseldess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @lucy-zhang)


v19.2/validate-constraint.md, line 9 at r1 (raw file):

Previously, lucy-zhang (Lucy Zhang) wrote…

CONSTRAINT

Done.


v19.2/validate-constraint.md, line 40 at r1 (raw file):

Previously, lucy-zhang (Lucy Zhang) wrote…

Check constraints are also validated when added. As of 19.2, the only reason to use VALIDATE CONSTRAINT is to validate check/FK constraints that were added as NOT VALID (or were added in an earlier version of Cockroach). The example as it existed before could still work with NOT VALID.

(We didn't add full support for NOT VALID until 19.2, so as far as I know there's no existing documentation for that.)

Ah, ok. Then I should handle that change as part of this PR as well. I'll ping you when that's ready.

@RaduBerinde RaduBerinde self-requested a review December 10, 2019 18:45
@RaduBerinde RaduBerinde force-pushed the add-constraint-validates branch from 14e68c9 to cda3ce4 Compare December 10, 2019 20:49
@RaduBerinde
Copy link
Member

@jseldess @lucy-zhang I updated the PR to include more information on unvalidated constraints. I will open a separate PR to fix the ADD CONSTRAINT diagram to include opt_validate_behavior (see cockroachdb/cockroach#43087).

@RaduBerinde RaduBerinde force-pushed the add-constraint-validates branch from cda3ce4 to 6d4f05c Compare December 10, 2019 21:13
@RaduBerinde
Copy link
Member

I will incorporate an updated diagram for add constraint (cockroachdb/cockroach#43087). I think I also need to do a bit more work on the 20.1 version - should I remove the "new in 19.2" in that version?

@RaduBerinde RaduBerinde force-pushed the add-constraint-validates branch from 6d4f05c to 40c3ae0 Compare December 11, 2019 16:30
@jseldess
Copy link
Contributor Author

@ericharmeling, I'll close this, since I expect you'll want a clean start on #5187 and #4891.

@jseldess jseldess closed this May 29, 2021
@lnhsingh lnhsingh deleted the add-constraint-validates branch June 23, 2022 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants