-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Foreign key cascade planning for DELETE and UPDATE queries #13823
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
Changes from all commits
23bfeb3
eefc89c
4a82709
272ec1d
836c04c
5f6a3cc
f6e6789
c02be0a
a554bfb
2c7fdc7
06d73ec
af323bb
124b458
8d25546
22797fd
91ec17f
effb8d4
20ac58a
dac40bf
20eb4cf
d1b9756
4182593
c70dc24
7e589ed
21f7aa5
4220c51
928c1ae
caefaca
f15fb52
f92561a
c81f64e
6a722e9
d6b025b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| create table u_t1 | ||
| ( | ||
| id bigint, | ||
| col1 bigint, | ||
| index(col1), | ||
| primary key (id) | ||
| ) Engine = InnoDB; | ||
|
|
||
| create table u_t2 | ||
| ( | ||
| id bigint, | ||
| col2 bigint, | ||
| primary key (id), | ||
| foreign key (col2) references u_t1 (col1) on delete set null on update set null | ||
| ) Engine = InnoDB; | ||
|
|
||
| create table u_t3 | ||
| ( | ||
| id bigint, | ||
| col3 bigint, | ||
| primary key (id), | ||
| foreign key (col3) references u_t1 (col1) on delete cascade on update cascade | ||
| ) Engine = InnoDB; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "sharded": false, | ||
| "foreignKeyMode": "FK_MANAGED", | ||
| "tables": { | ||
| "u_a": {}, | ||
| "u_b": {} | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ type FkCascade struct { | |
| // Selection is the Primitive that is used to find the rows that are going to be modified in the child tables. | ||
| Selection Primitive | ||
| // Children is a list of child foreign key Primitives that are executed using rows from the Selection Primitive. | ||
| Children []FkChild | ||
| Children []*FkChild | ||
| // Parent is the Primitive that is executed after the children are modified. | ||
| Parent Primitive | ||
|
|
||
|
|
@@ -168,17 +168,30 @@ func (fkc *FkCascade) TryStreamExecute(ctx context.Context, vcursor VCursor, bin | |
|
|
||
| // Inputs implements the Primitive interface. | ||
| func (fkc *FkCascade) Inputs() []Primitive { | ||
| inputs := []Primitive{fkc.Selection} | ||
| for _, child := range fkc.Children { | ||
| inputs = append(inputs, child.Exec) | ||
| } | ||
| inputs = append(inputs, fkc.Parent) | ||
| return inputs | ||
| return nil | ||
| } | ||
|
|
||
| func (fkc *FkCascade) description() PrimitiveDescription { | ||
| var childrenDesc []PrimitiveDescription | ||
| for _, child := range fkc.Children { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need to visit children here. this is done outside, from the caller of this method
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't put the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed it offline, and we'll change this. cc - @harshit-gangal |
||
| childrenDesc = append(childrenDesc, PrimitiveDescription{ | ||
| OperatorType: "FkCascadeChild", | ||
| Inputs: []PrimitiveDescription{ | ||
| PrimitiveToPlanDescription(child.Exec), | ||
| }, | ||
| Other: map[string]any{ | ||
| "BvName": child.BVName, | ||
| "Cols": child.Cols, | ||
| }, | ||
| }) | ||
| } | ||
| return PrimitiveDescription{ | ||
| OperatorType: fkc.RouteType(), | ||
| Other: map[string]any{ | ||
| "Selection": PrimitiveToPlanDescription(fkc.Selection), | ||
| "Parent": PrimitiveToPlanDescription(fkc.Parent), | ||
| "Children": childrenDesc, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.