Commit 7371ecc8 authored by unknown's avatar unknown

Fixed LP bug #613009

The set of Ordered keys of a rowid merge engine is dense. Thus when
we decide not to create a key for a column that has only NULLs, this
column shouldn't be counted.

Notice that the caller has already precomputed the correct total
number of keys that should be created.
parent a158d478
...@@ -21,7 +21,8 @@ INSERT INTO t1 VALUES (4,NULL); ...@@ -21,7 +21,8 @@ INSERT INTO t1 VALUES (4,NULL);
CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL); CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL);
INSERT INTO t2 VALUES (6,NULL); INSERT INTO t2 VALUES (6,NULL);
INSERT INTO t2 VALUES (NULL,0); INSERT INTO t2 VALUES (NULL,0);
SET @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on'; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on';
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT * FROM (SELECT * FROM t1 WHERE a1 NOT IN (SELECT b2 FROM t2)) table1; SELECT * FROM (SELECT * FROM t1 WHERE a1 NOT IN (SELECT b2 FROM t2)) table1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
...@@ -31,3 +32,19 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -31,3 +32,19 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings: Warnings:
Note 1003 select NULL AS `a1`,NULL AS `a2` from (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ()))))) `table1` Note 1003 select NULL AS `a1`,NULL AS `a2` from (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ()))))) `table1`
DROP TABLE t1, t2; DROP TABLE t1, t2;
set @@optimizer_switch=@save_optimizer_switch;
#
# LP BUG#613009 Crash in Ordered_key::get_field_idx
#
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=off';
create table t1 (a1 char(3) DEFAULT NULL, a2 char(3) DEFAULT NULL);
insert into t1 values (NULL, 'a21'), (NULL, 'a22');
explain select * from t1 where (a1, a2) not in (select a1, a2 from t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
select * from t1 where (a1, a2) not in (select a1, a2 from t1);
a1 a2
drop table t1;
set @@optimizer_switch=@save_optimizer_switch;
...@@ -32,9 +32,25 @@ CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL); ...@@ -32,9 +32,25 @@ CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL);
INSERT INTO t2 VALUES (6,NULL); INSERT INTO t2 VALUES (6,NULL);
INSERT INTO t2 VALUES (NULL,0); INSERT INTO t2 VALUES (NULL,0);
SET @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on'; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on';
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT * FROM (SELECT * FROM t1 WHERE a1 NOT IN (SELECT b2 FROM t2)) table1; SELECT * FROM (SELECT * FROM t1 WHERE a1 NOT IN (SELECT b2 FROM t2)) table1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
set @@optimizer_switch=@save_optimizer_switch;
--echo #
--echo # LP BUG#613009 Crash in Ordered_key::get_field_idx
--echo #
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=off';
create table t1 (a1 char(3) DEFAULT NULL, a2 char(3) DEFAULT NULL);
insert into t1 values (NULL, 'a21'), (NULL, 'a22');
explain select * from t1 where (a1, a2) not in (select a1, a2 from t1);
select * from t1 where (a1, a2) not in (select a1, a2 from t1);
drop table t1;
set @@optimizer_switch=@save_optimizer_switch;
...@@ -4804,7 +4804,10 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, ...@@ -4804,7 +4804,10 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts,
continue; continue;
if (result_sink->get_null_count_of_col(i) == row_count) if (result_sink->get_null_count_of_col(i) == row_count)
{
bitmap_set_bit(&null_only_columns, cur_keyid); bitmap_set_bit(&null_only_columns, cur_keyid);
continue;
}
else else
{ {
merge_keys[cur_keyid]= new Ordered_key( merge_keys[cur_keyid]= new Ordered_key(
...@@ -4821,6 +4824,7 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, ...@@ -4821,6 +4824,7 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts,
++cur_keyid; ++cur_keyid;
} }
} }
DBUG_ASSERT(cur_keyid == keys_count);
/* Populate the indexes with data from the temporary table. */ /* Populate the indexes with data from the temporary table. */
tmp_table->file->ha_rnd_init(1); tmp_table->file->ha_rnd_init(1);
......
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