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

Gen4: query timeout in comment directive #9008

Merged
merged 2 commits into from
Oct 18, 2021
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
3 changes: 3 additions & 0 deletions go/vt/vtgate/engine/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ func (route *Route) description() PrimitiveDescription {
if route.ScatterErrorsAsWarnings {
other["ScatterErrorsAsWarnings"] = true
}
if route.QueryTimeout > 0 {
other["QueryTimeout"] = route.QueryTimeout
}
return PrimitiveDescription{
OperatorType: "Route",
Variant: routeName[route.Opcode],
Expand Down
33 changes: 24 additions & 9 deletions go/vt/vtgate/planbuilder/gen4_planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,9 @@ func newBuildSelectPlan(selStmt sqlparser.SelectStatement, reservedVars *sqlpars
return nil, err
}

directives := sqlparser.ExtractCommentDirectives(sqlparser.GetFirstSelect(selStmt).Comments)
if directives.IsSet(sqlparser.DirectiveScatterErrorsAsWarnings) {
_, _ = visit(plan, func(logicalPlan logicalPlan) (bool, logicalPlan, error) {
switch plan := logicalPlan.(type) {
case *route:
plan.eroute.ScatterErrorsAsWarnings = true
}
return true, logicalPlan, nil
})
plan, err = pushCommentDirectivesOnPlan(plan, selStmt)
if err != nil {
return nil, err
}

return plan, nil
Expand Down Expand Up @@ -270,3 +264,24 @@ func planOrderByOnUnion(ctx *planningContext, plan logicalPlan, union *sqlparser
}
return plan, nil
}

func pushCommentDirectivesOnPlan(plan logicalPlan, stmt sqlparser.SelectStatement) (logicalPlan, error) {
directives := sqlparser.ExtractCommentDirectives(sqlparser.GetFirstSelect(stmt).Comments)
scatterAsWarns := false
if directives.IsSet(sqlparser.DirectiveScatterErrorsAsWarnings) {
scatterAsWarns = true
}
queryTimeout := queryTimeout(directives)
if scatterAsWarns || queryTimeout > 0 {
_, _ = visit(plan, func(logicalPlan logicalPlan) (bool, logicalPlan, error) {
switch plan := logicalPlan.(type) {
case *route:
plan.eroute.ScatterErrorsAsWarnings = scatterAsWarns
plan.eroute.QueryTimeout = queryTimeout
}
return true, logicalPlan, nil
})
}

return plan, nil
}
5 changes: 5 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/select_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Gen4 plan same as above
},
"FieldQuery": "select * from `user` where 1 != 1",
"Query": "select /*vt+ QUERY_TIMEOUT_MS=1000 */ * from `user`",
"QueryTimeout": 1000,
"Table": "`user`"
}
}
Expand All @@ -93,6 +94,7 @@ Gen4 plan same as above
},
"FieldQuery": "select count(*) from `user` where 1 != 1",
"Query": "select /*vt+ QUERY_TIMEOUT_MS=1000 */ count(*) from `user`",
"QueryTimeout": 1000,
"Table": "`user`"
}
]
Expand All @@ -115,6 +117,7 @@ Gen4 plan same as above
},
"FieldQuery": "select count(*) from `user` where 1 != 1",
"Query": "select /*vt+ QUERY_TIMEOUT_MS=1000 */ count(*) from `user`",
"QueryTimeout": 1000,
"Table": "`user`"
}
]
Expand All @@ -139,6 +142,7 @@ Gen4 plan same as above
},
"FieldQuery": "select * from `user` where 1 != 1",
"Query": "select /*vt+ QUERY_TIMEOUT_MS=1000 */ * from `user` limit :__upper_limit",
"QueryTimeout": 1000,
"Table": "`user`"
}
]
Expand Down Expand Up @@ -1597,6 +1601,7 @@ Gen4 plan same as above
},
"FieldQuery": "select * from unsharded as route2 where 1 != 1",
"Query": "select /*vt+ QUERY_TIMEOUT_MS=1000 */ * from unsharded as route2",
"QueryTimeout": 1000,
"Table": "unsharded"
}
}
Expand Down