Commit b0a92333 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-15262 Wrong results for SELECT..WHERE non_indexed_datetime_column=indexed_time_column

parent 6f0b316f
...@@ -2308,3 +2308,47 @@ col_int_nokey ...@@ -2308,3 +2308,47 @@ col_int_nokey
1 1
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
SET TIMESTAMP=0; SET TIMESTAMP=0;
#
# MDEV-15262 Wrong results for SELECT..WHERE non_indexed_datetime_column=indexed_time_column
#
SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35');
CREATE TABLE t1 (col_time_key TIME, KEY(col_time_key));
CREATE TABLE t2 (col_datetime_key DATETIME);
INSERT INTO t1 VALUES ('-760:00:00'),('760:00:00');
INSERT INTO t1 VALUES ('-770:00:00'),('770:00:00');
INSERT INTO t2 SELECT * FROM t1;
SELECT * FROM t2 STRAIGHT_JOIN t1 IGNORE INDEX(col_time_key) WHERE col_time_key = col_datetime_key;
col_datetime_key col_time_key
2011-12-30 08:00:00 -760:00:00
2012-03-02 16:00:00 760:00:00
2011-12-29 22:00:00 -770:00:00
2012-03-03 02:00:00 770:00:00
SELECT * FROM t2 STRAIGHT_JOIN t1 FORCE INDEX (col_time_key) WHERE col_time_key = col_datetime_key;
col_datetime_key col_time_key
2011-12-29 22:00:00 -770:00:00
2011-12-30 08:00:00 -760:00:00
2012-03-02 16:00:00 760:00:00
2012-03-03 02:00:00 770:00:00
INSERT INTO t1 VALUES ('-838:59:59'),('838:59:59');
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '-838:59:59' HOUR_SECOND));
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '838:59:59' HOUR_SECOND));
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '-839:00:00' HOUR_SECOND));
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '839:00:00' HOUR_SECOND));
SELECT * FROM t2 STRAIGHT_JOIN t1 IGNORE INDEX(col_time_key) WHERE col_time_key = col_datetime_key;
col_datetime_key col_time_key
2011-12-30 08:00:00 -760:00:00
2012-03-02 16:00:00 760:00:00
2011-12-29 22:00:00 -770:00:00
2012-03-03 02:00:00 770:00:00
2011-12-27 01:00:01 -838:59:59
2012-03-05 22:59:59 838:59:59
SELECT * FROM t2 STRAIGHT_JOIN t1 FORCE INDEX (col_time_key) WHERE col_time_key = col_datetime_key;
col_datetime_key col_time_key
2011-12-29 22:00:00 -770:00:00
2011-12-30 08:00:00 -760:00:00
2012-03-02 16:00:00 760:00:00
2012-03-03 02:00:00 770:00:00
2011-12-27 01:00:01 -838:59:59
2012-03-05 22:59:59 838:59:59
DROP TABLE t1, t2;
SET TIMESTAMP=DEFAULT;
...@@ -172,6 +172,29 @@ eval $query; ...@@ -172,6 +172,29 @@ eval $query;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
SET TIMESTAMP=0; # back to current time SET TIMESTAMP=0; # back to current time
--echo #
--echo # MDEV-15262 Wrong results for SELECT..WHERE non_indexed_datetime_column=indexed_time_column
--echo #
SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35');
CREATE TABLE t1 (col_time_key TIME, KEY(col_time_key));
CREATE TABLE t2 (col_datetime_key DATETIME);
INSERT INTO t1 VALUES ('-760:00:00'),('760:00:00');
INSERT INTO t1 VALUES ('-770:00:00'),('770:00:00');
INSERT INTO t2 SELECT * FROM t1;
SELECT * FROM t2 STRAIGHT_JOIN t1 IGNORE INDEX(col_time_key) WHERE col_time_key = col_datetime_key;
SELECT * FROM t2 STRAIGHT_JOIN t1 FORCE INDEX (col_time_key) WHERE col_time_key = col_datetime_key;
INSERT INTO t1 VALUES ('-838:59:59'),('838:59:59');
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '-838:59:59' HOUR_SECOND));
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '838:59:59' HOUR_SECOND));
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '-839:00:00' HOUR_SECOND));
INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '839:00:00' HOUR_SECOND));
SELECT * FROM t2 STRAIGHT_JOIN t1 IGNORE INDEX(col_time_key) WHERE col_time_key = col_datetime_key;
SELECT * FROM t2 STRAIGHT_JOIN t1 FORCE INDEX (col_time_key) WHERE col_time_key = col_datetime_key;
DROP TABLE t1, t2;
SET TIMESTAMP=DEFAULT;
# #
# End of 10.0 tests # End of 10.0 tests
# #
...@@ -5330,6 +5330,13 @@ static void calc_datetime_days_diff(MYSQL_TIME *ltime, long days) ...@@ -5330,6 +5330,13 @@ static void calc_datetime_days_diff(MYSQL_TIME *ltime, long days)
ltime->second) * 1000000LL + ltime->second) * 1000000LL +
ltime->second_part); ltime->second_part);
unpack_time(timediff, ltime); unpack_time(timediff, ltime);
/*
unpack_time() broke down hours into ltime members hour,day,month.
Mix them back to ltime->hour using the same factors
that pack_time()/unpack_time() use (i.e. 32 for month).
*/
ltime->hour+= (ltime->month * 32 + ltime->day) * 24;
ltime->month= ltime->day= 0;
} }
ltime->time_type= MYSQL_TIMESTAMP_TIME; ltime->time_type= MYSQL_TIMESTAMP_TIME;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment