fix: cap the row count of LIMIT offset, count instead of its offset - #444
Open
serhiizghama wants to merge 2 commits into
Open
serhiizghama wants to merge 2 commits into
serhiizghama wants to merge 2 commits into
Conversation
Member
|
Please open an issue first |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused implementation correctly addresses both failure modes and includes appropriate regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes row limiting for MySQL/MariaDB/SQLite LIMIT offset, count queries.
Changes:
- Caps the second
LIMIToperand while preserving the offset. - Retains subquery wrapping for parameterized counts.
- Adds unit and SQLite integration coverage.
| File | Description |
|---|---|
src/utils/sql-row-limiter.ts |
Correctly parses and rewrites comma-form limits. |
src/utils/__tests__/sql-row-limiter.test.ts |
Tests literal, parameterized, and probe behavior. |
src/connectors/__tests__/sqlite.integration.test.ts |
Verifies returned rows, offsets, and truncation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
With
max_rowsset, a MySQL/MariaDB/SQLite query using theLIMIT offset, countform gets the wrong rows back. The limiter reads the first number afterLIMITas the row count, so onLIMIT 10, 5it tightens the offset and leaves the count alone.On SQLite with
max_rows = 3,SELECT n FROM numbers ORDER BY n LIMIT 10, 5came back as 5, 6, 7 instead of 11, 12, 13. It fails the other way too:LIMIT 2, 10withmax_rows = 5looked like it was already under the cap (2 <= 5), so it wasn't rewritten at all and returned 10 rows.findTopLevelLimitnow also matches the optional, countpart and treats the second operand as the row count. When it tightens the clause it writes the offset back as it was. A parameterized count (LIMIT 10, ?) takes the existing subquery-wrap path. Copilot flagged the same thing in its review of #400, but it didn't make it into #429.I added unit cases and an SQLite integration test that fails on main. I couldn't run the MySQL/MariaDB containers locally, but they go through the same function.