Repository navigation
Plan ORDER BY ordinals that name a scalar over an aggregate - #439
Conversation
Monoscope production impact · Worth checkingProject Evidence window (UTC): 2026-10-19 10:15:26.755286388 UTC → 2026-10-26 10:15:26.755286388 UTC
Production details are available in Monoscope.
Production details are available in Monoscope. Coverage: Open Monoscope for evidence and coverage details. |
ReviewOverall this is a small, well-scoped fix. The case table runs against a real DataFusion session, there is a pgwire test on both protocols, and the red arm was checked. I found one correctness gap and a few smaller points. Possible bug: wildcards break the ordinal-to-projection mapping (
Minor
Tests
Nothing security-relevant. The change is purely a planner-side AST rewrite. |
DataFusion rejects
SELECT k, round(avg(v)) FROM t GROUP BY 1 ORDER BY 2with "Column in ORDER BY must be in GROUP BY or an aggregate function", but accepts the same item spelled out. Postgres accepts both. On prod, per-route p95 queries such asapprox_percentile(0.95, percentile_agg(duration))ordered by2failed this way.row_to_json) now replaces anORDER BY <n>ordinal with its select item when all of these hold:GROUP BY 1 ORDER BY 1time-bucket charts keep their exact SQL.Tests:
order_by_ordinal_over_a_scalar_aggregate_plans_on_both_protocols, a pgwire test on both the simple and extended protocols.Both fail with the rewrite disabled (red arm checked).
Local signoff (
make ci-signoffon 64ae142): fmt, clippy, test, pg-smoke and e2e all pass and are attested.🤖 Generated with Claude Code