Re:Many small queries are efficient in SQLite
by wongarsu on Tuesday February 16, 2021 @12:14PM
(#26156158)
In a GraphQL API backed by a single database you could write resolvers that analyze the entire query and rephrase it as a single database query. But I'm not aware of anyone doing this. The common/straight forward solutions resolve each layer after each other, which you can optimize to 1 DB query per layer of the GraphQL query using dataloader patterns, with further optimizations for known common patterns.
[ Parent
| on HN ]
Re:Many small queries are efficient in SQLite
by heneryville on Tuesday February 16, 2021 @12:35PM
(#26156440)
Some people do try to generate a single SQL query that covers all nested resolves. See Join Monster [1]. I'm skeptical that it would ever work well in SQL.
Datomic, being close to a graph database, makes constructing a single deep query for all resolvers fairly straight forward. This is the approach my team is taking now. It's worked quite a bit better than my DataLoader biased intuition suggested.
Re:Many small queries are efficient in SQLite
by topspin on Tuesday February 16, 2021 @12:28PM
(#26156344)
> But I'm not aware of anyone doing this.
I have, for a bespoke internal application. PostgreSQL is actually capable of expressing GraphQL queries as (rather elaborate) SQL queries. You end up generating queries that use a lot of LATERAL sub-selects. The risk is generating queries with poor performance, and that risk is high enough that I don't think this is a viable approach for complex applications.
Which is a shame.