Skip to content

Write prefix partition for tsid in tsdb codec#144617

Open
dnhatn wants to merge 4 commits intoelastic:mainfrom
dnhatn:codec-write-tsid-prefixes
Open

Write prefix partition for tsid in tsdb codec#144617
dnhatn wants to merge 4 commits intoelastic:mainfrom
dnhatn:codec-write-tsid-prefixes

Conversation

@dnhatn
Copy link
Member

@dnhatn dnhatn commented Mar 20, 2026

Follow-up to #143955, which introduced a single-byte metric prefix in the tsid layout.

This PR writes prefix partition metadata for the _tsid field. The _tsid field is grouped by its first 2 bytes - the metric prefix byte (byte-0) plus one random byte (byte-1) - yielding up to 256 partitions per metric. The partition records the starting document for each prefix group, allowing the query engine to slice data so that each slice contains only time-series sharing the same prefix.

This enables ESQL to partition work across slices without splitting any individual time-series - a requirement for aggregations like rate. This should reduce memory usage and improve performance compared to time-interval partitioning, which requires multiple queries over fragmented data.

The compute engine is not wired up yet, so no improvements are expected yet, but this change may cause a small regression in indexing throughput and storage overhead, which is expected to be trivial.

Relates #143955

@dnhatn dnhatn added :StorageEngine/TSDB You know, for Metrics :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL :StorageEngine/Codec >non-issue labels Mar 20, 2026
@dnhatn dnhatn added the test-release Trigger CI checks against release build label Mar 20, 2026
@dnhatn dnhatn requested a review from kkrik-es March 20, 2026 16:51
Copy link
Contributor

@kkrik-es kkrik-es left a comment

Choose a reason for hiding this comment

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

It'd be nice if @martijnvg can also take a look.

@dnhatn
Copy link
Member Author

dnhatn commented Mar 20, 2026

It'd be nice if @martijnvg can also take a look.

++ we should wait for a review from Martijn!

readNumeric(meta, entry.ordsEntry, numericBlockShift);
entry.termsDictEntry = new TermsDictEntry();
readTermDict(meta, entry.termsDictEntry);
if (version >= ES819TSDBDocValuesFormat.VERSION_PREFIX_PARTITIONS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Dod we have protection from the feature flag too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's guarded by

public static final boolean SINGLE_PREFIX_BYTE_ENABLED = new FeatureFlag("tsid_layout_single_prefix_byte").isEnabled();

@dnhatn dnhatn marked this pull request as ready for review March 21, 2026 17:14
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@dnhatn
Copy link
Member Author

dnhatn commented Mar 21, 2026

tsdb-metricsgen-270m

@elastic elastic deleted a comment from elasticmachine Mar 21, 2026
@dnhatn dnhatn removed the test-release Trigger CI checks against release build label Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :StorageEngine/Codec :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL :StorageEngine/TSDB You know, for Metrics Team:StorageEngine v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants