Drizzle ORM uses correlated subqueries, not JOINs, for relational queries
Drizzle ORM's relational query API, using the `with` option in `findMany`, does not generate SQL JOINs or trigger N+1 queries as many developers might assume. A developer running Drizzle with Cloudflare D1 investigated by attaching a custom logger to capture every SQL statement the ORM produces. The findings showed that Drizzle compiles all nested relations into a single SQL statement built around correlated subqueries and SQLite's `json_group_array` function. Regardless of how deeply relations are nested, only one database query is ever sent. This behavior has practical performance implications for latency-sensitive environments like Cloudflare D1, where each additional query carries a measurable cost.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in