colinmarc opened a new issue, #27949:
URL: https://github.com/apache/datafusion/issues/27949

   ### Describe the bug
   
   `TypeCoercionRewriter::coerce_binary_op` calls `get_type` on both sides for 
every
   `BinaryExpr`:
   
   
https://github.com/apache/datafusion/blob/0aa2005667d5f529a2eb13bfd4e25151a338d823/datafusion/optimizer/src/analyzer/type_coercion.rs#L532-L533
   
   If you construct a long enough chain of binary expressions, this blows up 
pretty quick.
   
   ### To Reproduce
   
   ```rust
   use std::time::Instant;
   use datafusion::prelude::*;
   
   #[tokio::main(flavor = "current_thread")]
   async fn main() -> datafusion::error::Result<()> {
       let ctx = SessionContext::new();
       ctx.sql("CREATE TABLE t (x DOUBLE)").await?;
   
       for n in [1000, 2000, 5000] {
           let sql = format!("SELECT x{} FROM t", " + 1".repeat(n));
           let start = Instant::now();
           ctx.sql(&sql).await?.into_optimized_plan()?;
           println!("n={n}: {:?}", start.elapsed());
       }
   
       Ok(())
   }
   ```
   
   On my MBP:
   
   ```
   | n | SQL size | time |
   |---|---|---|
   | 1,000 | ~4 KB | 0.42 s |
   | 2,000 | ~8 KB | 1.59 s |
   | 5,000 | ~20 KB | 9.95 s |
   ```
   
   Anything higher causes a stack overflow, which I guess is a separate issue.
   
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   I used an LLM adversarially to discover this. (We use the datafusion planner 
in our API surface.)
   
   ### Willingness to contribute
   
   None


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to