-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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;
- Loading branch information
Alexander Barkov
committed
Mar 23, 2016
1 parent
f66303d
commit e4435b5
Showing
6 changed files
with
263 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# | ||
# MDEV-9604 crash in Item::save_in_field with empty enum value | ||
# | ||
SELECT TIME'00:00:00'=''; | ||
TIME'00:00:00'='' | ||
1 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
CREATE TABLE t1 (a ENUM('a'), b TIME, c INT, KEY(b)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES ('','00:00:00',0); | ||
Warnings: | ||
Warning 1265 Data truncated for column 'a' at row 1 | ||
SELECT * FROM t1 WHERE b=''; | ||
a b c | ||
00:00:00 0 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
a b c | ||
00:00:00 0 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
SELECT * FROM t1 WHERE a=b; | ||
a b c | ||
00:00:00 0 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
1 | ||
1 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
ALTER TABLE t1 ENGINE=MyISAM; | ||
SELECT * FROM t1 WHERE b=''; | ||
a b c | ||
00:00:00 0 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
a b c | ||
00:00:00 0 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
SELECT * FROM t1 WHERE a=b; | ||
a b c | ||
00:00:00 0 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
1 | ||
1 | ||
Warnings: | ||
Warning 1292 Truncated incorrect time value: '' | ||
DROP TABLE t1; | ||
SELECT DATE'0000-00-00'=''; | ||
DATE'0000-00-00'='' | ||
1 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
CREATE TABLE t1 (a ENUM('a'), b DATE, c INT, KEY(b)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES ('','0000-00-00',0); | ||
Warnings: | ||
Warning 1265 Data truncated for column 'a' at row 1 | ||
SELECT * FROM t1 WHERE b=''; | ||
a b c | ||
0000-00-00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
a b c | ||
0000-00-00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 WHERE a=b; | ||
a b c | ||
0000-00-00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
1 | ||
1 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
ALTER TABLE t1 ENGINE=MyISAM; | ||
SELECT * FROM t1 WHERE b=''; | ||
a b c | ||
0000-00-00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
a b c | ||
0000-00-00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 WHERE a=b; | ||
a b c | ||
0000-00-00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
1 | ||
1 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
DROP TABLE t1; | ||
SELECT TIMESTAMP'0000-00-00 00:00:00'=''; | ||
TIMESTAMP'0000-00-00 00:00:00'='' | ||
1 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
CREATE TABLE t1 (a ENUM('a'), b DATETIME, c INT, KEY(b)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES ('','0000-00-00 00:00:00',0); | ||
Warnings: | ||
Warning 1265 Data truncated for column 'a' at row 1 | ||
SELECT * FROM t1 WHERE b=''; | ||
a b c | ||
0000-00-00 00:00:00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
a b c | ||
0000-00-00 00:00:00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 WHERE a=b; | ||
a b c | ||
0000-00-00 00:00:00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
1 | ||
1 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
ALTER TABLE t1 ENGINE=MyISAM; | ||
SELECT * FROM t1 WHERE b=''; | ||
a b c | ||
0000-00-00 00:00:00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
a b c | ||
0000-00-00 00:00:00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT * FROM t1 WHERE a=b; | ||
a b c | ||
0000-00-00 00:00:00 0 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
1 | ||
1 | ||
Warnings: | ||
Warning 1292 Incorrect datetime value: '' | ||
DROP TABLE t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--source include/have_innodb.inc | ||
|
||
# | ||
# testing of temporal data types with InnoDB | ||
# | ||
|
||
|
||
--echo # | ||
--echo # MDEV-9604 crash in Item::save_in_field with empty enum value | ||
--echo # | ||
|
||
SELECT TIME'00:00:00'=''; | ||
|
||
CREATE TABLE t1 (a ENUM('a'), b TIME, c INT, KEY(b)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES ('','00:00:00',0); | ||
SELECT * FROM t1 WHERE b=''; | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
SELECT * FROM t1 WHERE a=b; | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
|
||
ALTER TABLE t1 ENGINE=MyISAM; | ||
SELECT * FROM t1 WHERE b=''; | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
SELECT * FROM t1 WHERE a=b; | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
DROP TABLE t1; | ||
|
||
|
||
SELECT DATE'0000-00-00'=''; | ||
|
||
CREATE TABLE t1 (a ENUM('a'), b DATE, c INT, KEY(b)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES ('','0000-00-00',0); | ||
SELECT * FROM t1 WHERE b=''; | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
SELECT * FROM t1 WHERE a=b; | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
|
||
ALTER TABLE t1 ENGINE=MyISAM; | ||
SELECT * FROM t1 WHERE b=''; | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
SELECT * FROM t1 WHERE a=b; | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
DROP TABLE t1; | ||
|
||
|
||
SELECT TIMESTAMP'0000-00-00 00:00:00'=''; | ||
|
||
CREATE TABLE t1 (a ENUM('a'), b DATETIME, c INT, KEY(b)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES ('','0000-00-00 00:00:00',0); | ||
SELECT * FROM t1 WHERE b=''; | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
SELECT * FROM t1 WHERE a=b; | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
|
||
ALTER TABLE t1 ENGINE=MyISAM; | ||
SELECT * FROM t1 WHERE b=''; | ||
SELECT * FROM t1 IGNORE KEY (b) WHERE b=''; | ||
SELECT * FROM t1 WHERE a=b; | ||
SELECT 1 FROM t1 WHERE (SELECT a FROM t1 group by c) = b; | ||
DROP TABLE t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.