Skip to content

Parquet row-group pruning drops all rows for a != b when two columns have the same min/max #7718

Open

Description

@fcollman

Describe the bug

read_parquet drops every row of a row group for a != filter between two columns when the two columns have the same min and the same max in that row group. In src/daft-stats/src/column_stats/comparison.rs, ColumnRangeStatistics::equal sets the "always equal" bound to s_lower == r_lower AND s_upper == r_upper. That only proves every row is equal when both ranges hold a single value. not_equal is equal(..).not(), so for column ranges like a in [1, 2], b in [1, 2] it decides no row can match and prunes the row group. NOT (a = b) and SQL a <> b are pruned the same way. Comparing a column with a literal is unaffected, because the literal's range is a single value.

Two ID columns drawn from the same pool, such as pre- and post-synaptic IDs, often have matching bounds in every row group, so the filter silently returns an empty result.

To Reproduce

import daft, pyarrow as pa, pyarrow.parquet as pq

t = pa.table({"a": [1, 2], "b": [2, 1]})
pq.write_table(t, "stats.parquet")
pq.write_table(t, "nostats.parquet", write_statistics=False)

for p in ["stats.parquet", "nostats.parquet"]:
    df = daft.read_parquet(p)
    print(df.where(daft.col("a") != daft.col("b")).to_pydict()["a"],
          df.where(~(daft.col("a") == daft.col("b"))).to_pydict()["a"],
          daft.sql("SELECT a FROM df WHERE a <> b").to_pydict()["a"])
# [] [] []                  <- with statistics
# [1, 2] [1, 2] [1, 2]      <- same rows, no statistics

m = daft.from_pydict({"a": [1, 2], "b": [2, 1]})
print(m.where(daft.col("a") != daft.col("b")).to_pydict()["a"])
# [1, 2]

Expected behavior

[1, 2] for both files, the rows Daft returns when it filters the same data in memory. Range statistics can only prove two columns are equal on every row when both ranges hold a single value (s_lower == s_upper == r_lower == r_upper), so that is the only case where != should be pruned.

Workaround: (a < b) | (a > b) returns the right rows.

Component(s)

Data Sources & Sinks

Additional context

daft 0.7.26, pyarrow 20.0.0, Python 3.12.12, macOS 26.0 arm64. equal/not_equal in src/daft-stats/src/column_stats/comparison.rs are unchanged on main. #7655 (NaN rows dropped for != on floats) involves the same not_equal, but its fix, #7660, does not change the column-vs-column case.

Activity

  1. pcbeingused333 commented on Nov 13, 2026

    @pcbeingused333
    Contributor

    I think the cause is in ColumnRangeStatistics::equal (src/daft-stats/src/column_stats/comparison.rs). It sets the "always true" bound to s_lower == r_lower && s_upper == r_upper, which only means the two ranges are identical. It doesn't mean every row is equal, because a row group with min=1, max=2 on both columns satisfies it. not_equal then flips that bound into an upper bound of false, so the row group is pruned even though it holds rows where a != b. That matches the empty result on the Parquet with statistics, and the correct [1, 2] without them.

    Proposed fix: in equal, treat the lower bound as true only when both ranges are a single value (min == max on both sides and equal to each other). Keep the overlap check for the upper bound. I'd add a regression test with a != b over two columns whose row-group ranges coincide.

    CONTRIBUTING asks for an approved issue before planner changes. If a maintainer is happy with this approach, I can open a PR.

    (Disclosure: this comment was drafted with the help of an AI assistant.)

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions