Wrong result with derived_merge=ON, derived table, RIGHT JOIN
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
High
|
Igor Babaev |
Bug Description
The following query:
SELECT alias2.b, alias2.c, t1.a
FROM t1 , (
SELECT t3.* FROM t2
RIGHT JOIN t3
ON ( t3.a = t2.b )
) AS alias2
WHERE alias2.b
AND alias2.c = t1.a;
returns no rows with derived_merge=ON (impossible where, even though the WHERE clause is true) and 1 row with derived_merge=ON (which is the correct result:
EXPLAIN with derived_merge=ON:
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables |
| Note | 1003 | select 8 AS `b`,'c' AS `c`,'c' AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where 0 |
EXPLAIN with derived_merge=off:
| 1 | PRIMARY | t1 | system | NULL | NULL | NULL | NULL | 1 | 100.00 | |
| 1 | PRIMARY | <derived2> | system | NULL | NULL | NULL | NULL | 1 | 100.00 | |
| 2 | DERIVED | t2 | system | NULL | NULL | NULL | NULL | 0 | 0.00 | const row not found |
| 2 | DERIVED | t3 | system | NULL | NULL | NULL | NULL | 1 | 100.00 | |
select 8 AS `b`,'c' AS `c`,'c' AS `a` from `test`.`t1` join (select 29 AS `a`,8 AS `b`,'c' AS `c` from `test`.`t3` left join `test`.`t2` on(0)) `alias2` where (8)
minimal optimizer switch: derived_merge=on
full optimizer_switch: index_merge=
test case:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 ( a varchar(1)) engine=myisam ;
INSERT INTO t1 VALUES ('c');
DROP TABLE IF EXISTS t2;
CREATE TABLE t2 ( b int) engine=myisam;
DROP TABLE IF EXISTS t3;
CREATE TABLE t3 ( a int(11) NOT NULL , b int, c varchar(1)) engine=myisam;
INSERT INTO t3 VALUES (29,8,'c');
SELECT alias2.b, alias2.c, t1.a
FROM t1 , (
SELECT t3.* FROM t2
RIGHT JOIN t3
ON ( t3.a = t2.b )
) AS alias2
WHERE alias2.b
AND alias2.c = t1.a;
This particular test case contains a degenerate WHERE condition, however the bug was also observed with a WHERE condition containing x IN (SELECT y), so I think it is a valid bug.
bzr version-info:
revision-id: <email address hidden>
date: 2011-10-22 00:14:27 -0700
build-date: 2011-10-22 15:04:21 +0300
revno: 3246
branch-nick: maria-5.3
Changed in maria: | |
milestone: | none → 5.3 |
assignee: | nobody → Igor Babaev (igorb-seattle) |
Changed in maria: | |
status: | New → Confirmed |
importance: | Undecided → High |
Changed in maria: | |
status: | Confirmed → In Progress |
Changed in maria: | |
status: | In Progress → Fix Committed |
Changed in maria: | |
status: | Fix Committed → Fix Released |