perf(sql): improve performance of cross joins#5741
Merged
bluestreak01 merged 23 commits intomasterfrom Jul 4, 2025
Merged
Conversation
jerrinot
reviewed
Jul 2, 2025
jerrinot
reviewed
Jul 2, 2025
core/src/main/java/io/questdb/griffin/engine/groupby/DistinctRecordCursorFactory.java
Show resolved
Hide resolved
jerrinot
reviewed
Jul 2, 2025
core/src/main/java/io/questdb/griffin/engine/groupby/DistinctRecordCursorFactory.java
Show resolved
Hide resolved
jerrinot
reviewed
Jul 2, 2025
jerrinot
requested changes
Jul 2, 2025
Contributor
jerrinot
left a comment
There was a problem hiding this comment.
please fix the bug in the distinct cursor and symbol columns. others things are not critical.
also: do you have a query + schema this is aiming to improve? I don't want to invent my own to test it.
Member
Author
|
thanks @jerrinot 👍 this was the trigger: WITH
curr_usd_data AS (
SELECT count(*) as symbol, sum(price)
FROM trades
WHERE side='buy'
)
SELECT dateadd('m', x::int, '2024-11-13T11:00:00.000000Z'::timestamp) AS send_ts, 'USD' as sym, 1.0 AS usd_rate, symbol
FROM long_sequence(60)
CROSS JOIN curr_usd_data; |
jerrinot
approved these changes
Jul 4, 2025
Contributor
[PR Coverage check]😍 pass : 204 / 235 (86.81%) file detail
|
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.
Background
Cross joins are in active production use. They rely heavily on
RecordCursor.toTop()to be a lightweight operation to restart the cursor. Cross join will restart the secondary cursor for every row of the primary. Some of our cursor implementations are unnecessarily heavy to restart. Such asselect count() ....Implementation
I introduced an abstract method that is meant to compute the hash of the "heavy" state of the cursor. For example, "mapIsBuilt" boolean field is used as input to this hash. If toTop() changes the value of this field - hash will change too.
assertQuery()exercisestopTop()and asserts that this hash does not change before and aftertoTopcall.Details
toTop()does not discard cursor's state where this state was pre-builtImportant