Skip to content

Commit

Permalink
[release-19.0] Fix routing rule query rewrite (#15253) (#15259)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Co-authored-by: Harshit Gangal <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
  • Loading branch information
4 people authored Feb 16, 2024
1 parent 576e2b6 commit 602e243
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
1 change: 1 addition & 0 deletions go/vt/vtgate/planbuilder/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (r *rewriter) rewriteDown(cursor *sqlparser.Cursor) bool {
node.As = tableName.Name
}
// replace the table name with the original table
tableName.Qualifier = sqlparser.IdentifierCS{}
tableName.Name = vindexTable.Name
node.Expr = tableName
}
Expand Down
73 changes: 73 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/dml_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -5550,5 +5550,78 @@
"user.user"
]
}
},
{
"comment": "Delete with routed table on music",
"query": "delete from second_user.bar",
"plan": {
"QueryType": "DELETE",
"Original": "delete from second_user.bar",
"Instructions": {
"OperatorType": "Delete",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"TargetTabletType": "PRIMARY",
"KsidLength": 1,
"KsidVindex": "user_index",
"OwnedVindexQuery": "select user_id, id from music as bar for update",
"Query": "delete from music as bar",
"Table": "music"
},
"TablesUsed": [
"user.music"
]
}
},
{
"comment": "Update with routed table on music",
"query": "update second_user.bar set col = 23",
"plan": {
"QueryType": "UPDATE",
"Original": "update second_user.bar set col = 23",
"Instructions": {
"OperatorType": "Update",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"TargetTabletType": "PRIMARY",
"Query": "update music as bar set col = 23",
"Table": "music"
},
"TablesUsed": [
"user.music"
]
}
},
{
"comment": "Insert with routed table on music",
"query": "insert into second_user.bar(id) values (2)",
"plan": {
"QueryType": "INSERT",
"Original": "insert into second_user.bar(id) values (2)",
"Instructions": {
"OperatorType": "Insert",
"Variant": "Sharded",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"TargetTabletType": "PRIMARY",
"Query": "insert into music(id, user_id) values (:_id_0, :_user_id_0)",
"TableName": "music",
"VindexValues": {
"music_user_map": "2",
"user_index": "null"
}
},
"TablesUsed": [
"user.music"
]
}
}
]
22 changes: 22 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/select_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,28 @@
]
}
},
{
"comment": "routing table on music",
"query": "select * from second_user.bar where id > 2",
"plan": {
"QueryType": "SELECT",
"Original": "select * from second_user.bar where id > 2",
"Instructions": {
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select * from music as bar where 1 != 1",
"Query": "select * from music as bar where id > 2",
"Table": "music"
},
"TablesUsed": [
"user.music"
]
}
},
{
"comment": "testing SingleRow Projection",
"query": "select 42",
Expand Down
9 changes: 7 additions & 2 deletions go/vt/vtgate/planbuilder/testdata/vschemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"user.user"
]
},
{
"from_table": "second_user.bar",
"to_tables": [
"user.music"
]
},
{
"from_table": "primary_redirect@primary",
"to_tables": [
Expand Down Expand Up @@ -508,8 +514,7 @@
"sharded": true,
"vindexes": {
"hash_dup": {
"type": "hash_test",
"owner": "user"
"type": "hash_test"
}
},
"tables": {
Expand Down

0 comments on commit 602e243

Please sign in to comment.