diff --git a/mysql-test/r/compare.result b/mysql-test/r/compare.result index 44c258d7611d47a91db855ee19df9b6a128f2070..f9563b89b761f6709c544b28be1e0c8d67f1bee4 100644 --- a/mysql-test/r/compare.result +++ b/mysql-test/r/compare.result @@ -90,4 +90,9 @@ Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1003 select `test`.`t2`.`a` AS `a`,(select count(0) AS `COUNT(*)` from `test`.`t1` where ((`test`.`t1`.`b` = `test`.`t2`.`a`) and (concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = concat('0',`test`.`t2`.`a`,'01')))) AS `x` from `test`.`t2` order by `test`.`t2`.`a` DROP TABLE t1,t2; +CREATE TABLE t1 (a TIMESTAMP); +INSERT INTO t1 VALUES (NOW()),(NOW()),(NOW()); +SELECT * FROM t1 WHERE a > '2008-01-01' AND a = '0000-00-00'; +a +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/compare.test b/mysql-test/t/compare.test index 8863ed825c2cdb0eb37c206223ba1bbf19b3abeb..103244eb2f7a4c44014716f2cd991645b382a546 100644 --- a/mysql-test/t/compare.test +++ b/mysql-test/t/compare.test @@ -76,4 +76,13 @@ FROM t2 ORDER BY a; DROP TABLE t1,t2; +# +# Bug #39353: Multiple conditions on timestamp column crashes server +# + +CREATE TABLE t1 (a TIMESTAMP); +INSERT INTO t1 VALUES (NOW()),(NOW()),(NOW()); +SELECT * FROM t1 WHERE a > '2008-01-01' AND a = '0000-00-00'; +DROP TABLE t1; + --echo End of 5.0 tests diff --git a/mysql-test/t/mysqldump-max.test b/mysql-test/t/mysqldump-max.test index 1876d759372798fe1b4b517a93711f7d88a56893..1e8b9647503f03affe9d41ef3523bdf71854c55a 100644 --- a/mysql-test/t/mysqldump-max.test +++ b/mysql-test/t/mysqldump-max.test @@ -1114,9 +1114,9 @@ CREATE VIEW v1 AS SELECT * FROM t1; INSERT INTO t1 VALUES(); SELECT COUNT(*) FROM v1; ---exec $MYSQL_DUMP --allow-keywords --single-transaction --quick --verbose test --result-file $MYSQL_TEST_DIR/var/tmp/bug31434.sql ---exec $MYSQL test < $MYSQL_TEST_DIR/var/tmp/bug31434.sql ---remove_file $MYSQL_TEST_DIR/var/tmp/bug31434.sql +--exec $MYSQL_DUMP --allow-keywords --single-transaction --quick --verbose test --result-file $MYSQLTEST_VARDIR/tmp/bug31434.sql +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug31434.sql +--remove_file $MYSQLTEST_VARDIR/tmp/bug31434.sql SELECT COUNT(*) FROM v1; diff --git a/sql/item.cc b/sql/item.cc index 951336cce248c340efb99865e80f9741ffc68b4b..cdb71e86694af0a76a3c8347006e5f642bb1821f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4342,7 +4342,12 @@ Item *Item_field::equal_fields_propagator(uchar *arg) item= this; else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type())) { - if (item && cmp_context != INT_RESULT) + /* + We don't need to zero-fill timestamp columns here because they will be + first converted to a string (in date/time format) and compared as such if + compared with another string. + */ + if (item && field->type() != FIELD_TYPE_TIMESTAMP && cmp_context != INT_RESULT) convert_zerofill_number_to_string(&item, (Field_num *)field); else item= this;