Skip to content

feat(sql): require a query hint to enable rare-symbols optimization in ASOF JOIN#6333

Merged
bluestreak01 merged 3 commits intomasterfrom
mt_driveby-caching-hint
Oct 31, 2025
Merged

feat(sql): require a query hint to enable rare-symbols optimization in ASOF JOIN#6333
bluestreak01 merged 3 commits intomasterfrom
mt_driveby-caching-hint

Conversation

@mtopolnik
Copy link
Copy Markdown
Contributor

@mtopolnik mtopolnik commented Oct 30, 2025

The Memoized Scan algorithm for ASOF JOIN on symbol column has two kinds of caching:

  1. Match Caching: after finding a matching symbol in the RHS column, cache its location so we don't have to repeat the search later
  2. Drive-By Caching: while looking for a matching symbol, cache all symbols seen in passing as well, in the hope future LHS rows will need some of them

For Match Caching, we only need a single hash lookup per LHS row for a cache hit, and another one for a cache miss.

For Drive-By Caching, we need a hash lookup for every visited RHS row. It pays off when many of the symbols to look for occur in the deep past of the RHS table. It allows us to make just one deep scan and find all of them. However, when there aren't many such symbols, hash lookups introduce a significant overhead, and result in worse performance in many typical cases.

Therefore, we're putting Drive-By Caching behind a query hint.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 30, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mt_driveby-caching-hint

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 12 / 12 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/SqlHints.java 1 1 100.00%
🔵 io/questdb/griffin/SqlCodeGenerator.java 1 1 100.00%
🔵 io/questdb/griffin/engine/join/AsOfJoinMemoizedRecordCursorFactory.java 10 10 100.00%

@RaphDal RaphDal self-requested a review October 31, 2025 11:19
Copy link
Copy Markdown
Contributor

@RaphDal RaphDal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@bluestreak01 bluestreak01 merged commit 64c8d13 into master Oct 31, 2025
37 checks passed
@bluestreak01 bluestreak01 deleted the mt_driveby-caching-hint branch October 31, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants