@@ -1570,7 +1570,7 @@ func allowCmpArgsRefining4PlanCache(ctx sessionctx.Context, args []Expression) (
1570
1570
// 3. It also handles comparing datetime/timestamp column with numeric constant, try to cast numeric constant as timestamp type, do nothing if failed.
1571
1571
// This refining operation depends on the values of these args, but these values can change when using plan-cache.
1572
1572
// So we have to skip this operation or mark the plan as over-optimized when using plan-cache.
1573
- func (c * compareFunctionClass ) refineArgs (ctx sessionctx.Context , args []Expression ) []Expression {
1573
+ func (c * compareFunctionClass ) refineArgs (ctx sessionctx.Context , args []Expression ) ( []Expression , error ) {
1574
1574
arg0Type , arg1Type := args [0 ].GetType (), args [1 ].GetType ()
1575
1575
arg0EvalType , arg1EvalType := arg0Type .EvalType (), arg1Type .EvalType ()
1576
1576
arg0IsInt := arg0EvalType == types .ETInt
@@ -1581,17 +1581,19 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
1581
1581
isPositiveInfinite , isNegativeInfinite := false , false
1582
1582
1583
1583
if ! allowCmpArgsRefining4PlanCache (ctx , args ) {
1584
- return args
1584
+ return args , nil
1585
1585
}
1586
1586
// We should remove the mutable constant for correctness, because its value may be changed.
1587
- RemoveMutableConst (ctx , args )
1587
+ if err := RemoveMutableConst (ctx , args ); err != nil {
1588
+ return nil , err
1589
+ }
1588
1590
1589
1591
if arg0IsCon && ! arg1IsCon && matchRefineRule3Pattern (arg0EvalType , arg1Type ) {
1590
- return c .refineNumericConstantCmpDatetime (ctx , args , arg0 , 0 )
1592
+ return c .refineNumericConstantCmpDatetime (ctx , args , arg0 , 0 ), nil
1591
1593
}
1592
1594
1593
1595
if ! arg0IsCon && arg1IsCon && matchRefineRule3Pattern (arg1EvalType , arg0Type ) {
1594
- return c .refineNumericConstantCmpDatetime (ctx , args , arg1 , 1 )
1596
+ return c .refineNumericConstantCmpDatetime (ctx , args , arg1 , 1 ), nil
1595
1597
}
1596
1598
1597
1599
// int non-constant [cmp] non-int constant
@@ -1657,24 +1659,24 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
1657
1659
}
1658
1660
if isExceptional && (c .op == opcode .EQ || c .op == opcode .NullEQ ) {
1659
1661
// This will always be false.
1660
- return []Expression {NewZero (), NewOne ()}
1662
+ return []Expression {NewZero (), NewOne ()}, nil
1661
1663
}
1662
1664
if isPositiveInfinite {
1663
1665
// If the op is opcode.LT, opcode.LE
1664
1666
// This will always be true.
1665
1667
// If the op is opcode.GT, opcode.GE
1666
1668
// This will always be false.
1667
- return []Expression {NewZero (), NewOne ()}
1669
+ return []Expression {NewZero (), NewOne ()}, nil
1668
1670
}
1669
1671
if isNegativeInfinite {
1670
1672
// If the op is opcode.GT, opcode.GE
1671
1673
// This will always be true.
1672
1674
// If the op is opcode.LT, opcode.LE
1673
1675
// This will always be false.
1674
- return []Expression {NewOne (), NewZero ()}
1676
+ return []Expression {NewOne (), NewZero ()}, nil
1675
1677
}
1676
1678
1677
- return c .refineArgsByUnsignedFlag (ctx , []Expression {finalArg0 , finalArg1 })
1679
+ return c .refineArgsByUnsignedFlag (ctx , []Expression {finalArg0 , finalArg1 }), nil
1678
1680
}
1679
1681
1680
1682
// see https://github.com/pingcap/tidb/issues/38361 for more details
@@ -1767,7 +1769,10 @@ func (c *compareFunctionClass) getFunction(ctx sessionctx.Context, rawArgs []Exp
1767
1769
if err = c .verifyArgs (rawArgs ); err != nil {
1768
1770
return nil , err
1769
1771
}
1770
- args := c .refineArgs (ctx , rawArgs )
1772
+ args , err := c .refineArgs (ctx , rawArgs )
1773
+ if err != nil {
1774
+ return nil , err
1775
+ }
1771
1776
cmpType := GetAccurateCmpType (args [0 ], args [1 ])
1772
1777
sig , err = c .generateCmpSigs (ctx , args , cmpType )
1773
1778
return sig , err
0 commit comments