-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
separating joins and eager loads #3
Comments
Person reporting this referred to Laravel's ORM. A quick check reveils that it doesn't do joins at all, it runs a separate query for each relation included in the question, so it suffers from the N+1 problem, which is absolutely a bad idea. So we shouldn't go that route! |
What was the original request/issue regarding this? |
This was a comment in two stages: the first line was originally reported, and was triggered by the way we do it in v1: when you run a query with relations, ORM v1 does a full join, and then runs a hydration process to split each row into the different model instances. Laravel's ORM runs separate queries and the statement was that it was faster. I did a quick check at the time, and it seemed to run a separate query for each parent->child relation, leading to my statement about the N+1 problem. I think now it runs WHERE pk IN (list of FK's) queries on child tables, and uses a separate hydration process to create objects for these rows and link them to their parent. There are heated debates which of the two solutions is faster, but I think the answer is "it depends". It might be a bit more memory efficient, since you don't pull the entire result into memory (before hydration) in one go. |
No description provided.
The text was updated successfully, but these errors were encountered: