зеркало из https://github.com/github/vitess-gh.git
v3 proto: keyrange tests for plan building
This commit is contained in:
Родитель
bbbee66eb5
Коммит
fe105a7013
|
@ -110,6 +110,34 @@
|
|||
"Values": 1
|
||||
}
|
||||
|
||||
# update KEYRANGE
|
||||
"update user set val = 1 where keyrange(1, 2)"
|
||||
{
|
||||
"ID": "NoPlan",
|
||||
"Reason": "too complex",
|
||||
"Table": "user",
|
||||
"Original": "update user set val = 1 where keyrange(1, 2)",
|
||||
"Rewritten": "",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": null
|
||||
}
|
||||
|
||||
# delete KEYRANGE
|
||||
"delete from user where keyrange(1, 2)"
|
||||
{
|
||||
"ID": "NoPlan",
|
||||
"Reason": "too complex",
|
||||
"Table": "user",
|
||||
"Original": "delete from user where keyrange(1, 2)",
|
||||
"Rewritten": "",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": null
|
||||
}
|
||||
|
||||
# update with primary id through IN clause
|
||||
"update user set val = 1 where id in (1, 2)"
|
||||
{
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
"Reason":"",
|
||||
"Table": "main1",
|
||||
"Original":"select * from main1",
|
||||
"Rewritten":"select * from main1",
|
||||
"Rewritten":"",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
|
@ -637,6 +637,90 @@
|
|||
"Values": 1
|
||||
}
|
||||
|
||||
# select with KEYRANGE
|
||||
"select * from user where keyrange(1, 2)"
|
||||
{
|
||||
"ID": "SelectKeyrange",
|
||||
"Reason": "",
|
||||
"Table": "user",
|
||||
"Original":"select * from user where keyrange(1, 2)",
|
||||
"Rewritten": "select * from user",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": [1, 2]
|
||||
}
|
||||
|
||||
# select with KEYRANGE parenthesized
|
||||
"select * from user where (keyrange(1, 2))"
|
||||
{
|
||||
"ID": "SelectKeyrange",
|
||||
"Reason": "",
|
||||
"Table": "user",
|
||||
"Original":"select * from user where (keyrange(1, 2))",
|
||||
"Rewritten": "select * from user",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": [1, 2]
|
||||
}
|
||||
|
||||
# select KEYRANGE in AND
|
||||
"select * from user where a = 1 and keyrange(1, 2)"
|
||||
{
|
||||
"ID": "SelectKeyrange",
|
||||
"Reason": "",
|
||||
"Table": "user",
|
||||
"Original":"select * from user where a = 1 and keyrange(1, 2)",
|
||||
"Rewritten": "select * from user where a = 1",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": [1, 2]
|
||||
}
|
||||
|
||||
# select KEYRANGE in AND parenthesized
|
||||
"select * from user where a = 1 and (keyrange(1, 2))"
|
||||
{
|
||||
"ID": "SelectKeyrange",
|
||||
"Reason": "",
|
||||
"Table": "user",
|
||||
"Original":"select * from user where a = 1 and (keyrange(1, 2))",
|
||||
"Rewritten": "select * from user where a = 1",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": [1, 2]
|
||||
}
|
||||
|
||||
# select KEYRANGE in AND double parenthesized
|
||||
"select * from user where a = 1 and ((keyrange(1, 2)))"
|
||||
{
|
||||
"ID": "SelectKeyrange",
|
||||
"Reason": "",
|
||||
"Table": "user",
|
||||
"Original":"select * from user where a = 1 and ((keyrange(1, 2)))",
|
||||
"Rewritten": "select * from user where a = 1",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": [1, 2]
|
||||
}
|
||||
|
||||
# select KEYRANGE in double AND double parenthesized
|
||||
"select * from user where a = 1 and (b = 2 and (keyrange(1, 2)))"
|
||||
{
|
||||
"ID": "SelectKeyrange",
|
||||
"Reason": "",
|
||||
"Table": "user",
|
||||
"Original":"select * from user where a = 1 and (b = 2 and (keyrange(1, 2)))",
|
||||
"Rewritten": "select * from user where a = 1 and (b = 2)",
|
||||
"Subquery": "",
|
||||
"Vindex": "",
|
||||
"Col": "",
|
||||
"Values": [1, 2]
|
||||
}
|
||||
|
||||
# aggregates in select, simple
|
||||
"select count(*) from user where id in (1, 2)"
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@ func buildUpdatePlan(upd *sqlparser.Update, schema *Schema) *Plan {
|
|||
switch plan.ID {
|
||||
case SelectEqual:
|
||||
plan.ID = UpdateEqual
|
||||
case SelectIN, SelectScatter:
|
||||
case SelectIN, SelectScatter, SelectKeyrange:
|
||||
plan.ID = NoPlan
|
||||
plan.Reason = "too complex"
|
||||
return plan
|
||||
|
@ -77,7 +77,7 @@ func buildDeletePlan(del *sqlparser.Delete, schema *Schema) *Plan {
|
|||
case SelectEqual:
|
||||
plan.ID = DeleteEqual
|
||||
plan.Subquery = generateDeleteSubquery(del, plan.Table)
|
||||
case SelectIN, SelectScatter:
|
||||
case SelectIN, SelectScatter, SelectKeyrange:
|
||||
plan.ID = NoPlan
|
||||
plan.Reason = "too complex"
|
||||
default:
|
||||
|
|
|
@ -7,10 +7,7 @@ package planbuilder
|
|||
import "github.com/youtube/vitess/go/vt/sqlparser"
|
||||
|
||||
func buildSelectPlan(sel *sqlparser.Select, schema *Schema) *Plan {
|
||||
plan := &Plan{
|
||||
ID: NoPlan,
|
||||
Rewritten: generateQuery(sel),
|
||||
}
|
||||
plan := &Plan{ID: NoPlan}
|
||||
tablename, _ := analyzeFrom(sel.From)
|
||||
plan.Table, plan.Reason = schema.FindTable(tablename)
|
||||
if plan.Reason != "" {
|
||||
|
@ -28,9 +25,9 @@ func buildSelectPlan(sel *sqlparser.Select, schema *Schema) *Plan {
|
|||
plan.Reason = "too complex"
|
||||
return plan
|
||||
}
|
||||
// The where clause might have changed.
|
||||
plan.Rewritten = generateQuery(sel)
|
||||
}
|
||||
// The where clause might have changed.
|
||||
plan.Rewritten = generateQuery(sel)
|
||||
return plan
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ func hasSubquery(node sqlparser.Expr) bool {
|
|||
return true
|
||||
case sqlparser.StrVal, sqlparser.NumVal, sqlparser.ValArg,
|
||||
*sqlparser.NullVal, *sqlparser.ColName, sqlparser.ValTuple,
|
||||
sqlparser.ListArg:
|
||||
sqlparser.ListArg, *sqlparser.KeyrangeExpr:
|
||||
return false
|
||||
case *sqlparser.Subquery:
|
||||
return true
|
||||
|
|
Загрузка…
Ссылка в новой задаче