Skip to content

Commit e4435b5

Browse files
author
Alexander Barkov
committed
MDEV-9604 crash in Item::save_in_field with empty enum value
1. Fixing Field_time::get_equal_const_item() to pass TIME_FUZZY_DATES and TIME_INVALID_DATES to get_time_with_conversion(). This is needed to make the recursively called Item::get_date() return non-NULL values on garbage input. This makes Field_time::get_equal_const_item() work consistently with how Item::val_time_packed() works. 2. Fixing Item::get_date() to return TIME'00:00:00' rather than DATE'0000-00-00' on empty or garbage input when: - TIME_FUZZY_DATES is enabled - The caller requested a TIME value (by passing TIME_TIME_ONLY). This is needed to avoid conversion of DATE'0000-00-00' to TIME in get_time_with_conversion(), which would erroneously try to subtract CURRENT_DATE from DATE'0000-00-00' and return TIME'-838:59:59' rather than the desired zero value TIME'00:00:00'. #1 and #2 fix these type of scripts to return one row with both MyISAM and InnoDB, with and without an index on t1.b: CREATE TABLE t1 (a ENUM('a'), b TIME, c INT, KEY(b)); INSERT INTO t1 VALUES ('','00:00:00',0); SELECT * FROM t1 WHERE b=''; SELECT * FROM t1 WHERE a=b; SELECT * FROM t1 IGNORE INDEX(b) WHERE b=''; SELECT * FROM t1 IGNORE INDEX(b) WHERE a=b; Additionally, #1 and #2 fix the originally reported in MDEV-9604 crash in Item::save_in_field(), because now execution goes through a different path, so save_in_field() is called for a Item_time_literal instance (which is non-NULL) rather than a Item_cache_str instance (which could return NULL without setting null_value). 3. Fixing Field_temporal::get_equal_const_item_datetime() to enable equal field propagation for DATETIME and TIMESTAMP in case of comparison (e.g. when ANY_SUBST), for symmetry with Field_newdate::get_equal_const_item(). This fixes a number of problems with empty set returned on comparison to empty/garbage input. Now all SELECT queries in this script return one row for MyISAM and InnoDB, with and without an index on t1.b: CREATE TABLE t1 (a ENUM('a'), b DATETIME, c INT, KEY(b)); INSERT INTO t1 VALUES ('','0000-00-00 00:00:00',0); SELECT * FROM t1 WHERE b=''; SELECT * FROM t1 WHERE a=b; SELECT * FROM t1 IGNORE INDEX(b) WHERE b=''; SELECT * FROM t1 IGNORE INDEX(b) WHERE a=b;
1 parent f66303d commit e4435b5

File tree

6 files changed

+263
-18
lines changed

6 files changed

+263
-18
lines changed

mysql-test/r/type_datetime.result

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 FORCE INDEX(attime) WHERE AtTime = '2010-02-22
747747
id select_type table type possible_keys key key_len ref rows filtered Extra
748748
1 SIMPLE t1 ref AtTime AtTime 6 const 1 100.00
749749
Warnings:
750-
Note 1003 select `test`.`t1`.`Id` AS `Id`,`test`.`t1`.`AtTime` AS `AtTime` from `test`.`t1` FORCE INDEX (`attime`) where (`test`.`t1`.`AtTime` = '2010-02-22 18:40:07')
750+
Note 1003 select `test`.`t1`.`Id` AS `Id`,`test`.`t1`.`AtTime` AS `AtTime` from `test`.`t1` FORCE INDEX (`attime`) where (`test`.`t1`.`AtTime` = TIMESTAMP'2010-02-22 18:40:07')
751751
DROP TABLE t1;
752752
SET NAMES latin1;
753753
#
@@ -963,21 +963,20 @@ a
963963
2001-01-01 00:00:00
964964
Warnings:
965965
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
966-
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
967966
EXPLAIN EXTENDED
968967
SELECT * FROM t1 WHERE LENGTH(a) != 20 AND a='2001-01-01 00:00:00x';
969968
id select_type table type possible_keys key key_len ref rows filtered Extra
970969
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
971970
Warnings:
972971
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
973-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '2001-01-01 00:00:00x')
972+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00')
974973
EXPLAIN EXTENDED
975974
SELECT * FROM t1 WHERE LENGTH(a)!=30+RAND() AND a='2001-01-01 00:00:00x';
976975
id select_type table type possible_keys key key_len ref rows filtered Extra
977976
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
978977
Warnings:
979978
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
980-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '2001-01-01 00:00:00x') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) <> (30 + rand())))
979+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) <> (30 + rand())))
981980
DROP TABLE t1;
982981
CREATE TABLE t1 (a DATETIME);;
983982
INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2001-01-01 00:00:01');
@@ -993,20 +992,20 @@ SELECT * FROM t1 WHERE LENGTH(a)=19 AND a=' 2001-01-01 00:00:00';
993992
id select_type table type possible_keys key key_len ref rows filtered Extra
994993
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
995994
Warnings:
996-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = ' 2001-01-01 00:00:00')
995+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00')
997996
EXPLAIN EXTENDED
998997
SELECT * FROM t1 WHERE LENGTH(a)=19+RAND() AND a=' 2001-01-01 00:00:00';
999998
id select_type table type possible_keys key key_len ref rows filtered Extra
1000999
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
10011000
Warnings:
1002-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = ' 2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (19 + rand())))
1001+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (19 + rand())))
10031002
EXPLAIN EXTENDED
10041003
SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=' garbage ';
10051004
id select_type table type possible_keys key key_len ref rows filtered Extra
10061005
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
10071006
Warnings:
10081007
Warning 1292 Incorrect datetime value: ' garbage '
1009-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = ' garbage ') and (length(`test`.`t1`.`a`) = (30 + rand())))
1008+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'0000-00-00 00:00:00') and (<cache>(length(TIMESTAMP'0000-00-00 00:00:00')) = (30 + rand())))
10101009
DROP TABLE t1;
10111010
CREATE TABLE t1 (a DATETIME);;
10121011
INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2001-01-01 00:00:01');
@@ -1076,13 +1075,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=19 AND a=TIME'00:00:00';
10761075
id select_type table type possible_keys key key_len ref rows filtered Extra
10771076
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
10781077
Warnings:
1079-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00')
1078+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00')
10801079
EXPLAIN EXTENDED
10811080
SELECT * FROM t1 WHERE LENGTH(a)=40+RAND() AND a=TIME'00:00:00';
10821081
id select_type table type possible_keys key key_len ref rows filtered Extra
10831082
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
10841083
Warnings:
1085-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (40 + rand())))
1084+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (40 + rand())))
10861085
DROP TABLE t1;
10871086
#
10881087
# MDEV-8795 Equal expression propagation does not work for temporal literals
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#
2+
# MDEV-9604 crash in Item::save_in_field with empty enum value
3+
#
4+
SELECT TIME'00:00:00'='';
5+
TIME'00:00:00'=''
6+
1
7+
Warnings:
8+
Warning 1292 Truncated incorrect time value: ''
9+
CREATE TABLE t1 (a ENUM('a'), b TIME, c INT, KEY(b)) ENGINE=InnoDB;
10+
INSERT INTO t1 VALUES ('','00:00:00',0);
11+
Warnings:
12+
Warning 1265 Data truncated for column 'a' at row 1
13+
SELECT * FROM t1 WHERE b='';
14+
a b c
15+
00:00:00 0
16+
Warnings:
17+
Warning 1292 Truncated incorrect time value: ''
18+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
19+
a b c
20+
00:00:00 0
21+
Warnings:
22+
Warning 1292 Truncated incorrect time value: ''
23+
SELECT * FROM t1 WHERE a=b;
24+
a b c
25+
00:00:00 0
26+
Warnings:
27+
Warning 1292 Truncated incorrect time value: ''
28+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
29+
1
30+
1
31+
Warnings:
32+
Warning 1292 Truncated incorrect time value: ''
33+
ALTER TABLE t1 ENGINE=MyISAM;
34+
SELECT * FROM t1 WHERE b='';
35+
a b c
36+
00:00:00 0
37+
Warnings:
38+
Warning 1292 Truncated incorrect time value: ''
39+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
40+
a b c
41+
00:00:00 0
42+
Warnings:
43+
Warning 1292 Truncated incorrect time value: ''
44+
SELECT * FROM t1 WHERE a=b;
45+
a b c
46+
00:00:00 0
47+
Warnings:
48+
Warning 1292 Truncated incorrect time value: ''
49+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
50+
1
51+
1
52+
Warnings:
53+
Warning 1292 Truncated incorrect time value: ''
54+
DROP TABLE t1;
55+
SELECT DATE'0000-00-00'='';
56+
DATE'0000-00-00'=''
57+
1
58+
Warnings:
59+
Warning 1292 Incorrect datetime value: ''
60+
CREATE TABLE t1 (a ENUM('a'), b DATE, c INT, KEY(b)) ENGINE=InnoDB;
61+
INSERT INTO t1 VALUES ('','0000-00-00',0);
62+
Warnings:
63+
Warning 1265 Data truncated for column 'a' at row 1
64+
SELECT * FROM t1 WHERE b='';
65+
a b c
66+
0000-00-00 0
67+
Warnings:
68+
Warning 1292 Incorrect datetime value: ''
69+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
70+
a b c
71+
0000-00-00 0
72+
Warnings:
73+
Warning 1292 Incorrect datetime value: ''
74+
SELECT * FROM t1 WHERE a=b;
75+
a b c
76+
0000-00-00 0
77+
Warnings:
78+
Warning 1292 Incorrect datetime value: ''
79+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
80+
1
81+
1
82+
Warnings:
83+
Warning 1292 Incorrect datetime value: ''
84+
ALTER TABLE t1 ENGINE=MyISAM;
85+
SELECT * FROM t1 WHERE b='';
86+
a b c
87+
0000-00-00 0
88+
Warnings:
89+
Warning 1292 Incorrect datetime value: ''
90+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
91+
a b c
92+
0000-00-00 0
93+
Warnings:
94+
Warning 1292 Incorrect datetime value: ''
95+
SELECT * FROM t1 WHERE a=b;
96+
a b c
97+
0000-00-00 0
98+
Warnings:
99+
Warning 1292 Incorrect datetime value: ''
100+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
101+
1
102+
1
103+
Warnings:
104+
Warning 1292 Incorrect datetime value: ''
105+
DROP TABLE t1;
106+
SELECT TIMESTAMP'0000-00-00 00:00:00'='';
107+
TIMESTAMP'0000-00-00 00:00:00'=''
108+
1
109+
Warnings:
110+
Warning 1292 Incorrect datetime value: ''
111+
CREATE TABLE t1 (a ENUM('a'), b DATETIME, c INT, KEY(b)) ENGINE=InnoDB;
112+
INSERT INTO t1 VALUES ('','0000-00-00 00:00:00',0);
113+
Warnings:
114+
Warning 1265 Data truncated for column 'a' at row 1
115+
SELECT * FROM t1 WHERE b='';
116+
a b c
117+
0000-00-00 00:00:00 0
118+
Warnings:
119+
Warning 1292 Incorrect datetime value: ''
120+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
121+
a b c
122+
0000-00-00 00:00:00 0
123+
Warnings:
124+
Warning 1292 Incorrect datetime value: ''
125+
SELECT * FROM t1 WHERE a=b;
126+
a b c
127+
0000-00-00 00:00:00 0
128+
Warnings:
129+
Warning 1292 Incorrect datetime value: ''
130+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
131+
1
132+
1
133+
Warnings:
134+
Warning 1292 Incorrect datetime value: ''
135+
ALTER TABLE t1 ENGINE=MyISAM;
136+
SELECT * FROM t1 WHERE b='';
137+
a b c
138+
0000-00-00 00:00:00 0
139+
Warnings:
140+
Warning 1292 Incorrect datetime value: ''
141+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
142+
a b c
143+
0000-00-00 00:00:00 0
144+
Warnings:
145+
Warning 1292 Incorrect datetime value: ''
146+
SELECT * FROM t1 WHERE a=b;
147+
a b c
148+
0000-00-00 00:00:00 0
149+
Warnings:
150+
Warning 1292 Incorrect datetime value: ''
151+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
152+
1
153+
1
154+
Warnings:
155+
Warning 1292 Incorrect datetime value: ''
156+
DROP TABLE t1;

mysql-test/r/type_timestamp.result

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -818,21 +818,20 @@ a
818818
2001-01-01 00:00:00
819819
Warnings:
820820
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
821-
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
822821
EXPLAIN EXTENDED
823822
SELECT * FROM t1 WHERE LENGTH(a) != 20 AND a='2001-01-01 00:00:00x';
824823
id select_type table type possible_keys key key_len ref rows filtered Extra
825824
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
826825
Warnings:
827826
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
828-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '2001-01-01 00:00:00x')
827+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00')
829828
EXPLAIN EXTENDED
830829
SELECT * FROM t1 WHERE LENGTH(a)!=30+RAND() AND a='2001-01-01 00:00:00x';
831830
id select_type table type possible_keys key key_len ref rows filtered Extra
832831
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
833832
Warnings:
834833
Warning 1292 Truncated incorrect datetime value: '2001-01-01 00:00:00x'
835-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '2001-01-01 00:00:00x') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) <> (30 + rand())))
834+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) <> (30 + rand())))
836835
DROP TABLE t1;
837836
CREATE TABLE t1 (a TIMESTAMP);;
838837
INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2001-01-01 00:00:01');
@@ -848,20 +847,20 @@ SELECT * FROM t1 WHERE LENGTH(a)=19 AND a=' 2001-01-01 00:00:00';
848847
id select_type table type possible_keys key key_len ref rows filtered Extra
849848
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
850849
Warnings:
851-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = ' 2001-01-01 00:00:00')
850+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00')
852851
EXPLAIN EXTENDED
853852
SELECT * FROM t1 WHERE LENGTH(a)=19+RAND() AND a=' 2001-01-01 00:00:00';
854853
id select_type table type possible_keys key key_len ref rows filtered Extra
855854
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
856855
Warnings:
857-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = ' 2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (19 + rand())))
856+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (19 + rand())))
858857
EXPLAIN EXTENDED
859858
SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=' garbage ';
860859
id select_type table type possible_keys key key_len ref rows filtered Extra
861860
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
862861
Warnings:
863862
Warning 1292 Incorrect datetime value: ' garbage '
864-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = ' garbage ') and (length(`test`.`t1`.`a`) = (30 + rand())))
863+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'0000-00-00 00:00:00') and (<cache>(length(TIMESTAMP'0000-00-00 00:00:00')) = (30 + rand())))
865864
DROP TABLE t1;
866865
CREATE TABLE t1 (a TIMESTAMP);;
867866
INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2001-01-01 00:00:01');
@@ -931,13 +930,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=19 AND a=TIME'00:00:00';
931930
id select_type table type possible_keys key key_len ref rows filtered Extra
932931
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
933932
Warnings:
934-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00')
933+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00')
935934
EXPLAIN EXTENDED
936935
SELECT * FROM t1 WHERE LENGTH(a)=40+RAND() AND a=TIME'00:00:00';
937936
id select_type table type possible_keys key key_len ref rows filtered Extra
938937
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
939938
Warnings:
940-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (40 + rand())))
939+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 00:00:00') and (<cache>(length(TIMESTAMP'2001-01-01 00:00:00')) = (40 + rand())))
941940
DROP TABLE t1;
942941
#
943942
# End of 10.1 tests
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--source include/have_innodb.inc
2+
3+
#
4+
# testing of temporal data types with InnoDB
5+
#
6+
7+
8+
--echo #
9+
--echo # MDEV-9604 crash in Item::save_in_field with empty enum value
10+
--echo #
11+
12+
SELECT TIME'00:00:00'='';
13+
14+
CREATE TABLE t1 (a ENUM('a'), b TIME, c INT, KEY(b)) ENGINE=InnoDB;
15+
INSERT INTO t1 VALUES ('','00:00:00',0);
16+
SELECT * FROM t1 WHERE b='';
17+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
18+
SELECT * FROM t1 WHERE a=b;
19+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
20+
21+
ALTER TABLE t1 ENGINE=MyISAM;
22+
SELECT * FROM t1 WHERE b='';
23+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
24+
SELECT * FROM t1 WHERE a=b;
25+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
26+
DROP TABLE t1;
27+
28+
29+
SELECT DATE'0000-00-00'='';
30+
31+
CREATE TABLE t1 (a ENUM('a'), b DATE, c INT, KEY(b)) ENGINE=InnoDB;
32+
INSERT INTO t1 VALUES ('','0000-00-00',0);
33+
SELECT * FROM t1 WHERE b='';
34+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
35+
SELECT * FROM t1 WHERE a=b;
36+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
37+
38+
ALTER TABLE t1 ENGINE=MyISAM;
39+
SELECT * FROM t1 WHERE b='';
40+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
41+
SELECT * FROM t1 WHERE a=b;
42+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
43+
DROP TABLE t1;
44+
45+
46+
SELECT TIMESTAMP'0000-00-00 00:00:00'='';
47+
48+
CREATE TABLE t1 (a ENUM('a'), b DATETIME, c INT, KEY(b)) ENGINE=InnoDB;
49+
INSERT INTO t1 VALUES ('','0000-00-00 00:00:00',0);
50+
SELECT * FROM t1 WHERE b='';
51+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
52+
SELECT * FROM t1 WHERE a=b;
53+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
54+
55+
ALTER TABLE t1 ENGINE=MyISAM;
56+
SELECT * FROM t1 WHERE b='';
57+
SELECT * FROM t1 IGNORE KEY (b) WHERE b='';
58+
SELECT * FROM t1 WHERE a=b;
59+
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b;
60+
DROP TABLE t1;

sql/field.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5624,6 +5624,18 @@ Item *Field_temporal::get_equal_const_item_datetime(THD *thd,
56245624
}
56255625
break;
56265626
case ANY_SUBST:
5627+
if (!is_temporal_type_with_date(const_item->field_type()))
5628+
{
5629+
MYSQL_TIME ltime;
5630+
if (const_item->get_date_with_conversion(&ltime,
5631+
TIME_FUZZY_DATES |
5632+
TIME_INVALID_DATES))
5633+
return NULL;
5634+
return new (thd->mem_root)
5635+
Item_datetime_literal_for_invalid_dates(thd, &ltime,
5636+
ltime.second_part ?
5637+
TIME_SECOND_PART_DIGITS : 0);
5638+
}
56275639
break;
56285640
}
56295641
return const_item;
@@ -5932,7 +5944,10 @@ Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx,
59325944
{
59335945
MYSQL_TIME ltime;
59345946
// Get the value of const_item with conversion from DATETIME to TIME
5935-
if (const_item->get_time_with_conversion(thd, &ltime, TIME_TIME_ONLY))
5947+
if (const_item->get_time_with_conversion(thd, &ltime,
5948+
TIME_TIME_ONLY |
5949+
TIME_FUZZY_DATES |
5950+
TIME_INVALID_DATES))
59365951
return NULL;
59375952
/*
59385953
Replace a DATE/DATETIME constant to a TIME constant:

0 commit comments

Comments
 (0)