mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
[PR #970] [DDC-357] Effective toOne joins #8980
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?
Original Pull Request: https://github.com/doctrine/orm/pull/970
State: closed
Merged: No
What is this?
I've kind of rewriten querying of toOne relations. It is more data and query-count effective.
How?
Let's demonstrate it on
CmsUserandCmsAddressfrom tests models. Let's solve behaviour for toOne relations that are not mentioned in the query.lazy + mapped by side
Already implemented, result is that CmsAddress would be proxy.
lazy + inverse side
CmsUserhasCmsAddressrelation that is mapped and owned byCmsAddressentity.What has to happen? The identifier of
CmsAddresscannot be loaded from users table nad has to be added automatic join for the table. Because it's lazy it will be hydrated as proxy, becase that is exactly what I've asked for.If it would have been eagerly loaded, It would create 1+N queries problem that I'm trying to avoid with this. I have the relation as lazy, if I knew I would have needed it and wanned to optimized, I'd join it, but I didn't.
Result is therefore
CmsUserentity +CmsAddressproxyeager - both inverse and mapped by sides
The appropriate query component is generated with autojoin and auto selecting of the entity.
If it is self-referencing, the auto join is not generated becase it would cause infinite recursion.
Why?
I've given this a lot of thought and tested it on our not-so-small application. We have unfortunately lot of entitiy relations that are mapped on the inverse side than we need to select, which is effectively killing performace DDC-357
I would have to go and list all the entities as partials to save performace creating such monsters as this
We all know that hydrating a large result set is a bottleneck and if I say the relation is lazy and I'm not joining it I really don't want it to be joined with all it's data!
Now imagine I just want to select few orders and render some data on the page.. I have tens of queries like this just because I have to. This is wrong that the ORM is tripping my feet like this.
What now?
I know I have to solve theese:
Any suggestions? Let's have a reasonable discussion, please don't just close this, I've put a lot of effort into this.