Wrong result (NULLs instead of real values) with RIGHT JOIN in a FROM subquery and derived_merge=on

Description

Assigning it to Sanja because it's a regression introduced with a bugfix for (revno 3574 on maria/5.3 and revno 3526 on maria/5.5).

The following test case

returns

on the affected versions, and

on unaffected versions. The latter is correct.

Reproducible with MyISAM, Aria, InnoDB.
Reproducible starting from revno 3574 on maria/5.3 from revno 3526 on maria/5.5, and up to current ones (3584 and 3544, correspondingly).
Not reproducible if I replace the subquery with a view.
Not reproducible if I replace RIGHT JOIN with LEFT JOIN.
The subquery itself, executed separately, produces the expected result.

Reproducible with the default optimizer switch as well as with optimizer_switch='derived_merge=on' only.

EXPLAIN (with the default optimizer_switch):

Environment

None

Status

Assignee

Oleksandr Byelkin

Reporter

Elena Stepanova

Labels

None

Fix versions

Affects versions

Priority

Major
Configure