Wrong empty result instead of NULL for MAX/MIN with derived_merge=ON or with a view
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
High
|
Igor Babaev |
Bug Description
The following query
SELECT MAX(a)
FROM ( SELECT * FROM t1 ) AS alias
WHERE (1,2) IN ( SELECT 3,4 );
returns an empty set if it is executed with derived_merge=ON (current default), and NULL otherwise.
NULL is correct.
bzr version-info
revision-id: <email address hidden>
date: 2011-12-14 04:56:54 +0400
build-date: 2011-12-14 20:55:23 +0400
revno: 3349
branch-nick: maria-5.3
Also reproducible on revno 3250.
EXPLAIN with derived_merge=ON (wrong result):
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
select max(`test`
EXPLAIN with derived_merge=OFF (correct result):
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00
3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
2 DERIVED t1 index NULL a 4 NULL 2 100.00 Using index
select max(`alias`.`a`) AS `MAX(a)` from (select `test`.`t1`.`a` AS `a` from `test`.`t1`) `alias` where <expr_cache>
Minimal optimizer_switch: derived_merge=ON (by default)
Full optimizer_switch: index_merge=
Test case:
SET optimizer_
CREATE TABLE t1 ( a int(11) NOT NULL, KEY(a) );
INSERT INTO t1 VALUES (10);
INSERT INTO t1 VALUES (11);
SELECT MAX(a)
FROM ( SELECT * FROM t1 ) AS alias
WHERE (1,2) IN ( SELECT 3,4 );
Changed in maria: | |
status: | New → In Progress |
importance: | Undecided → Medium |
Changed in maria: | |
assignee: | Oleksandr "Sanja" Byelkin (sanja-byelkin) → Igor Babaev (igorb-seattle) |
Changed in maria: | |
status: | In Progress → Fix Committed |
Changed in maria: | |
status: | Fix Committed → Fix Released |
As Igor pointed out, the problem is reproducible without a derived table, with a view:
CREATE TABLE t1 ( a int(11) NOT NULL, KEY(a) );
INSERT INTO t1 VALUES (10),(11);
CREATE VIEW v AS SELECT * FROM t1;
SELECT MAX(a) FROM v WHERE (1,2) IN ( SELECT 3,4 );
Reproducible on 5.2.10 and 5.1.60, and on MySQL 5.1.60.