Skip to content

Commit 9158212

Browse files
author
Alexander Barkov
committed
MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
Disable IDENTITY_SUBST propagation for ZEROFILL columns, as discussed with Sergei.
1 parent df9b8ae commit 9158212

12 files changed

+201
-38
lines changed

mysql-test/r/compare.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ EXPLAIN EXTENDED SELECT b,c FROM t1 WHERE b = 1 AND CONCAT(b,c) = '0101';
6464
id select_type table type possible_keys key key_len ref rows filtered Extra
6565
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
6666
Warnings:
67-
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`b` = 1) and (concat('01',`test`.`t1`.`c`) = '0101'))
67+
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`b` = 1) and (concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = '0101'))
6868
SELECT b,c FROM t1 WHERE b = 1 AND CONCAT(b,c) = '0101';
6969
b c
7070
01 01

mysql-test/r/func_encrypt.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,21 @@ insert into t1 values (null,'contraction\'s');
190190
insert into t1 values (-15818,'requirement\'s');
191191
select encrypt(f1,f2) as a from t1,(select encrypt(f1,f2) as b from t1) a;
192192
drop table t1;
193+
#
194+
# Start of 10.1 tests
195+
#
196+
#
197+
# MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
198+
#
199+
CREATE TABLE t1 (a INT(6) ZEROFILL);
200+
INSERT INTO t1 VALUES (1),(2);
201+
EXPLAIN EXTENDED
202+
SELECT * FROM t1 WHERE a=1 AND DES_ENCRYPT('test',a)=_latin1 'abc' COLLATE latin1_bin;
203+
id select_type table type possible_keys key key_len ref rows filtered Extra
204+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
205+
Warnings:
206+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1) and (des_encrypt('test',`test`.`t1`.`a`) = 'abc'))
207+
DROP TABLE t1;
208+
#
209+
# End of 10.1 tests
210+
#

mysql-test/r/func_str.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4535,3 +4535,30 @@ set global max_allowed_packet=default;
45354535
#
45364536
# End of 5.6 tests
45374537
#
4538+
#
4539+
# Start of 10.1 tests
4540+
#
4541+
#
4542+
# MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
4543+
#
4544+
CREATE TABLE t1 (a BIGINT(20) ZEROFILL);
4545+
INSERT INTO t1 VALUES (18446744073709551615),(0);
4546+
SELECT * FROM t1 WHERE a=18446744073709551615;
4547+
a
4548+
18446744073709551615
4549+
SELECT * FROM t1 WHERE FORMAT(a,0)='18,446,744,073,709,551,615';
4550+
a
4551+
18446744073709551615
4552+
SELECT * FROM t1 WHERE a=18446744073709551615 AND FORMAT(a,0)='18,446,744,073,709,551,615';
4553+
a
4554+
18446744073709551615
4555+
EXPLAIN EXTENDED
4556+
SELECT * FROM t1 WHERE a=18446744073709551615 AND FORMAT(a,0)='18,446,744,073,709,551,615';
4557+
id select_type table type possible_keys key key_len ref rows filtered Extra
4558+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
4559+
Warnings:
4560+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 18446744073709551615) and (format(`test`.`t1`.`a`,0) = '18,446,744,073,709,551,615'))
4561+
DROP TABLE t1;
4562+
#
4563+
# End of 10.1 tests
4564+
#

mysql-test/r/func_weight_string.result

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,51 @@ Warnings:
9292
Warning 1301 Result of cast_as_binary() was larger than max_allowed_packet (1048576) - truncated
9393
Warning 1301 Result of weight_string() was larger than max_allowed_packet (1048576) - truncated
9494
set global max_allowed_packet=default;
95+
#
96+
# Start of 10.1 tests
97+
#
98+
#
99+
# MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
100+
#
101+
CREATE TABLE t1 (a INT(6) ZEROFILL);
102+
INSERT INTO t1 VALUES (1),(2);
103+
SELECT * FROM t1 WHERE a=1;
104+
a
105+
000001
106+
SELECT * FROM t1 WHERE WEIGHT_STRING(a) IS NULL;
107+
a
108+
000001
109+
000002
110+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
111+
a
112+
000001
113+
EXPLAIN EXTENDED
114+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
115+
id select_type table type possible_keys key key_len ref rows filtered Extra
116+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
117+
Warnings:
118+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1) and isnull(weight_string(`test`.`t1`.`a`)))
119+
ALTER TABLE t1 MODIFY a DOUBLE ZEROFILL;
120+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
121+
a
122+
0000000000000000000001
123+
EXPLAIN EXTENDED
124+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
125+
id select_type table type possible_keys key key_len ref rows filtered Extra
126+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
127+
Warnings:
128+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1) and isnull(weight_string(`test`.`t1`.`a`)))
129+
ALTER TABLE t1 MODIFY a DECIMAL(10,1) ZEROFILL;
130+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
131+
a
132+
000000001.0
133+
EXPLAIN EXTENDED
134+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
135+
id select_type table type possible_keys key key_len ref rows filtered Extra
136+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
137+
Warnings:
138+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1) and isnull(weight_string(`test`.`t1`.`a`)))
139+
DROP TABLE t1;
140+
#
141+
# End of 10.1 tests
142+
#

mysql-test/r/null.result

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,15 +1427,15 @@ a
14271427
EXPLAIN EXTENDED
14281428
SELECT * FROM t1 WHERE a=10 AND NULLIF(a,2011.1)='2011';
14291429
id select_type table type possible_keys key key_len ref rows filtered Extra
1430-
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1430+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
14311431
Warnings:
1432-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
1432+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and ((case when 2010 = 2011 then NULL else `test`.`t1`.`a` end) = '2011'))
14331433
EXPLAIN EXTENDED
14341434
SELECT * FROM t1 WHERE a=10 AND NULLIF(a,2011.1)=CONCAT('2011',RAND());
14351435
id select_type table type possible_keys key key_len ref rows filtered Extra
14361436
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
14371437
Warnings:
1438-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and (<cache>((case when 2010 = 2011 then NULL else '2010' end)) = concat('2011',rand())))
1438+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and ((case when 2010 = 2011 then NULL else `test`.`t1`.`a` end) = concat('2011',rand())))
14391439
DROP TABLE t1;
14401440
#
14411441
# MDEV-8754 Wrong result for SELECT..WHERE year_field=2020 AND NULLIF(year_field,2010)='2020'
@@ -1456,13 +1456,13 @@ SELECT * FROM t1 WHERE a=2020 AND NULLIF(a,2010)='2020';
14561456
id select_type table type possible_keys key key_len ref rows filtered Extra
14571457
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
14581458
Warnings:
1459-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2020)
1459+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2020) and ((case when 2020 = 2010 then NULL else `test`.`t1`.`a` end) = '2020'))
14601460
EXPLAIN EXTENDED
14611461
SELECT * FROM t1 WHERE a=2020 AND NULLIF(a,2010)=CONCAT('2020',RAND());
14621462
id select_type table type possible_keys key key_len ref rows filtered Extra
14631463
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
14641464
Warnings:
1465-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2020) and (<cache>((case when 2020 = 2010 then NULL else '2020' end)) = concat('2020',rand())))
1465+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2020) and ((case when 2020 = 2010 then NULL else `test`.`t1`.`a` end) = concat('2020',rand())))
14661466
DROP TABLE t1;
14671467
#
14681468
# End of 10.1 tests

mysql-test/r/type_int.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,26 @@ Warnings:
1313
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010)
1414
DROP TABLE t1;
1515
#
16+
# MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
17+
#
18+
CREATE TABLE t1 (a INT ZEROFILL);
19+
INSERT INTO t1 VALUES (128),(129);
20+
SELECT * FROM t1 WHERE a=128;
21+
a
22+
0000000128
23+
SELECT * FROM t1 WHERE hex(a)='80';
24+
a
25+
0000000128
26+
SELECT * FROM t1 WHERE a=128 AND hex(a)='80';
27+
a
28+
0000000128
29+
EXPLAIN EXTENDED
30+
SELECT * FROM t1 WHERE a=128 AND hex(a)='80';
31+
id select_type table type possible_keys key key_len ref rows filtered Extra
32+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
33+
Warnings:
34+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 128) and (hex(`test`.`t1`.`a`) = '80'))
35+
DROP TABLE t1;
36+
#
1637
# End of 10.1 tests
1738
#

mysql-test/t/func_encrypt.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,21 @@ insert into t1 values (-15818,'requirement\'s');
103103
select encrypt(f1,f2) as a from t1,(select encrypt(f1,f2) as b from t1) a;
104104
--enable_result_log
105105
drop table t1;
106+
107+
--echo #
108+
--echo # Start of 10.1 tests
109+
--echo #
110+
111+
--echo #
112+
--echo # MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
113+
--echo #
114+
CREATE TABLE t1 (a INT(6) ZEROFILL);
115+
INSERT INTO t1 VALUES (1),(2);
116+
# This should not propagate a=1 into DES_ENCRYPT
117+
EXPLAIN EXTENDED
118+
SELECT * FROM t1 WHERE a=1 AND DES_ENCRYPT('test',a)=_latin1 'abc' COLLATE latin1_bin;
119+
DROP TABLE t1;
120+
121+
--echo #
122+
--echo # End of 10.1 tests
123+
--echo #

mysql-test/t/func_str.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,3 +1750,24 @@ set global max_allowed_packet=default;
17501750
--echo #
17511751
--echo # End of 5.6 tests
17521752
--echo #
1753+
1754+
--echo #
1755+
--echo # Start of 10.1 tests
1756+
--echo #
1757+
1758+
--echo #
1759+
--echo # MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
1760+
--echo #
1761+
CREATE TABLE t1 (a BIGINT(20) ZEROFILL);
1762+
INSERT INTO t1 VALUES (18446744073709551615),(0);
1763+
SELECT * FROM t1 WHERE a=18446744073709551615;
1764+
SELECT * FROM t1 WHERE FORMAT(a,0)='18,446,744,073,709,551,615';
1765+
SELECT * FROM t1 WHERE a=18446744073709551615 AND FORMAT(a,0)='18,446,744,073,709,551,615';
1766+
# This should not propagate the equality into FORMAT()
1767+
EXPLAIN EXTENDED
1768+
SELECT * FROM t1 WHERE a=18446744073709551615 AND FORMAT(a,0)='18,446,744,073,709,551,615';
1769+
DROP TABLE t1;
1770+
1771+
--echo #
1772+
--echo # End of 10.1 tests
1773+
--echo #

mysql-test/t/func_weight_string.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,31 @@ SELECT HEX(WEIGHT_STRING('ab' AS BINARY(1000000000000000000)));
119119
disconnect conn1;
120120
connection default;
121121
set global max_allowed_packet=default;
122+
123+
--echo #
124+
--echo # Start of 10.1 tests
125+
--echo #
126+
127+
--echo #
128+
--echo # MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
129+
--echo #
130+
CREATE TABLE t1 (a INT(6) ZEROFILL);
131+
INSERT INTO t1 VALUES (1),(2);
132+
SELECT * FROM t1 WHERE a=1;
133+
SELECT * FROM t1 WHERE WEIGHT_STRING(a) IS NULL;
134+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
135+
EXPLAIN EXTENDED
136+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
137+
ALTER TABLE t1 MODIFY a DOUBLE ZEROFILL;
138+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
139+
EXPLAIN EXTENDED
140+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
141+
ALTER TABLE t1 MODIFY a DECIMAL(10,1) ZEROFILL;
142+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
143+
EXPLAIN EXTENDED
144+
SELECT * FROM t1 WHERE a=1 AND WEIGHT_STRING(a) IS NULL;
145+
DROP TABLE t1;
146+
147+
--echo #
148+
--echo # End of 10.1 tests
149+
--echo #

mysql-test/t/type_int.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ INSERT INTO t1 VALUES (2010),(2020);
1111
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
1212
DROP TABLE t1;
1313

14+
--echo #
15+
--echo # MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
16+
--echo #
17+
CREATE TABLE t1 (a INT ZEROFILL);
18+
INSERT INTO t1 VALUES (128),(129);
19+
SELECT * FROM t1 WHERE a=128;
20+
SELECT * FROM t1 WHERE hex(a)='80';
21+
SELECT * FROM t1 WHERE a=128 AND hex(a)='80';
22+
EXPLAIN EXTENDED
23+
SELECT * FROM t1 WHERE a=128 AND hex(a)='80';
24+
DROP TABLE t1;
25+
1426
--echo #
1527
--echo # End of 10.1 tests
1628
--echo #

0 commit comments

Comments
 (0)