Skip to content

Logical error with suspicious LowCardinality: Function toInt256 with Null argument and default implementation for Nulls is expected to return Nullable result, got Int256 #72265

@CurtizJ

Description

@CurtizJ

Describe the bug
A link to the report

How to reproduce

SET allow_suspicious_low_cardinality_types = 1;
SET send_logs_level = 'error';

DROP TABLE IF EXISTS t_primary_index_cache__fuzz_15;

CREATE TABLE t_primary_index_cache__fuzz_15 (`a` LowCardinality(Nullable(Int64)), `b` UInt64) ENGINE = MergeTree PARTITION BY a % 2 ORDER BY a SETTINGS allow_nullable_key = 1, index_granularity = 64, index_granularity_bytes = '10M', min_bytes_for_wide_part = 0;

INSERT INTO t_primary_index_cache__fuzz_15 SELECT number, number FROM numbers(10000);

SELECT count() FROM t_primary_index_cache__fuzz_15 WHERE (a > 100) AND ((a % 2) = toUInt128(0));
<Error> executeQuery: Code: 49. DB::Exception: Function toInt256 with Null argument and default implementation for Nulls is expected to return Nullable result, got Int256. (LOGICAL_ERROR) (version 24.12.1.1) (from 127.0.0.1:57226) (in query: SELECT count() FROM t_primary_index_cache__fuzz_15 WHERE (a > 100) AND ((a % 2) = toUInt128(0));), Stack trace (when copying this message, always include the lines below):

0. ./contrib/llvm-project/libcxx/include/exception:141: Poco::Exception::Exception(String const&, int) @ 0x0000000014cd6072
1. ./build_clang/./src/Common/Exception.cpp:109: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000000ba81c99
2. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x00000000069b0f0c
3. DB::Exception::Exception<String, String>(int, FormatStringHelperImpl<std::type_identity<String>::type, std::type_identity<String>::type>, String&&, String&&) @ 0x00000000069b236b
4. DB::IExecutableFunction::defaultImplementationForNulls(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b0ba1
5. DB::IExecutableFunction::executeWithoutLowCardinalityColumns(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b029d
6. DB::IExecutableFunction::executeWithoutSparseColumns(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b12e2
7. DB::IExecutableFunction::execute(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b249b
8. DB::IFunctionBase::execute(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b28d9
9. COW<DB::IColumn>::immutable_ptr<DB::IColumn> std::__function::__policy_invoker<COW<DB::IColumn>::immutable_ptr<DB::IColumn> (std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long)>::__call_impl<std::__function::__default_alloc_func<DB::(anonymous namespace)::FunctionCast::createFunctionAdaptor(std::shared_ptr<DB::IFunction>, std::shared_ptr<DB::IDataType const> const&)::'lambda'(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long), COW<DB::IColumn>::immutable_ptr<DB::IColumn> (std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long)>>(std::__function::__policy_storage const*, std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long) @ 0x000000000f4411b6
10. COW<DB::IColumn>::immutable_ptr<DB::IColumn> std::__function::__policy_invoker<COW<DB::IColumn>::immutable_ptr<DB::IColumn> (std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long)>::__call_impl<std::__function::__default_alloc_func<DB::(anonymous namespace)::FunctionCast::prepareRemoveNullable(std::shared_ptr<DB::IDataType const> const&, std::shared_ptr<DB::IDataType const> const&, bool) const::'lambda'(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long), COW<DB::IColumn>::immutable_ptr<DB::IColumn> (std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long)>>(std::__function::__policy_storage const*, std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>>&, std::shared_ptr<DB::IDataType const> const&, DB::ColumnNullable const*, unsigned long) @ 0x000000000f5ec6e7
11. DB::(anonymous namespace)::ExecutableFunctionCast::executeImpl(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0x000000000f42007a
12. DB::IExecutableFunction::executeWithoutLowCardinalityColumns(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b02e5
13. DB::IExecutableFunction::defaultImplementationForConstantArguments(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3afedb
14. DB::IExecutableFunction::executeWithoutLowCardinalityColumns(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b0272
15. DB::IExecutableFunction::executeWithoutSparseColumns(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b11fb
16. DB::IExecutableFunction::execute(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b249b
17. DB::IFunctionBase::execute(std::vector<DB::ColumnWithTypeAndName, std::allocator<DB::ColumnWithTypeAndName>> const&, std::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x000000000f3b28d9
18. ./build_clang/./src/Storages/MergeTree/KeyCondition.cpp:909: DB::applyFunction(std::shared_ptr<DB::IFunctionBase const> const&, std::shared_ptr<DB::IDataType const> const&, DB::FieldRef const&) @ 0x0000000011f750dc
19. ./build_clang/./src/Storages/MergeTree/KeyCondition.cpp:2745: DB::KeyCondition::applyMonotonicFunctionsChainToRange(DB::Range, std::vector<std::shared_ptr<DB::IFunctionBase const>, std::allocator<std::shared_ptr<DB::IFunctionBase const>>> const&, std::shared_ptr<DB::IDataType const>, bool) @ 0x0000000011f74c37
20. ./build_clang/./src/Storages/MergeTree/KeyCondition.cpp:3046: DB::KeyCondition::checkInHyperrectangle(std::vector<DB::Range, std::allocator<DB::Range>> const&, std::vector<std::shared_ptr<DB::IDataType const>, std::allocator<std::shared_ptr<DB::IDataType const>>> const&) const @ 0x0000000011f7841a
21. ./build_clang/./src/Storages/MergeTree/KeyCondition.cpp:2708: DB::KeyCondition::checkInRange(unsigned long, DB::FieldRef const*, DB::FieldRef const*, std::vector<std::shared_ptr<DB::IDataType const>, std::allocator<std::shared_ptr<DB::IDataType const>>> const&, BoolMask) const @ 0x0000000011f7457a
22. ./build_clang/./src/Storages/MergeTree/KeyCondition.cpp:3290: DB::KeyCondition::mayBeTrueInRange(unsigned long, DB::FieldRef const*, DB::FieldRef const*, std::vector<std::shared_ptr<DB::IDataType const>, std::allocator<std::shared_ptr<DB::IDataType const>>> const&) const @ 0x0000000011f7a24e
23. ./build_clang/./src/Storages/MergeTree/PartitionPruner.cpp:37: DB::PartitionPruner::canBePruned(DB::IMergeTreeDataPart const&) const @ 0x00000000122562bc
24. ./build_clang/./src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:1621: DB::MergeTreeDataSelectExecutor::selectPartsToRead(std::vector<std::shared_ptr<DB::IMergeTreeDataPart const>, std::allocator<std::shared_ptr<DB::IMergeTreeDataPart const>>>&, std::optional<std::unordered_set<String, std::hash<String>, std::equal_to<String>, std::allocator<String>>> const&, std::optional<DB::KeyCondition> const&, std::vector<std::shared_ptr<DB::IDataType const>, std::allocator<std::shared_ptr<DB::IDataType const>>> const&, std::optional<DB::PartitionPruner> const&, std::unordered_map<String, long, std::hash<String>, std::equal_to<String>, std::allocator<std::pair<String const, long>>> const*, DB::MergeTreeDataSelectExecutor::PartFilterCounters&, std::shared_ptr<DB::QueryStatus>) @ 0x00000000120d3ab3
25. ./build_clang/./src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:581: DB::MergeTreeDataSelectExecutor::filterPartsByPartition(std::vector<std::shared_ptr<DB::IMergeTreeDataPart const>, std::allocator<std::shared_ptr<DB::IMergeTreeDataPart const>>>&, std::optional<DB::PartitionPruner> const&, std::optional<DB::KeyCondition> const&, std::optional<std::unordered_set<String, std::hash<String>, std::equal_to<String>, std::allocator<String>>> const&, std::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::MergeTreeData const&, std::shared_ptr<DB::Context const> const&, std::unordered_map<String, long, std::hash<String>, std::equal_to<String>, std::allocator<std::pair<String const, long>>> const*, std::shared_ptr<Poco::Logger>, std::vector<DB::ReadFromMergeTree::IndexStat, std::allocator<DB::ReadFromMergeTree::IndexStat>>&) @ 0x00000000120d22db
26. ./build_clang/./src/Processors/QueryPlan/ReadFromMergeTree.cpp:1736: DB::ReadFromMergeTree::selectRangesToRead(std::vector<std::shared_ptr<DB::IMergeTreeDataPart const>, std::allocator<std::shared_ptr<DB::IMergeTreeDataPart const>>>, std::shared_ptr<DB::MergeTreeData::IMutationsSnapshot const>, std::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo const&, std::shared_ptr<DB::Context const>, unsigned long, std::shared_ptr<std::unordered_map<String, long, std::hash<String>, std::equal_to<String>, std::allocator<std::pair<String const, long>>>>, DB::MergeTreeData const&, std::vector<String, std::allocator<String>> const&, std::shared_ptr<Poco::Logger>, std::optional<DB::ReadFromMergeTree::Indexes>&, bool) @ 0x0000000012a58b6d
27. ./build_clang/./src/Processors/QueryPlan/ReadFromMergeTree.cpp:1480: DB::ReadFromMergeTree::selectRangesToRead(std::vector<std::shared_ptr<DB::IMergeTreeDataPart const>, std::allocator<std::shared_ptr<DB::IMergeTreeDataPart const>>>, bool) const @ 0x0000000012a57f7b
28. ./build_clang/./src/Processors/QueryPlan/ReadFromMergeTree.cpp:1475: DB::ReadFromMergeTree::selectRangesToRead(bool) const @ 0x0000000012a57d88
29. ./build_clang/./src/Processors/QueryPlan/Optimizations/optimizeUseAggregateProjection.cpp:612: DB::QueryPlanOptimizations::optimizeUseAggregateProjections(DB::QueryPlan::Node&, std::list<DB::QueryPlan::Node, std::allocator<DB::QueryPlan::Node>>&, bool) @ 0x0000000012afa10d
30. ./build_clang/./src/Processors/QueryPlan/Optimizations/optimizeTree.cpp:164: DB::QueryPlanOptimizations::optimizeTreeSecondPass(DB::QueryPlanOptimizationSettings const&, DB::QueryPlan::Node&, std::list<DB::QueryPlan::Node, std::allocator<DB::QueryPlan::Node>>&) @ 0x0000000012ad99ec
31. ./build_clang/./src/Processors/QueryPlan/QueryPlan.cpp:471: DB::QueryPlan::buildQueryPipeline(DB::QueryPlanOptimizationSettings const&, DB::BuildQueryPipelineSettings const&) @ 0x0000000012a3ef3d
32. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    fuzzProblem found by one of the fuzzers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions