You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(sql): propagate ORDER BY into aggregate plans and support derived-FROM subqueries
Three silent-correctness bugs fixed end-to-end through planner, converter, and executor:
ORDER BY after GROUP BY was silently dropped
The planner's apply_order_by did not handle SqlPlan::Aggregate, so every
GROUP BY … ORDER BY query returned groups in hash-map iteration order.
SqlPlan::Aggregate gains a sort_keys field; apply_order_by populates it;
the executor sorts finalized group rows before truncating to LIMIT. The
converter rejects non-column sort expressions with a typed error rather
than silently discarding them. ORDER BY on a CTE (used by derived-FROM
subqueries) is now pushed into the outer plan.
Derived FROM subquery support
FROM (SELECT …) AS t was not a recognised pattern; the resolver dropped
the factor silently, the scope was empty, and the planner errored with
"multi-table FROM without JOIN". try_plan_derived_from desugars the
single non-LATERAL derived-table into a synthetic CTE so the outer
SELECT plans normally against the alias.
Aggregate alias case mismatch
UnnamedExpr aliases were kept in the case emitted by the AST formatter
(e.g. COUNT(DISTINCT user_id)), but expr_column_names produced lowercase
keys. The JSON row key never matched, and clients saw NULL. Alias
generation now lowercases the expression string to align with the
column-name lookup.
0 commit comments