Deep `WHERE` clause overflow stack in `select_to_plan` via derived `expr::clone`
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
Planning a `SELECT` with a long `OR`/`AND` chain in `WHERE` aborts with a stack overflow.
Snippet from the stack trace via GDB:
```
#31430 0x00005555589da229 in datafusion_expr::expr::{impl#96}::clone (self=0x7ffffff96ea8) at datafusion/expr/src/expr.rs:774
#31431 0x00005555589d9211 in datafusion_expr::expr::{impl#66}::clone (self=0x7ffffff96ea0) at datafusion/expr/src/expr.rs:336
#31432 0x0000555558950527 in datafusion_expr::logical_plan::plan::{impl#90}::clone (self=0x7ffffff96ea0) at datafusion/expr/src/logical_plan/plan.rs:2618
#31433 0x0000555558951c49 in datafusion_expr::logical_plan::plan::{impl#53}::clone (self=0x7ffffff96e90) at datafusion/expr/src/logical_plan/plan.rs:222
#31434 0x000055555886eeaf in datafusion_sql::planner::SqlToRel<...>::select_to_plan<...> (...) at datafusion/sql/src/select.rs:141
#31435 0x0000555558867976 in datafusion_sql::planner::SqlToRel<...>::query_to_plan<...> (...) at datafusion/sql/src/query.rs:75
```
### To Reproduce
```
printf 'CREATE TABLE t AS SELECT 1 AS col;\nSELECT count(*) FROM t WHERE ' > repro.sql
seq -s ' OR ' -f 'col = %g' 0 19999 >> repro.sql; printf ';\n' >> repro.sql
datafusion-cli -f repro.sql
```
### Expected behavior
We should gracefully fail returning a planning error. Not crash.
Contributor guide
Assessment
This issue has not been assessed yet.