Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <disxiaofei@163.com>

fix

Signed-off-by: yisaer <disxiaofei@163.com>

Revert "fix"

This reverts commit 14a73794db9fd0eb6f236a063004e7172d1acaa6.

fix

Signed-off-by: yisaer <disxiaofei@163.com>
  • Loading branch information
Yisaer committed Oct 12, 2022
1 parent 9ea964d commit ef36380
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 0 additions & 5 deletions expression/constant_fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ func foldConstant(expr Expression) (Expression, bool) {
if !hasNullArg || !sc.InNullRejectCheck || x.FuncName.L == ast.NullEQ {
return expr, isDeferredConst
}
// For `AND` and `OR`, if any of the arguments is null and not all arguments are constant, then it is unFoldAble.
switch x.FuncName.L {
case ast.LogicAnd, ast.LogicOr:
return expr, isDeferredConst
}
constArgs := make([]Expression, len(args))
for i, arg := range args {
if argIsConst[i] {
Expand Down
19 changes: 15 additions & 4 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,21 +818,32 @@ func EvaluateExprWithNull(ctx sessionctx.Context, schema *Schema, expr Expressio
if MaybeOverOptimized4PlanCache(ctx, []Expression{expr}) {
return expr
}
return evaluateExprWithNull(ctx, schema, expr)
return evaluateExprWithNull(ctx, schema, expr, nil)
}

func evaluateExprWithNull(ctx sessionctx.Context, schema *Schema, expr Expression) Expression {
func evaluateExprWithNull(ctx sessionctx.Context, schema *Schema, expr Expression, parExpr Expression) Expression {
switch x := expr.(type) {
case *ScalarFunction:
args := make([]Expression, len(x.GetArgs()))
for i, arg := range x.GetArgs() {
args[i] = evaluateExprWithNull(ctx, schema, arg)
args[i] = evaluateExprWithNull(ctx, schema, arg, expr)
}
return NewFunctionInternal(ctx, x.FuncName.L, x.RetType.Clone(), args...)
c := NewFunctionInternal(ctx, x.FuncName.L, x.RetType.Clone(), args...)
return c
case *Column:
if !schema.Contains(x) {
return x
}
if parExpr != nil {
if sf, ok := parExpr.(*ScalarFunction); ok {
if sf.FuncName.L == ast.LogicAnd {
return NewOne()
}
if sf.FuncName.L == ast.LogicOr {
return NewZero()
}
}
}
return &Constant{Value: types.Datum{}, RetType: types.NewFieldType(mysql.TypeNull)}
case *Constant:
if x.DeferredExpr != nil {
Expand Down
1 change: 0 additions & 1 deletion planner/core/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,6 @@ func TestOuterJoinOnNull(t *testing.T) {
tk.MustExec("CREATE TABLE t0(c0 BLOB(5), c1 BLOB(5));")
tk.MustExec("CREATE TABLE t1 (c0 BOOL);")
tk.MustExec("INSERT INTO t1 VALUES(false);")
tk.MustExec("")
tk.MustExec("INSERT INTO t0(c0, c1) VALUES ('>', true);")
tk.MustQuery("SELECT * FROM t0 LEFT OUTER JOIN t1 ON NULL; ").Check(testkit.Rows("> 1 <nil>"))
tk.MustQuery("SELECT NOT '2' =(t1.c0 AND t0.c1 IS NULL) FROM t0 LEFT OUTER JOIN t1 ON NULL; ").Check(testkit.Rows("1"))
Expand Down

0 comments on commit ef36380

Please sign in to comment.