Skip to content

Fix premature TTL column removal causing merge failures and wrong defaults#88860

Merged
jkartseva merged 20 commits intoClickHouse:masterfrom
amosbird:fix-88002
Dec 12, 2025
Merged

Fix premature TTL column removal causing merge failures and wrong defaults#88860
jkartseva merged 20 commits intoClickHouse:masterfrom
amosbird:fix-88002

Conversation

@amosbird
Copy link
Copy Markdown
Collaborator

@amosbird amosbird commented Oct 21, 2025

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed several issues caused by premature column removal in TTL. Resolves #88002

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Details

  1. Fix merge failures in GraphiteMergeTree, VersionedCollapsingMergeTree, ReplacingMergeTree, and AggregatingMergeTree when TTL-removed columns were still required by merge logic
  2. Fix incorrect skip index or data values caused by filling missing columns with type defaults instead of column DEFAULT expressions
  3. Fix missing OPTIMIZE ... DEDUPLICATE BY behavior when deduplication columns were removed by TTL

…aults.

When column-level TTLs expired, columns were sometimes removed too early
(before DEFAULT expression evaluation or before merge-time transforms that
expect them to exist). As a result:

- Missing columns were filled with **type defaults** instead of the column’s
  **table-defined DEFAULT** expression.
- Skip index statistics became incorrect because indexes were computed using
  wrong default values.
- Merge algorithms depending on certain columns (e.g. GraphiteMergeTree’s
  `Timestamp`, VersionedCollapsingMergeTree’s `sign`, ReplacingMergeTree’s
  `version`, or AggregatingMergeTree’s state columns) could fail with
  `Not found column ... in block` errors.

Now TTL-expired columns are properly handled.
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Oct 21, 2025

Workflow [PR], commit [3deb13e]

Summary:

job_name test_name status info comment
Stateless tests (arm_asan, targeted) failure
01459_manual_write_to_replicas_quorum_detach_attach FAIL cidb, issue
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: FAIL cidb
BuzzHouse (amd_msan) failure
Unknown error FAIL cidb

@clickhouse-gh clickhouse-gh bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 21, 2025
@jkartseva jkartseva self-assigned this Oct 23, 2025
Copy link
Copy Markdown
Member

@jkartseva jkartseva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could you please add a test for one of the engines mentioned in the changelog?

Merge failures in GraphiteMergeTree, VersionedCollapsingMergeTree, ReplacingMergeTree, and AggregatingMergeTree when TTL-removed columns were still required by merge logic.

@amosbird
Copy link
Copy Markdown
Collaborator Author

Looks good. Could you please add a test for one of the engines mentioned in the changelog?

Sure. I've added more tests and fixed more issues.

@Felixoid
Copy link
Copy Markdown
Member

Felixoid commented Nov 3, 2025

Thanks for the PR!

Looks like the tests has failed, unfortunately =\

@amosbird
Copy link
Copy Markdown
Collaborator Author

Looks like the tests has failed, unfortunately =\

It should be fine now.

@Felixoid
Copy link
Copy Markdown
Member

Felixoid commented Nov 13, 2025

I wrote a test, unfortunately, it fails as following:

=================================== FAILURES ===================================
_______________________________ test_ttl_version _______________________________
[gw0] linux -- Python 3.10.12 /usr/bin/python3
test_graphite_merge_tree/test.py:534: in test_ttl_version
    q("OPTIMIZE TABLE test.graphite PARTITION 200109 FINAL")
helpers/cluster.py:4255: in query
    return self.client.query(
helpers/client.py:39: in wrap
    return func(self, *args, **kwargs)
helpers/client.py:79: in query
    ).get_answer()
helpers/client.py:247: in get_answer
    raise QueryRuntimeException(
E   helpers.client.QueryRuntimeException: Client failed! Return code: 10, stderr: Received exception from server (version 25.11.1):
E   Code: 10. DB::Exception: Received from 172.16.1.2:9000. DB::Exception: Not found column updated in block. There are only columns: metric, timestamp, value, date. Stack trace:
E
E   0. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x0000000013eab75f
E   1. DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000cb63fce
E   2. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000cb63a80
E   3. DB::Exception::Exception<String const&, String>(int, FormatStringHelperImpl<std::type_identity<String const&>::type, std::type_identity<String>::type>, String const&, String&&) @ 0x000000000dc115ab
E   4. DB::Block::getPositionByName(String const&, bool) const @ 0x0000000017681de4
E   5. DB::GraphiteRollupSortedAlgorithm::GraphiteRollupSortedAlgorithm(std::shared_ptr<DB::Block const>, unsigned long, DB::SortDescription, unsigned long, unsigned long, std::optional<unsigned long>, DB::Graphite::Params, long) @ 0x000000001ac60ef6
E   6. DB::IMergingTransform<DB::GraphiteRollupSortedAlgorithm>::IMergingTransform<std::shared_ptr<DB::Block const>&, unsigned long&, DB::SortDescription, unsigned long&, unsigned long&, std::optional<unsigned long>&, DB::Graphite::Params, long&>(unsigned long, std::shared_ptr<DB::Block const>, std::shared_ptr<DB::Block const>, bool, unsigned long, bool, std::shared_ptr<DB::Block const>&, unsigned long&, DB::SortDescription&&, unsigned long&, unsigned long&, std::optional<unsigned long>&, DB::Graphite::Params&&, long&) @ 0x0000000019e82d83
E   7. DB::MergePartsStep::transformPipeline(DB::QueryPipelineBuilder&, DB::BuildQueryPipelineSettings const&) @ 0x0000000019e762c6
E   8. DB::ITransformingStep::updatePipeline(std::vector<std::unique_ptr<DB::QueryPipelineBuilder, std::default_delete<DB::QueryPipelineBuilder>>, std::allocator<std::unique_ptr<DB::QueryPipelineBuilder, std::default_delete<DB::QueryPipelineBuilder>>>>, DB::BuildQueryPipelineSettings const&) @ 0x000000001ad51f57
E   9. DB::QueryPlan::buildQueryPipeline(DB::QueryPlanOptimizationSettings const&, DB::BuildQueryPipelineSettings const&, bool) @ 0x000000001ad96d80
E   10. DB::MergeTask::ExecuteAndFinalizeHorizontalPart::createMergedStream() const @ 0x0000000019e6020d
E   11. DB::MergeTask::ExecuteAndFinalizeHorizontalPart::prepare() const @ 0x0000000019e58ec1
E   12. DB::MergeTask::ExecuteAndFinalizeHorizontalPart::execute() @ 0x0000000019e6234e
E   13. DB::MergeTask::execute() @ 0x0000000019e6bd62
E   14. DB::MergePlainMergeTreeTask::executeStep() @ 0x0000000019e4a0bf
E   15. DB::StorageMergeTree::merge(bool, String const&, bool, bool, std::vector<String, std::allocator<String>> const&, bool, std::shared_ptr<DB::MergeTreeTransaction> const&, PreformattedMessage&, bool) @ 0x0000000019812b46
E   16. DB::StorageMergeTree::optimize(std::shared_ptr<DB::IAST> const&, std::shared_ptr<DB::StorageInMemoryMetadata const> const&, std::shared_ptr<DB::IAST> const&, bool, bool, std::vector<String, std::allocator<String>> const&, bool, std::shared_ptr<DB::Context const>) @ 0x000000001981cfd1
E   17. DB::InterpreterOptimizeQuery::execute() @ 0x000000001904fbf7
E   18. DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, std::unique_ptr<DB::ReadBuffer, std::default_delete<DB::ReadBuffer>>&, std::shared_ptr<DB::IAST>&, std::shared_ptr<DB::ImplicitTransactionControlExecutor>, std::function<void ()>) @ 0x0000000018fd0304
E   19. DB::executeQuery(String const&, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum) @ 0x0000000018fca133
E   20. DB::TCPHandler::runImpl() @ 0x000000001a77a8b7
E   21. DB::TCPHandler::run() @ 0x000000001a79ce99
E   22. Poco::Net::TCPServerConnection::start() @ 0x000000001f86f407
E   23. Poco::Net::TCPServerDispatcher::run() @ 0x000000001f86f899
E   24. Poco::PooledThread::run() @ 0x000000001f836047
E   25. Poco::ThreadImpl::runnableEntry(void*) @ 0x000000001f834441
E   26. ? @ 0x0000000000094ac3
E   27. ? @ 0x00000000001268c0
E   . (NOT_FOUND_COLUMN_IN_BLOCK)
E   (query: OPTIMIZE TABLE test.graphite PARTITION 200109 FINAL)

You can launch it locally as python -m ci.praktika run integration --test test_graphite_merge_tree/test.py::test_ttl_version from the repo root, the clickhouse binary could be placed in ci/tmp

@amosbird
Copy link
Copy Markdown
Collaborator Author

I wrote a test, unfortunately, it fails as following:

Thanks! The test passes now.

@amosbird
Copy link
Copy Markdown
Collaborator Author

I've updated the PR to address #37570 in a more general way, which also satisfies the second requirement of #4968.

@amosbird
Copy link
Copy Markdown
Collaborator Author

Now it exposes additional issues: dependencies in default expressions are not handled correctly during column TTL. I’ll work on a proper fix.

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Dec 12, 2025
@iankosen
Copy link
Copy Markdown

Any plans to backport to v25.8?

@Felixoid Felixoid added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Dec 16, 2025
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Dec 16, 2025
robot-ch-test-poll3 added a commit that referenced this pull request Dec 16, 2025
Cherry pick #88860 to 25.10: Fix premature TTL column removal causing merge failures and wrong defaults
robot-clickhouse added a commit that referenced this pull request Dec 16, 2025
robot-ch-test-poll3 added a commit that referenced this pull request Dec 16, 2025
Cherry pick #88860 to 25.11: Fix premature TTL column removal causing merge failures and wrong defaults
robot-clickhouse added a commit that referenced this pull request Dec 16, 2025
clickhouse-gh bot added a commit that referenced this pull request Dec 16, 2025
Backport #88860 to 25.10: Fix premature TTL column removal causing merge failures and wrong defaults
clickhouse-gh bot added a commit that referenced this pull request Dec 16, 2025
Backport #88860 to 25.11: Fix premature TTL column removal causing merge failures and wrong defaults
robot-ch-test-poll2 added a commit that referenced this pull request Dec 18, 2025
Cherry pick #88860 to 25.8: Fix premature TTL column removal causing merge failures and wrong defaults
robot-clickhouse added a commit that referenced this pull request Dec 18, 2025
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Dec 18, 2025
@Felixoid Felixoid removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Dec 18, 2025
Felixoid added a commit that referenced this pull request Dec 18, 2025
Backport #88860 to 25.8: Fix premature TTL column removal causing merge failures and wrong defaults
robot-ch-test-poll added a commit that referenced this pull request Dec 18, 2025
Cherry pick #88860 to 25.9: Fix premature TTL column removal causing merge failures and wrong defaults
robot-clickhouse added a commit that referenced this pull request Dec 18, 2025
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Dec 19, 2025
azat added a commit that referenced this pull request Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception: Not found column Timestamp in block during merge on GraphiteMergeTree/ReplicatedGraphiteMergeTree Table

8 participants