-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: enhance partition prune when comparing partition key with constant of different types #59155
Open
L-maple
wants to merge
1
commit into
pingcap:master
Choose a base branch
from
L-maple:feature/support_more_types_for_partition_prune
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
planner: enhance partition prune when comparing partition key with constant of different types #59155
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1593,10 +1593,23 @@ func (p *rangePruner) extractDataForPrune(sctx base.PlanContext, expr expression | |
if arg1, ok := op.GetArgs()[1].(*expression.Constant); ok { | ||
col, con = arg0, arg1 | ||
} | ||
} else if arg0, ok := op.GetArgs()[1].(*expression.Column); ok && arg0.ID == p.col.ID { | ||
if arg1, ok := op.GetArgs()[0].(*expression.Constant); ok { | ||
} else if arg1, ok := op.GetArgs()[1].(*expression.Column); ok && arg1.ID == p.col.ID { | ||
if arg0, ok := op.GetArgs()[0].(*expression.Constant); ok { | ||
ret.op = opposite(ret.op) | ||
col, con = arg0, arg1 | ||
col, con = arg1, arg0 | ||
} | ||
} else if sarg0, ok := op.GetArgs()[0].(*expression.ScalarFunction); ok && sarg0.FuncName.L == ast.Cast { | ||
if arg0, ok := sarg0.GetArgs()[0].(*expression.Column); ok && arg0.ID == p.col.ID { | ||
if arg1, ok := op.GetArgs()[1].(*expression.Constant); ok { | ||
col, con = arg0, arg1 | ||
} | ||
} | ||
} else if sarg1, ok := op.GetArgs()[1].(*expression.ScalarFunction); ok && sarg1.FuncName.L == ast.Cast { | ||
if arg1, ok := sarg1.GetArgs()[0].(*expression.Column); ok && arg1.ID == p.col.ID { | ||
if arg0, ok := op.GetArgs()[0].(*expression.Constant); ok { | ||
ret.op = opposite(ret.op) | ||
col, con = arg1, arg0 | ||
} | ||
} | ||
} | ||
if col == nil || con == nil { | ||
|
@@ -1606,6 +1619,14 @@ func (p *rangePruner) extractDataForPrune(sctx base.PlanContext, expr expression | |
// Current expression is 'col op const' | ||
var constExpr expression.Expression | ||
if p.partFn != nil { | ||
// If arg0 or arg1 is ScalarFunction, just skip it. | ||
// Maybe more complicated cases would be considered in the future. | ||
_, ok1 := op.GetArgs()[0].(*expression.ScalarFunction) | ||
_, ok2 := op.GetArgs()[1].(*expression.ScalarFunction) | ||
if ok1 || ok2 { | ||
return ret, false | ||
} | ||
|
||
// If the partition function is not monotone, only EQ condition can be pruning. | ||
if p.monotonous == monotoneModeInvalid && ret.op != ast.EQ { | ||
return ret, false | ||
|
@@ -1626,11 +1647,37 @@ func (p *rangePruner) extractDataForPrune(sctx base.PlanContext, expr expression | |
// If the partition expression is col, use constExpr. | ||
constExpr = con | ||
} | ||
c, isNull, err := constExpr.EvalInt(sctx.GetExprCtx().GetEvalCtx(), chunk.Row{}) | ||
if err == nil && !isNull { | ||
ret.c = c | ||
ret.unsigned = mysql.HasUnsignedFlag(constExpr.GetType(sctx.GetExprCtx().GetEvalCtx()).GetFlag()) | ||
return ret, true | ||
evalType := constExpr.GetType(sctx.GetExprCtx().GetEvalCtx()).EvalType() | ||
if evalType == types.ETInt { | ||
c, isNull, err := constExpr.EvalInt(sctx.GetExprCtx().GetEvalCtx(), chunk.Row{}) | ||
if err == nil && !isNull { | ||
ret.c = c | ||
ret.unsigned = mysql.HasUnsignedFlag(constExpr.GetType(sctx.GetExprCtx().GetEvalCtx()).GetFlag()) | ||
return ret, true | ||
} | ||
} else if evalType == types.ETReal { | ||
f, isNull, err := constExpr.EvalReal(sctx.GetExprCtx().GetEvalCtx(), chunk.Row{}) | ||
c := int64(f) | ||
if err == nil && !isNull { | ||
ret.c = c | ||
ret.unsigned = mysql.HasUnsignedFlag(constExpr.GetType(sctx.GetExprCtx().GetEvalCtx()).GetFlag()) | ||
return ret, true | ||
} | ||
} else if evalType == types.ETDecimal { | ||
d, isNull, err := constExpr.EvalDecimal(sctx.GetExprCtx().GetEvalCtx(), chunk.Row{}) | ||
if err != nil { | ||
return ret, false | ||
} | ||
f, err := d.ToFloat64() | ||
if err != nil { | ||
return ret, false | ||
} | ||
if err == nil && !isNull { | ||
ret.c = int64(f) | ||
ret.unsigned = mysql.HasUnsignedFlag(constExpr.GetType(sctx.GetExprCtx().GetEvalCtx()).GetFlag()) | ||
return ret, true | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above :) |
||
} | ||
return ret, false | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From linting/nogo, you should be able to reproduce these errors with
make bazel_lint
: