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

[release-19.0] Fix routing rule query rewrite (#15253) #15259

Merged
merged 1 commit into from
Feb 16, 2024
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
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
Loading