mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-31303 Key not used when IN clause has both signed and usigned values
Summary: This patch enables possible index optimization when the WHERE clause has an IN condition of the form: signed_or_unsigned_column IN (signed_or_unsigned_constant, signed_or_unsigned_constant [,signed_or_unsigned_constant]*) when the IN list constants are of different signess, e.g.: WHERE signed_column IN (signed_constant, unsigned_constant ...) WHERE unsigned_column IN (signed_constant, unsigned_constant ...) Details: In a condition like: WHERE unsigned_predicant IN (1, LONGLONG_MAX + 1) comparison handlers for individual (predicant,value) pairs are calculated as follows: * unsigned_predicant and 1 produce &type_handler_newdecimal * unsigned_predicant and (LONGLONG_MAX + 1) produce &type_handler_slonglong The old code decided that it could not use bisection because the two pairs had different comparison handlers. As a result, bisection was not allowed, and, in case of an indexed integer column predicant the index on the column was not used. The new code catches special cases like: signed_predicant IN (signed_constant, unsigned_constant) unsigned_predicant IN (signed_constant, unsigned_constant) It enables bisection using in_longlong, which supports a mixture of predicant and values of different signess. In case when the predicant is an indexed column this change automatically enables index range optimization. Thanks to Vicențiu Ciorbaru for proposing the idea and for preparing MTR tests.
This commit is contained in:
committed by
Vicențiu-Marian Ciorbaru
parent
e938d7c18f
commit
53499cd1ea
@ -912,7 +912,8 @@ a IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED))
|
||||
Warnings:
|
||||
Note 1105 DBUG: [0] arg=1 handler=0 (bigint)
|
||||
Note 1105 DBUG: [1] arg=2 handler=1 (decimal)
|
||||
Note 1105 DBUG: types_compatible=no bisect=no
|
||||
Note 1105 DBUG: found a mix of UINT and SINT
|
||||
Note 1105 DBUG: types_compatible=yes bisect=yes
|
||||
SELECT a IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL) FROM t1;
|
||||
a IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL)
|
||||
Warnings:
|
||||
@ -950,7 +951,8 @@ a NOT IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED))
|
||||
Warnings:
|
||||
Note 1105 DBUG: [0] arg=1 handler=0 (bigint)
|
||||
Note 1105 DBUG: [1] arg=2 handler=1 (decimal)
|
||||
Note 1105 DBUG: types_compatible=no bisect=no
|
||||
Note 1105 DBUG: found a mix of UINT and SINT
|
||||
Note 1105 DBUG: types_compatible=yes bisect=yes
|
||||
SELECT a NOT IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL) FROM t1;
|
||||
a NOT IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL)
|
||||
Warnings:
|
||||
@ -1624,7 +1626,8 @@ a b
|
||||
Warnings:
|
||||
Note 1105 DBUG: [0] arg=1 handler=0 (bigint)
|
||||
Note 1105 DBUG: [1] arg=2 handler=1 (decimal)
|
||||
Note 1105 DBUG: types_compatible=no bisect=no
|
||||
Note 1105 DBUG: found a mix of UINT and SINT
|
||||
Note 1105 DBUG: types_compatible=yes bisect=no
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-11554 Wrong result for CASE on a mixture of signed and unsigned expressions
|
||||
|
Reference in New Issue
Block a user