perf(sql): breaking change 💥- speed up IN comparisons on long lists#6109
Merged
bluestreak01 merged 15 commits intomasterfrom Sep 11, 2025
Merged
perf(sql): breaking change 💥- speed up IN comparisons on long lists#6109bluestreak01 merged 15 commits intomasterfrom
bluestreak01 merged 15 commits intomasterfrom
Conversation
|
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 ✨ Finishing Touches🧪 Generate unit tests
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 |
mtopolnik
reviewed
Sep 8, 2025
core/src/main/java/io/questdb/griffin/engine/functions/bool/InLongFunctionFactory.java
Outdated
Show resolved
Hide resolved
mtopolnik
reviewed
Sep 8, 2025
core/src/main/java/io/questdb/griffin/engine/functions/bool/InLongFunctionFactory.java
Outdated
Show resolved
Hide resolved
mtopolnik
previously approved these changes
Sep 8, 2025
bluestreak01
reviewed
Sep 9, 2025
benchmarks/src/main/java/org/questdb/BinarySearchVsHashSetBenchmark.java
Show resolved
Hide resolved
bluestreak01
reviewed
Sep 9, 2025
bluestreak01
reviewed
Sep 9, 2025
core/src/main/java/io/questdb/griffin/engine/functions/bool/InLongFunctionFactory.java
Show resolved
Hide resolved
bluestreak01
previously approved these changes
Sep 9, 2025
Member
|
test failure is unrelated but it a master regression, lets wait for test fix PR |
Contributor
[PR Coverage check]😍 pass : 42 / 43 (97.67%) file detail
|
bluestreak01
approved these changes
Sep 11, 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 changes the algorithm for serving
IN(longlist...)predicate to use a hashset instead of a binary search. The binary search does not scale well as the list size increases.Furthermore, a new config setting is introduced,
cairo.sql.jit.max.in.list.size.threshold. This specifies the size of the IN list that will be accepted by the JIT compiler. If this limit is exceeded, the JIT compiler will abort and compile a Java filter instead.This is because the JIT compiler will unroll
INlists into equality comparisons chained by logical or operators. This degrades the performance for large lists into semi-linear time. Whilst JIT compilation is beneficial for many filters, if theINcomparison is the dominant component, it is a net loss to JIT compile the query.Users can tune this parameter for their workload.
Future work:
Microbench
todo: fix JIT version
Also fixes an existing bug:
If list is empty, we shouldn't read a value from it.
After fast-failing JIT:
Java comparison for 200 entry IN list, when the element is always in the correct range: