mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
[join table inheritance]Suboptimal JOIN clause order for ToMany-association to parent class #6571
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @flaushi on GitHub (Nov 23, 2020).
Say we have a Class hierarchy
ParentandChild1 extends Parent, ...,ChildN extends Parent.Now if we hydrate such a ManyToMany relation
the following query is created (structurally):
So the left joins principially assemble the single table inheritance equivalent table, then the inner join and where clause restrict the result set.
On my postgres 12, this leads to a very bad execution plan, because the inner join is applied after all left joins are done.
However, nothing speaks against moving the inner join clause to the front ad first expression after the
FROM parent:I think this optimization should be generally doable. What do you think? Am I missing something?
@beberlei commented on GitHub (Nov 23, 2020):
Good idea! The current approach is used more for simplicity. The left joins are part of the code generating the from. This is completely separate from generating the inner join. Reordering them would probably increase code complexity quite a bit
@flaushi commented on GitHub (Nov 23, 2020):
I had a quick look into EntityManager but really could not find where the queries are built. Can you point me somewhere?
@beberlei commented on GitHub (Nov 23, 2020):
In the Persisters classes and in SqlWalker (for DQL)