Re:Efficient GraphQL Queries in Ruby on Rails and Postgres
by e12e on Wednesday September 25, 2019 @06:13PM
(#21076163)
No, you're probably right - I suppose the database drivers might naively serialize that in a one-to-one representation (to be honest, I've never really looked into the protocols that postgres or Ms sql use for transferring data).
I didn't consider the kind of expansion you're alluding to - on the other hand i can't ever remember seeing an indication that the amount of data returned is an issue with app performance.
But I've certainly seen the number of round-trips result in real issues. And complicated joins, for that matter.
Re:Efficient GraphQL Queries in Ruby on Rails and Postgres
by uhoh-itsmaciek on Wednesday September 25, 2019 @07:03PM
(#21076548)
I've worked on a few Postgres drivers and the protocol is basically sending data row-by-row, column-by-column. Sure, it could be more clever, but that's time and cpu and memory spent being clever instead of moving data.
But you're right, there are always trade-offs, and there are some situations where the current AR approach is not ideal, and a single join would be more efficient. However, I suspect this is the way AR does it because it's right enough often enough that it works well as the default approach.
For a query like
above, the user information is repeated for each comment, e.g., If you have a hundred comments, and many user fields, this can be a significant amount of data to pass around. Or maybe this is not what you meant? I feel like we may be talking past each other. Can you give an example of what you think the ideal sql should be for "give me user with id = 1 and all their comments"?