Skip to content

Logical Error: Block structure mismatch in UnionStep stream (due to a projection) #83614

Closed as duplicate

Description

@PedroTadim

Important: This issue was automatically generated and is used by CI for matching failures. DO NOT modify the body content. DO NOT remove labels.

Test name: Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6)
CI report: AST fuzzer (amd_debug)
CIDB statistics: cidb

Describe the bug

From this run: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=83596&sha=26956394811f37c8273cbdb30bf4cfd2d44464f5&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 Happens since v25.1. For some reason, the projection is not used in versions prior to that one.

How to reproduce

Simplified in this Fiddle: https://fiddle.clickhouse.com/2bdd510b-aded-43e3-8ab1-17014977341b

Error message and/or stacktrace

Stack trace:

<Fatal> : Logical error: 'Block structure mismatch in UnionStep stream: different number of columns:
i Int32 Int32(size = 0)
'.
<Fatal> : Stack trace (when copying this message, always include the lines below):

0. std::exception::exception[abi:ne190107]() @ 0x0000000019b82054
1. ci/tmp/build/./base/poco/Foundation/src/Exception.cpp:27: Poco::Exception::Exception(String const&, int) @ 0x000000003e3612c0
2. ci/tmp/build/./src/Common/Exception.cpp:115: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x0000000027bff70b
3. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000019a24116
4. src/Common/Exception.h:137: void DB::checkBlockStructure<void>(DB::Block const&, DB::Block const&, std::basic_string_view<char, std::char_traits<char>>, bool) @ 0x00000000309bbafa
5. ci/tmp/build/./src/Processors/QueryPlan/UnionStep.cpp:26: DB::UnionStep::updateOutputHeader() @ 0x00000000385049cc
6. ci/tmp/build/./src/Processors/QueryPlan/UnionStep.cpp:34: DB::UnionStep::UnionStep(std::vector<DB::Block, std::allocator<DB::Block>>, unsigned long) @ 0x000000003850480b
7. contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:634: std::__unique_if<DB::UnionStep>::__unique_single std::make_unique[abi:ne190107]<DB::UnionStep, std::vector<DB::Block, std::allocator<DB::Block>>>(std::vector<DB::Block, std::allocator<DB::Block>>&&) @ 0x000000003859b85a
8. ci/tmp/build/./src/Processors/QueryPlan/Optimizations/optimizeUseNormalProjection.cpp:415: DB::QueryPlanOptimizations::optimizeUseNormalProjections(std::vector<DB::QueryPlanOptimizations::Frame, std::allocator<DB::QueryPlanOptimizations::Frame>>&, std::list<DB::QueryPlan::Node, std::allocator<DB::QueryPlan::Node>>&) @ 0x0000000038598f34
9. ci/tmp/build/./src/Processors/QueryPlan/Optimizations/optimizeTree.cpp:265: DB::QueryPlanOptimizations::optimizeTreeSecondPass(DB::QueryPlanOptimizationSettings const&, DB::QueryPlan::Node&, std::list<DB::QueryPlan::Node, std::allocator<DB::QueryPlan::Node>>&, DB::QueryPlan&) @ 0x000000003851d45a
10. ci/tmp/build/./src/Processors/QueryPlan/QueryPlan.cpp:496: DB::QueryPlan::optimize(DB::QueryPlanOptimizationSettings const&) @ 0x00000000383c1a84
11. ci/tmp/build/./src/Processors/QueryPlan/QueryPlan.cpp:175: DB::QueryPlan::buildQueryPipeline(DB::QueryPlanOptimizationSettings const&, DB::BuildQueryPipelineSettings const&, bool) @ 0x00000000383c1097
12. ci/tmp/build/./src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:289: DB::InterpreterSelectQueryAnalyzer::buildQueryPipeline() @ 0x0000000032c2ac33
13. ci/tmp/build/./src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:256: DB::InterpreterSelectQueryAnalyzer::execute() @ 0x0000000032c2a806
14. ci/tmp/build/./src/Interpreters/executeQuery.cpp:1561: DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*, std::shared_ptr<DB::IAST>&, std::shared_ptr<DB::ImplicitTransactionControlExecutor>) @ 0x00000000330f1f5b
15. ci/tmp/build/./src/Interpreters/executeQuery.cpp:1769: DB::executeQuery(String const&, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum) @ 0x00000000330eba7c
16. ci/tmp/build/./src/Server/TCPHandler.cpp:723: DB::TCPHandler::runImpl() @ 0x000000003779b111
17. ci/tmp/build/./src/Server/TCPHandler.cpp:2730: DB::TCPHandler::run() @ 0x00000000377cd1cd
18. ci/tmp/build/./base/poco/Net/src/TCPServerConnection.cpp:40: Poco::Net::TCPServerConnection::start() @ 0x000000003e48fe42
19. ci/tmp/build/./base/poco/Net/src/TCPServerDispatcher.cpp:115: Poco::Net::TCPServerDispatcher::run() @ 0x000000003e490b12
20. ci/tmp/build/./base/poco/Foundation/src/ThreadPool.cpp:205: Poco::PooledThread::run() @ 0x000000003e3f5d17
21. base/poco/Foundation/src/Thread_POSIX.cpp:341: Poco::ThreadImpl::runnableEntry(void*) @ 0x000000003e3f156e
22. start_thread @ 0x00000000000a2ef1
23. __clone3 @ 0x000000000013445c

Activity

  1. added
    bugConfirmed user-visible misbehaviour in official release
    fuzzProblem found by one of the fuzzers
    comp-projectionsProjections: precomputed layouts for accelerating queries (projection parts, maintenance).
    on Jul 11, 2025
  2. added
    testingSpecial issue with list of bugs found by CI
    on Jan 5, 2026
  3. devcrafter commented on Jan 26, 2026

    @devcrafter
    Member

    Test name: Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6)
    CI report: AST fuzzer (amd_debug)

    @PedroTadim Actually, the report refers to query execution with parallel replicas. The Block structure mismatch in UnionStep stream error can occur for different reasons, but this one is reproduced during execution with parallel replicas.

  4. devcrafter commented on Jan 26, 2026

    @devcrafter
    Member

    It's happening with enabled parallel replicas and lazy materialization, ... and function in projection (in example below, greater())

    SELECT length(thread_ids) > 0                                                                                                                                                
    FROM system.query_log                                                               
    WHERE (current_database = currentDatabase()) AND (event_date >= (today() - 1)) AND (lower(query) LIKE '%select sum(number) from remote(_127.0.0.{1|2}_, numbers_mt(1000000)) group by number %') AND (type = 'QueryFinish')                                                                                                                                                                                                            
    ORDER BY query_start_time DESC                                                      
    LIMIT 1

    Changing length(thread_ids) > 0 to length(thread_ids) makes the query working i.e.

    SELECT length(thread_ids)                                                                                                                                                
    FROM system.query_log                                                               
    WHERE (current_database = currentDatabase()) AND (event_date >= (today() - 1)) AND (lower(query) LIKE '%select sum(number) from remote(_127.0.0.{1|2}_, numbers_mt(1000000)) group by number %') AND (type = 'QueryFinish')                                                                                                                                                                                                            
    ORDER BY query_start_time DESC                                                      
    LIMIT 1

    Also, removing any condition from WHERE makes it working too

    Explain for failing query
    https://pastila.clickhouse.com/?000f2592/b349a2d000373ad6aa6f8edeb4969ed1#aH8cdGiiKMet4ijPLWQP2Q==GCM

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed user-visible misbehaviour in official releasecomp-projectionsProjections: precomputed layouts for accelerating queries (projection parts, maintenance).fuzzProblem found by one of the fuzzersred CIVERY flaky testtestingSpecial issue with list of bugs found by CI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions