Skip to content

Commit

Permalink
fix issue:pingcap#11102
Browse files Browse the repository at this point in the history
handle `CASE WHEN` specially when folding constant during outerJoin Simplification
  • Loading branch information
lovewin99 committed Jul 22, 2019
1 parent 1842158 commit 97e81bd
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions expression/constant_fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,22 @@ func caseWhenHandler(expr *ScalarFunction) (Expression, bool) {
isDeferredConst = isDeferredConst || isDeferred
}

if l%2 == 1 && !hasNonConstCondition {
// If the number of arguments in casewhen is odd, and the previous conditions
// is const and false, then the folded else execution body is returned. otherwise
// the execution body of the else are folded and replaced.
if l%2 == 0 {
return expr, isDeferredConst
}

// If the number of arguments in casewhen is odd, and the previous conditions
// is const and false, then the folded else execution body is returned. otherwise
// the execution body of the else are folded and replaced.
if !hasNonConstCondition {
foldedExpr, isDeferred := foldConstant(args[l-1])
isDeferredConst = isDeferredConst || isDeferred
return BuildCastFunction(expr.GetCtx(), foldedExpr, expr.GetType()), isDeferredConst
} else if l%2 == 1 {
expr.GetArgs()[l-1], isDeferred = foldConstant(args[l-1])
isDeferredConst = isDeferredConst || isDeferred
}

expr.GetArgs()[l-1], isDeferred = foldConstant(args[l-1])
isDeferredConst = isDeferredConst || isDeferred

return expr, isDeferredConst
}

Expand Down

0 comments on commit 97e81bd

Please sign in to comment.