@@ -1620,7 +1620,7 @@ func allowCmpArgsRefining4PlanCache(ctx sessionctx.Context, args []Expression) (
1620
1620
// 3. It also handles comparing datetime/timestamp column with numeric constant, try to cast numeric constant as timestamp type, do nothing if failed.
1621
1621
// This refining operation depends on the values of these args, but these values can change when using plan-cache.
1622
1622
// So we have to skip this operation or mark the plan as over-optimized when using plan-cache.
1623
- func (c * compareFunctionClass ) refineArgs (ctx sessionctx.Context , args []Expression ) []Expression {
1623
+ func (c * compareFunctionClass ) refineArgs (ctx sessionctx.Context , args []Expression ) ( []Expression , error ) {
1624
1624
arg0Type , arg1Type := args [0 ].GetType (), args [1 ].GetType ()
1625
1625
arg0EvalType , arg1EvalType := arg0Type .EvalType (), arg1Type .EvalType ()
1626
1626
arg0IsInt := arg0EvalType == types .ETInt
@@ -1631,17 +1631,19 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
1631
1631
isPositiveInfinite , isNegativeInfinite := false , false
1632
1632
1633
1633
if ! allowCmpArgsRefining4PlanCache (ctx , args ) {
1634
- return args
1634
+ return args , nil
1635
1635
}
1636
1636
// We should remove the mutable constant for correctness, because its value may be changed.
1637
- RemoveMutableConst (ctx , args )
1637
+ if err := RemoveMutableConst (ctx , args ); err != nil {
1638
+ return nil , err
1639
+ }
1638
1640
1639
1641
if arg0IsCon && ! arg1IsCon && matchRefineRule3Pattern (arg0EvalType , arg1Type ) {
1640
- return c .refineNumericConstantCmpDatetime (ctx , args , arg0 , 0 )
1642
+ return c .refineNumericConstantCmpDatetime (ctx , args , arg0 , 0 ), nil
1641
1643
}
1642
1644
1643
1645
if ! arg0IsCon && arg1IsCon && matchRefineRule3Pattern (arg1EvalType , arg0Type ) {
1644
- return c .refineNumericConstantCmpDatetime (ctx , args , arg1 , 1 )
1646
+ return c .refineNumericConstantCmpDatetime (ctx , args , arg1 , 1 ), nil
1645
1647
}
1646
1648
1647
1649
// int non-constant [cmp] non-int constant
@@ -1707,24 +1709,24 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
1707
1709
}
1708
1710
if isExceptional && (c .op == opcode .EQ || c .op == opcode .NullEQ ) {
1709
1711
// This will always be false.
1710
- return []Expression {NewZero (), NewOne ()}
1712
+ return []Expression {NewZero (), NewOne ()}, nil
1711
1713
}
1712
1714
if isPositiveInfinite {
1713
1715
// If the op is opcode.LT, opcode.LE
1714
1716
// This will always be true.
1715
1717
// If the op is opcode.GT, opcode.GE
1716
1718
// This will always be false.
1717
- return []Expression {NewZero (), NewOne ()}
1719
+ return []Expression {NewZero (), NewOne ()}, nil
1718
1720
}
1719
1721
if isNegativeInfinite {
1720
1722
// If the op is opcode.GT, opcode.GE
1721
1723
// This will always be true.
1722
1724
// If the op is opcode.LT, opcode.LE
1723
1725
// This will always be false.
1724
- return []Expression {NewOne (), NewZero ()}
1726
+ return []Expression {NewOne (), NewZero ()}, nil
1725
1727
}
1726
1728
1727
- return c .refineArgsByUnsignedFlag (ctx , []Expression {finalArg0 , finalArg1 })
1729
+ return c .refineArgsByUnsignedFlag (ctx , []Expression {finalArg0 , finalArg1 }), nil
1728
1730
}
1729
1731
1730
1732
// see https://github.com/pingcap/tidb/issues/38361 for more details
@@ -1817,7 +1819,10 @@ func (c *compareFunctionClass) getFunction(ctx sessionctx.Context, rawArgs []Exp
1817
1819
if err = c .verifyArgs (rawArgs ); err != nil {
1818
1820
return nil , err
1819
1821
}
1820
- args := c .refineArgs (ctx , rawArgs )
1822
+ args , err := c .refineArgs (ctx , rawArgs )
1823
+ if err != nil {
1824
+ return nil , err
1825
+ }
1821
1826
cmpType := GetAccurateCmpType (args [0 ], args [1 ])
1822
1827
sig , err = c .generateCmpSigs (ctx , args , cmpType )
1823
1828
return sig , err
0 commit comments