@@ -407,7 +407,7 @@ func simplifyOuterJoin(p *LogicalJoin, predicates []expression.Expression) {
407
407
if expression .ExprFromSchema (expr , outerTable .Schema ()) {
408
408
continue
409
409
}
410
- isOk := isNullRejected (p .SCtx (), innerTable .Schema (), expr )
410
+ isOk := util . IsNullRejected (p .SCtx (), innerTable .Schema (), expr )
411
411
if isOk {
412
412
canBeSimplified = true
413
413
break
@@ -418,78 +418,6 @@ func simplifyOuterJoin(p *LogicalJoin, predicates []expression.Expression) {
418
418
}
419
419
}
420
420
421
- // isNullRejected check whether a condition is null-rejected
422
- // A condition would be null-rejected in one of following cases:
423
- // If it is a predicate containing a reference to an inner table that evaluates to UNKNOWN or FALSE when one of its arguments is NULL.
424
- // If it is a conjunction containing a null-rejected condition as a conjunct.
425
- // If it is a disjunction of null-rejected conditions.
426
- func isNullRejected (ctx base.PlanContext , schema * expression.Schema , expr expression.Expression ) bool {
427
- exprCtx := ctx .GetNullRejectCheckExprCtx ()
428
- expr = expression .PushDownNot (exprCtx , expr )
429
- if expression .ContainOuterNot (expr ) {
430
- return false
431
- }
432
- sc := ctx .GetSessionVars ().StmtCtx
433
- for _ , cond := range expression .SplitCNFItems (expr ) {
434
- if isNullRejectedSpecially (ctx , schema , expr ) {
435
- return true
436
- }
437
-
438
- result := expression .EvaluateExprWithNull (exprCtx , schema , cond )
439
- x , ok := result .(* expression.Constant )
440
- if ! ok {
441
- continue
442
- }
443
- if x .Value .IsNull () {
444
- return true
445
- } else if isTrue , err := x .Value .ToBool (sc .TypeCtxOrDefault ()); err == nil && isTrue == 0 {
446
- return true
447
- }
448
- }
449
- return false
450
- }
451
-
452
- // isNullRejectedSpecially handles some null-rejected cases specially, since the current in
453
- // EvaluateExprWithNull is too strict for some cases, e.g. #49616.
454
- func isNullRejectedSpecially (ctx base.PlanContext , schema * expression.Schema , expr expression.Expression ) bool {
455
- return specialNullRejectedCase1 (ctx , schema , expr ) // only 1 case now
456
- }
457
-
458
- // specialNullRejectedCase1 is mainly for #49616.
459
- // Case1 specially handles `null-rejected OR (null-rejected AND {others})`, then no matter what the result
460
- // of `{others}` is (True, False or Null), the result of this predicate is null, so this predicate is null-rejected.
461
- func specialNullRejectedCase1 (ctx base.PlanContext , schema * expression.Schema , expr expression.Expression ) bool {
462
- isFunc := func (e expression.Expression , lowerFuncName string ) * expression.ScalarFunction {
463
- f , ok := e .(* expression.ScalarFunction )
464
- if ! ok {
465
- return nil
466
- }
467
- if f .FuncName .L == lowerFuncName {
468
- return f
469
- }
470
- return nil
471
- }
472
- orFunc := isFunc (expr , ast .LogicOr )
473
- if orFunc == nil {
474
- return false
475
- }
476
- for i := 0 ; i < 2 ; i ++ {
477
- andFunc := isFunc (orFunc .GetArgs ()[i ], ast .LogicAnd )
478
- if andFunc == nil {
479
- continue
480
- }
481
- if ! isNullRejected (ctx , schema , orFunc .GetArgs ()[1 - i ]) {
482
- continue // the other side should be null-rejected: null-rejected OR (... AND ...)
483
- }
484
- for _ , andItem := range expression .SplitCNFItems (andFunc ) {
485
- if isNullRejected (ctx , schema , andItem ) {
486
- return true // hit the case in the comment: null-rejected OR (null-rejected AND ...)
487
- }
488
- }
489
- }
490
- return false
491
- }
492
-
493
421
// PredicatePushDown implements base.LogicalPlan PredicatePushDown interface.
494
422
func (p * LogicalExpand ) PredicatePushDown (predicates []expression.Expression , opt * coreusage.LogicalOptimizeOp ) (ret []expression.Expression , retPlan base.LogicalPlan ) {
495
423
// Note that, grouping column related predicates can't be pushed down, since grouping column has nullability change after Expand OP itself.
@@ -723,7 +651,7 @@ func deriveNotNullExpr(ctx base.PlanContext, expr expression.Expression, schema
723
651
if childCol == nil {
724
652
childCol = schema .RetrieveColumn (arg1 )
725
653
}
726
- if isNullRejected (ctx , schema , expr ) && ! mysql .HasNotNullFlag (childCol .RetType .GetFlag ()) {
654
+ if util . IsNullRejected (ctx , schema , expr ) && ! mysql .HasNotNullFlag (childCol .RetType .GetFlag ()) {
727
655
return expression .BuildNotNullExpr (ctx .GetExprCtx (), childCol )
728
656
}
729
657
return nil
0 commit comments