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

Foreign key cascade: retain "for update" lock on select query plans #13985

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go/vt/vtgate/planbuilder/dml_planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func setLockOnAllSelect(plan logicalPlan) {
_, _ = visit(plan, func(plan logicalPlan) (bool, logicalPlan, error) {
switch node := plan.(type) {
case *route:
node.Select.SetLock(sqlparser.ShareModeLock)
if node.Select.GetLock() == sqlparser.NoLock {
node.Select.SetLock(sqlparser.ShareModeLock)
}
return true, node, nil
}
return true, plan, nil
Expand Down
22 changes: 11 additions & 11 deletions go/vt/vtgate/planbuilder/testdata/foreignkey_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"Sharded": true
},
"FieldQuery": "select colb, cola, y, colc, x from multicol_tbl1 where 1 != 1",
"Query": "select colb, cola, y, colc, x from multicol_tbl1 where cola = 1 and colb = 2 and colc = 3 lock in share mode",
"Query": "select colb, cola, y, colc, x from multicol_tbl1 where cola = 1 and colb = 2 and colc = 3 for update",
"Table": "multicol_tbl1",
"Values": [
"INT64(1)",
Expand Down Expand Up @@ -155,7 +155,7 @@
"Sharded": true
},
"FieldQuery": "select col5, t5col5 from tbl5 where 1 != 1",
"Query": "select col5, t5col5 from tbl5 lock in share mode",
"Query": "select col5, t5col5 from tbl5 for update",
"Table": "tbl5"
},
{
Expand Down Expand Up @@ -233,7 +233,7 @@
"Sharded": false
},
"FieldQuery": "select col9 from u_tbl9 where 1 != 1",
"Query": "select col9 from u_tbl9 where col9 = 5 lock in share mode",
"Query": "select col9 from u_tbl9 where col9 = 5 for update",
"Table": "u_tbl9"
},
{
Expand Down Expand Up @@ -312,7 +312,7 @@
"Sharded": false
},
"FieldQuery": "select col2 from u_tbl2 where 1 != 1",
"Query": "select col2 from u_tbl2 where id = 1 lock in share mode",
"Query": "select col2 from u_tbl2 where id = 1 for update",
"Table": "u_tbl2"
},
{
Expand Down Expand Up @@ -423,7 +423,7 @@
"Sharded": true
},
"FieldQuery": "select t5col5 from tbl5 where 1 != 1",
"Query": "select t5col5 from tbl5 lock in share mode",
"Query": "select t5col5 from tbl5 for update",
"Table": "tbl5"
},
{
Expand Down Expand Up @@ -592,7 +592,7 @@
"Sharded": true
},
"FieldQuery": "select col9 from tbl9 where 1 != 1",
"Query": "select col9 from tbl9 where col9 = 34 lock in share mode",
"Query": "select col9 from tbl9 where col9 = 34 for update",
"Table": "tbl9",
"Values": [
"INT64(34)"
Expand Down Expand Up @@ -657,7 +657,7 @@
"Sharded": false
},
"FieldQuery": "select col1, col1 from u_tbl1 where 1 != 1",
"Query": "select col1, col1 from u_tbl1 lock in share mode",
"Query": "select col1, col1 from u_tbl1 for update",
"Table": "u_tbl1"
},
{
Expand Down Expand Up @@ -816,7 +816,7 @@
"Sharded": false
},
"FieldQuery": "select col2 from u_tbl2 where 1 != 1",
"Query": "select col2 from u_tbl2 where id = 1 lock in share mode",
"Query": "select col2 from u_tbl2 where id = 1 for update",
"Table": "u_tbl2"
},
{
Expand Down Expand Up @@ -873,7 +873,7 @@
"Sharded": false
},
"FieldQuery": "select col1, col1 from u_tbl1 where 1 != 1",
"Query": "select col1, col1 from u_tbl1 where id = 1 lock in share mode",
"Query": "select col1, col1 from u_tbl1 where id = 1 for update",
"Table": "u_tbl1"
},
{
Expand Down Expand Up @@ -1112,7 +1112,7 @@
"Sharded": false
},
"FieldQuery": "select col6 from u_tbl6 where 1 != 1",
"Query": "select col6 from u_tbl6 lock in share mode",
"Query": "select col6 from u_tbl6 for update",
"Table": "u_tbl6"
},
{
Expand Down Expand Up @@ -1188,7 +1188,7 @@
"Sharded": false
},
"FieldQuery": "select col7 from u_tbl7 where 1 != 1",
"Query": "select col7 from u_tbl7 lock in share mode",
"Query": "select col7 from u_tbl7 for update",
"Table": "u_tbl7"
},
{
Expand Down
Loading