Repository navigation
fix(rules): let SQLCLEAN004 skip constant-only projections - #22
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
SQLCLEAN004 reports
LIMITorOFFSETwithoutORDER BYbecause 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 addingORDER BYchanges 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
CASTtype. A column reference, function call (such asnow()), star or subquery still reports.engine.rsintoterminal_shape.rsso both files stay within the line limit.Verification
CASTstill reports atLIMIT, andnow()withOFFSETstill reports. The constant case fails without the exemption.cargo test -p sqlclean --lib sql_lint, clippy on 1.95,make skillsand the hygiene scan pass.