Skip to content

fix(rules): let SQLCLEAN004 skip constant-only projections - #22

Merged
kvlonge merged 1 commit into
mainfrom
fix/constant-projection-row-selection
Nov 1, 2026
Merged

kvlonge merged 1 commit into
mainfrom
fix/constant-projection-row-selection

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Why

SQLCLEAN004 reports LIMIT or OFFSET without ORDER BY because the rows kept depend on scan order. When the select list holds only constants, every row is identical, so the result does not depend on order and adding ORDER BY changes nothing. SQLBuild's measurement audits use this shape (SELECT CAST(@value AS DOUBLE) AS measured_value FROM @relation LIMIT 1), which has a fixed value for each non-empty relation and returns no row for an empty one, so the Rule should not report it.

Changes

  • Row selection is exempt when every name in the projection is an alias or a CAST type. A column reference, function call (such as now()), star or subquery still reports.
  • The row selection helpers move from engine.rs into terminal_shape.rs so both files stay within the line limit.
  • The Rules reference documents the exemption, and the generated skill is refreshed.

Verification

  • New cases: a constant projection passes, a column inside CAST still reports at LIMIT, and now() with OFFSET still reports. The constant case fails without the exemption.
  • cargo test -p sqlclean --lib sql_lint, clippy on 1.95, make skills and the hygiene scan pass.

A query whose select list holds only constants returns identical rows
whichever ones LIMIT or OFFSET keeps, so its row selection is not
nondeterministic. Column references, function calls and stars still
report.
@kvlonge
kvlonge merged commit 57fc554 into main Nov 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant