Commit e0c1b3f2 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #886145.

The bug happened because in some cases the function JOIN::exec
did not save the value of TABLE::pre_idx_push_select_cond in
TABLE::select->pre_idx_push_select_cond for the sort table.

Noticed and fixed a bug in the function make_cond_remainder
that builds the remainder condition after extraction of an index
pushdown condition from the where condition. The code
erroneously assumed that the function make_cond_for_table left
the value of ICP_COND_USES_INDEX_ONLY in sub-condition markers.
Adjusted many result files from the regression test suite
after this fix .
parent 928e94fb
...@@ -697,3 +697,30 @@ SELECT * FROM t1 ...@@ -697,3 +697,30 @@ SELECT * FROM t1
ORDER BY a; ORDER BY a;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # Bug#886145: join with ICP + ORDER BY
--echo #
CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b));
INSERT INTO t1 VALUES (1,4,'Ill');
CREATE TABLE t2 (a varchar(1024), KEY (a(512)));
INSERT INTO t2 VALUES
('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
DROP TABLE t1,t2;
...@@ -506,7 +506,7 @@ SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 ...@@ -506,7 +506,7 @@ SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
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 1 Using index condition 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Using where
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Using join buffer (flat, BNL join)
SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
...@@ -648,12 +648,43 @@ SELECT * FROM t1 ...@@ -648,12 +648,43 @@ SELECT * FROM t1
WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania' WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania'
ORDER BY a; ORDER BY a;
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 b b 13 NULL 2 Using index condition; Rowid-ordered scan; Using filesort 1 SIMPLE t1 range b b 13 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort
SELECT * FROM t1 SELECT * FROM t1
WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania' WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania'
ORDER BY a; ORDER BY a;
a b a b
d xdmbdkpjda d xdmbdkpjda
DROP TABLE t1; DROP TABLE t1;
#
# Bug#886145: join with ICP + ORDER BY
#
CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b));
INSERT INTO t1 VALUES (1,4,'Ill');
CREATE TABLE t2 (a varchar(1024), KEY (a(512)));
INSERT INTO t2 VALUES
('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a 1 Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
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; Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a 1 Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
DROP TABLE t1,t2;
set optimizer_switch=@innodb_icp_tmp; set optimizer_switch=@innodb_icp_tmp;
set storage_engine= @save_storage_engine; set storage_engine= @save_storage_engine;
...@@ -186,7 +186,7 @@ explain ...@@ -186,7 +186,7 @@ explain
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1' select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
or c='no-such-row2'); or c='no-such-row2');
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 t4 range idx1 idx1 29 NULL 16 Using index condition; Rowid-ordered scan 1 SIMPLE t4 range idx1 idx1 29 NULL 16 Using index condition; Using where; Rowid-ordered scan
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1' select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
or c='no-such-row2'); or c='no-such-row2');
a b c filler a b c filler
...@@ -208,7 +208,7 @@ NULL NULL NULL NULL-1 ...@@ -208,7 +208,7 @@ NULL NULL NULL NULL-1
explain explain
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2'); select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
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 t4 range idx1 idx1 29 NULL 32 Using index condition; Rowid-ordered scan 1 SIMPLE t4 range idx1 idx1 29 NULL 32 Using index condition; Using where; Rowid-ordered scan
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2'); select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
a b c filler a b c filler
b-1 NULL c-1 NULL-15 b-1 NULL c-1 NULL-15
......
...@@ -4968,7 +4968,7 @@ EXPLAIN ...@@ -4968,7 +4968,7 @@ EXPLAIN
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
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 2 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join)
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
......
...@@ -512,7 +512,7 @@ SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 ...@@ -512,7 +512,7 @@ SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
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 2 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join)
SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
...@@ -654,12 +654,43 @@ SELECT * FROM t1 ...@@ -654,12 +654,43 @@ SELECT * FROM t1
WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania' WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania'
ORDER BY a; ORDER BY a;
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 b b 13 NULL 2 Using index condition; Rowid-ordered scan; Using filesort 1 SIMPLE t1 range b b 13 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort
SELECT * FROM t1 SELECT * FROM t1
WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania' WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania'
ORDER BY a; ORDER BY a;
a b a b
d xdmbdkpjda d xdmbdkpjda
DROP TABLE t1; DROP TABLE t1;
#
# Bug#886145: join with ICP + ORDER BY
#
CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b));
INSERT INTO t1 VALUES (1,4,'Ill');
CREATE TABLE t2 (a varchar(1024), KEY (a(512)));
INSERT INTO t2 VALUES
('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref a a 515 const 1 Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref a a 515 const 1 Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
DROP TABLE t1,t2;
set storage_engine= @save_storage_engine; set storage_engine= @save_storage_engine;
set optimizer_switch=@maria_icp_tmp; set optimizer_switch=@maria_icp_tmp;
...@@ -187,7 +187,7 @@ explain ...@@ -187,7 +187,7 @@ explain
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1' select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
or c='no-such-row2'); or c='no-such-row2');
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 t4 range idx1 idx1 29 NULL 16 Using index condition; Rowid-ordered scan 1 SIMPLE t4 range idx1 idx1 29 NULL 16 Using index condition; Using where; Rowid-ordered scan
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1' select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
or c='no-such-row2'); or c='no-such-row2');
a b c filler a b c filler
...@@ -209,7 +209,7 @@ NULL NULL NULL NULL-1 ...@@ -209,7 +209,7 @@ NULL NULL NULL NULL-1
explain explain
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2'); select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
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 t4 range idx1 idx1 29 NULL 32 Using index condition; Rowid-ordered scan 1 SIMPLE t4 range idx1 idx1 29 NULL 32 Using index condition; Using where; Rowid-ordered scan
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2'); select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
a b c filler a b c filler
b-1 NULL c-1 NULL-15 b-1 NULL c-1 NULL-15
......
...@@ -72,7 +72,7 @@ insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2); ...@@ -72,7 +72,7 @@ insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2);
insert into t1 values (2, 11), (1, 11), (4, 14), (3, 14), (6, 12), (5, 12); insert into t1 values (2, 11), (1, 11), (4, 14), (3, 14), (6, 12), (5, 12);
explain select * from t1 where b=1 or b is null order by a; explain select * from t1 where b=1 or b is null order by a;
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 ref_or_null b b 5 const 4 Using index condition; Using filesort 1 SIMPLE t1 ref_or_null b b 5 const 4 Using index condition; Using where; Using filesort
select * from t1 where b=1 or b is null order by a; select * from t1 where b=1 or b is null order by a;
a b a b
1 1 1 1
...@@ -81,7 +81,7 @@ a b ...@@ -81,7 +81,7 @@ a b
4 NULL 4 NULL
explain select * from t1 where b=2 or b is null order by a; explain select * from t1 where b=2 or b is null order by a;
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 ref_or_null b b 5 const 3 Using index condition; Using filesort 1 SIMPLE t1 ref_or_null b b 5 const 3 Using index condition; Using where; Using filesort
select * from t1 where b=2 or b is null order by a; select * from t1 where b=2 or b is null order by a;
a b a b
3 NULL 3 NULL
...@@ -123,7 +123,7 @@ Table Op Msg_type Msg_text ...@@ -123,7 +123,7 @@ Table Op Msg_type Msg_text
test.t1 optimize status OK test.t1 optimize status OK
explain select * from t1 force index (a) where a=0 or a=2; explain select * from t1 force index (a) where a=0 or a=2;
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 4 NULL 4 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range a a 4 NULL 4 Using index condition; Using where; Rowid-ordered scan
select * from t1 force index (a) where a=0 or a=2; select * from t1 force index (a) where a=0 or a=2;
a b c a b c
0 NULL 0 0 NULL 0
......
...@@ -510,7 +510,7 @@ SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 ...@@ -510,7 +510,7 @@ SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
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 2 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join)
SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
...@@ -652,13 +652,44 @@ SELECT * FROM t1 ...@@ -652,13 +652,44 @@ SELECT * FROM t1
WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania' WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania'
ORDER BY a; ORDER BY a;
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 b b 13 NULL 2 Using index condition; Rowid-ordered scan; Using filesort 1 SIMPLE t1 range b b 13 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort
SELECT * FROM t1 SELECT * FROM t1
WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania' WHERE NOT(b = 'Texas') AND b BETWEEN 'wy' AND 'y' OR b = 'Pennsylvania'
ORDER BY a; ORDER BY a;
a b a b
d xdmbdkpjda d xdmbdkpjda
DROP TABLE t1; DROP TABLE t1;
#
# Bug#886145: join with ICP + ORDER BY
#
CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b));
INSERT INTO t1 VALUES (1,4,'Ill');
CREATE TABLE t2 (a varchar(1024), KEY (a(512)));
INSERT INTO t2 VALUES
('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref a a 515 const 1 Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref a a 515 const 1 Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
DROP TABLE t1,t2;
drop table if exists t0, t1, t1i, t1m; drop table if exists t0, t1, t1i, t1m;
# #
# BUG#826935 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed # BUG#826935 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed
......
...@@ -188,7 +188,7 @@ explain ...@@ -188,7 +188,7 @@ explain
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1' select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
or c='no-such-row2'); or c='no-such-row2');
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 t4 range idx1 idx1 29 NULL 10 Using index condition; Rowid-ordered scan 1 SIMPLE t4 range idx1 idx1 29 NULL 10 Using index condition; Using where; Rowid-ordered scan
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1' select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
or c='no-such-row2'); or c='no-such-row2');
a b c filler a b c filler
...@@ -210,7 +210,7 @@ NULL NULL NULL NULL-1 ...@@ -210,7 +210,7 @@ NULL NULL NULL NULL-1
explain explain
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2'); select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
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 t4 range idx1 idx1 29 NULL 21 Using index condition; Rowid-ordered scan 1 SIMPLE t4 range idx1 idx1 29 NULL 21 Using index condition; Using where; Rowid-ordered scan
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2'); select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
a b c filler a b c filler
b-1 NULL c-1 NULL-15 b-1 NULL c-1 NULL-15
......
...@@ -927,7 +927,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -927,7 +927,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Rowid-ordered scan
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B'; EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
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 status status 23 NULL 10 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Using where; Rowid-ordered scan
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B'; SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
id status id status
53 C 53 C
...@@ -1031,13 +1031,13 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1031,13 +1031,13 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 13 NULL # Using index condition; Rowid-ordered scan 1 SIMPLE t1 range a a 13 NULL # Using index condition; Rowid-ordered scan
explain select * from t1 where a = 'a' or a='a '; explain select * from t1 where a = 'a' or a='a ';
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 13 NULL # Using index condition; Rowid-ordered scan 1 SIMPLE t1 range a a 13 NULL # Using index condition; Using where; Rowid-ordered scan
explain select * from t2 where a between 'a' and 'a '; explain select * from t2 where a between 'a' and 'a ';
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 t2 ref a a 13 const # Using index condition 1 SIMPLE t2 ref a a 13 const # Using index condition
explain select * from t2 where a = 'a' or a='a '; explain select * from t2 where a = 'a' or a='a ';
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 t2 ref a a 13 const # Using index condition 1 SIMPLE t2 ref a a 13 const # Using index condition; Using where
update t1 set a='b' where a<>'a'; update t1 set a='b' where a<>'a';
explain select * from t1 where a not between 'b' and 'b'; explain select * from t1 where a not between 'b' and 'b';
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
...@@ -1795,7 +1795,7 @@ INSERT INTO t100(I,J) VALUES(8,26); ...@@ -1795,7 +1795,7 @@ INSERT INTO t100(I,J) VALUES(8,26);
EXPLAIN SELECT * FROM t100 WHERE I <> 6 OR (I <> 8 AND J = 5); EXPLAIN SELECT * FROM t100 WHERE I <> 6 OR (I <> 8 AND J = 5);
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 t100 range I I 10 NULL 4 Using index condition; Rowid-ordered scan 1 SIMPLE t100 range I I 10 NULL 4 Using index condition; Using where; Rowid-ordered scan
SELECT * FROM t100 WHERE I <> 6 OR (I <> 8 AND J = 5); SELECT * FROM t100 WHERE I <> 6 OR (I <> 8 AND J = 5);
K I J K I J
......
...@@ -3427,7 +3427,7 @@ SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr ...@@ -3427,7 +3427,7 @@ SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr
FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku); FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku);
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 t2 const PRIMARY PRIMARY 4 const 1 1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
DROP TABLE t1,t2; DROP TABLE t1,t2;
CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL); CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL);
INSERT t1 SET i = 0; INSERT t1 SET i = 0;
......
...@@ -285,7 +285,7 @@ WHERE Code NOT IN (SELECT Country FROM CountryLanguage WHERE Language = 'English ...@@ -285,7 +285,7 @@ WHERE Code NOT IN (SELECT Country FROM CountryLanguage WHERE Language = 'English
AND (CountryLanguage.Language = 'French' OR CountryLanguage.Language = 'Spanish') AND (CountryLanguage.Language = 'French' OR CountryLanguage.Language = 'Spanish')
AND Code = Country; AND Code = Country;
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 PRIMARY CountryLanguage range PRIMARY,Language Language 30 NULL 45 Using index condition; Rowid-ordered scan 1 PRIMARY CountryLanguage range PRIMARY,Language Language 30 NULL 45 Using index condition; Using where; Rowid-ordered scan
1 PRIMARY Country eq_ref PRIMARY PRIMARY 3 world.CountryLanguage.Country 1 Using index condition 1 PRIMARY Country eq_ref PRIMARY PRIMARY 3 world.CountryLanguage.Country 1 Using index condition
2 SUBQUERY CountryLanguage ref PRIMARY,Language Language 30 const 47 Using index condition 2 SUBQUERY CountryLanguage ref PRIMARY,Language Language 30 const 47 Using index condition
SELECT Country.Name SELECT Country.Name
...@@ -348,7 +348,7 @@ FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000)) ...@@ -348,7 +348,7 @@ FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000))
AND Language IN ('English','Spanish'); AND Language IN ('English','Spanish');
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 PRIMARY CountryLanguage range Language Language 30 NULL 72 Using index condition; Using where; Rowid-ordered scan 1 PRIMARY CountryLanguage range Language Language 30 NULL 72 Using index condition; Using where; Rowid-ordered scan
2 DEPENDENT SUBQUERY City ref CityName CityName 35 func 2 Using index condition 2 DEPENDENT SUBQUERY City ref CityName CityName 35 func 2 Using index condition; Using where
2 DEPENDENT SUBQUERY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using index 2 DEPENDENT SUBQUERY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using index
select count(*) select count(*)
from CountryLanguage from CountryLanguage
......
...@@ -239,11 +239,9 @@ Item *make_cond_for_index(Item *cond, TABLE *table, uint keyno, ...@@ -239,11 +239,9 @@ Item *make_cond_for_index(Item *cond, TABLE *table, uint keyno,
} }
Item *make_cond_remainder(Item *cond, bool exclude_index) Item *make_cond_remainder(Item *cond, TABLE *table, uint keyno,
bool other_tbls_ok, bool exclude_index)
{ {
if (exclude_index && cond->marker == ICP_COND_USES_INDEX_ONLY)
return 0; /* Already checked */
if (cond->type() == Item::COND_ITEM) if (cond->type() == Item::COND_ITEM)
{ {
table_map tbl_map= 0; table_map tbl_map= 0;
...@@ -257,7 +255,8 @@ Item *make_cond_remainder(Item *cond, bool exclude_index) ...@@ -257,7 +255,8 @@ Item *make_cond_remainder(Item *cond, bool exclude_index)
Item *item; Item *item;
while ((item=li++)) while ((item=li++))
{ {
Item *fix= make_cond_remainder(item, exclude_index); Item *fix= make_cond_remainder(item, table, keyno,
other_tbls_ok, exclude_index);
if (fix) if (fix)
{ {
new_cond->argument_list()->push_back(fix); new_cond->argument_list()->push_back(fix);
...@@ -284,7 +283,8 @@ Item *make_cond_remainder(Item *cond, bool exclude_index) ...@@ -284,7 +283,8 @@ Item *make_cond_remainder(Item *cond, bool exclude_index)
Item *item; Item *item;
while ((item=li++)) while ((item=li++))
{ {
Item *fix= make_cond_remainder(item, FALSE); Item *fix= make_cond_remainder(item, table, keyno,
other_tbls_ok, FALSE);
if (!fix) if (!fix)
return (COND*) 0; return (COND*) 0;
new_cond->argument_list()->push_back(fix); new_cond->argument_list()->push_back(fix);
...@@ -296,7 +296,14 @@ Item *make_cond_remainder(Item *cond, bool exclude_index) ...@@ -296,7 +296,14 @@ Item *make_cond_remainder(Item *cond, bool exclude_index)
return new_cond; return new_cond;
} }
} }
else
{
if (exclude_index &&
uses_index_fields_only(cond, table, keyno, other_tbls_ok))
return 0;
else
return cond; return cond;
}
} }
...@@ -368,7 +375,8 @@ void push_index_cond(JOIN_TAB *tab, uint keyno) ...@@ -368,7 +375,8 @@ void push_index_cond(JOIN_TAB *tab, uint keyno)
tab->ref.disable_cache= TRUE; tab->ref.disable_cache= TRUE;
Item *row_cond= tab->idx_cond_fact_out ? Item *row_cond= tab->idx_cond_fact_out ?
make_cond_remainder(tab->select_cond, TRUE) : make_cond_remainder(tab->select_cond, tab->table, keyno,
tab->icp_other_tables_ok, TRUE) :
tab->pre_idx_push_select_cond; tab->pre_idx_push_select_cond;
DBUG_EXECUTE("where", DBUG_EXECUTE("where",
......
...@@ -2566,6 +2566,8 @@ JOIN::exec() ...@@ -2566,6 +2566,8 @@ JOIN::exec()
!curr_table->pre_idx_push_select_cond->fixed) !curr_table->pre_idx_push_select_cond->fixed)
curr_table->pre_idx_push_select_cond->fix_fields(thd, 0); curr_table->pre_idx_push_select_cond->fix_fields(thd, 0);
curr_table->select->pre_idx_push_select_cond=
curr_table->pre_idx_push_select_cond;
curr_table->set_select_cond(curr_table->select->cond, __LINE__); curr_table->set_select_cond(curr_table->select->cond, __LINE__);
curr_table->select_cond->top_level_item(); curr_table->select_cond->top_level_item();
DBUG_EXECUTE("where",print_where(curr_table->select->cond, DBUG_EXECUTE("where",print_where(curr_table->select->cond,
......
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