Expand description
A real SQL SELECT engine — expressions, aliases, CASE, functions, joins.
§Why this module exists
The pgwire layer translates SQL text into NQL text. That works beautifully
for SELECT col FROM t WHERE x = 1, and it cannot be stretched any
further: NQL has no expressions, no table aliases, no CASE, no scalar
functions and no joins. Those are not missing features of the translation —
they are things the target language cannot say.
And they are exactly what catalogue introspection is made of. psql’s
\dt is one statement containing a two-table LEFT JOIN, a nine-branch
CASE, two scalar function calls, four qualified column references, an
IN list, a !~ regex and ORDER BY 1,2. Every one of those has to work
or the command does not.
So this is a small but genuine SQL evaluator: lexer, parser, expression evaluator, nested-loop join. It operates over rows supplied by a callback, which is what lets the same engine serve synthesised catalogue relations today and stored collections later.
§What it is NOT
It is not a query planner and does not pretend to be. The join is a nested loop, which is honest for catalogue relations (tens of rows) and would be wrong to point at a large collection without an index strategy. That boundary is enforced by the caller, not hidden here.
§The rule this module follows
Anything it cannot evaluate is REFUSED with an error naming the construct. It never guesses. A catalogue query that silently returns the wrong rows produces an empty or wrong table list, and a wrong table list is indistinguishable from a correct one until somebody’s data appears to be missing.
Structs§
- Bound
- One row of a (possibly joined) result: an ordered list of
(binding, row-or-NULL). - EvalCtx
- What an expression may reach beyond its own row.
- Join
- Opts
- Execution options. Every switch exists so a differential test can run the SAME query with the optimisation on and off and compare — without that, a test believing it exercised an optimisation could be measuring the unoptimised path, and the equivalence suite would prove nothing.
- OrderBy
- OutCol
- One output column: the key it is stored under, and the name the client sees.
- Select
- Select
Item - SetArm
- One further arm of a compound query:
<op> [ALL] SELECT .... - Table
Ref - VecRelation
- A relation backed by an already-materialised
Vec.
Enums§
Traits§
- Relation
- A relation, delivered one row at a time.
Functions§
- eval
- Evaluate an expression against one bound row.
- execute
- Run a parsed
SELECT, returning(column names, rows). - execute_
explain - Run a parsed
SELECT, also reporting how each join was executed. - execute_
opts - The full form.
- execute_
with - As
execute_explain, with predicate pushdown switchable. - from_
vec - Wrap a materialised relation.
- has_
aggregate - Does this expression call an aggregate at ITS level — not inside a subquery, whose aggregates belong to the subquery?
- lex
- parse
- Parse one
SELECTstatement — possibly a compound one. - run
- Parse and run in one call.
Type Aliases§
- Resolver
- Everything one execution needs from the outside world.