ClickHouse full-text search: text index vs LIKE vs ngrambf_v1, what '%error%' really does
ClickHouse's text index found a word in 10.5 billion rows in 0.42 s, vs 143 s with a bloom filter. But LIKE '%error%' only gets that speed in some setups.
On this page
- The short answer
- Three indexes, three ideas
- What the published numbers say
- LIKE '%error%' with tokenbf_v1: nothing to look up
- LIKE '%error%' with ngrambf_v1: works, at granule level
- LIKE '%error%' with the text index: a dictionary scan (26.4+)
- The preprocessor trap
- What the dictionary scan costs
- Which one to use for log search
- What I couldn’t verify
- FAQ
ClickHouse searched 10.5 billion GitHub events for one word three ways. A full scan took 193 s. A token bloom filter took 143 s. The new text index took 0.422 s, reading 1.36 GB instead of 2.96 TB (ClickHouse GA post, March 2026, 32-core Cloud node, best of 3 runs).
That number comes from hasToken(body, 'ClickHouse'). Most log searches people actually write look like WHERE message LIKE '%error%'. So the question for Day 18 is: what does that one line do under each index? I read the ClickHouse 26.11 source (tag v26.11.8.18-stable) to find out. The answer is different for all three, and a common setup recipe quietly switches the fast path off. Nothing was run for this post. Every number links to whoever measured it.
The short answer
Pattern (column message) |
tokenbf_v1 |
ngrambf_v1(3, …) |
text(tokenizer = splitByNonAlpha) on 26.4+ |
|---|---|---|---|
LIKE '%error%' |
no tokens: skips nothing | trigrams err, rro, ror: granule check |
dictionary scan, exact: the column isn’t read |
LIKE '% error %' |
token error: granule check |
trigrams incl. spaces: granule check | token error: row filter, then each row is re-checked |
LIKE 'error%' |
no tokens | err, rro, ror |
rewritten to startsWith, dictionary scan as a hint (not on Nullable columns) |
LIKE '%disk full%' |
no tokens | trigrams: granule check | no tokens: no pruning (multi-word patterns not handled yet) |
LIKE '%ab%' (short) |
no tokens | shorter than n: nothing | needle under 4 chars: no pruning |
hasToken(message, 'error') |
granule check | not supported | exact, column not read |
So with the text index, LIKE '%error%' is fast and '%disk full%' is a full scan. With tokenbf_v1, even '%error%' is a full scan. The rest of the post shows where each cell comes from.
Three indexes, three ideas
tokenbf_v1 and ngrambf_v1 are bloom filters, one per block of granules. The first splits text into words. The second into n-grams (every run of n characters). A filter can say “this word is definitely not in these 8,192 × GRANULARITY rows”, or “maybe”. So it can only skip whole granules, it gives false positives, and you tune it by hand: bytes per filter, hash functions, seed (MergeTree docs). Since the text index became GA in 26.2 both are marked deprecated and “no longer recommended for full text search” (same page). They still work.
text is an inverted index: a sorted dictionary of every token in a part, plus a posting list per token with the row numbers that contain it (text index docs). It’s built per part, with what the docs call infinite granularity (100 million; any GRANULARITY you set is ignored). Because it knows rows, not granules, it can do direct read: answer hasToken from the posting lists and never open the text column. That’s on by default (query_plan_direct_read_from_text_index = 1). It’s also why the GitHub query read 1.36 GB, not 729 GB.
The price is size. In the GitHub test the text index was 215.84 GiB compressed, against 7.04 GiB for the bloom filter and 477 GiB for the whole table. Overall compression fell from about 9× to about 6× (GA post). On a 50 TB log benchmark ClickHouse reports insert throughput “reduced by ~50 percent compared to no index”, and “typically slightly slower on inserts” than bloom filters (same post).
What the published numbers say
| Test (who ran it) | Full scan | Bloom filter | Text index |
|---|---|---|---|
| GitHub events, 10.50 B rows, one word (GA post) | 193.018 s, 2.96 TB | bloom_filter on tokens(lower(body)): 143.293 s, 729 GB |
0.422 s, 1.36 GB |
| OTel demo logs, 90.58 M rows, “Failed to place” (ClickStack Jan 2026) | 0.655 s, 14.03 GB | tokenbf_v1(32768, 3, 0): 0.199 s, 2.66 GB · bloom_filter(0.025) on tokens: 0.096 s, 159.73 MB |
0.011 s, 1.33 MB |
Hacker News, 28.7 M comments, hasToken, direct read off vs on (docs) |
n/a | n/a | 0.362 s → 0.008 s |
All three are ClickHouse’s own runs, and none of them is a LIKE '%…%' query. The GitHub bloom filter only pruned about 80% of granules: a common word in big granule blocks almost always hits. I found no published test of ngrambf_v1 against the text index on the same data. That’s why the rest of this post comes from the source and not from a chart.
LIKE '%error%' with tokenbf_v1: nothing to look up
tokenbf_v1 turns a LIKE pattern into words with SplitByNonAlphaTokenizer::nextInStringLike (ITokenizer.cpp, 26.11). A word only counts if a separator sits on both sides. A % or _ touching it “invalidates current token”:
if (!escaped && (data[pos] == '%' || data[pos] == '_'))
{
/// Unescaped wildcard: invalidates current token
token.clear();
bad_token = true;
In '%error%' both ends touch a wildcard, so the function returns zero tokens. An empty set of words can’t rule out any granule, so the index skips nothing. '% error %' works, because the spaces make error a complete word. That’s where the old “pad your LIKE with spaces” advice comes from. But it changes the meaning: '% error %' no longer matches error: at the start of a line, or ioerror.
LIKE '%error%' with ngrambf_v1: works, at granule level
NgramsTokenizer::nextInStringLike (same file, L74-L126) takes every n-character run that has no wildcard in it. With n = 3, '%error%' becomes err, rro, ror. A granule block is read only if its filter says “maybe” for all three. That’s why ngrambf_v1 was the usual answer for substring search: it works for any needle of at least n characters, including '%disk full%'. Two limits:
- It’s still granule-level. A trigram like
errappears in “server”, “terror” and “error”, so in real logs most blocks say “maybe”. - The docs say it plainly: “Functions with a constant argument that is less than ngram size can’t be used by
ngrambf_v1.”
LIKE '%error%' with the text index: a dictionary scan (26.4+)
Here 26.11 does something new. The like branch in MergeTreeIndexConditionText.cpp has two paths.
Path A, dictionary scan. If the tokenizer is splitByNonAlpha (or array), the index has no preprocessor or postprocessor, and use_text_index_like_evaluation_by_dictionary_scan is on (default true since 26.4, Settings.cpp), then a pattern of the shape %word%, word% or %word is matched against the part’s dictionary. Every token that contains error (error, errors, ioerror, myerror2…; case-sensitive, so not Error) is found, and their posting lists are merged. For the %word% form the code marks the result Exact (when direct read applies). The reasoning is in a comment: “a needle occurs in a value iff its %needle% pattern matches one of the value’s tokens”. That holds because the needle must be letters and digits only, so it can never span a separator. The text column isn’t read at all.
Guards (same files):
- The word must be at least 4 characters (
text_index_like_min_pattern_length).'%id%'falls through. - At most 50 large posting lists are read (
text_index_like_max_postings_to_read). Past that the index steps aside for the part. word%and%wordonly give a superset, so they’re used as a hint, and not onNullablecolumns.
Path B, fallback. Everything else (spaces in the needle, a preprocessor, the setting off) goes through the same word extraction tokenbf_v1 uses. The source comment is blunt: “No tokens means ‘cannot prune’, as for a pattern like LIKE '%a%'.” The TODO above the branch confirms that %foo bar% and %foo%bar% aren’t handled yet.
like branch of MergeTreeIndexConditionText.cpp (v26.11.8.18) and the settings use_text_index_like_evaluation_by_dictionary_scan, text_index_like_min_pattern_length = 4, text_index_like_max_postings_to_read = 50 (all since 26.4). word% and %word also need a non-Nullable column.The preprocessor trap
The GA post and many guides build the index with preprocessor = lowerUTF8(body), so searches are case-insensitive. Per the code above, a preprocessor disables path A. Then LIKE '%error%' falls to path B, which finds no complete word, so the index can’t prune at all. With a lowercasing preprocessor, write searches as hasToken(body, 'error') / hasAnyTokens / hasAllTokens, or '% error %'. Don’t expect the index to help a bare '%error%'. (The docs also list ilike as dictionary-scan only, and a lowerUTF8/upperUTF8 preprocessor sends it to a full scan.)
What the dictionary scan costs
Scanning a dictionary isn’t free, and it was tuned in the weeks before this post:
- PR #133140 (merged 2026-11-24, lands in 26.12) skips the scan when the primary key already narrowed the rows. The PR measures “~5 ms per MB of dictionary vs ~0.5 ms per MB of column”. On a synthetic 8M-row part with a 190 MB dictionary: 939 ms → 8 ms for a narrow time window. So on 26.11, a
LIKE '%x%'on a large part combined with a narrowWHERE tsrange can spend far more time in the dictionary than reading the few rows left would take. - Issue #128714 (open): patterns with a literal prefix that most tokens share (
'https://%/admin/secret',arraytokenizer) are 8–43× slower than on 26.10 (reported on master, not checked on a release). - Issue #130756 (open): the
pforposting codec, default since 26.11, makes a two-tokencount()7–10× slower in the reporter’s test (0.021–0.031 s vs 0.003 s).
Which one to use for log search
- On 26.2 or newer, use the
textindex on the message column:INDEX msg_idx message TYPE text(tokenizer = splitByNonAlpha). Leave out the preprocessor if your team writesLIKE '%word%'. Case-sensitive, but path A stays available. - Search for words with
hasToken/hasAllTokenswherever you can. Those are exact, read no text, andcount()over one of them is answered from posting-list sizes (query_plan_optimize_count_from_text_index, 26.8+). - For phrases (
'%disk full%'), writehasAllTokens(message, 'disk full') AND message LIKE '%disk full%'. The index narrows to rows with both words, and LIKE checks the order. Phrase support (hasPhrase,support_phrase_search = 1) exists but is experimental, and adds a positions file. - Keep an
ngrambf_v1only for substring needles that aren’t words (part of a hash, a path fragment with/) and you can’t move to thengrams(N)tokenizer of the text index. Substring indexes are big, though: in the 26.1 release blog, a text index with thesparseGramstokenizer was 16.19 GiB on 6.77 GiB of Hacker News text, against 2.00 GiB withsplitByNonAlpha, and took about 10× longer to insert (1,162 s vs 120 s). - Drop
tokenbf_v1. It’s deprecated, needs tuning by trial and error, and does nothing for'%word%'. - Check with
EXPLAIN PLAN actions = 1. A virtual column named__text_index_<index>_<function>_<id>means direct read is on. If it’s missing, the column is being read.
What I couldn’t verify
- No published test runs
LIKE '%word%'through the dictionary scan againstngrambf_v1on the same data. The table at the top comes from reading the 26.11 code, not from a measurement. - How many tokens a real log dictionary holds per part, so how long path A’s scan takes in practice. The object storage post says 94.5% of tokens in one internal log set occur in 6 rows or fewer (ClickHouse, March 2026), which suggests big dictionaries, but no timing was published.
- Hardware and version behind the GitHub and ClickStack numbers. Both are vendor runs on ClickHouse Cloud.
FAQ
Does LIKE ‘%word%’ use the ClickHouse text index?
On 26.4+, yes, if the tokenizer is splitByNonAlpha or array, the index has no preprocessor, and the word is at least 4 letters or digits with no spaces. Then it’s exact and doesn’t read the column. Otherwise it can’t prune.
Is ngrambf_v1 deprecated?
Yes, in the docs since the text index went GA in 26.2, together with tokenbf_v1. Both still work. Nothing says they’ll be removed.
Why doesn’t my tokenbf_v1 index skip anything for LIKE ‘%error%’?
Because the wildcards touch the word, so the tokenizer finds no complete token and has nothing to look up. '% error %' or hasToken(message, 'error') can use it.
How much bigger is a text index than a bloom filter? In ClickHouse’s GitHub test: 215.84 GiB vs 7.04 GiB on a 477 GiB table. The docs put it at “dozens to hundreds of megabytes per part” vs “a few kilobytes or megabytes” for bloom filters.
Does the text index support phrase search or BM25 ranking? Not GA. Phrases are narrowed by tokens and then checked row by row; positional phrase search is experimental. There’s no TF-IDF or BM25 scoring (GA post).
Tomorrow, Day 19: vector search in ClickHouse, brute-force cosineDistance vs the vector index: recall vs latency.