Late materialization of dimension fields in time-series#135961
Merged
dnhatn merged 12 commits intoelastic:mainfrom Oct 17, 2025
Merged
Late materialization of dimension fields in time-series#135961dnhatn merged 12 commits intoelastic:mainfrom
dnhatn merged 12 commits intoelastic:mainfrom
Conversation
kkrik-es
reviewed
Oct 4, 2025
| segments.set(groupId, docVector.segments().getInt(valuePosition)); | ||
| docIds = bigArrays.grow(docIds, groupId + 1); | ||
| docIds.set(groupId, docVector.docs().getInt(valuePosition)); | ||
| contextRefs.computeIfAbsent(shard, s -> { |
Contributor
There was a problem hiding this comment.
Nit: Felix noticed separately that this is too slow, mind replacing with a check and insert?
kkrik-es
reviewed
Oct 4, 2025
| try { | ||
| blocks[offset] = new DocVector(shardRefs::get, shardVector, segmentVector, docVector, null).asBlock(); | ||
| } catch (Exception e) { | ||
| throw e; |
Contributor
There was a problem hiding this comment.
What do we get by catching and rethrowing?
kkrik-es
approved these changes
Oct 4, 2025
Contributor
kkrik-es
left a comment
There was a problem hiding this comment.
So awesome.
I assume this doesn't apply if there are functions applied to dimensions in grouping, e.g.
TS metrics | STATS sum(rate(reqs)) BY substr(host, 3)
Collaborator
|
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
Collaborator
|
Hi @dnhatn, I've created a changelog YAML for you. |
Member
Author
|
@kkrik-es Thanks for the review! |
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 change adds an optimization rule for time-series queries that moves reading dimension fields from before the time-series operator to after, reading each dimension field once per group. This is possible because dimension field values for
_tsidare identical across all documents in the same time-series.For example:
Without this rule:
With this rule:
Ideally, dimension fields should be read once per _tsid in the final result, similar to the fetch phase. Currently, dimension fields are read once per group key in each pipeline; if there are multiple time buckets, dimensions for the same _tsid are read multiple times. This can be avoided by extending ValuesSourceReaderOperator to understand the ordinals of _tsid. I will follow up with this improvement later to keep this PR small.