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.

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

One document, three ways to store it (what a one-key read has to touch)String1 streamwhole document text{"user":{"id":7},"env":"prod", … 10,000 paths}parse allMap(String,String)keys + valueskeys arrayvalues arraykeys: user.id, env, tags, …values: 7, prod, […], …scan bothJSONsplit by pathtyped path (hint)typed path (hint)typed path (hint)dynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumndynamic path subcolumnshared data bucketshared data bucketshared data bucketshared data bucketshared data bucketshared data bucketshared data bucketshared data bucketone columnor one buckethintsdynamic paths≤ 1024 per partshared data: path 1,025 on(32 buckets in a Wide part)read whole for one keyown columnshared data bucket
Conceptual, not to scale. From the JSON and Map docs and the 26.11 MergeTreeSettings.cpp (object_shared_data_buckets_for_wide_part = 32, compact parts 8). Map shown with the default basic serialization.

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 Dynamic subcolumn each, up to max_dynamic_paths, default 1024 per data part. Each holds up to max_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.

Read one key from 200k documents with 10,000 paths each (ClickHouse 25.8)memory0.01 s0.1 s1 s10 sJSON, path has own columnJSON, path has own column: 0.027 s, 18.64 MiB0.027 s18.64 MiBJSON shared data · advancedJSON shared data · advanced: 0.063 s, 3.89 MiB0.063 s3.89 MiBJSON shared data · map_with_bucketsJSON shared data · map_with_buckets: 0.087 s, 403.55 MiB0.087 s403.55 MiBString (parse every document)String (parse every document): 3.216 s, 582.70 MiB3.216 s582.70 MiBMap(String, String)Map(String, String): 3.594 s, 538.37 MiB3.594 s538.37 MiBJSON shared data · map (old)JSON shared data · map (old): 3.63 s, 12.53 GiB3.63 s12.53 GiBLog scale. Reading the whole document reverses it: String 2.73 s, advanced 4.77 s, map_with_buckets 15.27 s.
Numbers from Pavel Kruglov, Making complex JSON 58× faster, use 3,300× less memory (ClickHouse v25.8, Wide parts, hardware not stated; details in PR #83777). Measured by ClickHouse, not here. Since 25.12, merged parts default to advanced and fresh insert parts to map_with_buckets.

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):

  1. advanced is the default since 25.12, together with object_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 set object_serialization_version='v2' and dynamic_serialization_version='v2' (or compatibility) until you’re sure.
  2. Fresh parts are different. object_shared_data_serialization_version_for_zero_level_parts defaults to map_with_buckets. The setting’s own description says advanced “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 of advanced. The latest data, which dashboards query most, is in the slower format until a merge rewrites it.
  3. advanced costs 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_buckets for fresh parts) are exactly the 26.11 defaults.
  • SigNoz made the same choice for its log store: max_dynamic_paths = 0 with 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

  1. Whole-document reads: String. Add a few MATERIALIZED columns with JSONExtract for the two or three fields you filter on.
  2. Known hot keys, open-ended tail: JSON(hot.key Type, …) with hints for the hot keys. With thousands of unique keys, think about max_dynamic_paths = 0 (like JSONBench and SigNoz) rather than letting merges choose.
  3. Flat key/value labels of one type: Map(LowCardinality(String), String). On 26.3+, try map_serialization_version = 'with_buckets' if maps are large and you look up single keys. Expect about 2× slower full scans and inserts.
  4. 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.
  5. Object storage: keep max_dynamic_paths low and watch the file count per part.

What I couldn’t verify

  • How many bytes advanced actually 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 + JSONExtract vs 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.