-
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, expression: fix simplify outer join with cast #12701
planner, expression: fix simplify outer join with cast #12701
Conversation
/run-unit-test |
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #12701 +/- ##
================================================
- Coverage 79.9122% 79.8713% -0.0409%
================================================
Files 462 462
Lines 105308 104786 -522
================================================
- Hits 84154 83694 -460
Misses 14906 14906
+ Partials 6248 6186 -62 |
expression/expression.go
Outdated
@@ -542,6 +542,9 @@ func EvaluateExprWithNull(ctx sessionctx.Context, schema *Schema, expr Expressio | |||
for i, arg := range x.GetArgs() { | |||
args[i] = EvaluateExprWithNull(ctx, schema, arg) | |||
} | |||
if x.FuncName.L == ast.Cast { | |||
return NewFunctionInternal(ctx, x.FuncName.L, x.RetType, args...) | |||
} | |||
return NewFunctionInternal(ctx, x.FuncName.L, types.NewFieldType(mysql.TypeTiny), args...) |
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.
Did you try to only change this line to NewFunctionInternal(ctx, x.FuncName.L, x.RetType, args...)
?
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.
I've tried, and it can pass all the tests :)
However, according to this line, it is possible that RetType cannot be overwritten by builtinRetTp. I don't know the exact reason why using mysql.TypeTiny as the default type, but in order to reduce the potential risks, I kept the original logic, that is, use mysql.TypeTiny as the default type.
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.
That line won't affect x.RetType
.
*retType = *builtinRetTp
would affect.
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.
In this scalar function, when f.getRetTp() is mysql.TypeUnspecified, sf.RetType is mysql.TypeTiny, instead of mysql.TypeUnspecified.
If we change this line to NewFunctionInternal(ctx, x.FuncName.L, x.RetType, args...)
, sf.RetType may not be mysql.TypeTiny anymore when f.getRetTp() is mysql.TypeUnspecified. I'm not sure if this change has bad influence.
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.
This method just subsitute some columns with NULLs. Use original type should not be worse.
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.
Applied, thanks!
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.
lgtm
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.
LGTM
/run-all-tests |
cherry pick to release-3.1 in PR #12720 |
cherry pick to release-3.0 in PR #12721 |
cherry pick to release-2.1 failed |
@justarandomstring |
@winoros No problem. I'll do it in a few days. |
Conflicts: planner/core/integration_test.go
What problem does this PR solve?
Before this PR, left outer join was incorrectly simplified into inner join:
After this PR:
What is changed and how it works?
Handle ScalarFunction Cast in a different logic in
EvaluateExprWithNull
.Before this PR, the following code is part of how
EvaluateExprWithNull
handles ScalarFunction.This line will set the default RetType of ScarlarFunction into mysql.TypeTiny. For those ScalarFunctions other than Cast, RetType can be determined correctly as it will be recalcuated in
NewFunctionImpl
. However, when handling Cast,newFunctionImpl
simply pass RetType toBuildCastFunction
without any other processing, which may lead a wrong RetType.In the example, the Cast is
CastStringToIntSig
before this PR instead ofCastStringToStringSig
, which it supposed to be.Check List
Tests
Code changes
Side effects
Related changes
Release note