Clickhouse: Unexepected query results because of corrupt table

Created on 3 Feb 2020  路  12Comments  路  Source: ClickHouse/ClickHouse

Table structure:

CREATE TABLE IF NOT EXISTS movement
(
  `time` DateTime DEFAULT now() CODEC(DoubleDelta, ZSTD),
  `configuration_id` UInt16 CODEC(ZSTD),
  `node_id` UInt16 CODEC(ZSTD)
)
ENGINE = MergeTree()
ORDER BY (configuration_id, lamp_id, time);

Query 1:

select configuration_id, count(*) from movement where configuration_id=67 group by configuration_id;
Result: 
configuration_id 67, count() 614 226

Query 2:

select configuration_id, count(*) from movement group by configuration_id;
Result contains:
configuration_id 67, count() 1 376 373

Same thing happens when doing min(time):
Query 1 2020-01-23 00:02:52
Query 2 2020-01-07 11:41:59

After creating a copy of this table using:

CREATE TABLE IF NOT EXISTS movement3
(
  `time` DateTime DEFAULT now() CODEC(DoubleDelta, ZSTD),
  `configuration_id` UInt16 CODEC(ZSTD),
  `lamp_id` UInt16 CODEC(ZSTD)
)
ENGINE = MergeTree()
ORDER BY (configuration_id, lamp_id, time)
insert into movement3 select time, configuration_id, lamp_id from movement;

I do get the same results for query 1 and 2. Does this mean that the original table is in a broken state?

If so, how did this happen and how can I detect and fix this?

bug v19.17 v20.1

Most helpful comment

I sent the data to your mailing list.

All 12 comments

CH Version?

What shows:
select configuration_id, count(*) from movement
where identity(configuration_id)=67
group by configuration_id;

Clickhouse version: 19.17.7.52
The query:

select configuration_id, count(*) from movement
where identity(configuration_id)=67
group by configuration_id;

Does return the expected configuration_id 67, count() 1 376 373

Please try one more -- toUInt16(67)

select configuration_id, count(*) from movement
where configuration_id=toUInt16(67)
group by configuration_id;

Above query using toUInt16(67) returns the incorrect value:
configuration_id 67, count() 614 226

Have you run mutations (alter delete) against this table?

Yes, a lot of alter delete's, even doing another alter delete before the first one is done. No updates though.

Can you show a couple examples of delete?

They are all of the same type:
alter table movement delete where configuration_id = x and time < y

Maybe you can provide data (parts) from the broken table? You can do it privately if you send them to our mailing list [email protected].

I sent the data to your mailing list.

Reproduced the issue. But found more serious one https://github.com/ClickHouse/ClickHouse/issues/9034.

The bug seems to be fixed in all supported versions (20.1, 20.3, 20.4, etc).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atk91 picture atk91  路  3Comments

fizerkhan picture fizerkhan  路  3Comments

goranc picture goranc  路  3Comments

vvp83 picture vvp83  路  3Comments

zhicwu picture zhicwu  路  3Comments