Skip to content

Recursive CTE: Logical error: '' is not recursive #64571

@Algunenano

Description

@Algunenano

https://s3.amazonaws.com/clickhouse-test-reports/0/2f1fb6c5d83d08e904dae1e1e8d4bd2297d2a0f3/ast_fuzzer__msan_.html

CREATE TABLE department__fuzz_0
(
    `id` UInt64,
    `parent_department` Decimal(76, 43),
    `name` String
)
ENGINE = TinyLog
INSERT INTO department__fuzz_0 FORMAT Values
(0, NULL, 'ROOT');
WITH RECURSIVE q AS
    (
        SELECT *
        FROM department__fuzz_0
        UNION ALL
        (
            WITH RECURSIVE x AS
                (
                    SELECT *
                    FROM department__fuzz_0
                    UNION ALL
                    (
                        SELECT *
                        FROM q
                        WHERE least(toFixedString('world', 5), 5, 5, inf, 58, nan, NULL)
                        UNION ALL
                        SELECT *
                        FROM x
                        WHERE sipHash128(toLowCardinality('world'), toLowCardinality(materialize(5)), toUInt128(greatest(1, nan, NULL), toUInt128(5)), toUInt128(5), 5, toUInt128(5), materialize(5))
                    )
                )
            SELECT *
            FROM x
        )
    )
SELECT 1
FROM q
LIMIT 32
← Progress: 0.00 rows, 0.00 B (0.00 rows/s., 0.00 B/s.)                                                                                                                                                                                                                                 2024.05.29 11:55:31.793455 [ 9772 ] {2b54282f-075b-4b9d-bc0f-84b6c4ed6141} <Fatal> : Logical error: 'UNION query x AS (SELECT * FROM department__fuzz_0 UNION ALL SELECT * FROM q WHERE least(toFixedString('world', 5), 5, 5, inf, 58, nan, NULL) UNION ALL SELECT * FROM x WHERE sipHash128(toLowCardinality('world'), toLowCardinality(materialize(5)), toUInt128(greatest(1, nan, NULL), toUInt128(5)), toUInt128(5), 5, toUInt128(5), materialize(5))) is not recursive'.
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x000072f049589eb3 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78
#2  0x000072f049531a30 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x000072f0495194c3 in __GI_abort () at abort.c:79
#4  0x0000000013e7465a in DB::abortOnFailedAssertion (description=...) at /mnt/ch/ClickHouse/src/Common/Exception.cpp:44
#5  0x0000000013e74815 in DB::handle_error_code (msg=..., code=49, remote=false, trace=...) at /mnt/ch/ClickHouse/src/Common/Exception.cpp:61
#6  0x0000000013e74eb1 in DB::Exception::Exception (this=0x72f043e4c480, msg_masked=..., code=49, remote_=false) at /mnt/ch/ClickHouse/src/Common/Exception.cpp:105
#7  0x000000000ac41b57 in DB::Exception::Exception (this=0x72f043e4c480, msg=..., code=49, remote_=false) at /mnt/ch/ClickHouse/src/Common/Exception.h:95
#8  0x000000000ac3ed09 in DB::Exception::Exception (this=0x72f043e4c480, msg=..., code=49) at /mnt/ch/ClickHouse/src/Common/Exception.h:66
#9  0x000000000ac3ea72 in DB::Exception::Exception<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > (this=0x72f043e4c480, code=49, fmt=..., args=...) at /mnt/ch/ClickHouse/src/Common/Exception.h:113
#10 0x0000000020283ef6 in DB::RecursiveCTEChunkGenerator::RecursiveCTEChunkGenerator (this=0x72f043f2b280, header_=..., recursive_cte_union_node_=...) at /mnt/ch/ClickHouse/src/Processors/Sources/RecursiveCTESource.cpp:74
#11 0x0000000020281e9b in std::__1::make_unique[abi:v15000]<DB::RecursiveCTEChunkGenerator, DB::Block, std::__1::shared_ptr<DB::IQueryTreeNode> >(DB::Block&&, std::__1::shared_ptr<DB::IQueryTreeNode>&&) (__args=..., __args=...)
    at /mnt/ch/ClickHouse/contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:714
#12 0x00000000202818bc in DB::RecursiveCTESource::RecursiveCTESource (this=0x72f043e5c918, header=..., recursive_cte_union_node_=...) at /mnt/ch/ClickHouse/src/Processors/Sources/RecursiveCTESource.cpp:249
#13 0x0000000020281561 in std::__1::construct_at[abi:v15000]<DB::RecursiveCTESource, DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&, DB::RecursiveCTESource*>(DB::RecursiveCTESource*, DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&) (
    __location=0x72f043e5c918, __args=..., __args=...) at /mnt/ch/ClickHouse/contrib/llvm-project/libcxx/include/__memory/construct_at.h:35
#14 0x0000000020281289 in std::__1::allocator_traits<std::__1::allocator<DB::RecursiveCTESource> >::construct[abi:v15000]<DB::RecursiveCTESource, DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&, void, void>(std::__1::allocator<DB::RecursiveCTESource>&, DB::RecursiveCTESource*, DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&) (__p=0x72f043e5c918, __args=..., __args=...) at /mnt/ch/ClickHouse/contrib/llvm-project/libcxx/include/__memory/allocator_traits.h:298
#15 0x0000000020280f3c in std::__1::__shared_ptr_emplace<DB::RecursiveCTESource, std::__1::allocator<DB::RecursiveCTESource> >::__shared_ptr_emplace[abi:v15000]<DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&>(DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&) (this=0x72f043e5c900, __a=..., __args=..., __args=...) at /mnt/ch/ClickHouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:292
#16 0x0000000020280d2f in std::__1::allocate_shared[abi:v15000]<DB::RecursiveCTESource, std::__1::allocator<DB::RecursiveCTESource>, DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&, void>(std::__1::allocator<DB::RecursiveCTESource> const&, DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&) (__a=..., __args=..., __args=...) at /mnt/ch/ClickHouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:953
#17 0x0000000020280b5b in std::__1::make_shared[abi:v15000]<DB::RecursiveCTESource, DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&, void>(DB::Block const&, std::__1::shared_ptr<DB::IQueryTreeNode>&) (__args=..., __args=...)
    at /mnt/ch/ClickHouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:962
#18 0x0000000020280a04 in DB::ReadFromRecursiveCTEStep::initializePipeline (this=0x72f043eb1500, pipeline=...) at /mnt/ch/ClickHouse/src/Processors/QueryPlan/ReadFromRecursiveCTEStep.cpp:17
#19 0x0000000020183e80 in DB::ISourceStep::updatePipeline (this=0x72f043eb1500, settings=...) at /mnt/ch/ClickHouse/src/Processors/QueryPlan/ISourceStep.cpp:20
#20 0x00000000201ade31 in DB::QueryPlan::buildQueryPipeline (this=0x72f043e5c218, optimization_settings=..., build_pipeline_settings=...) at /mnt/ch/ClickHouse/src/Processors/QueryPlan/QueryPlan.cpp:188
#21 0x000000001d4a3e46 in DB::InterpreterSelectQueryAnalyzer::buildQueryPipeline (this=0x72f043e5c180) at /mnt/ch/ClickHouse/src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:252
#22 0x0000000020282701 in DB::RecursiveCTEChunkGenerator::buildStepExecutor (this=0x72f045733b00) at /mnt/ch/ClickHouse/src/Processors/Sources/RecursiveCTESource.cpp:181
#23 0x0000000020282039 in DB::RecursiveCTEChunkGenerator::generate (this=0x72f045733b00) at /mnt/ch/ClickHouse/src/Processors/Sources/RecursiveCTESource.cpp:124
#24 0x0000000020281a37 in DB::RecursiveCTESource::generate (this=0x72f0456e0998) at /mnt/ch/ClickHouse/src/Processors/Sources/RecursiveCTESource.cpp:256
#25 0x000000001f883980 in DB::ISource::tryGenerate (this=0x72f0456e0998) at /mnt/ch/ClickHouse/src/Processors/ISource.cpp:139
#26 0x000000001f8835c3 in DB::ISource::work (this=0x72f0456e0998) at /mnt/ch/ClickHouse/src/Processors/ISource.cpp:108
#27 0x000000001f8c6339 in DB::executeJob (node=0x72f045488400, read_progress_callback=0x72f047791a50) at /mnt/ch/ClickHouse/src/Processors/Executors/ExecutionThreadContext.cpp:47
#28 0x000000001f8c6001 in DB::ExecutionThreadContext::executeTask (this=0x72f043e89000) at /mnt/ch/ClickHouse/src/Processors/Executors/ExecutionThreadContext.cpp:96
#29 0x000000001f8a499e in DB::PipelineExecutor::executeStepImpl (this=0x72f045477d98, thread_num=0, yield_flag=0x0) at /mnt/ch/ClickHouse/src/Processors/Executors/PipelineExecutor.cpp:272
#30 0x000000001f8a4dc4 in DB::PipelineExecutor::executeSingleThread (this=0x72f045477d98, thread_num=0) at /mnt/ch/ClickHouse/src/Processors/Executors/PipelineExecutor.cpp:238
#31 0x000000001f8a37c5 in DB::PipelineExecutor::executeImpl (this=0x72f045477d98, num_threads=1, concurrency_control=false) at /mnt/ch/ClickHouse/src/Processors/Executors/PipelineExecutor.cpp:410
#32 0x000000001f8a2c5a in DB::PipelineExecutor::execute (this=0x72f045477d98, num_threads=1, concurrency_control=false) at /mnt/ch/ClickHouse/src/Processors/Executors/PipelineExecutor.cpp:110
#33 0x000000001f8cd9f2 in DB::threadFunction (data=..., thread_group=..., num_threads=1, concurrency_control=false) at /mnt/ch/ClickHouse/src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:83

Metadata

Metadata

Assignees

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