ClickHouse / ClickHouse/ClickHouse

If the 'PARTITION BY' field is defined, the data cannot be deleted when using the 'delete on cluster where id in (select...)' statement.

Open
#87,873 0 comments 0 reactions 0 assignees View on GitHub
comp-mutations external question
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

### Company or project name

_No response_

### Question

Image

```
CREATE TABLE default.ye3_local ON CLUSTER cluster_2S_1R
(

`dt` String,

`event` String,

`user_id` UInt64,

`context` String
)
ENGINE = MergeTree
PARTITION BY event
ORDER BY (user_id)
SETTINGS
enable_block_offset_column = 1,
enable_block_number_column = 1;


CREATE TABLE ye3_Q on cluster 'cluster_2S_1R'
ENGINE = Distributed(cluster_2S_1R, default, ye3_local, rand());

INSERT INTO ye3_Q values('2024-06-25','6',66,'66'),('2024-06-26','6',17,'17'),('2024-06-27','7',27,'27'),('2024-01-25','7',1,'1'),('2024-01-26','3',3,'3'),('2024-01-27','3',32,'32')

SELECT * from ye3_Q

SELECT * from ye3_local

CREATE TABLE ye_tmp on cluster 'cluster_2S_1R'
(

`user_id` UInt64
)
ENGINE = MergeTree
ORDER BY (user_id)

truncate table ye_tmp on cluster 'cluster_2S_1R'

select * from ye_tmp

INSERT INTO ye_tmp values(1),(3)

delete from ye3_local on cluster 'cluster_2S_1R' where user_id in (select user_id from ye_tmp)

UPDATE default.ye3_local ON CLUSTER cluster_2S_1R SET dt = '300' WHERE user_id in (select user_id from ye_tmp)
```

In versions 25.8.4, 25.8.7, and 25.9.2.1, when creating a table and defining the 'PARTITION BY' field, the 'delete on cluster where id in (select ..)' statement cannot be used to delete data. However, if the 'PARTITION BY' field is not defined, data can be deleted.

lightweight_delete_mode=lightweight_update

UPDATE default.ye3_local ON CLUSTER cluster_2S_1R SET dt = '300' WHERE user_id in (select user_id from ye_tmp),This kind of statement cannot be executed successfully either.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.