Wrong result with derived_merge=on, EXISTS, RIGHT JOIN, derived table , correlated subquery in maria-5.3
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
High
|
Igor Babaev |
Bug Description
This query:
SELECT *
FROM ( SELECT * FROM t2 ) AS alias1
WHERE EXISTS (
SELECT t1.a
FROM t3
RIGHT JOIN t1
ON ( t3.d = t1.a )
WHERE t1.c < alias1.d
);
returns no rows when executed with derived_merge=on, whereas with derived_merge=off, in mysql-5.5 and in postgresql it returns:
+------+------+
| c | d |
+------+------+
| 0 | r |
| 0 | p |
+------+------+
explain:
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | PRIMARY | t2 | ALL | NULL | NULL | NULL | NULL | 2 | Using where |
| 3 | DEPENDENT SUBQUERY | t1 | system | NULL | NULL | NULL | NULL | 1 | |
| 3 | DEPENDENT SUBQUERY | t3 | ALL | NULL | NULL | NULL | NULL | 2 | Using where |
minimal optimizer_switch: derived_merge=on
full optimizer_switch: index_merge=
test case:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 ( a int NOT NULL , e int, c varchar(32)) ;
INSERT INTO t1 VALUES (28,9,'j');
DROP TABLE IF EXISTS t2;
CREATE TABLE t2 ( c int, d varchar(32)) ;
INSERT INTO t2 VALUES (0,'r'),(0,'p');
DROP TABLE IF EXISTS t3;
CREATE TABLE t3 (d int);
INSERT INTO t3 VALUES (0),(0);
SET SESSION optimizer_
SELECT *
FROM ( SELECT * FROM t2 ) AS alias1
WHERE EXISTS (
SELECT t1.a
FROM t3
RIGHT JOIN t1
ON ( t3.d = t1.a )
WHERE t1.c < alias1.d
);
bzr version-info
revision-id: <email address hidden>
date: 2011-08-09 18:34:26 +0300
build-date: 2011-08-10 13:26:22 +0300
revno: 3148
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: | In Progress → Fix Committed |
Changed in maria: | |
status: | Fix Committed → Fix Released |
This bug is actually a duplicate of bug #823189. The difference is that a merged derived table is used instead of a merged view in the offending test case for this bug. As in the test case for bug #823189 the correlated subquery is over a right join and contains an outer reference to a derived table in the where clause.