fix(sql): support order by desc with negative limit on Jit-filtered interval queries#5798
Merged
bluestreak01 merged 8 commits intomasterfrom Jul 1, 2025
Merged
Conversation
…_ASC with IntervalBwdFramePartitionFrameCursorFactory.
bluestreak01
reviewed
Jul 1, 2025
core/src/main/java/io/questdb/cairo/IntervalBwdPartitionFrameCursorFactory.java
Outdated
Show resolved
Hide resolved
Contributor
[PR Coverage check]😍 pass : 10 / 10 (100.00%) file detail
|
bluestreak01
approved these changes
Jul 1, 2025
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.
This PR fixes an internal error that occurs when a user runs a SELECT query with:
Here's an example of such a query:
Root cause
The issue arises under several specific conditions:
price > 0) is compatible with it, soAsyncJitFilteredRecordCursorFactoryis used.ORDER BY ts DESCcauses the optimiser to setforceBackwardScanto true.ts >= ... AND ts <= ...) leadsSqlCodeGeneratorto useIntervalBwdPartitionFrameCursorFactory.LIMITcauses theAsyncJitFilteredRecordCursorFactoryto reverse the order fromORDER_DESCtoORDER_ASC.However, unlike
FullBwdPartitionFrameCursorFactory, theIntervalBwdPartitionFrameCursorFactorydid not supportORDER_ASCand threw anUnsupportedOperationException.Fix
This PR resolves the issue by applying the same strategy used in
FullBwdPartitionFrameCursorFactory:If
ORDER_ASCis requested, the factory now creates anIntervalFwdPartitionFrameCursoron the fly.Work In Progress
I'm keeping the PR as work in progress as I'd like to add fuzzy testing to this use case.