Skip to content

Commit

Permalink
MDEV-10316 - main.type_date fails around midnight sporadically
Browse files Browse the repository at this point in the history
A better fix for MySQL Bug#41776: use hard timestamp rather than unreliable
sleep.
  • Loading branch information
Sergey Vojtovich committed Jul 21, 2016
1 parent 5cf49cd commit 1b5da2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 2 additions & 0 deletions mysql-test/r/type_date.result
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ str_to_date( '', a )
NULL
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b INT, PRIMARY KEY (a,b));
SET timestamp=UNIX_TIMESTAMP('2016-07-21 14:48:18');
INSERT INTO t1 VALUES (DATE(NOW()), 1);
SELECT COUNT(*) FROM t1 WHERE a = NOW();
COUNT(*)
Expand Down Expand Up @@ -192,6 +193,7 @@ COUNT(*)
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SET timestamp=DEFAULT;
DROP TABLE t1;
CREATE TABLE t1 (a DATE);
CREATE TABLE t2 (a DATE);
Expand Down
15 changes: 3 additions & 12 deletions mysql-test/t/type_date.test
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,8 @@ DROP TABLE t1;
#

CREATE TABLE t1 (a DATE, b INT, PRIMARY KEY (a,b));
## The current sub test could fail (difference to expected result) if we
## have just reached midnight.
## (Bug#41776 type_date.test may fail if run around midnight)
## Therefore we sleep a bit if we are too close to midnight.
## The complete test itself needs in average less than 1 second.
## Therefore a time_distance to midnight of 5 seconds should be sufficient.
if (`SELECT CURTIME() > SEC_TO_TIME(24 * 3600 - 5)`)
{
# We are here when CURTIME() is between '23:59:56' and '23:59:59'.
# So a sleep time of 5 seconds brings us between '00:00:01' and '00:00:04'.
--real_sleep 5
}

SET timestamp=UNIX_TIMESTAMP('2016-07-21 14:48:18');
INSERT INTO t1 VALUES (DATE(NOW()), 1);
SELECT COUNT(*) FROM t1 WHERE a = NOW();
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
Expand All @@ -192,6 +182,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW() AND b = 1;
ALTER TABLE t1 DROP PRIMARY KEY;
SELECT COUNT(*) FROM t1 WHERE a = NOW();
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
SET timestamp=DEFAULT;

DROP TABLE t1;

Expand Down

0 comments on commit 1b5da2c

Please sign in to comment.