Skip to content

SummingMergeTree yields incorrect results in case of ORDER BY ( func( ) ) #57818

@den-crane

Description

@den-crane

https://fiddle.clickhouse.com/85f27e31-6d9e-4951-9935-41bad4e2eba4

CREATE TABLE test  (
    d Date,
    s UInt64,
    cnt UInt64
)
ENGINE = SummingMergeTree()
PARTITION BY toYYYYMMDD(d)
ORDER BY (d,cityHash64(s));

insert into test(d, s, cnt) select '2020-01-01', number%111111, 1 from numbers(1e6);

select (
SELECT uniqExact(s)
FROM test
WHERE (d = '2020-01-01') AND (cityHash64(identity(s)) < 9223372036854775807)) a,
(
SELECT uniqExact(s)
FROM test
WHERE (d = '2020-01-01') AND (cityHash64(s) < 9223372036854775807)) b,
a=b format Pretty;

+-------+-------+--------------+
|     a |     b | equals(a, b) |
+-------+-------+--------------+
| 55767 | 28773 |            0 | -- expected the same
+-------+-------+--------------+


select sum(cnt) from 
(select '2020-01-01', number%111111 s, 1 cnt from numbers(1e6))
where cityHash64(s) < 9223372036854775807 
format Pretty
+----------+
| sum(cnt) |
+----------+
|   499825 |
+----------+


select sum(cnt) from test 
where cityHash64(identity(s)) < 9223372036854775807 
format Pretty;
+----------+
| sum(cnt) |
+----------+
|   501904 | -- wrong, expected 499825
+----------+

select sum(cnt) from test 
where cityHash64(s) < 9223372036854775807
format Pretty;
+----------+
| sum(cnt) |
+----------+
|   258958 | -- wrong, expected 499825
+----------+

Found during the investigation of Sample By issues.
It seems the issue exists from the beginning (20.8.16) https://fiddle.clickhouse.com/a67e1625-5670-4eec-bf96-bb84def03742

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions