When adding a restriction on a path to an entity from a treated left outer join, the restriction on the dtype is rendered twice: once in a sub-select in the outer join (this is correct) and once in where clause of the outer select (this is incorrect). The second restriction effectively transforms the left outer join into an inner join, because DTYPE will be NULL for all other records. The resulting query looks like this:
select
m1_0.id,
m1_0.ref2
from
MyEntity1 m1_0
left join
(select
*
from
MyEntity2 t
where
t.DTYPE='MySubEntity2') r1_0
on r1_0.id=m1_0.ref2
where
(
m1_0.ref2 is null
or m1_0.ref2 is not null
and r1_0.ref3=?
)
and r1_0.DTYPE='MySubEntity2'
I’ve attached a testcase that shows the problem. This test runs fine against 5.6.15. |