count + grouping on text index #118385
Replies: 2 comments 1 reply
|
The index is being used, but the plan shows why the query remains expensive: it still reads 89,757/157,795 granules for |
|
You are right to question that recommendation: my earlier suggestion to reduce the index GRANULARITY was incorrect. ClickHouse text indexes deliberately use βinfinite granularityβ (100 million), so that value is not a tuning knob like it is for conventional skip indexes: https://clickhouse.com/docs/reference/engines/table-engines/mergetree-family/textindexes#index-granularity. The 5-gram index can still return exact LIKE results for needles shorter than five characters because ClickHouse verifies the predicate against the rows, but the index cannot derive a 5-gram from such a needle, so it cannot make that case selective. Moving to 3-grams may increase recall so much that it reads more rows, exactly as you observed. You also did not miss a generic projection optimization. A projection definition cannot contain a WHERE clause, and an aggregate projection or materialized view can only pre-aggregate dimensions known at insert time. An arbitrary runtime LIKE/hasAllTokens substring is not such a dimension; after the text index identifies matching rows, ClickHouse still has to compute the grouping sets over those rows. A materialized view helps only if the search vocabulary can be normalized into a bounded token dimension at ingestion and aggregates are stored by token plus each facet. Expanding arbitrary n-grams for 140 billion rows would usually be prohibitively large. For this workload, I would keep the tokenizer that gives the best measured selectivity, apply any date/partition/tenant predicates before the text predicate, and compare read_rows/read_bytes in system.query_log. Common three-character searches that occur in a large fraction of rows are inherently expensive; there is no projection that can precompute exact facets for every possible substring without effectively materializing the search space. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Context: I got 140 bilion rows table where i create ft_blob an column that is combination of more columns by separator.
I need help to optimize this query or finding any solution that can help me get this outcome.
ft_blob_ng_5 here is text index ngrams 5 and text_ft_blob_sg is sparse ngrams (3,8)Β on combination of many columns with separator.
projection not help here i think it not supported for the text index.
this return:
For sparse ngrams between 3,8 :
Is there a way to optimize grouping count of distinct values on a LIKE/ hasAllATokens search on text index?
its very slow for search on 3-7 letters (20 sec to 2 min), i tried ngrams 5 and sparse ngrams (3,8)Β and nothing help.Β
All reactions