TSDB indices could speed up cardinality aggregations on dimension fields #85523
Labels
>enhancement
:Performance
All issues related to Elasticsearch performance including regressions and investigations
:StorageEngine/TSDB
You know, for Metrics
Team:Performance
Meta label for performance team
Team:StorageEngine
Description
The Kubernetes integration comes with dashboards where some of the slower visualizations are powered by queries that have this shape:
Cardinality aggregations on dimension fields have an interesting property: all documents that have the same TSID are guaranteed to also have the same value for the dimension field. This means that we only need to visit one document per TSID to be able to compute the cardinality of the dimension field across the entire set of matching documents.
And since TSDB indices are sorted by TSID, it's easy to skip documents that would have the same TSID. For instance say you have a top-level cardinality aggregation and just collected a document. You can look up the ordinal of the TSID field and then do an exponential search to find the first document that has a different TSID. All documents up to this document can be skipped safely. Assuming that the number of unique TSIDs is much lower than the number of documents that match the query, this would yield a massive speedup.
Lucene already has a mechanism to enable this via the
LeafCollector#competitiveIterator
API, which allows collectors to tell the query to skip documents that are not interesting to them.We could implement this
LeafCollector#competitiveIterator
API on cardinality aggregations, and this should cover all cases when the cardinality aggregation is collected directly via theIndexSearcher
, ie. for either top-levelcardinality
aggregations or second-levelcardinality
aggregations where the filter-by-filter execution mode is applicable, such as the above query.The text was updated successfully, but these errors were encountered: