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

Update Cascade Planning leading to Foreign key constraint verification #13902

Merged
merged 15 commits into from
Sep 8, 2023

Conversation

GuptaManan100
Copy link
Member

@GuptaManan100 GuptaManan100 commented Aug 31, 2023

Description

This PR adds two planning support

  • FK Cascade that validates that value exists on the parent table.
  • FK Restrict that validates that the value does not exist on the child table.

Related Issue(s)

Checklist

  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Aug 31, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Aug 31, 2023
@github-actions github-actions bot added this to the v18.0.0 milestone Aug 31, 2023
@harshit-gangal harshit-gangal added Type: Feature Component: Query Serving and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request labels Sep 5, 2023
@harshit-gangal harshit-gangal marked this pull request as ready for review September 6, 2023 04:54
Comment on lines +494 to +497
// Each child foreign key constraint is verified by a join query of the form:
// select 1 from child_tbl join parent_tbl on <columns in fk> where <clause same as original update> limit 1
// E.g:
// Child (c1, c2) references Parent (p1, p2)
// update Parent set p1 = 1 where id = 1
// verify query:
// select 1 from Child join Parent on Parent.p1 = Child.c1 and Parent.p2 = Child.c2
// where Parent.id = 1 limit 1
func createFkVerifyOpForChildFKForUpdate(ctx *plancontext.PlanningContext, updStmt *sqlparser.Update, cFk vindexes.ChildFKInfo) (ops.Operator, error) {
// ON UPDATE RESTRICT foreign keys that require validation, should only be allowed in the case where we
Copy link
Member

Choose a reason for hiding this comment

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

we should not fail the verify when updating to the same value.

@harshit-gangal harshit-gangal changed the title Fk verify update planning Update Cascade Planning leading to Foreign key constraint verification Sep 7, 2023
{
"comment": "update with fk on cross-shard with a where condition on non-literal value - disallowed",
"query": "update tbl3 set coly = colx + 10 where coly = 10",
"plan": "VT12001: unsupported: foreign keys management at vitess with non-literal values"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can come up with a better error message for this limitation. this one is a little hard to decipher, imho

harshit-gangal and others added 6 commits September 8, 2023 16:56
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
…rimitive for foreign key constraint verification

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
…cks 0 and validate all the foreign keys on vtgate

Signed-off-by: Manan Gupta <manan@planetscale.com>
GuptaManan100 and others added 8 commits September 8, 2023 16:56
Signed-off-by: Manan Gupta <manan@planetscale.com>
…herever required

Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal force-pushed the fk-verify-update-planning branch from b81e8e2 to fa6f6d1 Compare September 8, 2023 16:15
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal merged commit ee77f54 into vitessio:main Sep 8, 2023
@harshit-gangal harshit-gangal deleted the fk-verify-update-planning branch September 8, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants