ClickHouse JSON vs Map vs String: one key out of 10,000 paths, 0.027 s vs 3.2 s
Reading one key from 10,000-path JSON in ClickHouse: 0.027 s as a JSON subcolumn, 3.2 s from a String, 3.6 s from a Map. Reading whole rows flips the order.
On this page
- The short answer
- What each type actually writes to disk
- Path 1,025: shared data, and why 26.11 is much better at it
- When String wins: reading the whole thing
- Map got its own bucket trick in 26.3
- The bill JSON sends later: files and merges
- What people running it at scale chose
- Which one to use
- What I couldn’t verify
- FAQ
ClickHouse engineers stored 200,000 JSON documents, each with 10,000 different paths, in three ways: as a String, as a Map(String, String) and as the native JSON type. Then they read one key. From the String it took 3.216 s. From the Map, 3.594 s. From a JSON path stored as its own subcolumn, 0.027 s. That’s about 120× faster than the String (Pavel Kruglov, ClickHouse blog, v25.8). In the same test, reading the whole document went the other way: the String was fastest at 2.734 s, and one JSON storage format took 15.3 s.
That pair of results is the real answer to “JSON vs Map vs String”. It isn’t about which type is faster. It’s about what each one has to read to answer your query. Day 17 of this series was planned as a size-and-speed shootout. Under the no-local-benchmarks rule it became a read of the 26.11 source, the docs and the measurements ClickHouse and others have published. Nothing was run for this post, and every number links to whoever measured it.
The short answer
| You mostly… | Use | Why |
|---|---|---|
| Store and return whole documents | String (ZSTD compresses it well) |
One stream to read; nothing to rebuild |
| Filter on a few known keys | JSON with type hints for those keys |
Each hinted path is a normal column |
| Have many keys, all one value type (tags, labels) | Map(LowCardinality(String), String) |
Simple and cheap to insert; on 26.3+ consider with_buckets |
| Have nested, mixed-type data you query by path | JSON, default max_dynamic_paths or lower |
Popular paths get columns, the long tail goes to shared data |
The rest of this post explains the “why” column, and what happens to the path that doesn’t fit.
What each type actually writes to disk
String. One column, one stream. JSONExtract* functions parse the text at query time, so reading one key means decompressing and parsing every document. That is why the String took 3.2 s for one key in the test above: the cost is almost the same whether you want one key or all of them.
Map. A Map(K, V) is stored as Array(Tuple(K, V)): one stream of keys and one of values. m['key'] has to read and scan both, so its cost grows with the size of the map (Map docs). The Map in the test read 538 MiB to return one key.
JSON. The type splits every document by path (JSON docs):
- Typed paths (hints such as
JSON(user.id UInt64)) become ordinary columns. - Dynamic paths get their own
Dynamicsubcolumn each, up tomax_dynamic_paths, default 1024 per data part. Each holds up tomax_dynamic_types(default 32) types. - Everything else goes into shared data: one structure holding the path names and binary-encoded values of all the leftover paths.
So “JSON is fast” really means “a JSON path with its own column is fast”. The interesting question is what happens to path number 1,025.
Path 1,025: shared data, and why 26.11 is much better at it
When a part already has 1024 dynamic paths, new paths go to shared data. They can still be read as subcolumns, but the docs warn this “might be less efficient”. How much less depends on how shared data is serialized, and that has changed a lot:
| Shared data format (26.11 name) | One key: time | One key: memory | Whole object: time |
|---|---|---|---|
| Path has its own subcolumn (no shared data) | 0.027 s | 18.64 MiB | out of memory |
advanced |
0.063 s | 3.89 MiB | 4.774 s |
map_with_buckets |
0.087 s | 403.55 MiB | 15.271 s |
map (the original format) |
3.63 s | 12.53 GiB | 4.182 s |
| String column, for comparison | 3.216 s | 582.70 MiB | 2.734 s |
| Map column, for comparison | 3.594 s | 538.37 MiB | 3.869 s |
200k rows × 10k paths, Wide parts, ClickHouse 25.8. Numbers from Kruglov (benchmark details in PR #83777). The post doesn’t give the hardware. Measured by ClickHouse, not here.
Going from map to advanced is where the blog’s headline comes from: ~58× faster and ~3,300× less memory for one key (3.63 s → 0.063 s, 12.53 GiB → 3.89 MiB). The old format is one Map(String, String) per row, so finding one path means reading all of them (12.53 GiB of memory for one key). advanced is, in the setting’s own words, a “special serialization of shared data designed to significantly improve reading of individual paths”: it stores extra information so a read can go to the one path it needs.
Three details matter in practice. All three come from the 26.11 MergeTreeSettings.cpp (source):
advancedis the default since 25.12, together withobject_serialization_version = 'v3'(changelog, PR #92511). That change is marked backward-incompatible: after it you can’t downgrade below 25.8, because older versions can’t read the new parts. The changelog’s safe-upgrade advice is to setobject_serialization_version='v2'anddynamic_serialization_version='v2'(orcompatibility) until you’re sure.- Fresh parts are different.
object_shared_data_serialization_version_for_zero_level_partsdefaults tomap_with_buckets. The setting’s own description saysadvanced“can increase the insertion time significantly”. So data that hasn’t been merged yet is read through buckets: 0.087 s but 403 MiB for one key in the test above, about 100× the memory ofadvanced. The latest data, which dashboards query most, is in the slower format until a merge rewrites it. advancedcosts disk. The setting’s description says it “increases the shared data storage size on disk because we store a lot of additional information”. The 25.8 blog stored a copy of the data in the original format next to the advanced one, which it said “effectively doubles the storage requirement” for shared data. No table of sizes was published.
Bucket counts are object_shared_data_buckets_for_wide_part = 32 and …_for_compact_part = 8 in 26.11. There is also advanced_chunked, which splits rows into chunks to lower peak memory when merging JSON columns with many unique paths.
When String wins: reading the whole thing
Look at the last column of the table. Rebuilding a whole document from 10,000 paths means reading and reassembling thousands of streams. The JSON column with every path as its own subcolumn ran out of memory. The advanced format took 1.7× as long as the String (4.774 vs 2.734 s), and map_with_buckets took 5.6× as long. A String hands back the bytes it stored.
So if your queries are SELECT * or “give me the payload for this ID”, the native JSON type makes them slower, not faster. That matches the ClickHouse JSON runbook: use a String when you only store and retrieve the blob.
Map got its own bucket trick in 26.3
The Map has a similar new option. map_serialization_version = 'with_buckets' arrived in 26.3 and splits keys into buckets by hash, so m['key'] reads one bucket instead of the whole map. In 26.11 the default is still basic for both merged and freshly inserted parts, so you have to turn it on per table (source, settings docs).
The Map docs publish this table (sqrt strategy, up to 32 buckets, no version or hardware given):
| Keys per map | 10 | 100 | 1,000 | 10,000 |
|---|---|---|---|---|
| Single key lookup | 1.6–3.2× faster | 4.5–7.7× | 16–39× | 21–49× |
| Lookup in PREWHERE | 1.5–3.0× | 2.9–7.3× | 5.3–31× | 20–45× |
| Full map scan | ~2× slower | ~2× slower | ~2× slower | ~2× slower |
| INSERT | 1.5–2.5× slower | 1.5–2.5× slower | 1.5–2.5× slower | 1.5–2.5× slower |
It’s the same trade as JSON: point reads get much cheaper, and full reads and inserts pay for it. Since 26.8, with_buckets also keeps the original key order. The Map benchmark and the JSON benchmark are different tests, so don’t divide one table by the other.
The bill JSON sends later: files and merges
Every dynamic path is a subcolumn, and in a Wide part every subcolumn is files. The JSON docs warn that a column with hundreds of typed paths produces hundreds of files per part. On object storage every file read is a separate request. The guidance there is to keep max_dynamic_paths at or below 10,000 on local disks and around 1024 on remote storage. Kruglov’s blog says raising the limit is “usually a bad idea, especially when using remote storage like S3, because creating thousands of files per part increases memory usage during merges.”
Merges pick which paths keep their columns. When parts with different paths are merged, ClickHouse keeps the paths with the most non-null values as subcolumns and moves the rarest ones to shared data. A path’s speed can therefore change after a merge. Since 25.11 there’s also a direct cap: merge_max_dynamic_subcolumns_in_wide_part (and …_compact_part) limits how many dynamic subcolumns a merged part keeps, whatever the type says.
Type hints are the way out for the paths you know. A hinted path is a plain column: no Dynamic wrapper, no discriminator, and it never moves to shared data. SKIP path and SKIP REGEXP '…' drop paths you never query, so they cost nothing.
What people running it at scale chose
- JSONBench, ClickHouse’s own 1-billion-document Bluesky benchmark, declares
JSON(max_dynamic_paths = 0, …)with five typed hints (create.sql). That’s zero dynamic paths: the five hot keys are columns and every other path lives in shared data. Its settings (object_serialization_version = 'v3',advanced,map_with_bucketsfor fresh parts) are exactly the 26.11 defaults. - SigNoz made the same choice for its log store:
max_dynamic_paths = 0with the advanced format, plus a second JSON column for “promoted” hot paths. On 9 TB of logs they report JSON was about 30% faster than a String column and scanned about 99% less data, with slightly higher memory use (SigNoz engineering blog, their measurement). - ClickStack (ClickHouse’s observability stack) still recommends Map by default for OpenTelemetry attributes. Its Map vs JSON guide says JSON adds “significant” write overhead when keys are many and dynamic, and that shared data is slower than real subcolumns. JSON support there is beta.
The two JSON users above follow the same pattern: a handful of known paths get columns, and everything else goes into one indexed bag instead of up to 1024 Dynamic columns that merges reshuffle.
Which one to use
- Whole-document reads:
String. Add a fewMATERIALIZEDcolumns withJSONExtractfor the two or three fields you filter on. - Known hot keys, open-ended tail:
JSON(hot.key Type, …)with hints for the hot keys. With thousands of unique keys, think aboutmax_dynamic_paths = 0(like JSONBench and SigNoz) rather than letting merges choose. - Flat key/value labels of one type:
Map(LowCardinality(String), String). On 26.3+, trymap_serialization_version = 'with_buckets'if maps are large and you look up single keys. Expect about 2× slower full scans and inserts. - Upgrading across 25.8 → 25.12+ with JSON columns: plan for the one-way format change, and set the v2 serialization settings until rollback is no longer an option.
- Object storage: keep
max_dynamic_pathslow and watch the file count per part.
What I couldn’t verify
- How many bytes
advancedactually adds on disk. The setting says it increases storage, and the 25.8 blog says it doubled shared data at the time, but there’s no published size table for 25.12+. - A like-for-like published test of
String+JSONExtractvs a hinted JSON column on a normal (tens of paths) document. The 3.2 s vs 0.027 s above is the 10,000-path worst case. - The hardware behind the Kruglov benchmark and the Map bucket table. Both are vendor measurements.
FAQ
Is the ClickHouse JSON type production ready?
Yes, since 25.3 according to the docs. It was experimental from 24.8. The storage format changed again in 25.12 (advanced shared data by default).
What happens when a JSON column has more than 1024 paths?
Per data part, paths beyond max_dynamic_paths go into shared data. You can still query them as json.path. Since 25.12 that is fast for single keys (0.063 s vs 0.027 s in ClickHouse’s test), but it’s still slower than a real subcolumn, and freshly inserted parts use the slower map_with_buckets format until they merge.
Is JSONExtract on a String column slow? For one key out of big documents, yes: it parses every document. In ClickHouse’s 10,000-path test it was about 120× slower than a JSON subcolumn. For returning the whole document it was the fastest option.
Map or JSON for OpenTelemetry attributes?
ClickHouse’s own observability stack still defaults to Map, because JSON insert overhead grows with many dynamic keys. Turn on Map with_buckets (26.3+) if single-key lookups on large maps are slow.
Can I downgrade after upgrading to 25.12+?
Not below 25.8 once new JSON parts are written in the v3 format. Set object_serialization_version = 'v2' and dynamic_serialization_version = 'v2' (or compatibility) before upgrading if you need a way back.
Tomorrow, Day 18: full-text search in ClickHouse: the text index vs LIKE vs ngrambf_v1 for log search.