-
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: fix expression rewriter wrong compare logic #8269
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,15 +170,11 @@ type expressionRewriter struct { | |
} | ||
|
||
// 1. If op are EQ or NE or NullEQ, constructBinaryOpFunctions converts (a0,a1,a2) op (b0,b1,b2) to (a0 op b0) and (a1 op b1) and (a2 op b2) | ||
// 2. If op are LE or GE, constructBinaryOpFunctions converts (a0,a1,a2) op (b0,b1,b2) to | ||
// `IF( (a0 op b0) EQ 0, 0, | ||
// IF ( (a1 op b1) EQ 0, 0, a2 op b2))` | ||
// 3. If op are LT or GT, constructBinaryOpFunctions converts (a0,a1,a2) op (b0,b1,b2) to | ||
// 2. Else constructBinaryOpFunctions converts (a0,a1,a2) op (b0,b1,b2) to | ||
// `IF( a0 NE b0, a0 op b0, | ||
// IF( a1 NE b1, | ||
// a1 op b1, | ||
// a2 op b2) | ||
// )` | ||
// IF ( (a0 NE b0) EQ Null, Null, | ||
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. s/ (a0 NE b0) EQ Null/ IsNull(a0 NE b0)? |
||
// IF ( a0 NE b0, a1 op b1, | ||
// IF ( (a1 NE b1) EQ Null, Null, a2 op b2))))` | ||
func (er *expressionRewriter) constructBinaryOpFunction(l expression.Expression, r expression.Expression, op string) (expression.Expression, error) { | ||
lLen, rLen := expression.GetRowLen(l), expression.GetRowLen(r) | ||
if lLen == 1 && rLen == 1 { | ||
|
@@ -202,9 +198,10 @@ func (er *expressionRewriter) constructBinaryOpFunction(l expression.Expression, | |
return expression.ComposeCNFCondition(er.ctx, funcs...), nil | ||
default: | ||
larg0, rarg0 := expression.GetFuncArg(l, 0), expression.GetFuncArg(r, 0) | ||
var expr1, expr2, expr3 expression.Expression | ||
var expr1, expr2, expr3, expr4, expr5 expression.Expression | ||
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. Update the comments of this function. 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. ok 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. addressed |
||
expr1 = expression.NewFunctionInternal(er.ctx, ast.NE, types.NewFieldType(mysql.TypeTiny), larg0, rarg0) | ||
expr2 = expression.NewFunctionInternal(er.ctx, op, types.NewFieldType(mysql.TypeTiny), larg0, rarg0) | ||
expr3 = expression.NewFunctionInternal(er.ctx, ast.IsNull, types.NewFieldType(mysql.TypeTiny), expr1) | ||
var err error | ||
l, err = expression.PopRowFirstArg(er.ctx, l) | ||
if err != nil { | ||
|
@@ -214,23 +211,15 @@ func (er *expressionRewriter) constructBinaryOpFunction(l expression.Expression, | |
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
if evalexpr, ok := expr1.(*expression.Constant); ok { | ||
_, isNull, err1 := evalexpr.EvalInt(er.ctx, chunk.Row{}) | ||
if err1 != nil || isNull { | ||
return expr1, err1 | ||
} | ||
} | ||
if evalexpr, ok := expr2.(*expression.Constant); ok { | ||
_, isNull, err1 := evalexpr.EvalInt(er.ctx, chunk.Row{}) | ||
if err1 != nil || isNull { | ||
return expr2, err1 | ||
} | ||
expr4, err = er.constructBinaryOpFunction(l, r, op) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
expr3, err = er.constructBinaryOpFunction(l, r, op) | ||
expr5, err = expression.NewFunction(er.ctx, ast.If, types.NewFieldType(mysql.TypeTiny), expr3, expression.Null, expr4) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
return expression.NewFunction(er.ctx, ast.If, types.NewFieldType(mysql.TypeTiny), expr1, expr2, expr3) | ||
return expression.NewFunction(er.ctx, ast.If, types.NewFieldType(mysql.TypeTiny), expr1, expr2, expr5) | ||
} | ||
} | ||
|
||
|
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.
One tab here may be better?
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.
ok