I investigated this problem. It happens because the optimizer generates a plan with outer tables interleaving inner tables of an outer join. The problem is reproducible in 5.1 as well: MariaDB [test]> CREATE TABLE t2 (f4 varchar(1024), KEY (f4)) ; Query OK, 0 rows affected, 1 warning (0.02 sec) MariaDB [test]> INSERT IGNORE INTO t2 VALUES ('xcddwntkbxyorzdv'),('cnxxcddwntkbxyor'),('r'),('r'),('did'),('I'),('when'),('hczkfqjeggivdvac'),('e'),('okay'),('up'); Query OK, 11 rows affected (0.00 sec) Records: 11 Duplicates: 0 Warnings: 0 MariaDB [test]> MariaDB [test]> CREATE TABLE t4 (f1 int(11), f3 varchar(10)) ; Query OK, 0 rows affected (0.01 sec) MariaDB [test]> INSERT IGNORE INTO t4 VALUES ('8','n'),('9','nwzcerzsgx'),('10','c'); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 MariaDB [test]> CREATE TABLE t3 (f4 varchar(1024), f1 int(11), f2 int(11)) ; Query OK, 0 rows affected (0.01 sec) MariaDB [test]> INSERT IGNORE INTO t3 VALUES ('f','4','0'),('n','5','-996540416'); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 MariaDB [test]> MariaDB [test]> CREATE TABLE t1 (f1 int(11), PRIMARY KEY (f1)) ; Query OK, 0 rows affected (0.01 sec) MariaDB [test]> CREATE TABLE t5 (f5 int(11), KEY (f5)) ; Query OK, 0 rows affected (0.01 sec) MariaDB [test]> EXPLAIN EXTENDED -> SELECT alias2.f2 -> FROM t2 AS alias1 -> LEFT JOIN t3 AS alias2 -> LEFT JOIN t4 AS alias3 -> LEFT JOIN t1 AS alias4 ON alias3.f1 = alias4.f1 -> JOIN t5 AS alias5 -> ON alias3.f3 ON alias2.f1 = alias5.f5 ON alias1.f4 = alias2.f4 -> WHERE alias2.f2 ; +----+-------------+--------+------+---------------+------+---------+----------------+------+----------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+--------+------+---------------+------+---------+----------------+------+----------+-------------+ | 1 | SIMPLE | alias2 | ALL | NULL | NULL | NULL | NULL | 2 | 100.00 | Using where | | 1 | SIMPLE | alias5 | ref | f5 | f5 | 5 | test.alias2.f1 | 2 | 100.00 | Using index | | 1 | SIMPLE | alias1 | ref | f4 | f4 | 1003 | test.alias2.f4 | 2 | 100.00 | Using where | | 1 | SIMPLE | alias3 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | | +----+-------------+--------+------+---------------+------+---------+----------------+------+----------+-------------+ 4 rows in set, 1 warning (0.00 sec) MariaDB [test]> SHOW WARNINGS; +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Level | Code | Message | +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Note | 1003 | select `test`.`alias2`.`f2` AS `f2` from `test`.`t2` `alias1` join `test`.`t3` `alias2` left join (`test`.`t4` `alias3` join `test`.`t5` `alias5`) on((`test`.`alias3`.`f3` and (`test`.`alias5`.`f5` = `test`.`alias2`.`f1`))) where ((`test`.`alias1`.`f4` = `test`.`alias2`.`f4`) and `test`.`alias2`.`f2`) | +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ If we turn table elimination off the the plan becomes non-interleaving: MariaDB [test]> set optimizer_switch='table_elimination=off'; Query OK, 0 rows affected (0.00 sec) MariaDB [test]> EXPLAIN EXTENDED SELECT alias2.f2 FROM t2 AS alias1 LEFT JOIN t3 AS alias2 LEFT JOIN t4 AS alias3 LEFT JOIN t1 AS alias4 ON alias3.f1 = alias4.f1 JOIN t5 AS alias5 ON alias3.f3 ON alias2.f1 = alias5.f5 ON alias1.f4 = alias2.f4 WHERE alias2.f2; +----+-------------+--------+--------+---------------+---------+---------+----------------+------+----------+--------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+--------+--------+---------------+---------+---------+----------------+------+----------+--------------------------------+ | 1 | SIMPLE | alias2 | ALL | NULL | NULL | NULL | NULL | 2 | 100.00 | Using where | | 1 | SIMPLE | alias5 | ref | f5 | f5 | 5 | test.alias2.f1 | 2 | 100.00 | Using index | | 1 | SIMPLE | alias3 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | | | 1 | SIMPLE | alias4 | eq_ref | PRIMARY | PRIMARY | 4 | test.alias3.f1 | 1 | 100.00 | Using index | | 1 | SIMPLE | alias1 | ALL | f4 | NULL | NULL | NULL | 11 | 81.82 | Using where; Using join buffer | +----+-------------+--------+--------+---------------+---------+---------+----------------+------+----------+--------------------------------+ 5 rows in set, 1 warning (0.00 sec) The cause of the problem is the current code for the table elimination. It does not adjust the nested join structure when eliminating tables. At the same time the functions that build auxiliary bitmaps to check interleaving use this structure.