Skip to content
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

Open
WanWizard opened this issue Aug 22, 2013 · 3 comments
Open

separating joins and eager loads #3

WanWizard opened this issue Aug 22, 2013 · 3 comments

Comments

@WanWizard
Copy link
Contributor

No description provided.

@WanWizard
Copy link
Contributor Author

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!

@emlynwest
Copy link
Contributor

What was the original request/issue regarding this?

@WanWizard
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants