The embed half of the read compiler: lateral joins, the select items they add, spreads
and embed=is.null filters. Called from PgRest.SQL.Read, which compiles the child
nodes.
- to-one:
LEFT JOIN LATERAL (<child>), rendered withrow_to_json(...)::jsonb - to-many:
json_agg(<agg>)::jsonbinside the lateral,COALESCE(<agg>.<agg>, '[]')in the outer select list !inner:INNER JOIN LATERAL ... ON <agg>.<agg> IS NOT NULL(to-one:ON TRUE)- a spread merges a to-one embed's columns into the parent; a to-many spread yields one array per column, ordered by the child's order terms (the child keeps its limit and offset, as upstream does)
embed=is.nullcompares the lateral withIS [NOT] DISTINCT FROM NULL
Summary
Functions
The {joins, select_items, builder} of the plan's embeds. Each select item is
{sql, group?}: group? is false for an aggregate the parent computes, so the parent's
GROUP BY (PgRest.SQL.Aggregate.group_by/2) reads the same list. In a count query only the
embeds that can change the parent row count are joined.
SQL of an embed=is.null leaf of the node's filters.
Whether the child's ORDER BY moves into its aggregate (a to-many spread).
Extra select items of a to-many spread child: its order columns under unique names, so the aggregate can order by them. The child's order leaves its own query.
Output names and hoisted aggregates selected by a lateral, excluding empty embeds.
The column names a spread (or merge) embed's plan exposes to its parent.
The columns a spread (or merge) embed's plan exposes to its parent, each with the aggregate
the parent applies to it: a (non-legacy) aggregate of the plan or of a spread below it, which
a to-one spread leaves to its parent (PgRest.SQL.Aggregate), else nil.
Functions
@spec joins(PgRest.Plan.Read.t(), PgRest.SQL.Builder.t(), map()) :: {[iodata()], [{iodata(), boolean()}], PgRest.SQL.Builder.t()}
The {joins, select_items, builder} of the plan's embeds. Each select item is
{sql, group?}: group? is false for an aggregate the parent computes, so the parent's
GROUP BY (PgRest.SQL.Aggregate.group_by/2) reads the same list. In a count query only the
embeds that can change the parent row count are joined.
@spec null_filter(PgRest.Plan.Read.t(), String.t(), boolean()) :: iodata()
SQL of an embed=is.null leaf of the node's filters.
@spec order_in_aggregate?(PgRest.Plan.Embed.t() | nil) :: boolean()
Whether the child's ORDER BY moves into its aggregate (a to-many spread).
@spec order_selects( PgRest.Plan.Read.t(), PgRest.Plan.Embed.t() | nil, PgRest.SQL.Builder.t() ) :: {[iodata()], PgRest.SQL.Builder.t()}
Extra select items of a to-many spread child: its order columns under unique names, so the aggregate can order by them. The child's order leaves its own query.
@spec projected_items(PgRest.Plan.Embed.t()) :: [ {String.t(), PgRest.AST.Aggregate.t() | nil} ]
Output names and hoisted aggregates selected by a lateral, excluding empty embeds.
@spec spread_columns(PgRest.Plan.Read.t()) :: [String.t()]
The column names a spread (or merge) embed's plan exposes to its parent.
@spec spread_items(PgRest.Plan.Read.t()) :: [ {String.t(), PgRest.AST.Aggregate.t() | nil} ]
The columns a spread (or merge) embed's plan exposes to its parent, each with the aggregate
the parent applies to it: a (non-legacy) aggregate of the plan or of a spread below it, which
a to-one spread leaves to its parent (PgRest.SQL.Aggregate), else nil.