alamb opened a new issue, #9373: URL: https://github.com/apache/arrow-datafusion/issues/9373
### Describe the bug In InfluxDB we sometimes create deeply nested queries like this that cause a stack overflow, even in release builds: ### To Reproduce Download: [blowout.zip](https://github.com/apache/arrow-datafusion/files/14424888/blowout.zip) And run ```shell datafusion-cli -f blowout.sql ``` This results in ```shell andrewlamb@Andrews-MacBook-Pro Downloads % datafusion-cli -f blowout.sql datafusion-cli -f blowout.sql DataFusion CLI v36.0.0 thread 'main' has overflowed its stack fatal runtime error: stack overflow ``` The query looks like this ```sql SELECT (SELECT 1) UNION ALL (SELECT 1) UNION ALL (SELECT 1) UNION ALL (SELECT 1) .... (works with 2500 clauses, overflow with 3000) UNION ALL (SELECT 1) ``` ### Expected behavior a runtime error rather than stack overflow. Bonus points if the query actually completed ### Additional context It may be possible to change the treenode recursion to use an iterative approach rather than a recursive one (aka keep a worklist), much as we did in the sql parser to protect against deeply nested expressions In a debug build, the stack looks like this: ``` <sqlparser::ast::query::SetExpr as core::clone::Clone>::clone query.rs:89 <T as alloc::alloc::WriteCloneIntoRaw>::write_clone_into_raw alloc.rs:439 <alloc::boxed::Box<T,A> as core::clone::Clone>::clone boxed.rs:1305 .... Many more ... <T as alloc::alloc::WriteCloneIntoRaw>::write_clone_into_raw alloc.rs:439 <alloc::boxed::Box<T,A> as core::clone::Clone>::clone boxed.rs:1305 <sqlparser::ast::query::SetExpr as core::clone::Clone>::clone query.rs:102 <T as alloc::alloc::WriteCloneIntoRaw>::write_clone_into_raw alloc.rs:439 <alloc::boxed::Box<T,A> as core::clone::Clone>::clone boxed.rs:1305 <sqlparser::ast::query::SetExpr as core::clone::Clone>::clone query.rs:102 <T as alloc::alloc::WriteCloneIntoRaw>::write_clone_into_raw alloc.rs:439 <alloc::boxed::Box<T,A> as core::clone::Clone>::clone boxed.rs:1305 <sqlparser::ast::query::SetExpr as core::clone::Clone>::clone query.rs:102 <T as alloc::alloc::WriteCloneIntoRaw>::write_clone_into_raw alloc.rs:439 <alloc::boxed::Box<T,A> as core::clone::Clone>::clone boxed.rs:1305 <sqlparser::ast::query::SetExpr as core::clone::Clone>::clone query.rs:102 <T as alloc::alloc::WriteCloneIntoRaw>::write_clone_into_raw alloc.rs:439 <alloc::boxed::Box<T,A> as core::clone::Clone>::clone boxed.rs:1305 datafusion_sql::query::<impl datafusion_sql::planner::SqlToRel<S>>::query_to_plan_with_schema query.rs:190 datafusion_sql::query::<impl datafusion_sql::planner::SqlToRel<S>>::query_to_plan query.rs:43 datafusion_sql::statement::<impl datafusion_sql::planner::SqlToRel<S>>::sql_statement_to_plan_with_context_impl statement.rs:193 datafusion_sql::statement::<impl datafusion_sql::planner::SqlToRel<S>>::sql_statement_to_plan statement.rs:157 datafusion_sql::statement::<impl datafusion_sql::planner::SqlToRel<S>>::statement_to_plan statement.rs:145 datafusion::execution::context::SessionState::statement_to_plan::{{closure}} mod.rs:1731 datafusion_cli::exec::create_plan::{{closure}} exec.rs:257 datafusion_cli::exec::exec_and_print::{{closure}} exec.rs:222 datafusion_cli::exec::exec_from_lines::{{closure}} exec.rs:80 datafusion_cli::exec::exec_from_files::{{closure}} exec.rs:116 datafusion_cli::main_inner::{{closure}} main.rs:244 datafusion_cli::main::{{closure}} main.rs:147 tokio::runtime::park::CachedParkThread::block_on::{{closure}} park.rs:281 [Inlined] tokio::runtime::coop::with_budget coop.rs:107 [Inlined] tokio::runtime::coop::budget coop.rs:73 tokio::runtime::park::CachedParkThread::block_on park.rs:281 tokio::runtime::context::blocking::BlockingRegionGuard::block_on blocking.rs:66 tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}} mod.rs:87 tokio::runtime::context::runtime::enter_runtime runtime.rs:65 tokio::runtime::scheduler::multi_thread::MultiThread::block_on mod.rs:86 tokio::runtime::runtime::Runtime::block_on runtime.rs:350 datafusion_cli::main main.rs:147 core::ops::function::FnOnce::call_once function.rs:250 std::sys_common::backtrace::__rust_begin_short_backtrace backtrace.rs:155 std::rt::lang_start::{{closure}} rt.rs:166 [Inlined] core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once function.rs:284 [Inlined] std::panicking::try::do_call panicking.rs:552 [Inlined] std::panicking::try panicking.rs:516 [Inlined] std::panic::catch_unwind panic.rs:142 [Inlined] std::rt::lang_start_internal::{{closure}} rt.rs:148 [Inlined] std::panicking::try::do_call panicking.rs:552 [Inlined] std::panicking::try panicking.rs:516 [Inlined] std::panic::catch_unwind panic.rs:142 std::rt::lang_start_internal rt.rs:148 std::rt::lang_start rt.rs:165 main 0x000000010096d084 start 0x00000001825fd0e0 ``` I am not really sure how to solve this 🤔 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
