-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Include a preload joins vs. no joins discussion in the preload docs #4517
Conversation
lib/ecto/query.ex
Outdated
@@ -2667,6 +2667,34 @@ defmodule Ecto.Query do | |||
where: l.inserted_at > c.updated_at, | |||
preload: [:author, comments: {c, likes: l}] | |||
|
|||
## Choosing Between Preloading with Joins vs. Separate Queries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether to make it a separate section with a heading or not, but I ended up doing it because it got too big to just be part of the normal text.
I also put it "first" as it seemed most relevant to the preceeding setion flow-wise. Happy to re-evaluate and change!
I'm not sure if Ecto wants to provide this level of guidance in the docs, so I understand if this PR won't be merged. I've just seen many well-meaning people do this wrong (imo) by defaulting to joining all associations just to preload them, resulting in a lot more code and potentially worse performance. I also vaguely remember a tweet from José calling this out, but couldn't find it again. Here I tried to summarize what I think I know about the topic, hoping that it's accurate and helpful.
1175eac
to
a38584c
Compare
Updated, removed section about database load. Thanks for the feedback everyone! |
💚 💙 💜 💛 ❤️ |
I'm not sure if Ecto wants to provide this level of guidance in the docs, so I understand if this PR won't be merged.
I've just seen many well-meaning people do this wrong (imo) by defaulting to joining all associations just to preload them, resulting in a lot more code and potentially worse performance.
I also vaguely remember a tweet from José calling this out, but couldn't find it again.
Here I tried to summarize what I think I know about the topic, hoping that it's accurate and helpful.
As usual, thank you all very much for your work! 💚