Commit 4b4dfd57 authored by Igor Babaev's avatar Igor Babaev

Merge.

parents 21627048 adc1f2f4
...@@ -103,6 +103,8 @@ extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, const uchar *a); ...@@ -103,6 +103,8 @@ extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, const uchar *a);
if we're scanning "t.key BETWEEN 10 AND 20" and got a if we're scanning "t.key BETWEEN 10 AND 20" and got a
"t.key=21" tuple (the engine should stop scanning and "t.key=21" tuple (the engine should stop scanning and
return HA_ERR_END_OF_FILE right away). return HA_ERR_END_OF_FILE right away).
3=ICP_ABORTED_BY_USER - engine must stop scanning and should return
HA_ERR_ABORTED_BY_USER right away
-1= ICP_ERROR - Reserved for internal errors in engines. Should not be -1= ICP_ERROR - Reserved for internal errors in engines. Should not be
returned by index_cond_func_xxx returned by index_cond_func_xxx
*/ */
...@@ -111,7 +113,8 @@ typedef enum icp_result { ...@@ -111,7 +113,8 @@ typedef enum icp_result {
ICP_ERROR=-1, ICP_ERROR=-1,
ICP_NO_MATCH=0, ICP_NO_MATCH=0,
ICP_MATCH=1, ICP_MATCH=1,
ICP_OUT_OF_RANGE=2 ICP_OUT_OF_RANGE=2,
ICP_ABORTED_BY_USER=3,
} ICP_RESULT; } ICP_RESULT;
......
...@@ -86,6 +86,152 @@ SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; ...@@ -86,6 +86,152 @@ SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2;
--echo --echo
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # Bug#43617 - Innodb returns wrong results with timestamp's range value
--echo # in IN clause
--echo # (Note: Fixed by patch for BUG#42580)
--echo #
CREATE TABLE t1(
c1 TIMESTAMP NOT NULL,
c2 TIMESTAMP NULL,
c3 DATE,
c4 DATETIME,
PRIMARY KEY(c1),
UNIQUE INDEX(c2)
);
INSERT INTO t1 VALUES
('0000-00-00 00:00:00','0000-00-00 00:00:00','2008-01-04','2008-01-05 00:00:00'),
('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02 00:00:00'),
('1999-01-01 00:00:00','1999-01-01 00:00:00', NULL, NULL),
('2007-05-23 09:15:28','2007-05-23 09:15:28','2007-05-24','2007-05-24 09:15:28'),
('2007-05-27 00:00:00','2007-05-25 00:00:00','2007-05-26','2007-05-26 00:00:00'),
('2008-01-01 00:00:00', NULL, '2008-01-02','2008-01-03 00:00:00'),
('2009-01-29 11:11:27','2009-01-29 11:11:27','2009-01-29','2009-01-29 11:11:27'),
('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06 00:00:00');
--echo
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2;
--echo
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 LIMIT 2;
--echo
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC;
--echo
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC LIMIT 2;
--echo
DROP TABLE t1;
--echo #
--echo # BUG#43618: MyISAM&Maria returns wrong results with 'between'
--echo # on timestamp
--echo #
CREATE TABLE t1(
ts TIMESTAMP NOT NULL,
c char NULL,
PRIMARY KEY(ts)
);
INSERT INTO t1 VALUES
('1971-01-01','a'),
('2007-05-25','b'),
('2008-01-01','c'),
('2038-01-09','d');
--disable_warnings
--echo
--echo # Execute select with invalid timestamp, desc ordering
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
--echo
--echo # Should use index condition
EXPLAIN
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
--echo
--enable_warnings
DROP TABLE t1;
--echo #
--echo # BUG#49906: Assertion failed - Field_varstring::val_str in field.cc
--echo # (Note: Fixed by patch for LP BUG#625841)
--echo #
CREATE TABLE t1 (
f1 VARCHAR(1024),
f2 VARCHAR(10),
INDEX test_idx USING BTREE (f2,f1(5))
);
INSERT INTO t1 VALUES ('a','c'), ('b','d');
SELECT f1
FROM t1
WHERE f2 LIKE 'd'
ORDER BY f1;
DROP TABLE t1;
--echo #
--echo # Bug#52660 - "Perf. regr. using ICP for MyISAM on range queries on
--echo # an index containing TEXT"
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t2 (a INT);
INSERT INTO t2 SELECT A.a + 10*(B.a) FROM t1 A, t1 B;
CREATE TABLE t3 (
c1 TINYTEXT NOT NULL,
i1 INT NOT NULL,
KEY (c1(6),i1)
);
INSERT INTO t3 SELECT CONCAT('c-',1000+t2.a,'=w'), 1 FROM t2;
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
DROP TABLE t1, t2, t3;
--echo # --echo #
--echo # Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on --echo # Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on
--echo # --echo #
...@@ -102,6 +248,7 @@ SELECT * FROM t WHERE a > 2 FOR UPDATE; ...@@ -102,6 +248,7 @@ SELECT * FROM t WHERE a > 2 FOR UPDATE;
DROP TABLE t; DROP TABLE t;
--echo # --echo #
--echo # Bug#35080 - Innodb crash at mem_block_get_len line 72 --echo # Bug#35080 - Innodb crash at mem_block_get_len line 72
--echo # --echo #
...@@ -226,6 +373,100 @@ SELECT COUNT(*) FROM t3; ...@@ -226,6 +373,100 @@ SELECT COUNT(*) FROM t3;
DROP PROCEDURE insert_data; DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
--echo #
--echo # Bug#57372 "Multi-table updates and deletes fail when running with ICP
--echo # against InnoDB"
--echo #
CREATE TABLE t1 (
a INT KEY,
b INT
);
CREATE TABLE t2 (
a INT KEY,
b INT
);
INSERT INTO t1 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105);
INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
UPDATE t1, t2
SET t1.a = t1.a + 100, t2.b = t1.a + 10
WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b - 100;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
DROP TABLE t1, t2;
--echo #
--echo # Bug#52605 - "Adding LIMIT 1 clause to query with complex range
--echo # predicate causes wrong results"
--echo #
CREATE TABLE t1 (
pk INT NOT NULL,
c1 INT,
PRIMARY KEY (pk),
KEY k1 (c1)
);
INSERT INTO t1 VALUES (1,NULL);
INSERT INTO t1 VALUES (2,6);
INSERT INTO t1 VALUES (3,NULL);
INSERT INTO t1 VALUES (4,6);
INSERT INTO t1 VALUES (5,NULL);
INSERT INTO t1 VALUES (6,NULL);
INSERT INTO t1 VALUES (7,9);
INSERT INTO t1 VALUES (8,0);
SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
EXPLAIN SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
DROP TABLE t1;
--echo #
--echo # Bug#59259 "Incorrect rows returned for a correlated subquery
--echo # when ICP is on"
--echo #
CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
INSERT INTO t1 VALUES (11,0);
INSERT INTO t1 VALUES (12,5);
INSERT INTO t1 VALUES (15,0);
CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
INSERT INTO t2 VALUES (11,1);
INSERT INTO t2 VALUES (12,2);
INSERT INTO t2 VALUES (15,4);
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch='semijoin=off';
EXPLAIN
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1, t2;
--echo # --echo #
--echo # BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89 --echo # BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
--echo # --echo #
......
...@@ -783,7 +783,7 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h ...@@ -783,7 +783,7 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h
insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
explain select * from t1 where a > 0 and a < 50; explain select * from t1 where a > 0 and a < 50;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using index condition
drop table t1; drop table t1;
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb; create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL'); insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
......
...@@ -83,6 +83,150 @@ c1 c2 c3 c4 ...@@ -83,6 +83,150 @@ c1 c2 c3 c4
DROP TABLE t1; DROP TABLE t1;
# #
# Bug#43617 - Innodb returns wrong results with timestamp's range value
# in IN clause
# (Note: Fixed by patch for BUG#42580)
#
CREATE TABLE t1(
c1 TIMESTAMP NOT NULL,
c2 TIMESTAMP NULL,
c3 DATE,
c4 DATETIME,
PRIMARY KEY(c1),
UNIQUE INDEX(c2)
);
INSERT INTO t1 VALUES
('0000-00-00 00:00:00','0000-00-00 00:00:00','2008-01-04','2008-01-05 00:00:00'),
('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02 00:00:00'),
('1999-01-01 00:00:00','1999-01-01 00:00:00', NULL, NULL),
('2007-05-23 09:15:28','2007-05-23 09:15:28','2007-05-24','2007-05-24 09:15:28'),
('2007-05-27 00:00:00','2007-05-25 00:00:00','2007-05-26','2007-05-26 00:00:00'),
('2008-01-01 00:00:00', NULL, '2008-01-02','2008-01-03 00:00:00'),
('2009-01-29 11:11:27','2009-01-29 11:11:27','2009-01-29','2009-01-29 11:11:27'),
('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06 00:00:00');
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 LIMIT 2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC LIMIT 2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
DROP TABLE t1;
#
# BUG#43618: MyISAM&Maria returns wrong results with 'between'
# on timestamp
#
CREATE TABLE t1(
ts TIMESTAMP NOT NULL,
c char NULL,
PRIMARY KEY(ts)
);
INSERT INTO t1 VALUES
('1971-01-01','a'),
('2007-05-25','b'),
('2008-01-01','c'),
('2038-01-09','d');
# Execute select with invalid timestamp, desc ordering
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
ts c
2008-01-01 00:00:00 c
2007-05-25 00:00:00 b
# Should use index condition
EXPLAIN
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition
DROP TABLE t1;
#
# BUG#49906: Assertion failed - Field_varstring::val_str in field.cc
# (Note: Fixed by patch for LP BUG#625841)
#
CREATE TABLE t1 (
f1 VARCHAR(1024),
f2 VARCHAR(10),
INDEX test_idx USING BTREE (f2,f1(5))
);
INSERT INTO t1 VALUES ('a','c'), ('b','d');
SELECT f1
FROM t1
WHERE f2 LIKE 'd'
ORDER BY f1;
f1
b
DROP TABLE t1;
#
# Bug#52660 - "Perf. regr. using ICP for MyISAM on range queries on
# an index containing TEXT"
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t2 (a INT);
INSERT INTO t2 SELECT A.a + 10*(B.a) FROM t1 A, t1 B;
CREATE TABLE t3 (
c1 TINYTEXT NOT NULL,
i1 INT NOT NULL,
KEY (c1(6),i1)
);
INSERT INTO t3 SELECT CONCAT('c-',1000+t2.a,'=w'), 1 FROM t2;
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 range c1 c1 8 NULL 3 Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
c1
c-1004=w
c-1005=w
c-1006=w
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 range c1 c1 12 NULL 2 Using index condition; Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
c1
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL c1 NULL NULL NULL 100 Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
c1
c-1004=w
c-1005=w
c-1006=w
DROP TABLE t1, t2, t3;
#
# Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on # Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on
# #
CREATE TABLE t ( CREATE TABLE t (
...@@ -203,6 +347,98 @@ COUNT(*) ...@@ -203,6 +347,98 @@ COUNT(*)
DROP PROCEDURE insert_data; DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
# #
# Bug#57372 "Multi-table updates and deletes fail when running with ICP
# against InnoDB"
#
CREATE TABLE t1 (
a INT KEY,
b INT
);
CREATE TABLE t2 (
a INT KEY,
b INT
);
INSERT INTO t1 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105);
INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
UPDATE t1, t2
SET t1.a = t1.a + 100, t2.b = t1.a + 10
WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b - 100;
SELECT * FROM t1;
a b
1 101
102 102
103 103
104 104
5 105
SELECT * FROM t2;
a b
1 1
2 12
3 13
4 14
5 5
DROP TABLE t1, t2;
#
# Bug#52605 - "Adding LIMIT 1 clause to query with complex range
# predicate causes wrong results"
#
CREATE TABLE t1 (
pk INT NOT NULL,
c1 INT,
PRIMARY KEY (pk),
KEY k1 (c1)
);
INSERT INTO t1 VALUES (1,NULL);
INSERT INTO t1 VALUES (2,6);
INSERT INTO t1 VALUES (3,NULL);
INSERT INTO t1 VALUES (4,6);
INSERT INTO t1 VALUES (5,NULL);
INSERT INTO t1 VALUES (6,NULL);
INSERT INTO t1 VALUES (7,9);
INSERT INTO t1 VALUES (8,0);
SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
pk c1
4 6
EXPLAIN SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,k1 k1 5 NULL 3 Using where; Using index
DROP TABLE t1;
#
# Bug#59259 "Incorrect rows returned for a correlated subquery
# when ICP is on"
#
CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
INSERT INTO t1 VALUES (11,0);
INSERT INTO t1 VALUES (12,5);
INSERT INTO t1 VALUES (15,0);
CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
INSERT INTO t2 VALUES (11,1);
INSERT INTO t2 VALUES (12,2);
INSERT INTO t2 VALUES (15,4);
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch='semijoin=off';
EXPLAIN
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using index
2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using index condition
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
pk i
12 5
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1, t2;
#
# BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89 # BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
# #
CREATE TABLE t1 ( f11 int) ; CREATE TABLE t1 ( f11 int) ;
......
...@@ -728,6 +728,7 @@ JA USA ...@@ -728,6 +728,7 @@ JA USA
DROP TABLE t1,t2; DROP TABLE t1,t2;
# #
# Testcase backport: Bug#43249 # Testcase backport: Bug#43249
# (Note: Fixed by patch for BUG#42580)
# #
CREATE TABLE t1(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, PRIMARY KEY(c1), UNIQUE INDEX(c2)) engine=innodb; CREATE TABLE t1(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, PRIMARY KEY(c1), UNIQUE INDEX(c2)) engine=innodb;
INSERT INTO t1 VALUES('8:29:45',NULL,'2009-02-01'); INSERT INTO t1 VALUES('8:29:45',NULL,'2009-02-01');
......
...@@ -786,7 +786,7 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h ...@@ -786,7 +786,7 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h
insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
explain select * from t1 where a > 0 and a < 50; explain select * from t1 where a > 0 and a < 50;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using index condition
drop table t1; drop table t1;
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb; create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL'); insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
......
...@@ -83,6 +83,150 @@ c1 c2 c3 c4 ...@@ -83,6 +83,150 @@ c1 c2 c3 c4
DROP TABLE t1; DROP TABLE t1;
# #
# Bug#43617 - Innodb returns wrong results with timestamp's range value
# in IN clause
# (Note: Fixed by patch for BUG#42580)
#
CREATE TABLE t1(
c1 TIMESTAMP NOT NULL,
c2 TIMESTAMP NULL,
c3 DATE,
c4 DATETIME,
PRIMARY KEY(c1),
UNIQUE INDEX(c2)
);
INSERT INTO t1 VALUES
('0000-00-00 00:00:00','0000-00-00 00:00:00','2008-01-04','2008-01-05 00:00:00'),
('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02 00:00:00'),
('1999-01-01 00:00:00','1999-01-01 00:00:00', NULL, NULL),
('2007-05-23 09:15:28','2007-05-23 09:15:28','2007-05-24','2007-05-24 09:15:28'),
('2007-05-27 00:00:00','2007-05-25 00:00:00','2007-05-26','2007-05-26 00:00:00'),
('2008-01-01 00:00:00', NULL, '2008-01-02','2008-01-03 00:00:00'),
('2009-01-29 11:11:27','2009-01-29 11:11:27','2009-01-29','2009-01-29 11:11:27'),
('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06 00:00:00');
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 LIMIT 2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC LIMIT 2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
DROP TABLE t1;
#
# BUG#43618: MyISAM&Maria returns wrong results with 'between'
# on timestamp
#
CREATE TABLE t1(
ts TIMESTAMP NOT NULL,
c char NULL,
PRIMARY KEY(ts)
);
INSERT INTO t1 VALUES
('1971-01-01','a'),
('2007-05-25','b'),
('2008-01-01','c'),
('2038-01-09','d');
# Execute select with invalid timestamp, desc ordering
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
ts c
2008-01-01 00:00:00 c
2007-05-25 00:00:00 b
# Should use index condition
EXPLAIN
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using index condition
DROP TABLE t1;
#
# BUG#49906: Assertion failed - Field_varstring::val_str in field.cc
# (Note: Fixed by patch for LP BUG#625841)
#
CREATE TABLE t1 (
f1 VARCHAR(1024),
f2 VARCHAR(10),
INDEX test_idx USING BTREE (f2,f1(5))
);
INSERT INTO t1 VALUES ('a','c'), ('b','d');
SELECT f1
FROM t1
WHERE f2 LIKE 'd'
ORDER BY f1;
f1
b
DROP TABLE t1;
#
# Bug#52660 - "Perf. regr. using ICP for MyISAM on range queries on
# an index containing TEXT"
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t2 (a INT);
INSERT INTO t2 SELECT A.a + 10*(B.a) FROM t1 A, t1 B;
CREATE TABLE t3 (
c1 TINYTEXT NOT NULL,
i1 INT NOT NULL,
KEY (c1(6),i1)
);
INSERT INTO t3 SELECT CONCAT('c-',1000+t2.a,'=w'), 1 FROM t2;
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 range c1 c1 8 NULL 3 Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
c1
c-1004=w
c-1005=w
c-1006=w
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 range c1 c1 12 NULL 2 Using index condition; Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
c1
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL c1 NULL NULL NULL 100 Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
c1
c-1004=w
c-1005=w
c-1006=w
DROP TABLE t1, t2, t3;
#
# Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on # Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on
# #
CREATE TABLE t ( CREATE TABLE t (
...@@ -203,6 +347,104 @@ COUNT(*) ...@@ -203,6 +347,104 @@ COUNT(*)
DROP PROCEDURE insert_data; DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
# #
# Bug#57372 "Multi-table updates and deletes fail when running with ICP
# against InnoDB"
#
CREATE TABLE t1 (
a INT KEY,
b INT
);
CREATE TABLE t2 (
a INT KEY,
b INT
);
INSERT INTO t1 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105);
INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
UPDATE t1, t2
SET t1.a = t1.a + 100, t2.b = t1.a + 10
WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b - 100;
SELECT * FROM t1;
a b
1 101
102 102
103 103
104 104
5 105
SELECT * FROM t2;
a b
1 1
2 12
3 13
4 14
5 5
DROP TABLE t1, t2;
#
# Bug#52605 - "Adding LIMIT 1 clause to query with complex range
# predicate causes wrong results"
#
CREATE TABLE t1 (
pk INT NOT NULL,
c1 INT,
PRIMARY KEY (pk),
KEY k1 (c1)
);
INSERT INTO t1 VALUES (1,NULL);
INSERT INTO t1 VALUES (2,6);
INSERT INTO t1 VALUES (3,NULL);
INSERT INTO t1 VALUES (4,6);
INSERT INTO t1 VALUES (5,NULL);
INSERT INTO t1 VALUES (6,NULL);
INSERT INTO t1 VALUES (7,9);
INSERT INTO t1 VALUES (8,0);
SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
pk c1
4 6
EXPLAIN SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,k1 k1 5 NULL 4 Using where
DROP TABLE t1;
#
# Bug#59259 "Incorrect rows returned for a correlated subquery
# when ICP is on"
#
CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
Warnings:
Warning 1286 Unknown table engine 'InnoDB'
Warning 1266 Using storage engine Aria for table 't1'
INSERT INTO t1 VALUES (11,0);
INSERT INTO t1 VALUES (12,5);
INSERT INTO t1 VALUES (15,0);
CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
Warnings:
Warning 1286 Unknown table engine 'InnoDB'
Warning 1266 Using storage engine Aria for table 't2'
INSERT INTO t2 VALUES (11,1);
INSERT INTO t2 VALUES (12,2);
INSERT INTO t2 VALUES (15,4);
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch='semijoin=off';
EXPLAIN
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using index
2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using index condition
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
pk i
12 5
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1, t2;
#
# BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89 # BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
# #
CREATE TABLE t1 ( f11 int) ; CREATE TABLE t1 ( f11 int) ;
......
...@@ -105,7 +105,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -105,7 +105,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range FieldKey FieldKey 38 NULL 4 Using index condition; Rowid-ordered scan; Using filesort 1 SIMPLE t1 range FieldKey FieldKey 38 NULL 4 Using index condition; Rowid-ordered scan; Using filesort
EXPLAIN SELECT * FROM t1 IGNORE INDEX (FieldKey, LongField) WHERE FieldKey > '2' ORDER BY LongVal; EXPLAIN SELECT * FROM t1 IGNORE INDEX (FieldKey, LongField) WHERE FieldKey > '2' ORDER BY LongVal;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range StringField StringField 38 NULL 4 Using where; Using filesort 1 SIMPLE t1 range StringField StringField 38 NULL 4 Using index condition; Using filesort
SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY LongVal; SELECT * FROM t1 WHERE FieldKey > '2' ORDER BY LongVal;
FieldKey LongVal StringVal FieldKey LongVal StringVal
3 1 2 3 1 2
......
...@@ -79,6 +79,150 @@ c1 c2 c3 c4 ...@@ -79,6 +79,150 @@ c1 c2 c3 c4
DROP TABLE t1; DROP TABLE t1;
# #
# Bug#43617 - Innodb returns wrong results with timestamp's range value
# in IN clause
# (Note: Fixed by patch for BUG#42580)
#
CREATE TABLE t1(
c1 TIMESTAMP NOT NULL,
c2 TIMESTAMP NULL,
c3 DATE,
c4 DATETIME,
PRIMARY KEY(c1),
UNIQUE INDEX(c2)
);
INSERT INTO t1 VALUES
('0000-00-00 00:00:00','0000-00-00 00:00:00','2008-01-04','2008-01-05 00:00:00'),
('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02 00:00:00'),
('1999-01-01 00:00:00','1999-01-01 00:00:00', NULL, NULL),
('2007-05-23 09:15:28','2007-05-23 09:15:28','2007-05-24','2007-05-24 09:15:28'),
('2007-05-27 00:00:00','2007-05-25 00:00:00','2007-05-26','2007-05-26 00:00:00'),
('2008-01-01 00:00:00', NULL, '2008-01-02','2008-01-03 00:00:00'),
('2009-01-29 11:11:27','2009-01-29 11:11:27','2009-01-29','2009-01-29 11:11:27'),
('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06 00:00:00');
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 LIMIT 2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
SELECT *
FROM t1
WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
ORDER BY c2 DESC LIMIT 2;
c1 c2 c3 c4
2038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00
DROP TABLE t1;
#
# BUG#43618: MyISAM&Maria returns wrong results with 'between'
# on timestamp
#
CREATE TABLE t1(
ts TIMESTAMP NOT NULL,
c char NULL,
PRIMARY KEY(ts)
);
INSERT INTO t1 VALUES
('1971-01-01','a'),
('2007-05-25','b'),
('2008-01-01','c'),
('2038-01-09','d');
# Execute select with invalid timestamp, desc ordering
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
ts c
2008-01-01 00:00:00 c
2007-05-25 00:00:00 b
# Should use index condition
EXPLAIN
SELECT *
FROM t1
WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
ORDER BY ts DESC
LIMIT 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where
DROP TABLE t1;
#
# BUG#49906: Assertion failed - Field_varstring::val_str in field.cc
# (Note: Fixed by patch for LP BUG#625841)
#
CREATE TABLE t1 (
f1 VARCHAR(1024),
f2 VARCHAR(10),
INDEX test_idx USING BTREE (f2,f1(5))
);
INSERT INTO t1 VALUES ('a','c'), ('b','d');
SELECT f1
FROM t1
WHERE f2 LIKE 'd'
ORDER BY f1;
f1
b
DROP TABLE t1;
#
# Bug#52660 - "Perf. regr. using ICP for MyISAM on range queries on
# an index containing TEXT"
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t2 (a INT);
INSERT INTO t2 SELECT A.a + 10*(B.a) FROM t1 A, t1 B;
CREATE TABLE t3 (
c1 TINYTEXT NOT NULL,
i1 INT NOT NULL,
KEY (c1(6),i1)
);
INSERT INTO t3 SELECT CONCAT('c-',1000+t2.a,'=w'), 1 FROM t2;
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 range c1 c1 8 NULL 3 Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w';
c1
c-1004=w
c-1005=w
c-1006=w
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 range c1 c1 12 NULL 2 Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
c1
EXPLAIN
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL c1 NULL NULL NULL 100 Using where
SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' or i1 > 2;
c1
c-1004=w
c-1005=w
c-1006=w
DROP TABLE t1, t2, t3;
#
# Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on # Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on
# #
CREATE TABLE t ( CREATE TABLE t (
...@@ -199,6 +343,104 @@ COUNT(*) ...@@ -199,6 +343,104 @@ COUNT(*)
DROP PROCEDURE insert_data; DROP PROCEDURE insert_data;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
# #
# Bug#57372 "Multi-table updates and deletes fail when running with ICP
# against InnoDB"
#
CREATE TABLE t1 (
a INT KEY,
b INT
);
CREATE TABLE t2 (
a INT KEY,
b INT
);
INSERT INTO t1 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105);
INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
UPDATE t1, t2
SET t1.a = t1.a + 100, t2.b = t1.a + 10
WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b - 100;
SELECT * FROM t1;
a b
1 101
102 102
103 103
104 104
5 105
SELECT * FROM t2;
a b
1 1
2 12
3 13
4 14
5 5
DROP TABLE t1, t2;
#
# Bug#52605 - "Adding LIMIT 1 clause to query with complex range
# predicate causes wrong results"
#
CREATE TABLE t1 (
pk INT NOT NULL,
c1 INT,
PRIMARY KEY (pk),
KEY k1 (c1)
);
INSERT INTO t1 VALUES (1,NULL);
INSERT INTO t1 VALUES (2,6);
INSERT INTO t1 VALUES (3,NULL);
INSERT INTO t1 VALUES (4,6);
INSERT INTO t1 VALUES (5,NULL);
INSERT INTO t1 VALUES (6,NULL);
INSERT INTO t1 VALUES (7,9);
INSERT INTO t1 VALUES (8,0);
SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
pk c1
4 6
EXPLAIN SELECT pk, c1
FROM t1
WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1
LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,k1 k1 5 NULL 4 Using where
DROP TABLE t1;
#
# Bug#59259 "Incorrect rows returned for a correlated subquery
# when ICP is on"
#
CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
Warnings:
Warning 1286 Unknown table engine 'InnoDB'
Warning 1266 Using storage engine MyISAM for table 't1'
INSERT INTO t1 VALUES (11,0);
INSERT INTO t1 VALUES (12,5);
INSERT INTO t1 VALUES (15,0);
CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
Warnings:
Warning 1286 Unknown table engine 'InnoDB'
Warning 1266 Using storage engine MyISAM for table 't2'
INSERT INTO t2 VALUES (11,1);
INSERT INTO t2 VALUES (12,2);
INSERT INTO t2 VALUES (15,4);
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch='semijoin=off';
EXPLAIN
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using index
2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using where
SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
pk i
12 5
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1, t2;
#
# BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89 # BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
# #
CREATE TABLE t1 ( f11 int) ; CREATE TABLE t1 ( f11 int) ;
......
...@@ -365,7 +365,7 @@ update t1 set b=repeat(char(65+a), 20) where a < 25; ...@@ -365,7 +365,7 @@ update t1 set b=repeat(char(65+a), 20) where a < 25;
This must show range + using index condition: This must show range + using index condition:
explain select * from t1 where a < 10 and b = repeat(char(65+a), 20); explain select * from t1 where a < 10 and b = repeat(char(65+a), 20);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 19 Using where 1 SIMPLE t1 range a a 5 NULL 19 Using index condition; Using where
select * from t1 where a < 10 and b = repeat(char(65+a), 20); select * from t1 where a < 10 and b = repeat(char(65+a), 20);
a b filler a b filler
0 AAAAAAAAAAAAAAAAAAAA filler 0 AAAAAAAAAAAAAAAAAAAA filler
......
...@@ -420,6 +420,7 @@ DROP TABLE t1,t2; ...@@ -420,6 +420,7 @@ DROP TABLE t1,t2;
--echo # --echo #
--echo # Testcase backport: Bug#43249 --echo # Testcase backport: Bug#43249
--echo # (Note: Fixed by patch for BUG#42580)
--echo # --echo #
CREATE TABLE t1(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, PRIMARY KEY(c1), UNIQUE INDEX(c2)) engine=innodb; CREATE TABLE t1(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, PRIMARY KEY(c1), UNIQUE INDEX(c2)) engine=innodb;
INSERT INTO t1 VALUES('8:29:45',NULL,'2009-02-01'); INSERT INTO t1 VALUES('8:29:45',NULL,'2009-02-01');
......
...@@ -546,12 +546,11 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ...@@ -546,12 +546,11 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
/* Temporary set for register_used_fields and register_field_in_read_map */ /* Temporary set for register_used_fields and register_field_in_read_map */
sort_form->read_set= &sort_form->tmp_set; sort_form->read_set= &sort_form->tmp_set;
register_used_fields(param); register_used_fields(param);
if (select && select->cond) Item *sort_cond= !select ?
select->cond->walk(&Item::register_field_in_read_map, 1, 0 : !select->pre_idx_push_select_cond ?
(uchar*) sort_form); select->cond : select->pre_idx_push_select_cond;
if (select && select->pre_idx_push_select_cond) if (sort_cond)
select->pre_idx_push_select_cond->walk(&Item::register_field_in_read_map, sort_cond->walk(&Item::register_field_in_read_map, 1, (uchar*) sort_form);
1, (uchar*) sort_form);
sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set, sort_form->column_bitmaps_set(&sort_form->tmp_set, &sort_form->tmp_set,
&sort_form->tmp_set); &sort_form->tmp_set);
......
...@@ -1723,6 +1723,7 @@ class handler :public Sql_alloc ...@@ -1723,6 +1723,7 @@ class handler :public Sql_alloc
DBUG_ENTER("ha_rnd_init"); DBUG_ENTER("ha_rnd_init");
DBUG_ASSERT(inited==NONE || (inited==RND && scan)); DBUG_ASSERT(inited==NONE || (inited==RND && scan));
inited= (result= rnd_init(scan)) ? NONE: RND; inited= (result= rnd_init(scan)) ? NONE: RND;
end_range= NULL;
DBUG_RETURN(result); DBUG_RETURN(result);
} }
int ha_rnd_end() int ha_rnd_end()
...@@ -1730,6 +1731,7 @@ class handler :public Sql_alloc ...@@ -1730,6 +1731,7 @@ class handler :public Sql_alloc
DBUG_ENTER("ha_rnd_end"); DBUG_ENTER("ha_rnd_end");
DBUG_ASSERT(inited==RND); DBUG_ASSERT(inited==RND);
inited=NONE; inited=NONE;
end_range= NULL;
DBUG_RETURN(rnd_end()); DBUG_RETURN(rnd_end());
} }
int ha_rnd_init_with_error(bool scan) __attribute__ ((warn_unused_result)); int ha_rnd_init_with_error(bool scan) __attribute__ ((warn_unused_result));
......
...@@ -83,15 +83,44 @@ bool uses_index_fields_only(Item *item, TABLE *tbl, uint keyno, ...@@ -83,15 +83,44 @@ bool uses_index_fields_only(Item *item, TABLE *tbl, uint keyno,
case Item::FIELD_ITEM: case Item::FIELD_ITEM:
{ {
Item_field *item_field= (Item_field*)item; Item_field *item_field= (Item_field*)item;
if (item_field->field->table != tbl) Field *field= item_field->field;
if (field->table != tbl)
return TRUE; return TRUE;
/* /*
The below is probably a repetition - the first part checks the The below is probably a repetition - the first part checks the
other two, but let's play it safe: other two, but let's play it safe:
*/ */
return item_field->field->part_of_key.is_set(keyno) && if(!field->part_of_key.is_set(keyno) ||
item_field->field->type() != MYSQL_TYPE_GEOMETRY && field->type() == MYSQL_TYPE_GEOMETRY ||
item_field->field->type() != MYSQL_TYPE_BLOB; field->type() == MYSQL_TYPE_BLOB)
return FALSE;
KEY *key_info= tbl->key_info + keyno;
KEY_PART_INFO *key_part= key_info->key_part;
KEY_PART_INFO *key_part_end= key_part + key_info->key_parts;
for ( ; key_part < key_part_end; key_part++)
{
if (field->eq(key_part->field))
return !(key_part->key_part_flag & HA_PART_KEY_SEG);
}
if ((tbl->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
tbl->s->primary_key != MAX_KEY &&
tbl->s->primary_key != keyno)
{
key_info= tbl->key_info + tbl->s->primary_key;
key_part= key_info->key_part;
key_part_end= key_part + key_info->key_parts;
for ( ; key_part < key_part_end; key_part++)
{
/*
It does not make sense to use the fact that the engine can read in
a full field if the key if the index is built only over a part
of this field.
*/
if (field->eq(key_part->field))
return !(key_part->key_part_flag & HA_PART_KEY_SEG);
}
}
return FALSE;
} }
case Item::REF_ITEM: case Item::REF_ITEM:
return uses_index_fields_only(item->real_item(), tbl, keyno, return uses_index_fields_only(item->real_item(), tbl, keyno,
...@@ -288,30 +317,12 @@ void push_index_cond(JOIN_TAB *tab, uint keyno) ...@@ -288,30 +317,12 @@ void push_index_cond(JOIN_TAB *tab, uint keyno)
{ {
DBUG_ENTER("push_index_cond"); DBUG_ENTER("push_index_cond");
Item *idx_cond; Item *idx_cond;
bool do_index_cond_pushdown=
((tab->table->file->index_flags(keyno, 0, 1) &
HA_DO_INDEX_COND_PUSHDOWN) &&
optimizer_flag(tab->join->thd, OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN));
/* if ((tab->table->file->index_flags(keyno, 0, 1) &
Do not try index condition pushdown on indexes which have partially-covered HA_DO_INDEX_COND_PUSHDOWN) &&
columns. Unpacking from a column prefix into index tuple is not a supported optimizer_flag(tab->join->thd, OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN) &&
operation in some engines, see e.g. MySQL BUG#42991. tab->join->thd->lex->sql_command != SQLCOM_UPDATE_MULTI &&
TODO: a better solution would be not to consider partially-covered columns tab->join->thd->lex->sql_command != SQLCOM_DELETE_MULTI)
as parts of the index and still produce/check index condition for
fully-covered index columns.
*/
KEY *key_info= tab->table->key_info + keyno;
for (uint kp= 0; kp < key_info->key_parts; kp++)
{
if ((key_info->key_part[kp].key_part_flag & HA_PART_KEY_SEG))
{
do_index_cond_pushdown= FALSE;
break;
}
}
if (do_index_cond_pushdown)
{ {
DBUG_EXECUTE("where", DBUG_EXECUTE("where",
print_where(tab->select_cond, "full cond", QT_ORDINARY);); print_where(tab->select_cond, "full cond", QT_ORDINARY););
......
...@@ -472,10 +472,12 @@ Looks for column n in an index. ...@@ -472,10 +472,12 @@ Looks for column n in an index.
ULINT_UNDEFINED if not contained */ ULINT_UNDEFINED if not contained */
UNIV_INTERN UNIV_INTERN
ulint ulint
dict_index_get_nth_col_pos( dict_index_get_nth_col_or_prefix_pos(
/*=======================*/ /*=================================*/
const dict_index_t* index, /*!< in: index */ const dict_index_t* index, /*!< in: index */
ulint n) /*!< in: column number */ ulint n, /*!< in: column number */
ibool inc_prefix) /*!< in: TRUE=consider
column prefixes too */
{ {
const dict_field_t* field; const dict_field_t* field;
const dict_col_t* col; const dict_col_t* col;
...@@ -497,7 +499,8 @@ dict_index_get_nth_col_pos( ...@@ -497,7 +499,8 @@ dict_index_get_nth_col_pos(
for (pos = 0; pos < n_fields; pos++) { for (pos = 0; pos < n_fields; pos++) {
field = dict_index_get_nth_field(index, pos); field = dict_index_get_nth_field(index, pos);
if (col == field->col && field->prefix_len == 0) { if (col == field->col
&& (inc_prefix || field->prefix_len == 0)) {
return(pos); return(pos);
} }
......
This diff is collapsed.
...@@ -223,27 +223,81 @@ class ha_innobase: public handler ...@@ -223,27 +223,81 @@ class ha_innobase: public handler
bool check_if_incompatible_data(HA_CREATE_INFO *info, bool check_if_incompatible_data(HA_CREATE_INFO *info,
uint table_changes); uint table_changes);
bool check_if_supported_virtual_columns(void) { return TRUE; } bool check_if_supported_virtual_columns(void) { return TRUE; }
private:
/** Builds a 'template' to the prebuilt struct.
The template is used in fast retrieval of just those column
values MySQL needs in its processing.
@param whole_row true if access is needed to a whole row,
false if accessing individual fields is enough */
void build_template(bool whole_row);
/** Resets a query execution 'template'.
@see build_template() */
inline void reset_template();
public: public:
/** /** @name Multi Range Read interface @{ */
* Multi Range Read interface /** Initialize multi range read @see DsMrr_impl::dsmrr_init
* @param seq
* @param seq_init_param
* @param n_ranges
* @param mode
* @param buf
*/
int multi_range_read_init(RANGE_SEQ_IF* seq,
void* seq_init_param,
uint n_ranges, uint mode,
HANDLER_BUFFER *buf);
/** Process next multi range read @see DsMrr_impl::dsmrr_next
* @param range_info
*/ */
int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
uint n_ranges, uint mode, HANDLER_BUFFER *buf);
int multi_range_read_next(range_id_t *range_info); int multi_range_read_next(range_id_t *range_info);
/** Initialize multi range read and get information.
* @see ha_myisam::multi_range_read_info_const
* @see DsMrr_impl::dsmrr_info_const
* @param keyno
* @param seq
* @param seq_init_param
* @param n_ranges
* @param bufsz
* @param flags
* @param cost
*/
ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq, ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
void *seq_init_param, void *seq_init_param,
uint n_ranges, uint *bufsz, uint n_ranges, uint *bufsz,
uint *flags, COST_VECT *cost); uint *flags, COST_VECT *cost);
/** Initialize multi range read and get information.
* @see DsMrr_impl::dsmrr_info
* @param keyno
* @param n_ranges
* @param keys
* @param key_parts
* @param bufsz
* @param flags
* @param cost
*/
ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys, ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
uint key_parts, uint *bufsz, uint key_parts, uint *bufsz,
uint *flags, COST_VECT *cost); uint *flags, COST_VECT *cost);
int multi_range_read_explain_info(uint mrr_mode, char *str, size_t size); int multi_range_read_explain_info(uint mrr_mode,
DsMrr_impl ds_mrr; char *str, size_t size);
Item *idx_cond_push(uint keyno, Item* idx_cond); /** Attempt to push down an index condition.
* @param[in] keyno MySQL key number
* @param[in] idx_cond Index condition to be checked
* @return idx_cond if pushed; NULL if not pushed
*/
class Item* idx_cond_push(uint keyno, class Item* idx_cond);
/* An helper function for index_cond_func_innodb: */ /* An helper function for index_cond_func_innodb: */
bool is_thd_killed(); bool is_thd_killed();
private:
/** The multi range read session object */
DsMrr_impl ds_mrr;
/* @} */
}; };
/* Some accessor functions which the InnoDB plugin needs, but which /* Some accessor functions which the InnoDB plugin needs, but which
......
...@@ -839,6 +839,18 @@ dict_index_get_nth_col_pos( ...@@ -839,6 +839,18 @@ dict_index_get_nth_col_pos(
const dict_index_t* index, /*!< in: index */ const dict_index_t* index, /*!< in: index */
ulint n); /*!< in: column number */ ulint n); /*!< in: column number */
/********************************************************************//** /********************************************************************//**
Looks for column n in an index.
@return position in internal representation of the index;
ULINT_UNDEFINED if not contained */
UNIV_INTERN
ulint
dict_index_get_nth_col_or_prefix_pos(
/*=================================*/
const dict_index_t* index, /*!< in: index */
ulint n, /*!< in: column number */
ibool inc_prefix); /*!< in: TRUE=consider
column prefixes too */
/********************************************************************//**
Returns TRUE if the index contains a column or a prefix of that column. Returns TRUE if the index contains a column or a prefix of that column.
@return TRUE if contains the column or its prefix */ @return TRUE if contains the column or its prefix */
UNIV_INTERN UNIV_INTERN
......
...@@ -656,6 +656,20 @@ dict_index_get_nth_col_no( ...@@ -656,6 +656,20 @@ dict_index_get_nth_col_no(
return(dict_col_get_no(dict_index_get_nth_col(index, pos))); return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
} }
/********************************************************************//**
Looks for column n in an index.
@return position in internal representation of the index;
ULINT_UNDEFINED if not contained */
UNIV_INLINE
ulint
dict_index_get_nth_col_pos(
/*=======================*/
const dict_index_t* index, /*!< in: index */
ulint n) /*!< in: column number */
{
return(dict_index_get_nth_col_or_prefix_pos(index, n, FALSE));
}
#ifndef UNIV_HOTBACKUP #ifndef UNIV_HOTBACKUP
/********************************************************************//** /********************************************************************//**
Returns the minimum data size of an index record. Returns the minimum data size of an index record.
......
...@@ -247,6 +247,15 @@ innobase_get_at_most_n_mbchars( ...@@ -247,6 +247,15 @@ innobase_get_at_most_n_mbchars(
ulint data_len, /*!< in: length of the string in bytes */ ulint data_len, /*!< in: length of the string in bytes */
const char* str); /*!< in: character string */ const char* str); /*!< in: character string */
/*************************************************************//**
InnoDB index push-down condition check
@return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */
UNIV_INTERN
enum icp_result
innobase_index_cond(
/*================*/
void* file) /*!< in/out: pointer to ha_innobase */
__attribute__((nonnull, warn_unused_result));
/******************************************************************//** /******************************************************************//**
Returns true if the thread supports XA, Returns true if the thread supports XA,
global value of innodb_supports_xa if thd is NULL. global value of innodb_supports_xa if thd is NULL.
......
...@@ -547,6 +547,10 @@ struct mysql_row_templ_struct { ...@@ -547,6 +547,10 @@ struct mysql_row_templ_struct {
Innobase record in the clustered index; Innobase record in the clustered index;
not defined if template_type is not defined if template_type is
ROW_MYSQL_WHOLE_ROW */ ROW_MYSQL_WHOLE_ROW */
ulint icp_rec_field_no; /*!< field number of the column in an
Innobase record in the current index;
not defined unless
index condition pushdown is used */
ulint mysql_col_offset; /*!< offset of the column in the MySQL ulint mysql_col_offset; /*!< offset of the column in the MySQL
row format */ row format */
ulint mysql_col_len; /*!< length of the column in the MySQL ulint mysql_col_len; /*!< length of the column in the MySQL
...@@ -585,16 +589,6 @@ struct mysql_row_templ_struct { ...@@ -585,16 +589,6 @@ struct mysql_row_templ_struct {
#define ROW_PREBUILT_ALLOCATED 78540783 #define ROW_PREBUILT_ALLOCATED 78540783
#define ROW_PREBUILT_FREED 26423527 #define ROW_PREBUILT_FREED 26423527
typedef enum xtradb_icp_result {
XTRADB_ICP_ERROR=-1,
XTRADB_ICP_NO_MATCH=0,
XTRADB_ICP_MATCH=1,
XTRADB_ICP_OUT_OF_RANGE=2,
XTRADB_ICP_ABORTED_BY_USER=3,
} xtradb_icp_result_t;
typedef xtradb_icp_result_t (*index_cond_func_t)(void *param);
/** A struct for (sometimes lazily) prebuilt structures in an Innobase table /** A struct for (sometimes lazily) prebuilt structures in an Innobase table
handle used within MySQL; these are used to save CPU time. */ handle used within MySQL; these are used to save CPU time. */
...@@ -792,16 +786,15 @@ struct row_prebuilt_struct { ...@@ -792,16 +786,15 @@ struct row_prebuilt_struct {
store it here so that we can return store it here so that we can return
it to MySQL */ it to MySQL */
/*----------------------*/ /*----------------------*/
void* idx_cond; /*!< In ICP, pointer to a ha_innobase,
passed to innobase_index_cond().
NULL if index condition pushdown is
not used. */
ulint idx_cond_n_cols;/*!< Number of fields in idx_cond_cols.
0 if and only if idx_cond == NULL. */
/*----------------------*/
ulint magic_n2; /*!< this should be the same as ulint magic_n2; /*!< this should be the same as
magic_n */ magic_n */
/*----------------------*/
index_cond_func_t idx_cond_func;/* Index Condition Pushdown function,
or NULL if there is none set */
void* idx_cond_func_arg;/* ICP function argument */
ulint n_index_fields; /* Number of fields at the start of
mysql_template. Valid only when using
ICP. */
/*----------------------*/
}; };
#define ROW_PREBUILT_FETCH_MAGIC_N 465765687 #define ROW_PREBUILT_FETCH_MAGIC_N 465765687
......
This diff is collapsed.
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