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

planner: make clear for MaybeOverOptimized4PlanCache #29782

Merged
merged 13 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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 expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,9 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
} else {
return args
}
} else if ctx.GetSessionVars().StmtCtx.MaybeOverOptimized4PlanCache {
// We should remove the mutable constant for correctness, because it's value maybe changed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's value maybe -> its value may be

RemoveMutableConst(ctx, args)
}
// int non-constant [cmp] non-int constant
if arg0IsInt && !arg0IsCon && !arg1IsInt && arg1IsCon {
Expand Down
7 changes: 1 addition & 6 deletions expression/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,12 +920,7 @@ func ContainCorrelatedColumn(exprs []Expression) bool {
// TODO: Do more careful check here.
func MaybeOverOptimized4PlanCache(ctx sessionctx.Context, exprs []Expression) bool {
// If we do not enable plan cache, all the optimization can work correctly.
if !ctx.GetSessionVars().StmtCtx.UseCache {
return false
}
if ctx.GetSessionVars().StmtCtx.MaybeOverOptimized4PlanCache {
// If the current statement can not be cached. We should remove the mutable constant.
RemoveMutableConst(ctx, exprs)
if !ctx.GetSessionVars().StmtCtx.UseCache || ctx.GetSessionVars().StmtCtx.MaybeOverOptimized4PlanCache {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be more readable if we change StmtCtx.MaybeOverOptimized4PlanCache to SkipPlanCache? Since we will since plan-cache, we can return false here so that other optimizations can continue.

return false
}
return containMutableConst(ctx, exprs)
Expand Down
3 changes: 3 additions & 0 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,9 @@ func (er *expressionRewriter) inToExpression(lLen int, not bool, tp *types.Field
} else {
continue
}
} else if er.sctx.GetSessionVars().StmtCtx.MaybeOverOptimized4PlanCache {
// We should remove the mutable constant for correctness, because it's value maybe changed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's value maybe -> its value may be

expression.RemoveMutableConst(er.sctx, []expression.Expression{c})
}
args[i], isExceptional = expression.RefineComparedConstant(er.sctx, *leftFt, c, opcode.EQ)
if isExceptional {
Expand Down