mirror of
https://github.com/MariaDB/server.git
synced 2025-07-02 14:22:51 +03:00
Fix for bug#47963: Wrong results when index is used
Problem: using null microsecond part (e.g. "YYYY-MM-DD HH:MM:SS.0000") in a WHERE condition may lead to wrong results due to improper DATETIMEs comparison in some cases. Fix: as we compare DATETIMEs as strings we must trim trailing 0's in such cases.
This commit is contained in:
@ -2209,4 +2209,46 @@ EXPLAIN SELECT * FROM t1 FORCE INDEX(PRIMARY) WHERE b=1 AND c=1 ORDER BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL PRIMARY 4 NULL 128 Using where
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug #47963: Wrong results when index is used
|
||||
#
|
||||
CREATE TABLE t1(
|
||||
a VARCHAR(5) NOT NULL,
|
||||
b VARCHAR(5) NOT NULL,
|
||||
c DATETIME NOT NULL,
|
||||
KEY (c)
|
||||
) ENGINE=InnoDB;
|
||||
INSERT INTO t1 VALUES('TEST', 'TEST', '2009-10-09 00:00:00');
|
||||
SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00';
|
||||
a b c
|
||||
TEST TEST 2009-10-09 00:00:00
|
||||
SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00.0';
|
||||
a b c
|
||||
TEST TEST 2009-10-09 00:00:00
|
||||
SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00';
|
||||
a b c
|
||||
TEST TEST 2009-10-09 00:00:00
|
||||
SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00.0';
|
||||
a b c
|
||||
TEST TEST 2009-10-09 00:00:00
|
||||
SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00.000' AND c <= '2009-10-09 00:00:00.000';
|
||||
a b c
|
||||
TEST TEST 2009-10-09 00:00:00
|
||||
SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00.00' AND c <= '2009-10-09 00:00:00.001';
|
||||
a b c
|
||||
TEST TEST 2009-10-09 00:00:00
|
||||
SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
|
||||
a b c
|
||||
EXPLAIN SELECT * FROM t1 WHERE a = 'TEST' AND
|
||||
c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
DROP TABLE t1;
|
||||
End of 5.1 tests
|
||||
|
Reference in New Issue
Block a user