mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed bug lp:809245
In addition to the bug fix explained below, the patch performs few renames, and adds some comments to avoid similar problems. Analysis: The failed assert was due to a bug in MWL#68, where it was incorrectly assumed that the size of the bitmap subselect_rowid_merge_engine::null_only_columns should be the same as the size of the array of Ordered_keys. The bitmap null_only_columns contains bits to mark columns that contain only NULLs. Therefore the indexes of the bits to be set in null_only_columns are different from the indexes of the Ordered_keys. If there is a NULL-only column that appears in a table after the last partial match column with Ordered_key, this NULL-only column would require setting a bit with index bigger than the size of the bitmap null_only_columns. Accessing such a bit caused the failed assert. Solution: Upon analysis, it turns out that null_only_columns is not needed at all, because we are looking for partial matches, and having such columns guarantees that there is a partial match for any corresponding outer value. Therefore the patch removes subselect_rowid_merge_engine::null_only_columns.
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
drop table if exists t1, t2;
|
||||
#
|
||||
# LP BUG#608744
|
||||
#
|
||||
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(1), a2 char(1));
|
||||
insert into t1 values (NULL, 'b');
|
||||
@ -11,7 +11,6 @@ insert into t2 values ('a','b'), ('c', 'd');
|
||||
select * from t1 where (a1, a2) NOT IN (select b1, b2 from t2);
|
||||
a1 a2
|
||||
drop table t1,t2;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
#
|
||||
# LP BUG#601156
|
||||
#
|
||||
@ -21,7 +20,6 @@ INSERT INTO t1 VALUES (4,NULL);
|
||||
CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL);
|
||||
INSERT INTO t2 VALUES (6,NULL);
|
||||
INSERT INTO t2 VALUES (NULL,0);
|
||||
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
|
||||
SELECT * FROM (SELECT * FROM t1 WHERE a1 NOT IN (SELECT b2 FROM t2)) table1;
|
||||
@ -31,11 +29,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b2` from `test`.`t2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery3>`.`b2`)))))))
|
||||
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');
|
||||
@ -46,7 +42,6 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
select * from t1 where (a1, a2) not in (select a1, a2 from t1);
|
||||
a1 a2
|
||||
drop table t1;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
#
|
||||
# LP BUG#680058 void Ordered_key::add_key(rownum_t):
|
||||
# Assertion `key_buff_elements && cur_key_idx < key_buff_elements' failed
|
||||
@ -55,10 +50,53 @@ create table t1 (f1 char(1), f2 char(1));
|
||||
insert into t1 values ('t', '0'), ('0', 't');
|
||||
create table t2 (f3 char(1), f4 char(1));
|
||||
insert into t2 values ('t', NULL), ('t', NULL), ('d', 'y');
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
SET @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,semijoin=off';
|
||||
set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,semijoin=off';
|
||||
select * from t1 where (f1, f2) not in (select * from t2);
|
||||
f1 f2
|
||||
0 t
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
drop table t1, t2;
|
||||
#
|
||||
# LP BUG#809245 Second assertion `bit < (map)->n_bits' with partial_match_merge
|
||||
#
|
||||
CREATE TABLE t1 (d varchar(32)) ;
|
||||
INSERT INTO t1 VALUES ('r');
|
||||
CREATE TABLE t2 ( a int, c varchar(32)) ;
|
||||
INSERT INTO t2 VALUES (5,'r');
|
||||
CREATE TABLE t3 ( a int NOT NULL , d varchar(32)) ;
|
||||
INSERT INTO t3 VALUES (10,'g');
|
||||
set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off';
|
||||
EXPLAIN SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 system NULL NULL NULL NULL 1
|
||||
2 SUBQUERY t3 system NULL NULL NULL NULL 1
|
||||
2 SUBQUERY t2 system NULL NULL NULL NULL 1
|
||||
SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
d
|
||||
r
|
||||
set @@optimizer_switch='materialization=off,in_to_exists=on';
|
||||
EXPLAIN SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 system NULL NULL NULL NULL 1
|
||||
2 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 1
|
||||
2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1
|
||||
SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
d
|
||||
r
|
||||
drop table t1, t2, t3;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
|
@ -3,6 +3,8 @@
|
||||
# MWL#68: Subquery optimization: Efficient NOT IN execution with NULLs
|
||||
#
|
||||
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t1, t2;
|
||||
--enable_warnings
|
||||
@ -10,7 +12,6 @@ drop table if exists t1, t2;
|
||||
--echo #
|
||||
--echo # LP BUG#608744
|
||||
--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(1), a2 char(1));
|
||||
insert into t1 values (NULL, 'b');
|
||||
@ -18,7 +19,6 @@ create table t2 (b1 char(1), b2 char(2));
|
||||
insert into t2 values ('a','b'), ('c', 'd');
|
||||
select * from t1 where (a1, a2) NOT IN (select b1, b2 from t2);
|
||||
drop table t1,t2;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
|
||||
|
||||
--echo #
|
||||
@ -32,20 +32,17 @@ CREATE TABLE t2 (b1 int DEFAULT NULL, b2 int DEFAULT NULL);
|
||||
INSERT INTO t2 VALUES (6,NULL);
|
||||
INSERT INTO t2 VALUES (NULL,0);
|
||||
|
||||
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
|
||||
SELECT * FROM (SELECT * FROM t1 WHERE a1 NOT IN (SELECT b2 FROM t2)) table1;
|
||||
|
||||
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);
|
||||
@ -53,7 +50,6 @@ 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;
|
||||
|
||||
--echo #
|
||||
--echo # LP BUG#680058 void Ordered_key::add_key(rownum_t):
|
||||
@ -65,8 +61,52 @@ insert into t1 values ('t', '0'), ('0', 't');
|
||||
create table t2 (f3 char(1), f4 char(1));
|
||||
insert into t2 values ('t', NULL), ('t', NULL), ('d', 'y');
|
||||
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
SET @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,semijoin=off';
|
||||
set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,semijoin=off';
|
||||
select * from t1 where (f1, f2) not in (select * from t2);
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
drop table t1, t2;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # LP BUG#809245 Second assertion `bit < (map)->n_bits' with partial_match_merge
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (d varchar(32)) ;
|
||||
INSERT INTO t1 VALUES ('r');
|
||||
|
||||
CREATE TABLE t2 ( a int, c varchar(32)) ;
|
||||
INSERT INTO t2 VALUES (5,'r');
|
||||
|
||||
CREATE TABLE t3 ( a int NOT NULL , d varchar(32)) ;
|
||||
INSERT INTO t3 VALUES (10,'g');
|
||||
|
||||
set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off';
|
||||
|
||||
EXPLAIN SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
|
||||
SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
|
||||
set @@optimizer_switch='materialization=off,in_to_exists=on';
|
||||
|
||||
EXPLAIN SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
|
||||
SELECT *
|
||||
FROM t1
|
||||
WHERE (t1.d , t1.d) NOT IN (
|
||||
SELECT t3.d , t2.c
|
||||
FROM t3 LEFT JOIN t2 ON t3.a = t2.a);
|
||||
|
||||
drop table t1, t2, t3;
|
||||
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
|
Reference in New Issue
Block a user