Skip to content

Remove QueryExpr::Ref / QueryExpr::LetBinding — no producer exists #181

Description

@milindsrivastava1997

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.srcipreferences 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions