The doc values codec iterates a few times over the doc value instance that needs to be written to disk. In case when merging and index sorting is enabled, this is much more expensive, as each time the doc values instance is iterated a merge sort is performed (in order to get the doc ids from different segments in order of index sorting).
There are several reasons why the doc value instance is iterated multiple times:
- To compute stats (num values, number of docs with value) required for writing values to disk.
- To write bitset that indicate which documents have a value. (indexed disi, jump table)
- To write the actual values to disk.
- To write the addresses to disk (in case docs have multiple values)
This applies for numeric doc values, but also for the ordinals of sorted (set) doc values.
The following changes should be made to address this performance issue:
The doc values codec iterates a few times over the doc value instance that needs to be written to disk. In case when merging and index sorting is enabled, this is much more expensive, as each time the doc values instance is iterated a merge sort is performed (in order to get the doc ids from different segments in order of index sorting).
There are several reasons why the doc value instance is iterated multiple times:
This applies for numeric doc values, but also for the ordinals of sorted (set) doc values.
The following changes should be made to address this performance issue:
numDocsWithFieldas metadata and store jump table after the values (Prepare tsdb doc values format for merging optimizations. #125933).SortedNumericDocValues(First step optimizing tsdb doc values codec merging. #125403).docValueCountwhile iterating over values and write to later for the address offsets. (Coalesce getSortedNumeric calls for ES819 doc values merging #126732)