Skip to content

Commit ac4e2f4

Browse files
authored
Small time series agg improvement (elastic#106288)
After tsid hashing was introduced (elastic#98023), the time series aggregator generates the tsid (from all dimension fields) instead of using the value from the _tsid field directly. This generation of the tsid happens for every time serie, parent bucket and segment combination. This changes alters that by only generating the tsid once per time serie and segment. This is done by just locally recording the current tsid.
1 parent 25e31b9 commit ac4e2f4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

docs/changelog/106288.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 106288
2+
summary: Small time series agg improvement
3+
area: TSDB
4+
type: enhancement
5+
issues: []

modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCt
144144
long currentTsidOrd = -1;
145145
long currentBucket = -1;
146146
long currentBucketOrdinal;
147+
BytesRef currentTsid;
147148

148149
@Override
149150
public void collect(int doc, long bucket) throws IOException {
@@ -157,12 +158,16 @@ public void collect(int doc, long bucket) throws IOException {
157158
return;
158159
}
159160

160-
TimeSeriesIdFieldMapper.TimeSeriesIdBuilder tsidBuilder = new TimeSeriesIdFieldMapper.TimeSeriesIdBuilder(null);
161-
for (TsidConsumer consumer : dimensionConsumers.values()) {
162-
consumer.accept(doc, tsidBuilder);
161+
BytesRef tsid;
162+
if (currentTsidOrd == aggCtx.getTsidHashOrd()) {
163+
tsid = currentTsid;
164+
} else {
165+
TimeSeriesIdFieldMapper.TimeSeriesIdBuilder tsidBuilder = new TimeSeriesIdFieldMapper.TimeSeriesIdBuilder(null);
166+
for (TsidConsumer consumer : dimensionConsumers.values()) {
167+
consumer.accept(doc, tsidBuilder);
168+
}
169+
currentTsid = tsid = tsidBuilder.buildLegacyTsid().toBytesRef();
163170
}
164-
165-
BytesRef tsid = tsidBuilder.buildLegacyTsid().toBytesRef();
166171
long bucketOrdinal = bucketOrds.add(bucket, tsid);
167172
if (bucketOrdinal < 0) { // already seen
168173
bucketOrdinal = -1 - bucketOrdinal;

0 commit comments

Comments
 (0)