zhuqi-lucas opened a new issue, #27891:
URL: https://github.com/apache/datafusion/issues/27891

   ### Describe the bug
   
   `LimitPushdown` passes a limit to the children of a node whose 
`limit_behavior` is `MoveToInput` or `CopyToChildren`. The default 
`limit_behavior` returns one of these when the deprecated 
`supports_limit_pushdown` returns `true`. A leaf has no children, so the limit 
is dropped and the query can return too many rows.
   
   Built-in leaves don't return `true`, so only custom leaves that still 
implement the deprecated hook hit this. The rule did the same before #26660.
   
   ### To Reproduce
   
   `TestScan` in `datafusion/core/tests/physical_optimizer/test_utils.rs` 
returns `supports_fetch` from `supports_limit_pushdown`:
   
   ```rust
   let scan: Arc<dyn ExecutionPlan> =
       Arc::new(TestScan::new(schema, vec![]).with_supports_fetch(true));
   let plan = global_limit_exec(scan, 0, Some(5));
   let optimized = LimitPushdown::new().optimize(plan, &ConfigOptions::new())?;
   // `TestScan`: no fetch, and no limit above it
   ```
   
   ### Expected behavior
   
   The leaf takes the limit as its fetch (`TestScan: fetch=5`), or the limit 
stays above it.
   
   ### Additional context
   
   Found in the review of #27816, which lets `PushdownSort` use the same logic 
for `ORDER BY ... LIMIT`. A possible fix is to treat a leaf as `Stops` in 
`step()` in `limit_pushdown.rs`; I have it with a test and can open a PR if we 
want to fix it. Related to #26697.
   


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