Repository navigation
Description
Company or project name
No response
Describe the unexpected behaviour
I have a table (the full database copy in the repro section):
CREATE TABLE stack_map_v2
(
`id` UInt128 CODEC(NONE),
`stack` Array(LowCardinality(String)) CODEC(ZSTD(1)),
`seen` datetime CODEC(ZSTD(1))
)
ENGINE = ReplacingMergeTree(seen)
PRIMARY KEY (id, stack)
SETTINGS index_granularity = 256I have a copy of this table that was populated with the following settings (see #98968):
low_cardinality_use_single_dictionary_for_part=1low_cardinality_max_dictionary_size=1048576
CREATE TABLE stack_map_v2_single_dict
(
`id` UInt128 CODEC(NONE),
`stack` Array(LowCardinality(String)) CODEC(ZSTD(1)),
`seen` datetime CODEC(ZSTD(1))
)
ENGINE = ReplacingMergeTree(seen)
PRIMARY KEY (id, stack)
SETTINGS index_granularity = 256The second table is much smaller even with toy data (354MiB -> 155MiB), but unfortunately it is much slower to query due to repeated decompressions.
Bad query (single dict): the amount of data read from disk is 50x (!) the table size!
Good query (baseline table): everything seems in order in terms of read data.
Here's the flamegraph at the time of slow read:
Which ClickHouse versions are affected?
26.1 and 25.10 reproduce with the provided data.
How to reproduce
Download and extract the database:
curl -s https://r2.ivan.computer/clickhouse-extra-read-repro.tar | tar -C /tmp -xvf-
Run clickhouse-local pointed to the database above:
docker run --rm -it -v /tmp/repro:/tmp/repro clickhouse/clickhouse-server:25.10.3.100 clickhouse-local --path /tmp/repro
Select a lot of data (fast on either table, faster with a single dict, but using more memory):
:) select sum(length(stack)) from (SELECT id, stack FROM stack_map_v2 WHERE seen > '2026-03-08 04:00:00')
┌─sum(length(stack))─┐
1. │ 102617735 │ -- 102.62 million
└────────────────────┘
1 row in set. Elapsed: 2.895 sec. Processed 2.51 million rows, 1.50 GB (865.27 thousand rows/s., 516.53 MB/s.)
Peak memory usage: 31.00 MiB.
:) select sum(length(stack)) from (SELECT id, stack FROM stack_map_v2_single_dict WHERE seen > '2026-03-08 04:00:00')
┌─sum(length(stack))─┐
1. │ 102257695 │ -- 102.26 million
└────────────────────┘
1 row in set. Elapsed: 1.625 sec. Processed 2.37 million rows, 534.10 MB (1.46 million rows/s., 328.68 MB/s.)
Peak memory usage: 265.92 MiB.
Select a little bit of data (much slower with a single dict despite querying for less data):
:) select sum(length(stack)) from (SELECT id, stack FROM stack_map_v2 WHERE seen > '2026-03-11 04:00:00')
┌─sum(length(stack))─┐
1. │ 734536 │
└────────────────────┘
1 row in set. Elapsed: 1.801 sec. Processed 2.48 million rows, 481.58 MB (1.38 million rows/s., 267.46 MB/s.)
Peak memory usage: 23.83 MiB.
:) select sum(length(stack)) from (SELECT id, stack FROM stack_map_v2_single_dict WHERE seen > '2026-03-11 04:00:00')
┌─sum(length(stack))─┐
1. │ 657712 │
└────────────────────┘
1 row in set. Elapsed: 27.805 sec. Processed 2.51 million rows, 692.90 MB (90.40 thousand rows/s., 24.92 MB/s.)
Peak memory usage: 339.64 MiB.
Expected behavior
Smaller amounts of data selected mean faster queries, or at least not slower.
Error message and/or stacktrace
No response
Additional context
No response
Activity
PedroTadim commentedon Mar 11, 2026
Hello! The dictionary is going to be applied to the whole part. If a query has to read a few granules from it, it still has to decompress it entirely. I see it only gets an advantage in full scans.
bobrik commentedon Mar 11, 2026
@PedroTadim, I think you skipped over some key parts in the report.
My whole table is 155MiB, there's 8.10GiB read from disk to fulfill the query. That's 50x more than reading it entirely.
The dict is less than 5MiB:
bobrik commentedon Mar 11, 2026
I made this change:
I'm seeing a lot of these log lines with it:
This makes no sense as there's only one dictionary for the part.
Commenting out this
need_update_dictionary = truehelps:It makes the single dict table query succeed in 0.32s with one dictionary open per thread (arguably it should be opened once, but who's counting). The multiple dict table (the default behavior) runs in 0.93s, which slower.
I think there are two ways to go about this.
bobrik commentedon Mar 11, 2026
I might be able to figure out the patch for the first approach here.
PedroTadim commentedon Mar 13, 2026
Hello again! You are right, there is something missing for sure.