Skip to main content

Module alias

Module alias 

Source
Expand description

The SQL table aliases a record’s rows are addressed by inside a nested statement, minted HERE rather than at the moment one is rendered.

§Why an expansion computes them and the engine only indexes

An alias is a pure function of two compile-time facts — the table’s name, and the nesting DEPTH of the scope wearing it — so there is nothing about it a running statement knows that a macro does not. Minting at render time therefore bought nothing and cost a Utf8BytesMut per occurrence per statement, on the one path this family is arranged to keep allocation off.

What the engine gets instead is &'static [&'static str] beside the row’s address: an index, a slice bound, and no string built at all.

§Both halves are a DECLARATION’s to move, and the defaults are what most of them keep

ALIAS_PREFIX and DEPTH_CEILING are the answers a record that names nothing gets. <db>(alias(prefix = "__mine", depth = 16)) is the record that names one, and the knob is per DATABASE because the emitted table is: ALIASES rides one SqlQuery<Db> impl, so two databases of one record already carry two of them and nothing had to be widened to let them differ.

§The DEPTH is the axis, and it is the only one that separates anything

An alias is scoped to the subquery that states it, so two SIBLING subqueries may each call their row source the same thing and neither can see the other’s. What has to differ is a name and the name it NESTS inside — and nesting depth is exactly that, which is why the array is indexed by it and why a per-occurrence counter would have been both unobtainable and unnecessary.

§No parity, and no alternating pair

Two alternating names — one for even depths, one for odd — would be enough for a reference that never reaches two levels, and that is the whole objection: it is correct until a declaration nests a relation inside a relation over the same table, at which point the third level silently takes the first level’s name, SQL resolves every reference to the inner scope, and the statement answers from the wrong row source with no error anywhere. A scheme that fails silently at a reachable depth is not a smaller version of this one. The ceiling is a REFUSAL for the same reason: past it the engine says so.

Constants§

ALIAS_PREFIX
The framework’s DEFAULT identifier namespace — the four characters a minted alias begins with where the declaration named no other, and the prefix ingraph-derive refuses a declared table or column name for taking wherever any database still defaults.
DEPTH_CEILING
How deep a record’s aliases are minted where its declaration names no number, and therefore how deep a relation over such a record may nest before the engine refuses.

Functions§

alias
<prefix>_<table>_<depth>__, clamped to what every shipped engine stores whole.
aliases
Every alias one table wears in one database, indexed by the depth of the scope wearing it.
refused
Why this (prefix, depth) pair cannot be minted, or None where it can.
sort_column
The ORDER-PRESERVING COMPANION COLUMN one sortable collection is mirrored into.