Skip to content

Another Unexpected return type from equals. Expected Nullable(UInt8). Got UInt8 #89802

Closed

Description

@PedroTadim

Describe the bug

This one happens since v25.5 with set index, and with query_plan_merge_expressions = 0. It may be different from the others.

How to reproduce

Run Fiddle: https://fiddle.clickhouse.com/6dc1980e-30b2-4082-b570-5ef45287afc9

Error message and/or stacktrace

Stack trace:

<Fatal> : Logical error: 'Unexpected return type from equals. Expected Nullable(UInt8). Got UInt8. Action:
FUNCTION equals(c0 :: 0, 0 :: 1) -> equals(c0, 0) Nullable(UInt8) : 2,
input block structure:c0 Int32 Int32(size = 1), 0 UInt8 Const(size = 1, UInt8(size = 1))'.
<Fatal> : Stack trace (when copying this message, always include the lines below):

0. contrib/llvm-project/libcxx/include/__exception/exception.h:113: Poco::Exception::Exception(String const&, int) @ 0x0000000024ab61f2
1. src/Common/Exception.cpp:129: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x0000000014fc97e9
2. src/Common/Exception.h:123: DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000d55fcce
3. src/Common/Exception.h:58: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000d55f6d1
4. src/Common/Exception.h:141: 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&&) @ 0x000000000fc6e004
5. src/Interpreters/ExpressionActions.cpp:696: DB::ExpressionActions::execute(DB::Block&, unsigned long&, bool, bool) const @ 0x000000001ac80cc0
6. src/Interpreters/ExpressionActions.cpp:882: DB::ExpressionActions::execute(DB::Block&, bool, bool) const @ 0x000000001ac81346
7. src/Storages/MergeTree/MergeTreeIndexSet.cpp:452: DB::MergeTreeIndexConditionSet::getPossibleGranules(std::shared_ptr<DB::IMergeTreeIndexBulkGranules> const&) const @ 0x000000001e4c1c30
8. src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:1815: DB::MergeTreeDataSelectExecutor::filterMarksUsingIndex(std::shared_ptr<DB::IMergeTreeIndex const>, std::shared_ptr<DB::IMergeTreeIndexCondition>, std::shared_ptr<DB::IMergeTreeDataPart const>, DB::MarkRanges const&, DB::RangesInDataPartReadHints const&, DB::MergeTreeReaderSettings const&, DB::MarkCache*, DB::UncompressedCache*, DB::VectorSimilarityIndexCache*, std::shared_ptr<Poco::Logger>) @ 0x000000001e454924
9. src/Storages/MergeTree/MergeTreeIndexReadResultPool.cpp:57: DB::MergeTreeSkipIndexReader::read(DB::RangesInDataPart const&) @ 0x000000001e572504
10. src/Storages/MergeTree/MergeTreeIndexReadResultPool.cpp:461: DB::MergeTreeIndexReadResultPool::getOrBuildIndexReadResult(DB::RangesInDataPart const&, DB::RangesInDataParts const&) @ 0x000000001e574234
11. src/Storages/MergeTree/MergeTreeSelectProcessor.cpp:112: DB::MergeTreeIndexBuildContext::getPreparedIndexReadResult(DB::MergeTreeReadTask const&) const @ 0x000000001e56c4fd
12. src/Storages/MergeTree/MergeTreeReadTask.cpp:272: DB::MergeTreeReadTask::initializeIndexReader(DB::MergeTreeIndexBuildContext const&) @ 0x000000001e55fe1b
13. src/Storages/MergeTree/MergeTreeReadTask.cpp:256: DB::MergeTreeReadTask::initializeReadersChain(DB::PrewhereExprInfo const&, std::shared_ptr<DB::MergeTreeIndexBuildContext>, DB::ReadStepsPerformanceCounters&) @ 0x000000001e55fb1f
14. src/Storages/MergeTree/MergeTreeSelectProcessor.cpp:347: DB::MergeTreeSelectProcessor::read() @ 0x000000001e56ed4f
15. src/Storages/MergeTree/MergeTreeSource.cpp:229: DB::MergeTreeSource::tryGenerate() @ 0x000000001f1655e9
16. src/Processors/ISource.cpp:110: DB::ISource::work() @ 0x000000001eb826c2
17. src/Processors/Executors/ExecutionThreadContext.cpp:53: DB::ExecutionThreadContext::executeTask() @ 0x000000001eb9fad0
18. src/Processors/Executors/PipelineExecutor.cpp:351: DB::PipelineExecutor::executeStepImpl(unsigned long, DB::IAcquiredSlot*, std::atomic<bool>*) @ 0x000000001eb91858
19. src/Processors/Executors/PipelineExecutor.cpp:279: DB::PipelineExecutor::executeSingleThread(unsigned long, DB::IAcquiredSlot*) @ 0x000000001eb91e69
20. src/Processors/Executors/PipelineExecutor.cpp:602: DB::PipelineExecutor::executeImpl(unsigned long, bool) @ 0x000000001eb90761
21. src/Processors/Executors/PipelineExecutor.cpp:136: DB::PipelineExecutor::execute(unsigned long, bool) @ 0x000000001eb8fe7f
22. src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:76: void std::__function::__policy_invoker<void ()>::__call_impl[abi:se190107]<std::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::'lambda'(), void ()>>(std::__function::__policy_storage const*) @ 0x000000001eba7fe4
23. contrib/llvm-project/libcxx/include/__functional/function.h:716: ? @ 0x000000001510a6e6
24. contrib/llvm-project/libcxx/include/__type_traits/invoke.h:117: void* std::__thread_proxy[abi:se190107]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x0000000015111100
25. ? @ 0x00000000000a3d64
26. __clone3 @ 0x00000000001373bc

Version info

Activity

  1. added
    bug
    fuzz
    on Nov 10, 2025
  2. alexey-milovidov commented on Feb 11, 2026

    @alexey-milovidov
    Member

    Possibly related fix: #95098

  3. alexey-milovidov commented on Mar 2, 2026

    @alexey-milovidov
    Member

    Tested on current master (ed6302e) with clickhouse-local. The issue is still reproducible:

    SELECT 1 FROM v0 WHERE c0 = 0 SETTINGS query_plan_merge_expressions = 0;
    -- Code: 49. DB::Exception: Unexpected return type from equals.
    -- Expected Nullable(UInt8). Got UInt8. (LOGICAL_ERROR)
  4. PedroTadim commented on May 21, 2026

    @PedroTadim
    MemberAuthor

    @groeneai can you fix this?

  5. groeneai commented on May 21, 2026

    @groeneai
    Collaborator

    Filed a fix in #105552.

    Root cause: MergeTreeIndexConditionSet reused the predicate's equals function whose result_type was resolved against the MV layer's Nullable(Int32) input. The granule block carries the storage column at the storage type (Int32), so ExpressionActions::execute ran equals on (Int32, UInt8) -> UInt8 and failed the result-type invariant check against Nullable(UInt8).

    The fix looks up the granule type for each key column from index_description.sample_block, adds an INPUT of that type, and CASTs it back to the predicate's expected type before any downstream pre-resolved function reads it. Regression test added at tests/queries/0_stateless/04272_89802_set_index_mv_nullable_column_type.sql — without the fix the new test crashes the debug server; with it the test passes 30 consecutive runs and the existing 10 stateless set-index tests all pass.

  6. added a commit that references this issue on Jul 9, 2026
  7. added
    comp-skip-index
    on Jul 29, 2026
  8. added 2 commits that reference this issue on Jul 29, 2026
    3f45aa8
    e329276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcomp-skip-indexfuzz

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions