ClickHouse/tests/queries/0_stateless/02892_SummingMergeTree_Nested.sql
Azat Khuzhin 099665478d Fix incorrect merging of Nested for SELECT FINAL FROM SummingMergeTree
The problem was the order of the columns, in case of SELECT FINAL it got
"counters_Map.count", "counters_Map.id"

But in case of OPTIMIZE FINAL it got "counters_Map.id",
"counters_Map.count" correctly.

Note, that this bugs exists there from the very recent versions, I've
checked 19.x and it was there.

P.S. there is a workaround for this problem, if you will use one of the
following patterns for key columns:
- *ID
- *Key
- *Type

That way it will be explicitly matched as key and everything will work.

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-10-08 07:32:47 +02:00

27 lines
583 B
SQL

drop table if exists nested_smt;
create table nested_smt (
date date,
val UInt64,
counters_Map Nested (
id UInt8,
count Int32
)
)
ENGINE = SummingMergeTree()
ORDER BY (date);
system stop merges nested_smt;
insert into nested_smt values ('2023-10-05', 1, [1,2,3], [10,20,30]);
insert into nested_smt values ('2023-10-05', 2, [1,2,3], [1,1,1]);
-- { echo }
select * from nested_smt order by val;
select * from nested_smt final;
system start merges nested_smt;
optimize table nested_smt final;
select * from nested_smt;
drop table nested_smt;