Table scan when NULL appears in IN clause
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Drizzle |
Fix Released
|
Medium
|
Stewart Smith | ||
MySQL Server |
Unknown
|
Unknown
|
Bug Description
http://
Optimizer chooses a table scan when there is a NULL in the IN clause.
This is a regression. Compare EXPLAIN output from 5.1.79:
mysql [localhost] {msandbox} (test) > explain select * from foo where a in (160000,
160001, 160002)\G
*******
id: 1
select_type: SIMPLE
table: foo
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: NULL
rows: 3
Extra: Using where
1 row in set (0.00 sec)
mysql [localhost] {msandbox} (test) > explain select * from foo where a in (null, 160000,
160001, 160002)\G
*******
id: 1
select_type: SIMPLE
table: foo
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: NULL
rows: 3
Extra: Using where
1 row in set (0.01 sec)
To 5.1.32:
mysql [localhost] {msandbox} (test) > explain select * from foo where a in (160000,
160001, 160002)\G
*******
id: 1
select_type: SIMPLE
table: foo
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: NULL
rows: 3
Extra: Using where
1 row in set (0.06 sec)
mysql [localhost] {msandbox} (test) > explain select * from foo where a in (null, 160000,
160001, 160002)\G
*******
id: 1
select_type: SIMPLE
table: foo
type: ALL
possible_keys: PRIMARY
key: NULL
key_len: NULL
ref: NULL
rows: 327680
Extra: Using where
1 row in set (0.00 sec)
How to repeat:
use test;
drop table if exists foo;
create table foo (
a int not null auto_increment,
b int,
primary key( a )
);
insert into foo( b ) values (1),(1)
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
insert into foo( b ) select b from foo;
explain select * from foo where a in (160000, 160001, 160002)\G
explain select * from foo where a in (null, 160000, 160001, 160002)\G
Related branches
- Brian Aker: Pending requested
- Jay Pipes: Pending requested
-
Diff: 325 lines5 files modifieddrizzled/item/cmpfunc.cc (+14/-3)
tests/r/func_in_null_scan.result (+105/-0)
tests/r/select_in_null.result (+33/-0)
tests/t/func_in_null_scan.test (+67/-0)
tests/t/select_in_null.test (+36/-0)
Changed in drizzle: | |
assignee: | nobody → Stewart Smith (stewart-flamingspork) |
importance: | Undecided → Medium |
Changed in drizzle: | |
milestone: | none → bell |
status: | Confirmed → In Progress |
Changed in drizzle: | |
status: | In Progress → Fix Committed |
Changed in drizzle: | |
status: | Fix Committed → Fix Released |
verified on trunk