Skip to content

LimitPushdown drops the limit above a leaf that returns true from supports_limit_pushdown #27891

Done

Description

@zhuqi-lucas

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:

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.

Activity

  1. added
    bug
    on Dec 1, 2026
  2. added a commit that references this issue on Dec 1, 2026
    c75bc57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions