Skip to content

feat: re-land Decimal filter selectivity estimation without the TPC-H Q18 regression - #27148

Open
shrivasshankar wants to merge 5 commits into
apache:mainfrom
shrivasshankar:reland-decimal-filter-selectivity
Open

shrivasshankar wants to merge 5 commits into
apache:mainfrom
shrivasshankar:reland-decimal-filter-selectivity

Conversation

@shrivasshankar

@shrivasshankar shrivasshankar commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

#25790 gave two kinds of decimal filters bad estimates:

  • No min/max stats, like Q18's HAVING sum(l_quantity) > 300: estimated at
    100% of rows instead of 20%, which flipped the Q18 semi join.
  • Equality, like TPC-DS ca_gmt_offset = -5 on DECIMAL(5, 2): interval
    analysis counts every 0.01 step, so it estimated 100 rows instead of 18,246.

What changes are included in this PR?

What is the testing strategy for this PR?

Are there any user-facing changes?

Better estimates for range filters on decimal columns with min/max stats. One
new public function, check_statistics_support.

Re-applies apache#25790, which was reverted in apache#27145 because of a TPC-H Q18
regression (apache#27108). The next commit fixes the regression.
… stats

Interval analysis estimates a selectivity of 1.0 for a column without
bounds. In TPC-H Q18, `HAVING sum(l_quantity) > 300` filters an aggregate
output, which has no min/max stats, so apache#25790 changed its estimate from the
default 20% to 100% and the semi join built its hash table on the wrong side.

Decimal predicates now use interval analysis only when every decimal column
in them has min and max stats. Otherwise they keep the default selectivity,
as before apache#25790.
@github-actions github-actions Bot added logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Nov 6, 2026
@shrivasshankar

Copy link
Copy Markdown
Contributor Author

cc @asolimando @devanbenz @kosiew, this re-lands apache/datafusion#25790 · feat: estimate Decimal filter… with the Q18 fix. The Q18 plan check is in filter_statistics_decimal.slt.

Interval analysis estimates an equality from the number of values in the
column's range, and for a decimal that counts every step of its scale. In
TPC-DS, `ca_gmt_offset = -5` on a DECIMAL(5, 2) column holding whole numbers
from -10 to -5 was estimated at 100 rows instead of 18,246, which flipped
the semi joins in q33, q56, q60, q61 and q91.

Decimal equality filters now keep the estimate they had before apache#25790.
Range filters on decimal columns still use interval analysis.
@shrivasshankar

Copy link
Copy Markdown
Contributor Author

Update: while checking TPC-DS, I found that = filters on decimal columns were also badly underestimated (100 rows instead of 18,246 for ca_gmt_offset = -5), which flipped 5 TPC-DS plans. I added a commit so decimal equality keeps its old estimate. All TPC-H and TPC-DS plans now match main.

@xudong963
xudong963 self-requested a review November 6, 2026 14:05
@devanbenz

devanbenz commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

@kosiew @xudong963 Are you able to kick off the automated benchmarks? We should run all available benchmarks both with pushdown filtering on and off. If we can think of any other configurations which may be impacted by this as well please run those as well.

@shrivasshankar

Better estimates for range filters on decimal columns with min/max stats. One new public function, check_statistics_support.

Better estimates is nice! But also, it would be cool to see metrics associated with performance goodness. If you have them please add them to the PR description :)

@shrivasshankar

Copy link
Copy Markdown
Contributor Author

@kosiew @xudong963 Are you able to kick off the automated benchmarks? We should run all available benchmarks both with pushdown filtering on and off. If we can think of any other configurations which may be impacted by this as well please run those as well.

@shrivasshankar

Better estimates for range filters on decimal columns with min/max stats. One new public function, check_statistics_support.

Better estimates is nice! But also, it would be cool to see metrics associated with performance goodness. If you have them please add them to the PR description :)

Thanks! With this PR, every TPC-H (SF1, SF10) and TPC-DS (SF1) plan is identical to main, with pushdown_filters both on and off, so I wouldn’t expect runtime changes on those benchmarks. The gain for now is in the estimates themselves. For example, the Q6-style filter goes from 1.2M estimated rows to 111K (actual 114K). I’ll add the benchmark results to the description once they’ve run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-land Decimal filter selectivity estimation (#25790) without the TPC-H Q18 regression

2 participants