fix(sql): query with limit x, y (x > 0 & y > 0) return correct size()#6409
fix(sql): query with limit x, y (x > 0 & y > 0) return correct size()#6409bluestreak01 merged 7 commits intomasterfrom
size()#6409Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe pull request refactors the LimitRecordCursor logic in LimitRecordCursorFactory to consistently use countRows() for determining row counts, replacing previous base.size()-based optimization paths in two branches. A test case is added to verify limit and offset behavior on normal tables. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
core/src/main/java/io/questdb/griffin/engine/LimitRecordCursorFactory.java(2 hunks)core/src/test/java/io/questdb/test/griffin/OrderByAscRowSkippingTest.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (34)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-other)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-pgwire)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-sub)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-root)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz2)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz1)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-sub)
- GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
- GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
- GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-root)
- GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
- GitHub Check: New pull request (Hosted Running tests on windows-other-2)
- GitHub Check: New pull request (Hosted Running tests on windows-other-1)
- GitHub Check: New pull request (Hosted Running tests on windows-pgwire)
- GitHub Check: New pull request (Hosted Running tests on windows-cairo-2)
- GitHub Check: New pull request (Hosted Running tests on windows-cairo-1)
- GitHub Check: New pull request (Hosted Running tests on windows-fuzz2)
- GitHub Check: New pull request (Hosted Running tests on windows-fuzz1)
- GitHub Check: New pull request (Hosted Running tests on windows-griffin-sub)
- GitHub Check: New pull request (Hosted Running tests on windows-griffin-base)
- GitHub Check: New pull request (Hosted Running tests on mac-other)
- GitHub Check: New pull request (Hosted Running tests on mac-pgwire)
- GitHub Check: New pull request (Hosted Running tests on mac-cairo-fuzz)
- GitHub Check: New pull request (Hosted Running tests on mac-cairo)
- GitHub Check: New pull request (SelfHosted Cairo tests on linux-x64-zfs)
- GitHub Check: New pull request (SelfHosted Cairo tests on linux-x86-graal)
- GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
- GitHub Check: New pull request (Hosted Running tests on mac-griffin)
- GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
- GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
- GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
- GitHub Check: New pull request (Check Changes Check changes)
- GitHub Check: build
🔇 Additional comments (2)
core/src/main/java/io/questdb/griffin/engine/LimitRecordCursorFactory.java (2)
267-271: LGTM! Correct handling of first N rows.The logic now properly counts rows before calculating the limit, ensuring
size()returns the minimum of the requested rows (lo) and the actual row count. This prevents returning an incorrect size when fewer rows are available than requested.
312-318: LGTM! Critical fix for LIMIT x,y size calculation.This change correctly fixes the bug described in the PR. By using
Math.min(rowCount, hi), the code now caps the upper bound to the actual number of rows available in the base cursor, preventingsize()from incorrectly returninghi - lowhen fewer rows exist. TheMath.max(0, ...)wrapper properly handles edge cases whereloexceeds the capped upper bound.Example: With 5 rows available,
LIMIT 2,10now correctly computeslimit = max(0, min(5, 10) - 2) = 3instead of potentially returning 8.
core/src/test/java/io/questdb/test/griffin/OrderByAscRowSkippingTest.java
Outdated
Show resolved
Hide resolved
[PR Coverage check]😍 pass : 4 / 4 (100.00%) file detail
|
When executing
LIMIT x, yqueries (where both x > 0 and y > 0),LimitRecordCursorFactory.size()returns incorrect results(y -x) when the underlying base cursor has fewer rows thany - xI'm not certain if calling
countRows()(which invokesbase.calculateSize()) whenbase.size() == -1is optimal, but I followed the existing pattern used in other branches for consistency. If we need to preservesize()efficiency by returning
-1in such cases, we should review all other branches and update numerous tests accordingly.Found when testing windowJoin