Wrong result with in_to_exists=ON and NOT IN
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
Critical
|
Timour Katchaounov |
Bug Description
This query:
SELECT *
FROM t1 , t2
WHERE ( t1.f2 , t2.f3 ) NOT IN (
SELECT t3.f3 , t4.f3
FROM t3 STRAIGHT_JOIN t4
ON ( t4.f1 = t3.f1 )
);
returns 1 row when run with in_to_exists:
| g | c |
and 2 rows otherwise:
| NULL | c |
| g | c |
explain:
| 1 | PRIMARY | t2 | system | NULL | NULL | NULL | NULL | 1 | |
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 2 | Using where |
| 2 | DEPENDENT SUBQUERY | t3 | ALL | NULL | NULL | NULL | NULL | 17 | Using where |
| 2 | DEPENDENT SUBQUERY | t4 | ALL | NULL | NULL | NULL | NULL | 43 | Using where |
minimal optimizer switch: in_to_Exists=
full switch: index_merge=
also affects mysql 5.5
test case:
CREATE TABLE t1 ( f2 varchar(1) ) ;
INSERT INTO t1 VALUES (NULL),('g');
CREATE TABLE t2 ( f3 varchar(1) ) ;
INSERT INTO t2 VALUES ('c');
CREATE TABLE t3 ( f1 int(11), f3 varchar(1) ) ;
INSERT INTO t3 VALUES (4,'v')
DROP TABLE IF EXISTS t4;
CREATE TABLE t4 ( f1 int(11), f3 varchar(1) ) ;
INSERT INTO t4 VALUES (1,'x')
SET SESSION optimizer_
SELECT *
FROM t1 , t2
WHERE ( t1.f2 , t2.f3 ) NOT IN (
SELECT t3.f3 , t4.f3
FROM t3 STRAIGHT_JOIN t4
ON ( t4.f1 = t3.f1 )
);
bzr version-info:
revision-id: <email address hidden>
date: 2011-10-06 01:21:15 +0400
build-date: 2011-10-06 13:02:50 +0300
revno: 3213
branch-nick: maria-5.3
Related branches
Changed in maria: | |
milestone: | none → 5.3 |
assignee: | nobody → Timour Katchaounov (timour) |
Changed in maria: | |
status: | New → In Progress |
importance: | Undecided → Critical |
Changed in maria: | |
status: | In Progress → Fix Committed |
Changed in maria: | |
status: | Fix Committed → Fix Released |
The problem can be demonstrate with the following very simple test case:
create table outer_sq (f1 char(1), f2 char(1));
insert into outer_sq values (NULL, 'c'), ('g', 'c');
create table inner_sq (f3 char(1), f4 char(1));
insert into inner_sq values(null, 'i'), ('v', null);
set @@optimizer_ switch= 'in_to_ exists= off,materializa tion=on, partial_ match_rowid_ merge=on, partial_ match_table_ scan=off' ;
SELECT outer_sq.*, (f1, f2) IN (select * from inner_sq) from outer_sq;
SELECT * from outer_sq where (f1, f2) NOT IN (select * from inner_sq);
set @@optimizer_ switch= 'in_to_ exists= off,materializa tion=on, partial_ match_rowid_ merge=off, partial_ match_table_ scan=on' ;
SELECT outer_sq.*, (f1, f2) IN (select * from inner_sq) from outer_sq;
SELECT * from outer_sq where (f1, f2) NOT IN (select * from inner_sq);
set @@optimizer_ switch= 'in_to_ exists= on,materializat ion=off' ;
SELECT outer_sq.*, (f1, f2) IN (select * from inner_sq) from outer_sq;
SELECT * from outer_sq where (f1, f2) NOT IN (select * from inner_sq);