Tyler Benfield @rtbenfield.dev · Jan 19

Why write a query like that instead of a JOIN? JOINs begin to explode the result set and confuse the query optimizer once you have more than one relationship branch. This approach makes a subquery that the optimizer will construct an independent subplan for.

0 likes 1 replies

?

Replies

Tyler Benfield · Jan 19

The common alternative is to use JSON_AGG to achieve the same query plan benefits while collapsing the results into a JSON text column. That puts more work on the database to convert to JSON and still loses some type information in serialization, but it works within the text protocol limitations.