Wrong result (missing rows) with firstmatch+BNL, IN subquery, MyISAM or InnoDB, given join order
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
Critical
|
Sergey Petrunia |
Bug Description
The following query
SELECT * FROM t1 alias1, t2 alias2
WHERE alias2.c IN (
SELECT alias4.c FROM t1 alias3, t2 alias4
);
on test data returns two or 14 rows depending on the table join order. 14 is correct.
bzr version-info
revision-id: <email address hidden>
date: 2012-01-23 15:14:13 +0200
build-date: 2012-01-24 02:51:18 +0400
revno: 3393
branch-nick: maria-5.3
The test case also requires debug_optimizer
Initially a similar problem was observed on 5.3-extended_keys, on a more complicated dataset and query, without debug_optimizer
EXPLAIN with debug_optimizer
id select_type table type possible_keys key key_len ref rowsfiltered Extra
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY alias4 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(alias2); Using join buffer (flat, BNL join)
1 PRIMARY alias1 ALL NULL NULL NULL NULL 7 100.00 Using join buffer (incremental, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 7 100.00 FirstMatch(alias1); Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`alias1`.`a` AS `a`,`test`
EXPLAIN without specified join order:
id select_type table type possible_keys key key_len ref rowsfiltered Extra
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY alias4 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY alias3 ALL NULL NULL NULL NULL 7 100.00 FirstMatch(alias2); Using join buffer (incremental, BNL join)
1 PRIMARY alias1 ALL NULL NULL NULL NULL 7 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`alias1`.`a` AS `a`,`test`
Minimal optimizer_switch: semijoin=
Full optimizer_switch: index_merge=
Test case:
SET optimizer_switch = 'semijoin=
# t1 should be MyISAM or InnoDB
CREATE TABLE t1 ( a VARCHAR(1) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES
('e')
CREATE TABLE t2 ( b INT, c VARCHAR(1) );
INSERT INTO t2 VALUES (0,'j'),(8,'v');
SET debug_optimizer
'alias2,
SELECT * FROM t1 alias1, t2 alias2
WHERE alias2.c IN (
SELECT alias4.c FROM t1 alias3, t2 alias4
);
# End of test case
# Expected test result:
a b c
e 0 j
e 8 v
w 0 j
w 8 v
a 0 j
a 8 v
h 0 j
h 8 v
x 0 j
x 8 v
k 0 j
k 8 v
g 0 j
g 8 v
# Actual test result:
a b c
e 0 j
e 8 v
Changed in maria: | |
importance: | Undecided → Critical |
Changed in maria: | |
status: | New → Fix Committed |
Changed in maria: | |
status: | Fix Committed → Fix Released |