Skip to content

Commit 115fd86

Browse files
frouiouirvrangel
authored andcommitted
Use proper keyspace when updating the query graph of a reference DML (vitessio#17226)
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr> Signed-off-by: Renan Rangel <rrangel@slack-corp.com>
1 parent 3c31991 commit 115fd86

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

go/test/endtoend/vtgate/queries/reference/reference_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,12 @@ func TestMultiReferenceQuery(t *testing.T) {
171171

172172
utils.Exec(t, conn, query)
173173
}
174+
175+
func TestDMLReferenceUsingShardedKS(t *testing.T) {
176+
utils.SkipIfBinaryIsBelowVersion(t, 22, "vtgate")
177+
conn, closer := start(t)
178+
defer closer()
179+
180+
utils.Exec(t, conn, "use sks")
181+
utils.Exec(t, conn, "update zip_detail set zip_id = 1 where id = 1")
182+
}

go/vt/vtgate/planbuilder/operators/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func updateQueryGraphWithSource(ctx *plancontext.PlanningContext, input Operator
328328
if tbl.ID != tblID {
329329
continue
330330
}
331-
tbl.Alias = sqlparser.NewAliasedTableExpr(sqlparser.NewTableName(vTbl.Name.String()), tbl.Alias.As.String())
331+
tbl.Alias = sqlparser.NewAliasedTableExpr(sqlparser.NewTableNameWithQualifier(vTbl.Name.String(), vTbl.Keyspace.Name), tbl.Alias.As.String())
332332
tbl.Table, _ = tbl.Alias.TableName()
333333
}
334334
return op, Rewrote("change query table point to source table")

go/vt/vtgate/planbuilder/plan_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ func (s *planTestSuite) TestWithUserDefaultKeyspaceFromFileSharded() {
557557
}
558558

559559
s.testFile("select_cases_with_user_as_default.json", vschema, false)
560+
s.testFile("dml_cases_with_user_as_default.json", vschema, false)
560561
}
561562

562563
func (s *planTestSuite) TestWithSystemSchemaAsDefaultKeyspace() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"comment": "Update reference table from sharded keyspace to unsharded keyspace",
4+
"query": "update ambiguous_ref_with_source set done = true where id = 1;",
5+
"plan": {
6+
"QueryType": "UPDATE",
7+
"Original": "update ambiguous_ref_with_source set done = true where id = 1;",
8+
"Instructions": {
9+
"OperatorType": "Update",
10+
"Variant": "Unsharded",
11+
"Keyspace": {
12+
"Name": "main",
13+
"Sharded": false
14+
},
15+
"TargetTabletType": "PRIMARY",
16+
"Query": "update ambiguous_ref_with_source set done = true where id = 1",
17+
"Table": "ambiguous_ref_with_source"
18+
},
19+
"TablesUsed": [
20+
"main.ambiguous_ref_with_source"
21+
]
22+
}
23+
}
24+
]

0 commit comments

Comments
 (0)