Summary
QueryExpr::Ref and QueryExpr::LetBinding (crates/ir/src/intent_algebra/query_expr.rs:496, :667) are marked Reserved — the doc comments say no front end emits them yet, CSE is expected to run on L3. Verified empirically rather than just by reading: lowered every query across all 7 corpora we have (4 PromQL corpora + 3 SQL corpora, ~2600 queries total) and walked every resulting QueryExpr tree — neither variant ever appears.
Also tested the specific case these two exist for — SQL CTEs / repeated references:
WITH totals AS (SELECT srcip, COUNT(*) cnt FROM packets GROUP BY srcip) SELECT * FROM totals WHERE cnt > 10
WITH a AS (...) SELECT x.srcip FROM a x JOIN a y ON x.srcip = y.srcip — references the CTE twice, a deliberate diamond
SELECT * FROM (SELECT ...) t WHERE cnt > 10 — plain derived table, no WITH at all
All three lower to identical shapes (Filter/Join over Project/Aggregate/Scan) with the CTE body inlined verbatim at every reference site — the diamond case duplicates the whole Aggregate{Scan} subtree instead of sharing it via a Ref. This matches the actual code path: DataFusion desugars WITH into SubqueryAlias at every use site, and frontend-sql/src/sql/mod.rs's SubqueryAlias handling just recurses like any derived table (crates/frontend-sql/src/sql/mod.rs:142). PromQL has no CTE-equivalent syntax at all today.
So both variants are unreachable by construction, not just untested by the corpora we happen to have.
Summary
QueryExpr::RefandQueryExpr::LetBinding(crates/ir/src/intent_algebra/query_expr.rs:496,:667) are marked Reserved — the doc comments say no front end emits them yet, CSE is expected to run on L3. Verified empirically rather than just by reading: lowered every query across all 7 corpora we have (4 PromQL corpora + 3 SQL corpora, ~2600 queries total) and walked every resultingQueryExprtree — neither variant ever appears.Also tested the specific case these two exist for — SQL CTEs / repeated references:
WITH totals AS (SELECT srcip, COUNT(*) cnt FROM packets GROUP BY srcip) SELECT * FROM totals WHERE cnt > 10WITH a AS (...) SELECT x.srcip FROM a x JOIN a y ON x.srcip = y.srcip— references the CTE twice, a deliberate diamondSELECT * FROM (SELECT ...) t WHERE cnt > 10— plain derived table, noWITHat allAll three lower to identical shapes (
Filter/JoinoverProject/Aggregate/Scan) with the CTE body inlined verbatim at every reference site — the diamond case duplicates the wholeAggregate{Scan}subtree instead of sharing it via aRef. This matches the actual code path: DataFusion desugarsWITHintoSubqueryAliasat every use site, andfrontend-sql/src/sql/mod.rs'sSubqueryAliashandling just recurses like any derived table (crates/frontend-sql/src/sql/mod.rs:142). PromQL has no CTE-equivalent syntax at all today.So both variants are unreachable by construction, not just untested by the corpora we happen to have.