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
Changes from 1 commit
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
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
}