Skip to content

storage-query-datafusion: narrow scan for unscoped service_key (#4727)#4731

Open
tillrohrmann wants to merge 1 commit into
restatedev:mainfrom
tillrohrmann:issues/4727
Open

storage-query-datafusion: narrow scan for unscoped service_key (#4727)#4731
tillrohrmann wants to merge 1 commit into
restatedev:mainfrom
tillrohrmann:issues/4727

Conversation

@tillrohrmann
Copy link
Copy Markdown
Contributor

PR #4726 dropped the service_key partition-key extractor from the state and sys_promise tables because scoped rows for the same service_key are sharded under hash(scope) rather than hash(service_key). The unconditional fallback to a full partition-key range scan is a noticeable regression for unscoped lookups vs. v1.6.

Recover the optimization by gating it on an explicit scope IS NULL conjunct: when the user has already promised, via the filter, that scoped rows aren't of interest, narrowing to hash(service_key) is safe. The two extractors needed by state / sys_promise (scope-based and service_key-when-null) are bundled into a single builder with_scope_or_service_key(scope_column, service_key_column) so the call site reads as the dispatch it actually performs.

This fixes #4727.

…tedev#4727)

PR restatedev#4726 dropped the `service_key` partition-key extractor from the `state`
and `sys_promise` tables because scoped rows for the same service_key are
sharded under `hash(scope)` rather than `hash(service_key)`. The unconditional
fallback to a full partition-key range scan is a noticeable regression for
unscoped lookups vs. v1.6.

Recover the optimization by gating it on an explicit `scope IS NULL` conjunct:
when the user has already promised, via the filter, that scoped rows aren't of
interest, narrowing to `hash(service_key)` is safe. The two extractors needed
by `state` / `sys_promise` (scope-based and service_key-when-null) are bundled
into a single builder `with_scope_or_service_key(scope_column,
service_key_column)` so the call site reads as the dispatch it actually
performs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

This fixes restatedev#4727.
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@tillrohrmann
Copy link
Copy Markdown
Contributor Author

@nikrooz the optimization only works if we add the scope is null filter to a query.

@nikrooz
Copy link
Copy Markdown
Contributor

nikrooz commented May 13, 2026

@tillrohrmann thanks. do you mean I should add scope is null when vqueque is not enabled?

Copy link
Copy Markdown
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

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

@tillrohrmann thanks for the fast turnaround, LGTM

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.

Add support for conditional partition key extractor for datafusion

3 participants