Skip to content

Fix logic error which leads endless mutation failures. - #109860

Open
RinChanNOWWW wants to merge 1 commit into
ClickHouse:masterfrom
RinChanNOWWW:clickhouse/fix-mutation
Open

RinChanNOWWW wants to merge 1 commit into
ClickHouse:masterfrom
RinChanNOWWW:clickhouse/fix-mutation

Conversation

@RinChanNOWWW

Copy link
Copy Markdown
Contributor

Summary

Fix type mismatch exception in performRequiredConversions after DROP+re-ADD column

When multiple mutations are squashed (e.g. DELETE + DROP COLUMN + DELETE),
and the dropped column is later re-added with a different type and no
DEFAULT expression, the mutation execution hits a logical error:
Unexpected return type from ifNull. Expected Int32. Got UInt64.

Error log
2026.07.09 04:41:51.869001 [ 849 ] {29efafa0-a4c4-4943-abaf-c4ea1baca885::all_2_2_0_5} <Fatal> : Logical error: 'Unexpected return type from ifNull. Expected Int32. Got UInt64. Action:
FUNCTION ifNull(extra :: 0, 0_UInt8 :: 1) -> ifNull(extra, 0_UInt8) Int32 : 3,
input block structure:extra Nullable(Int32) UInt64(size = 3), 0_UInt8 UInt8 Const(size = 3, UInt8(size = 1))'.
2026.07.09 04:41:51.869048 [ 849 ] {29efafa0-a4c4-4943-abaf-c4ea1baca885::all_2_2_0_5} <Fatal> : Format string: 'Unexpected return type from {}. Expected {}. Got {}. Action:
{},
input block structure:{}'.
2026.07.09 04:41:52.195826 [ 849 ] {29efafa0-a4c4-4943-abaf-c4ea1baca885::all_2_2_0_5} <Fatal> : Stack trace (when copying this message, always include the lines below):

0. ../contrib/llvm-project/libcxx/include/__exception/exception.h:115:14: Poco::Exception::Exception(String&&, int) @ 0x0000000022dfd5b3
1. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Common/Exception.cpp:139:7: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000115f001e
2. ../src/Common/Exception.h:171:100: DB::Exception::Exception(String&&, int, String, bool) @ 0x0000000009d89e96
3. ../src/Common/Exception.h:57:54: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000009d89951
4. ../src/Common/Exception.h:189:77: DB::Exception::Exception<String, String, String, String, String>(int, FormatStringHelperImpl<std::type_identity<String>::type, std::type_identity<String>::type, std::type_identity<String>::type, std::type_identity<String>::type, std::type_identity<String>::type>, String&&, String&&, String&&, String&&, String&&) @ 0x000000000c553dcf
5. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/ExpressionActions.cpp:696:27: DB::executeAction(DB::ExpressionActions::Action const&, DB::(anonymous namespace)::ExecutionContext&, bool, bool, bool) @ 0x0000000016cb9040
6. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/ExpressionActions.cpp:837:13: DB::ExpressionActions::execute(DB::Block&, unsigned long&, bool, bool, std::function<bool ()>) const @ 0x0000000016cb710a
7. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/ExpressionActions.cpp:1003:5: DB::ExpressionActions::execute(DB::Block&, bool, bool, std::function<bool ()>) const @ 0x0000000016cb9f49
8. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/inplaceBlockConversions.cpp:285:21: DB::performRequiredConversions(DB::Block&, DB::NamesAndTypesList const&, std::shared_ptr<DB::Context const>, std::unordered_map<String, DB::ColumnDefault, std::hash<String>, std::equal_to<String>, std::allocator<std::pair<String const, DB::ColumnDefault>>> const&, bool) @ 0x00000000171f4cf1
9. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/IMergeTreeReader.cpp:425:9: DB::IMergeTreeReader::performRequiredConversions(std::vector<COW<DB::IColumn>::immutable_ptr<DB::IColumn>, std::allocator<COW<DB::IColumn>::immutable_ptr<DB::IColumn>>>&) const @ 0x000000001ce684c9
10. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeReadersChain.cpp:457:28: DB::MergeTreeReadersChain::executeActionsBeforePrewhere(DB::MergeTreeRangeReader::ReadResult&, std::vector<COW<DB::IColumn>::immutable_ptr<DB::IColumn>, std::allocator<COW<DB::IColumn>::immutable_ptr<DB::IColumn>>>&, DB::MergeTreeRangeReader&, DB::Block const&, unsigned long) const @ 0x000000001d180e90
11. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeReadersChain.cpp:317:9: DB::MergeTreeReadersChain::read(unsigned long, DB::MarkRanges&, std::vector<DB::MarkRanges, std::allocator<DB::MarkRanges>>&, std::function<void (std::vector<DB::ColumnWithTypeAndName, AllocatorWithMemoryTracking<DB::ColumnWithTypeAndName>> const&, unsigned long, std::optional<bool>&)> const&) @ 0x000000001d17f79a
12. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeSequentialSource.cpp:221:38: DB::MergeTreeSequentialSource::generate() @ 0x000000001d171edb
13. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/ISource.cpp:153:18: DB::ISource::tryGenerate() @ 0x000000001d8bf19f
14. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/ISource.cpp:119:26: DB::ISource::work() @ 0x000000001d8bee76
15. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/ExecutionThreadContext.cpp:54:28: DB::ExecutionThreadContext::executeTask() @ 0x000000001d8dea33
16. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PipelineExecutor.cpp:384:26: DB::PipelineExecutor::executeStepImpl(unsigned long, DB::WorkloadResources&&, std::atomic<bool>*) @ 0x000000001d8d1bbc
17. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PipelineExecutor.cpp:252:5: DB::PipelineExecutor::executeStep(std::atomic<bool>*) @ 0x000000001d8d1698
18. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PullingPipelineExecutor.cpp:60:20: DB::PullingPipelineExecutor::pull(DB::Chunk&) @ 0x000000001d8e6d60
19. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PullingPipelineExecutor.cpp:71:10: DB::PullingPipelineExecutor::pull(DB::Block&) @ 0x000000001d8e6eb1
20. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutateTask.cpp:1744:77: DB::PartMergerWriter::mutateOriginalPartAndPrepareProjections() @ 0x000000001d1ff83b
21. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutateTask.cpp:1609:21: DB::MutateAllPartColumnsTask::executeStep() @ 0x000000001d218116
22. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutateTask.cpp:2920:23: DB::MutateTask::execute() @ 0x000000001d203cea
23. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutatePlainMergeTreeTask.cpp:114:34: DB::MutatePlainMergeTreeTask::executeStep() @ 0x000000001d1fd6bc
24. ../src/Storages/MergeTree/MergeTreeBackgroundExecutor.h:74:22: DB::TaskRuntimeData::executeStep() const @ 0x000000001cf0c4e0
25. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:369:36: DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::routine(std::shared_ptr<DB::TaskRuntimeData>) @ 0x000000001cf11a4b
26. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:432:13: DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::threadFunction() @ 0x000000001cf13bb2
27. ../contrib/llvm-project/libcxx/include/__functional/function.h:502:12: ? @ 0x00000000117ada89
28. ../contrib/llvm-project/libcxx/include/__functional/function.h:502:12: ? @ 0x00000000117b67cb
29. ../contrib/llvm-project/libcxx/include/__functional/function.h:502:12: ? @ 0x00000000117aacfc
30. ../contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: void* std::__thread_proxy[abi:sqe220101]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x00000000117b3cce
31. start_thread @ 0x0000000000094ac3

Bug trigger conditions:

  • A part physically stores column extra as Nullable(Int32)
  • Mutations are squashed: DELETE + DROP COLUMN extra + DELETE
  • After DROP, the column is re-added as extra UInt64 (no DEFAULT)
  • The squashed mutation executes on the original part in one pass

You can see test case 04509_drop_readd_column_different_type_mutation.sql.

Execution flow that leads to the exception:

  1. AlterConversions marks extra as dropped (DROP COLUMN mutation pending)
  2. Reader skips reading extra (isColumnDroppedByPendingMutation = true),
    sets res_columns[pos] = nullptr
  3. fillMissingColumns sees no DEFAULT expression (hasDefault = false),
    fills with the requested type's default (UInt64 zero)
  4. performRequiredConversions finds res_columns[pos] is non-null,
    calls getColumnInPart which returns the part's old type Nullable(Int32)
  5. It inserts the UInt64 column data into a Block tagged as Nullable(Int32)
  6. Builds ifNull(extra, 0) expecting return type Int32, but actual column
    data is UInt64 -> type mismatch exception

Root cause

performRequiredConversions assumes that non-null res_columns
data matches getColumnInPart type (true when reader actually reads from
part). But when a column is skipped by isColumnDroppedByPendingMutation
and then filled by fillMissingColumns with the requested type, this
assumption breaks.

Fix

Skip performRequiredConversions for columns marked as dropped by
pending mutations - their data was not read from the part and is already
in the correct requested type.

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):

Fix type mismatch exception in performRequiredConversions after DROP+re-ADD column

@CLAassistant

CLAassistant commented Jul 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…re-ADD column

When multiple mutations are squashed (e.g. DELETE + DROP COLUMN + DELETE),
and the dropped column is later re-added with a different type and no
DEFAULT expression, the mutation execution hits a logical error:

  Unexpected return type from ifNull. Expected Int32. Got UInt64.

Bug trigger conditions:
- A part physically stores column `extra` as Nullable(Int32)
- Mutations are squashed: DELETE + DROP COLUMN `extra` + DELETE
- After DROP, the column is re-added as `extra UInt64` (no DEFAULT)
- The squashed mutation executes on the original part in one pass

Execution flow that leads to the exception:
1. `AlterConversions` marks `extra` as dropped (DROP COLUMN mutation pending)
2. Reader skips reading `extra` (`isColumnDroppedByPendingMutation` = true),
   sets `res_columns[pos] = nullptr`
3. `fillMissingColumns` sees no DEFAULT expression (`hasDefault` = false),
   fills with the requested type's default (UInt64 zero)
4. `performRequiredConversions` finds `res_columns[pos]` is non-null,
   calls `getColumnInPart` which returns the part's old type Nullable(Int32)
5. It inserts the UInt64 column data into a Block tagged as Nullable(Int32)
6. Builds `ifNull(extra, 0)` expecting return type Int32, but actual column
   data is UInt64 -> type mismatch exception

Root cause: `performRequiredConversions` assumes that non-null `res_columns`
data matches `getColumnInPart` type (true when reader actually reads from
part). But when a column is skipped by `isColumnDroppedByPendingMutation`
and then filled by `fillMissingColumns` with the *requested* type, this
assumption breaks.

Fix: skip `performRequiredConversions` for columns marked as dropped by
pending mutations - their data was not read from the part and is already
in the correct requested type.
@RinChanNOWWW
RinChanNOWWW force-pushed the clickhouse/fix-mutation branch from 51adc48 to 5422432 Compare July 9, 2026 03:05
@RinChanNOWWW RinChanNOWWW changed the title Fix logic error in mutation Fix logic error which leads endless mutation failures. Jul 9, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Hello! Which bug this PR fixes?

@RinChanNOWWW

RinChanNOWWW commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Hello! Which bug this PR fixes?

Hello, please see the "Error log" section in the PR summay or the test case added by this PR. There isn't any relevant issue yet. @PedroTadim

2026.07.09 04:41:51.869001 [ 849 ] {29efafa0-a4c4-4943-abaf-c4ea1baca885::all_2_2_0_5} <Fatal> : Logical error: 'Unexpected return type from ifNull. Expected Int32. Got UInt64. Action:
FUNCTION ifNull(extra :: 0, 0_UInt8 :: 1) -> ifNull(extra, 0_UInt8) Int32 : 3,
input block structure:extra Nullable(Int32) UInt64(size = 3), 0_UInt8 UInt8 Const(size = 3, UInt8(size = 1))'.
2026.07.09 04:41:51.869048 [ 849 ] {29efafa0-a4c4-4943-abaf-c4ea1baca885::all_2_2_0_5} <Fatal> : Format string: 'Unexpected return type from {}. Expected {}. Got {}. Action:
{},
input block structure:{}'.
2026.07.09 04:41:52.195826 [ 849 ] {29efafa0-a4c4-4943-abaf-c4ea1baca885::all_2_2_0_5} <Fatal> : Stack trace (when copying this message, always include the lines below):

0. ../contrib/llvm-project/libcxx/include/__exception/exception.h:115:14: Poco::Exception::Exception(String&&, int) @ 0x0000000022dfd5b3
1. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Common/Exception.cpp:139:7: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000115f001e
2. ../src/Common/Exception.h:171:100: DB::Exception::Exception(String&&, int, String, bool) @ 0x0000000009d89e96
3. ../src/Common/Exception.h:57:54: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000009d89951
4. ../src/Common/Exception.h:189:77: DB::Exception::Exception<String, String, String, String, String>(int, FormatStringHelperImpl<std::type_identity<String>::type, std::type_identity<String>::type, std::type_identity<String>::type, std::type_identity<String>::type, std::type_identity<String>::type>, String&&, String&&, String&&, String&&, String&&) @ 0x000000000c553dcf
5. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/ExpressionActions.cpp:696:27: DB::executeAction(DB::ExpressionActions::Action const&, DB::(anonymous namespace)::ExecutionContext&, bool, bool, bool) @ 0x0000000016cb9040
6. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/ExpressionActions.cpp:837:13: DB::ExpressionActions::execute(DB::Block&, unsigned long&, bool, bool, std::function<bool ()>) const @ 0x0000000016cb710a
7. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/ExpressionActions.cpp:1003:5: DB::ExpressionActions::execute(DB::Block&, bool, bool, std::function<bool ()>) const @ 0x0000000016cb9f49
8. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Interpreters/inplaceBlockConversions.cpp:285:21: DB::performRequiredConversions(DB::Block&, DB::NamesAndTypesList const&, std::shared_ptr<DB::Context const>, std::unordered_map<String, DB::ColumnDefault, std::hash<String>, std::equal_to<String>, std::allocator<std::pair<String const, DB::ColumnDefault>>> const&, bool) @ 0x00000000171f4cf1
9. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/IMergeTreeReader.cpp:425:9: DB::IMergeTreeReader::performRequiredConversions(std::vector<COW<DB::IColumn>::immutable_ptr<DB::IColumn>, std::allocator<COW<DB::IColumn>::immutable_ptr<DB::IColumn>>>&) const @ 0x000000001ce684c9
10. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeReadersChain.cpp:457:28: DB::MergeTreeReadersChain::executeActionsBeforePrewhere(DB::MergeTreeRangeReader::ReadResult&, std::vector<COW<DB::IColumn>::immutable_ptr<DB::IColumn>, std::allocator<COW<DB::IColumn>::immutable_ptr<DB::IColumn>>>&, DB::MergeTreeRangeReader&, DB::Block const&, unsigned long) const @ 0x000000001d180e90
11. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeReadersChain.cpp:317:9: DB::MergeTreeReadersChain::read(unsigned long, DB::MarkRanges&, std::vector<DB::MarkRanges, std::allocator<DB::MarkRanges>>&, std::function<void (std::vector<DB::ColumnWithTypeAndName, AllocatorWithMemoryTracking<DB::ColumnWithTypeAndName>> const&, unsigned long, std::optional<bool>&)> const&) @ 0x000000001d17f79a
12. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeSequentialSource.cpp:221:38: DB::MergeTreeSequentialSource::generate() @ 0x000000001d171edb
13. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/ISource.cpp:153:18: DB::ISource::tryGenerate() @ 0x000000001d8bf19f
14. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/ISource.cpp:119:26: DB::ISource::work() @ 0x000000001d8bee76
15. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/ExecutionThreadContext.cpp:54:28: DB::ExecutionThreadContext::executeTask() @ 0x000000001d8dea33
16. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PipelineExecutor.cpp:384:26: DB::PipelineExecutor::executeStepImpl(unsigned long, DB::WorkloadResources&&, std::atomic<bool>*) @ 0x000000001d8d1bbc
17. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PipelineExecutor.cpp:252:5: DB::PipelineExecutor::executeStep(std::atomic<bool>*) @ 0x000000001d8d1698
18. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PullingPipelineExecutor.cpp:60:20: DB::PullingPipelineExecutor::pull(DB::Chunk&) @ 0x000000001d8e6d60
19. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Processors/Executors/PullingPipelineExecutor.cpp:71:10: DB::PullingPipelineExecutor::pull(DB::Block&) @ 0x000000001d8e6eb1
20. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutateTask.cpp:1744:77: DB::PartMergerWriter::mutateOriginalPartAndPrepareProjections() @ 0x000000001d1ff83b
21. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutateTask.cpp:1609:21: DB::MutateAllPartColumnsTask::executeStep() @ 0x000000001d218116
22. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutateTask.cpp:2920:23: DB::MutateTask::execute() @ 0x000000001d203cea
23. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MutatePlainMergeTreeTask.cpp:114:34: DB::MutatePlainMergeTreeTask::executeStep() @ 0x000000001d1fd6bc
24. ../src/Storages/MergeTree/MergeTreeBackgroundExecutor.h:74:22: DB::TaskRuntimeData::executeStep() const @ 0x000000001cf0c4e0
25. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:369:36: DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::routine(std::shared_ptr<DB::TaskRuntimeData>) @ 0x000000001cf11a4b
26. /data/home/zheyuhe/ClickHouses/tchouse/worktrees/clickhouse-fix-mutation/build/../src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:432:13: DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::threadFunction() @ 0x000000001cf13bb2
27. ../contrib/llvm-project/libcxx/include/__functional/function.h:502:12: ? @ 0x00000000117ada89
28. ../contrib/llvm-project/libcxx/include/__functional/function.h:502:12: ? @ 0x00000000117b67cb
29. ../contrib/llvm-project/libcxx/include/__functional/function.h:502:12: ? @ 0x00000000117aacfc
30. ../contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: void* std::__thread_proxy[abi:sqe220101]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x00000000117b3cce
31. start_thread @ 0x0000000000094ac3

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5422432]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, parallel) FAIL
01730_distributed_group_by_no_merge_order_by_long FAIL cidb
AST fuzzer (arm_asan_ubsan) FAIL
Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0) FAIL cidb, issue

AI Review

Summary

This PR skips performRequiredConversions for columns already treated as dropped by a pending mutation, which addresses the straight DROP/ADD-without-DEFAULT path described in the PR. The same stale-data invariant is still broken once a RENAME COLUMN participates in the chain, so the change is not mergeable yet.

Findings

❌ Blockers

  • [src/Storages/MergeTree/IMergeTreeReader.cpp:94-106,339-345,416-417; src/Storages/MergeTree/MergeTreeBlockReadUtils.cpp:105-119] [dismissed by author -- https://github.com/Fix logic error which leads endless mutation failures. #109860#discussion_r3550139928] The dropped-column check is still keyed on the old on-disk name after rename_map resolution instead of the logical requested name. With RENAME COLUMN a TO b; DROP COLUMN b; ADD COLUMN b UInt64, dropped_columns contains b, but both isColumnDroppedByPendingMutation and injectRequiredColumnsRecursively query a, so the reader keeps stale a data and treats the re-added b as if it still existed in the part. That violates the same "ignore pre-drop data for a re-added column" contract this PR is trying to restore and can still produce wrong results for rename chains.
    Suggested fix: resolve dropped-ness against the logical/requested name, or teach AlterConversions::isColumnDropped to normalize through rename_map, in both the reader path and injectRequiredColumnsRecursively, then add a focused regression test for the rename/drop/re-add sequence.
Final Verdict
  • Status: ❌ Block
  • Minimum required actions: fix the rename-chain case above in both read paths and add a regression test that exercises RENAME COLUMN a TO b; DROP COLUMN b; ADD COLUMN b UInt64.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 9, 2026
{
if (res_columns[pos] == nullptr)
continue;
if (isColumnDroppedByPendingMutation(pos))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still misses rename chains. isColumnDroppedByPendingMutation ends up checking dropped_columns against columns_to_read[pos].getNameInStorage(), i.e. the old on-disk name after getColumnInPart has followed rename_map. With RENAME COLUMN a TO b; DROP COLUMN b; ADD COLUMN b UInt64, dropped_columns contains b but this path queries a, so the reader keeps the stale a data and performRequiredConversions casts it into the re-added b instead of treating b as missing/defaulted. Could we base the dropped check on the requested/logical column name, or make AlterConversions::isColumnDropped resolve old names through rename_map first, and add a regression test for that sequence?

@RinChanNOWWW RinChanNOWWW Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deal with RENAME is quite complicated. This PR won't fix this. I'll create a new issue about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deal with RENAME is quite complicated. This PR is won't fix this. I'll create a new issue about it.

#109957

@clickhouse-gh

clickhouse-gh Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 78.00% +0.10%

Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). label Jul 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @scanhex12

Hey @groeneai, please investigate the root cause of this crash, verify whether @scanhex12 is the right person to fix it, and suggest a solution.

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated the root cause.

Root cause. During a squashed mutation the part is read while a DROP COLUMN is still pending. In IMergeTreeReader:

  1. isColumnDroppedByPendingMutation(pos) is true, so the reader skips reading the column and leaves res_columns[pos] = nullptr.
  2. fillMissingColumns sees no DEFAULT and fills the column with the default of the requested (current-schema) type (UInt64 zero).
  3. performRequiredConversions (IMergeTreeReader.cpp) then sees res_columns[pos] is non-null, calls getColumnInPart which returns the part's stored type (Nullable(Int32)), and builds the block with that type over the just-filled UInt64 data.
  4. The conversion action ifNull(extra, 0) is typed for Int32 but the actual column is UInt64 -> Unexpected return type from ifNull. Expected Int32. Got UInt64 (a LOGICAL_ERROR exception, so it is caught in release but aborts under debug/sanitizer, and the mutation retries endlessly).

The broken assumption is that a non-null res_columns entry was read from the part and therefore matches getColumnInPart's type. That does not hold for a column skipped by a pending DROP and then filled by fillMissingColumns with the requested type.

On the fix. Skipping performRequiredConversions for isColumnDroppedByPendingMutation(pos) columns is the right narrow fix for the plain DROP COLUMN + re-ADD (different type, no DEFAULT) chain, and the added test covers it.

Remaining gap (out of scope here, tracked in #109957). The rename chain RENAME a TO b; DROP b; ADD b UInt64 is still broken: the dropped-ness check keys on the storage name (columns_to_read[pos].getNameInStorage()), which does not line up with dropped_columns once rename_map is involved, so the reader keeps the stale old-column data and casts it into the re-added column. The #109957 repro (Cannot parse string 'hello' as UInt64) is direct evidence: the old a String data is being cast to the re-added b UInt64 instead of defaulted. A complete fix would resolve dropped-ness against the logical/requested name (or normalize through rename_map in AlterConversions::isColumnDropped) in both the reader path and injectRequiredColumnsRecursively, plus a rename-chain regression test.

Owner. comp-mutations is correct, and scanhex12 is a valid owner for it (comp-mutations experts: Michicosun, scanhex12, CurtizJ, alesapin).

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @Michicosun

Hey @groeneai, please investigate the root cause of this crash, verify whether @Michicosun is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @scanhex12

Hey @groeneai, please investigate the root cause of this crash, verify whether @scanhex12 is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

2 similar comments
@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @CurtizJ

Hey @groeneai, please investigate the root cause of this crash, verify whether @CurtizJ is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @scanhex12

Hey @groeneai, please investigate the root cause of this crash, verify whether @scanhex12 is the right person to fix it, and suggest a solution.

2 similar comments
@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @scanhex12

Hey @groeneai, please investigate the root cause of this crash, verify whether @scanhex12 is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @scanhex12

Hey @groeneai, please investigate the root cause of this crash, verify whether @scanhex12 is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @CurtizJ

Hey @groeneai, please investigate the root cause of this crash, verify whether @CurtizJ is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @scanhex12

Hey @groeneai, please investigate the root cause of this crash, verify whether @scanhex12 is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @CurtizJ

Hey @groeneai, please investigate the root cause of this crash, verify whether @CurtizJ is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @Michicosun

Hey @groeneai, please investigate the root cause of this crash, verify whether @Michicosun is the right person to fix it, and suggest a solution.

1 similar comment
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @Michicosun

Hey @groeneai, please investigate the root cause of this crash, verify whether @Michicosun is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @Michicosun

Hey @groeneai, please investigate the root cause of this crash, verify whether @Michicosun is the right person to fix it, and suggest a solution.

@RinChanNOWWW

Copy link
Copy Markdown
Contributor Author

The robot seems to be stuck in an infinite loop. Can someone fix it? @alexey-milovidov @scanhex12

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @CurtizJ

Hey @groeneai, please investigate the root cause of this crash, verify whether @CurtizJ is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @Michicosun

Hey @groeneai, please investigate the root cause of this crash, verify whether @Michicosun is the right person to fix it, and suggest a solution.

1 similar comment
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @Michicosun

Hey @groeneai, please investigate the root cause of this crash, verify whether @Michicosun is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @scanhex12

Hey @groeneai, please investigate the root cause of this crash, verify whether @scanhex12 is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @alesapin

Hey @groeneai, please investigate the root cause of this crash, verify whether @alesapin is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🎉 Crash classifier applied: comp-mutations, the issue goes to @CurtizJ

Hey @groeneai, please investigate the root cause of this crash, verify whether @CurtizJ is the right person to fix it, and suggest a solution.

@clickhouse-gh

clickhouse-gh Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Dear @Michicosun, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants