Re:How to GraphQL with Ruby, Rails, Active Record, and No N+1
by tehlike on Monday November 09, 2020 @05:21PM
(#25040647)
Postgres supports json_agg which solves n+1 and also cartesian product problem. It's neat, hasura does it nicely for example.
[ Parent
| on HN ]
Re:How to GraphQL with Ruby, Rails, Active Record, and No N+1
by advance512 on Monday November 09, 2020 @06:59PM
(#25041413)
How does json_agg solve the n+1 problem?
Re:How to GraphQL with Ruby, Rails, Active Record, and No N+1
by tehlike on Monday November 09, 2020 @09:43PM
(#25042360)
It can eagerload more complex queries.
If you are eagerloading multiple joins relationships, normally that would create a result set of n x m x k x ... rows. With json_agg each relation could be single column in a row etc.
Re:How to GraphQL with Ruby, Rails, Active Record, and No N+1
by dmitrytsepelev on Tuesday November 10, 2020 @01:53AM
(#25043403)
In this case the row size can become huge. Also, how to make sure it's consistent? (I mean foreign keys/unique indexes/etc)