You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LimitPushdown drops the limit above a leaf that returns true from supports_limit_pushdown #27891
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:
let scan:Arc<dynExecutionPlan> =
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.
Activity
fix: don't drop a limit above a leaf in LimitPushdown (apache#27892)