Expand description
Relationship embedding: fetching related rows for a set of parent rows.
Both the REST and GraphQL surfaces embed related resources, and both do it the same way: take the parent rows already fetched, collect the values of the join column, and issue one query for all of them rather than one query per parent row.
SELECT row_to_json(t) FROM (
SELECT * FROM "public"."posts" WHERE "user_id" = ANY($1::int4[])
) tThe children are then grouped by that column and attached to the parent rows, so a request embedding two relationships across a page of 25 parents costs three queries, not fifty-one.
Structs§
- Embed
Plan - Everything needed to fetch one relationship’s rows for a set of parents.
Functions§
- attach_
to_ parent - Attach grouped children onto a parent row under
field_name. - group_
by_ key - group_
from_ aggregated - Group related rows by the value of their join column. Build the grouping from rows PostgreSQL has already grouped.
- key_
to_ text - Render a JSON value as the text form used to match join keys.
- parent_
keys - Collect the distinct, non-null join keys of a set of parent rows.