Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Jan 27, 2025
1 parent 0ac6d80 commit 7254e73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
13 changes: 13 additions & 0 deletions pkg/expression/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2162,3 +2162,16 @@ func binaryDurationWithMS(pos int, paramValues []byte,
pos += 4
return pos, fmt.Sprintf("%s.%06d", dur, microSecond)
}

// IsConstFalse is used to check whether the expression is a constant false expression.
func IsConstFalse(expr Expression) bool {
if e, ok := expr.(*ScalarFunction); ok {
switch e.FuncName.L {
case ast.LT, ast.LE, ast.GT, ast.GE, ast.EQ, ast.NE:
if constExpr, ok := e.GetArgs()[1].(*Constant); ok && constExpr.Value.IsNull() && constExpr.DeferredExpr == nil {
return true
}
}
}
return false
}
16 changes: 1 addition & 15 deletions pkg/planner/core/operator/logicalop/expression_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,13 @@ package logicalop

import (
"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/planner/core/base"
)

// isConstFalse is used to check whether the expression is a constant false expression.
func isConstFalse(expr expression.Expression) bool {
if e, ok := expr.(*expression.ScalarFunction); ok {
switch e.FuncName.L {
case ast.LT, ast.LE, ast.GT, ast.GE, ast.EQ, ast.NE:
if constExpr, ok := e.GetArgs()[1].(*expression.Constant); ok && constExpr.Value.IsNull() && constExpr.DeferredExpr == nil {
return true
}
}
}
return false
}

// Conds2TableDual builds a LogicalTableDual if cond is constant false or null.
func Conds2TableDual(p base.LogicalPlan, conds []expression.Expression) base.LogicalPlan {
for _, cond := range conds {
if isConstFalse(cond) {
if expression.IsConstFalse(cond) {
if expression.MaybeOverOptimized4PlanCache(p.SCtx().GetExprCtx(), conds) {
return nil
}
Expand Down

0 comments on commit 7254e73

Please sign in to comment.