-
Notifications
You must be signed in to change notification settings - Fork 962
proposal: eager loading support #91
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 clic 8000 king “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
Comments
Update:
|
Will it be implemented with JOIN? |
Yes. |
Like @alexsn said, JOINs will be used for eager loading. But, in cases of loading multiple and nested relations, additional queries will be executed as well. For Gremlin, we didn't figure out yet what is the "best" way for doing this. |
By the same token, if I get a user and all of his/her cars in one eager query, will the return value have both the user's columns as well as the cars? Right now, graph traversals only return the last edge but not the edges you've visited along the way. |
Yes, as an example: users, err := client.User.
Query().
// eagerly load cars along with users
WithCars().
All(ctx)
if err != nil {
// handle error
}
for _, user := range users {
for _, car := range user.Edges.Cars {
// do something with car
}
} |
@a8m this is awesome 👏 👏 👏 -- gonna give it a try this week |
Multiple database queries for a single ent query means multiple database round trips and increased latency. Microsoft Entity framework 3 is now generating only one sql query for each LINQ query. Previously they were using ent approch but they had to change it due to performance and data consistency issues, https://www.youtube.com/watch?v=PXdgyPpfaz4&list=PLReL099Y5nRd04p81Q7p5TtyjCrj9tz1t&index=14&t=899s |
Thanks for the reference @ansarizafar, I'll go over it. I just want to mention that the development is never done, there's always room for performance improvements. We just discussed between us on how we can use We have a working solution now (better state than before), we'll improve it gradually, and we'll be able to compare the performance in each iteration. |
@a8m Please also take a look at Fauna Query Language https://docs.fauna.com/fauna/current/api/fql/ and https://github.com/volatiletech/sqlboiler |
@a8m This go project is can translate GraphQL queries into a single fast SQL query. We can use the same method for eager loading in ent. |
We open this task in order to get feedback for the generated-code API of eager loading.
The 3 requirements (maybe there are more) we thought about are:
.Where
)A few examples here for what we thought about:
Add a
With<EdgeName>
method to the builder:This example gets all users under a condition + their pets + their groups (with an admin).
What about getting all users + their groups (limit to X) + their admins (eager-loading with depth 2)?
I'm not sure how common this scenario, so I think either disable this, or add a
With<Edge>Fn
option for more flexible loading:Maybe we can change
With<Edge>
to behave likeWith<Edge>Fn
and make the function to be an optional parameter.The return type for eager loading:
We were thinking about the 2 options:
Add the schema edges as public fields in the generated struct (e.g.
ent.User
), and then populate the result into these fields.Add another struct
type
(struct) for holding the schema edges. For example:I'm not sure how this is supposed to handle nested eager-loading (User->Pets->Friends)?
The text was updated successfully, but these errors were encountered: