fix: support LIMIT 0 and improve error messages for NULL/negative LIMIT/OFFSET - #24455
Merged
mergify[bot] merged 10 commits intoMay 20, 2026
Merged
Conversation
- Add isOffset field to LimitBinder to distinguish LIMIT from OFFSET - Reject NULL with clear "LIMIT/OFFSET cannot be NULL" message - Use clause-specific error messages for negative values - Update all NewLimitBinder call sites with isOffset parameter
Cover LIMIT 0, LIMIT -1, LIMIT NULL, OFFSET -5, OFFSET NULL, string LIMIT, large uint64 LIMIT, and star-in-limit cases.
The NULL check now uses isOffset to output "LIMIT cannot be NULL" or "OFFSET cannot be NULL", consistent with other error paths in the binder. Also adds nil guard for Expr_Lit.Lit.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Contributor
Merge Queue Status
This pull request spent 2 hours 3 minutes 7 seconds in the queue, including 1 hour 1 minute 59 seconds running CI. Required conditions to merge
|
7 tasks
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.
What type of PR is this?
Which issue(s) this PR fixes:
issue #23103
What this PR does / why we need it:
Fix three problems with LIMIT/OFFSET value handling:
SELECT * FROM t LIMIT 0failed with"only uint64 support in limit/offset clause", but 0 is a valid uint64 and should return 0 rows.LIMIT NULLandOFFSET NULLproduced the same generic"only uint64 support"message instead of explaining that NULL is not allowed.LIMIT -1andOFFSET -5also fell through to the generic uint64 message, instead of telling the user the value must be non-negative.### Changes
pkg/sql/plan/limit_binder.go— AddedisOffsetfield toLimitBinderto distinguish LIMIT from OFFSET in error messages. Added early interception ofUNARY_MINUS + NumVal(parser doesnot fold this into a negative literal). Added explicit NULL check. All error messages are now clause-specific.
pkg/sql/plan/query_builder.go— Updated 5 call sites inbindSelectClause,bindLimit,buildUnion,bindRecursiveCte, andbindSelectClauseto passisOffsetand use separate binderinstances for offset vs count.
pkg/sql/plan/types.go— AddedisOffset boolfield toLimitBinderstruct.pkg/sql/plan/limit_binder_test.go— 10 new tests covering: LIMIT 0, positive limits, OFFSET 0, negative LIMIT/OFFSET, NULL LIMIT/OFFSET, string coercion, large uint64, and star rejection.Behavior changes
LIMIT 0LIMIT NULLOFFSET NULLLIMIT -1OFFSET -5