Skip to content

FileScanConfig::statistics() ignores pushed down filters when parquet.pushdown_filters = true #27624

Open

Description

@hcrosse

Describe the bug

When datafusion.execution.parquet.pushdown_filters = true, FileScanConfig::statistics() ignores pushed down filters and reports the unfiltered file row count as Inexact(N). Once FilterPushdown absorbs FilterExec into DataSourceExec, the scan reports 100% of the table rows.

As a result, a tighter predicate that pushes completely into DataSourceExec can get a much higher row estimate than a looser predicate that stays in FilterExec, which can skew downstream join planning and build side selection.

To Reproduce

I reproduced this on main (57.0.0-dev):

SET datafusion.execution.target_partitions = 1;
SET datafusion.execution.parquet.pushdown_filters = true;
SET datafusion.explain.show_statistics = true;

COPY (
  SELECT i AS id,
         i % 10 AS k,
         CASE WHEN i % 2 = 0 THEN NULL ELSE named_struct('a', i) END AS st
  FROM generate_series(1, 1000) AS t(i)
) TO 't.parquet' STORED AS PARQUET;

CREATE EXTERNAL TABLE t STORED AS PARQUET LOCATION 't.parquet';

-- Looser predicate: FilterExec remains in the plan
-- Actual rows: 550, estimated rows: Inexact(200)
EXPLAIN SELECT id FROM t WHERE k = 1 OR st IS NULL;

-- Tighter predicate: absorbed into DataSourceExec
-- Actual rows: 100, estimated rows: Inexact(1000)
EXPLAIN SELECT id FROM t WHERE k = 1;

With WHERE k = 1, FilterExec is absorbed into DataSourceExec and the reported cardinality jumps to Inexact(1000) (all rows in the file), five times higher than the Inexact(200) estimate for the strictly looser WHERE k = 1 OR st IS NULL.

Expected behavior

When a filter is pushed down and absorbed into DataSourceExec (removing FilterExec), DataSourceExec statistics should reflect the selectivity of the absorbed filter rather than reporting 100% of the unfiltered table rows.

Additional context

FileScanConfig::statistics() currently only marks the unfiltered statistics as inexact when self.file_source.filter().is_some():

pub fn statistics(&self) -> Statistics {
let filter_may_change_row_count = self.file_source.filter().is_some()
&& self.statistics.num_rows != Precision::Exact(0);
if filter_may_change_row_count {
self.statistics.clone().to_inexact()
} else {
self.statistics.clone()
}
}

A couple of design points seem worth confirming before changing this:

  1. self.file_source.filter() can hold a pruning only filter while FilterExec remains above DataSourceExec (for example when pushdown_filters = false). Applying selectivity to pruning only filters would double count selectivity with the parent FilterExec, so estimation should apply only to filters actually absorbed into the scan (overlapping with Prototype: physical filter API (PhysicalFilter / FilterConjunct) with optional conjuncts #25760 and feat: keep optional filters pruning-only in the Parquet post-scan path #25722).
  2. FilterExec selectivity estimation currently lives in datafusion-physical-plan, above datafusion-datasource, so either the shared selectivity logic would need to live lower or FilterPushdown would need to propagate the adjusted statistics when absorbing FilterExec.

I would be happy to work on a fix once maintainers confirm the preferred direction.

Activity

  1. added
    Prolific Author
    on Nov 21, 2026
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

    Prolific Author

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions