ClickHouse/ClickHouse

Optimize search in pre-ordered arrays

Ouverte

#17 795 ouverte le 4 déc. 2020

 (13 commentaires) (5 réactions) (0 personne assignée)C++ (8 400 forks)batch import
featurehelp wanted

Métriques du dépôt

Stars
 (47 419 étoiles)
Métriques de merge PR
 (Merge moyen 2j 2h) (1 000 PRs mergées en 30 j)

Description

Use case In our principal table, we use the type Array(UInt64) for stocking the corresponding ids for a row. Each array can contain thousands of ids, and multiplying it to milliards of rows, we have a very heavy column that hardly limits the performance when we doing selects with WHERE has(ids, 123).

Describe the solution you'd like One solution that I can imagine is to pre-sort the ids in each row and, knowing that all arrays in the column are sorted, we can use it for a small optimization. Concretely, when we doing the search in the ordered array, we are not forced to scan the array entirely, but only before the current_value <= searched_value I estimate that it can be 2x faster in average. And more in special cases.

Guide contributeur