зеркало из https://github.com/github/vitess-gh.git
* BugFix: Unsharded query using a derived table and a dual table (#12484) * test: add failing test for a query in an unsharded keyspace using a derived table and reference table Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: fix logic to check if a single unsharded keyspace is used Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: fix test output Signed-off-by: Manan Gupta <manan@planetscale.com> --------- Signed-off-by: Manan Gupta <manan@planetscale.com> * feat: remove test files Signed-off-by: Manan Gupta <manan@planetscale.com> --------- Signed-off-by: Manan Gupta <manan@planetscale.com>
This commit is contained in:
Родитель
b55eae3b93
Коммит
9f173734bb
|
@ -7870,5 +7870,43 @@
|
|||
"main.dual"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"comment": "query with a derived table and dual table in unsharded keyspace",
|
||||
"query": "SELECT * FROM unsharded_a AS t1 JOIN (SELECT trim((SELECT MAX(name) FROM unsharded_a)) AS name) AS t2 WHERE t1.name >= t2.name ORDER BY t1.name ASC LIMIT 1;",
|
||||
"v3-plan": {
|
||||
"QueryType": "SELECT",
|
||||
"Original": "SELECT * FROM unsharded_a AS t1 JOIN (SELECT trim((SELECT MAX(name) FROM unsharded_a)) AS name) AS t2 WHERE t1.name >= t2.name ORDER BY t1.name ASC LIMIT 1;",
|
||||
"Instructions": {
|
||||
"OperatorType": "Route",
|
||||
"Variant": "Unsharded",
|
||||
"Keyspace": {
|
||||
"Name": "main",
|
||||
"Sharded": false
|
||||
},
|
||||
"FieldQuery": "select * from unsharded_a as t1 join (select trim((select max(`name`) from unsharded_a where 1 != 1)) as `name` from dual where 1 != 1) as t2 where 1 != 1",
|
||||
"Query": "select * from unsharded_a as t1 join (select trim((select max(`name`) from unsharded_a)) as `name` from dual) as t2 where t1.`name` >= t2.`name` order by t1.`name` asc limit 1",
|
||||
"Table": "unsharded_a, dual"
|
||||
}
|
||||
},
|
||||
"gen4-plan": {
|
||||
"QueryType": "SELECT",
|
||||
"Original": "SELECT * FROM unsharded_a AS t1 JOIN (SELECT trim((SELECT MAX(name) FROM unsharded_a)) AS name) AS t2 WHERE t1.name >= t2.name ORDER BY t1.name ASC LIMIT 1;",
|
||||
"Instructions": {
|
||||
"OperatorType": "Route",
|
||||
"Variant": "Unsharded",
|
||||
"Keyspace": {
|
||||
"Name": "main",
|
||||
"Sharded": false
|
||||
},
|
||||
"FieldQuery": "select * from unsharded_a as t1 join (select trim((select max(`name`) from unsharded_a where 1 != 1)) as `name` from dual where 1 != 1) as t2 where 1 != 1",
|
||||
"Query": "select * from unsharded_a as t1 join (select trim((select max(`name`) from unsharded_a)) as `name` from dual) as t2 where t1.`name` >= t2.`name` order by t1.`name` asc limit 1",
|
||||
"Table": "dual, unsharded_a"
|
||||
},
|
||||
"TablesUsed": [
|
||||
"main.dual",
|
||||
"main.unsharded_a"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
|
@ -372,7 +372,7 @@ func (st *SemTable) SingleUnshardedKeyspace() (*vindexes.Keyspace, []*vindexes.T
|
|||
for _, table := range st.Tables {
|
||||
vindexTable := table.GetVindexTable()
|
||||
|
||||
if vindexTable == nil || vindexTable.Type != "" {
|
||||
if vindexTable == nil {
|
||||
_, isDT := table.getExpr().Expr.(*sqlparser.DerivedTable)
|
||||
if isDT {
|
||||
// derived tables are ok, as long as all real tables are from the same unsharded keyspace
|
||||
|
@ -381,6 +381,13 @@ func (st *SemTable) SingleUnshardedKeyspace() (*vindexes.Keyspace, []*vindexes.T
|
|||
}
|
||||
return nil, nil
|
||||
}
|
||||
if vindexTable.Type != "" {
|
||||
// A reference table is not an issue when seeing if a query is going to an unsharded keyspace
|
||||
if vindexTable.Type == vindexes.TypeReference {
|
||||
continue
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
name, ok := table.getExpr().Expr.(sqlparser.TableName)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
|
|
Загрузка…
Ссылка в новой задаче