Skip to content

Commit a1f4cd9

Browse files
Merge pull request ClickHouse#88147 from ClickHouse/backport/25.8/88095
Backport ClickHouse#88095 to 25.8: Fix data corruption with expired column TTL and sparse serialization
2 parents c06c2fa + 57572f6 commit a1f4cd9

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

src/Storages/MergeTree/IMergeTreeDataPart.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ void IMergeTreeDataPart::setColumns(const NamesAndTypesList & new_columns, const
558558
serialization_infos = new_infos;
559559
metadata_version = new_metadata_version;
560560

561+
serializations.clear();
561562
column_name_to_position.clear();
562563
column_name_to_position.reserve(new_columns.size());
563564
size_t pos = 0;

src/Storages/MergeTree/MergeTask.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,9 @@ bool MergeTask::ExecuteAndFinalizeHorizontalPart::prepare() const
509509
const auto & expired_columns = global_ctx->new_data_part->expired_columns;
510510
if (!expired_columns.empty())
511511
{
512-
auto part_serialization_infos = global_ctx->new_data_part->getSerializationInfos();
513-
for (const auto & expired_column : expired_columns)
514-
part_serialization_infos.erase(expired_column);
515-
516512
global_ctx->gathering_columns = global_ctx->gathering_columns.eraseNames(expired_columns);
517513
global_ctx->merging_columns = global_ctx->merging_columns.eraseNames(expired_columns);
518514
global_ctx->storage_columns = global_ctx->storage_columns.eraseNames(expired_columns);
519-
global_ctx->new_data_part->setColumns(
520-
global_ctx->storage_columns,
521-
part_serialization_infos,
522-
global_ctx->metadata_snapshot->getMetadataVersion());
523515
}
524516

525517
global_ctx->new_data_part->uuid = global_ctx->future_part->uuid;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
435
2+
435
3+
435
4+
435
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
DROP TABLE IF EXISTS ttl_sparse_repro;
2+
3+
CREATE TABLE ttl_sparse_repro
4+
(
5+
a UInt64,
6+
dt DateTime,
7+
b UInt64 TTL dt + INTERVAL 2 SECOND, c UInt64
8+
)
9+
ENGINE = MergeTree ORDER BY a SETTINGS ratio_of_defaults_for_sparse_serialization = 0.9;
10+
11+
INSERT INTO ttl_sparse_repro SELECT number, now(), 1, if (number % 23 = 0, 1, 0) FROM numbers(10000);
12+
13+
SELECT sum(c) FROM ttl_sparse_repro;
14+
15+
SELECT sleep(3) FORMAT Null;
16+
17+
OPTIMIZE TABLE ttl_sparse_repro FINAL;
18+
SELECT sum(c) FROM ttl_sparse_repro;
19+
20+
OPTIMIZE TABLE ttl_sparse_repro FINAL;
21+
SELECT sum(c) FROM ttl_sparse_repro;
22+
23+
OPTIMIZE TABLE ttl_sparse_repro FINAL;
24+
SELECT sum(c) FROM ttl_sparse_repro;
25+
26+
DROP TABLE IF EXISTS ttl_sparse_repro;

0 commit comments

Comments
 (0)