Skip to content

[pull] main from apache:main#86

Merged
pull[bot] merged 2 commits intoburaksenn:mainfrom
apache:main
Apr 7, 2026
Merged

[pull] main from apache:main#86
pull[bot] merged 2 commits intoburaksenn:mainfrom
apache:main

Conversation

@pull
Copy link
Copy Markdown

@pull pull bot commented Apr 7, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

asolimando and others added 2 commits April 7, 2026 08:16
)

## Which issue does this PR close?

- Part of #20766

Related: #20789 (uses NDV for equality filter selectivity, complementary
- this PR improves the NDV output stats, that PR consumes them)

## Rationale for this change

When a filter predicate collapses a column interval to a single value
(e.g. `d_qoy = 1`), the output column can only have one distinct value.
Currently `distinct_count` is always demoted to `Inexact`, losing this
information.

This matters for downstream optimizers that rely on `distinct_count`,
such as join cardinality estimation in
`estimate_inner_join_cardinality`.

## What changes are included in this PR?

In `collect_new_statistics` (filter.rs), when the post-filter interval
has `lower == upper` (both non-null), set `distinct_count` to
`Precision::Exact(1)` instead of demoting the input NDV to `Inexact`.

## Are these changes tested?

Yes, 4 unit tests:
- Equality predicate (`a = 42`) -> NDV becomes `Exact(1)`
- OR predicate (`a = 42 OR a = 22`) -> interval does not collapse, NDV
stays `Inexact`
- AND with mixed predicates (`a = 42 AND b > 10 AND c = 7`) -> `a` and
`c` get `Exact(1)`, `b` stays `Inexact`
- Equality with absent bounds (`a = 42`, no min/max) -> interval
analysis still resolves to `Exact(1)`

## Are there any user-facing changes?

No breaking changes. Statistics consumers will now see `Exact(1)` for
`distinct_count` on columns constrained to a single value by filter
predicates.

Disclaimer: I used AI to assist in the code generation, I have manually
reviewed the output and it matches my intention and understanding.

---------

Co-authored-by: xudong.w <wxd963996380@gmail.com>
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->

- Closes #2976
- Part of #8227

## Rationale for this change

`get_statistics_with_limit` was copying first-file row/byte stats even
when`collect_stats=false`. This could return `Exact(0)` instead of
`Absent` (unknown stats).

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

## What changes are included in this PR?

Summary stats are only initialized and merged when `collect_stats=true`.
Also fixes first-file column `byte_size` initialization in the
`collect_stats=true` path, and adds regression tests for both paths and
limit behavior.

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

## Are these changes tested?

Yes

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

## Are there any user-facing changes?

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->

---------

Co-authored-by: Siew Kam Onn <kosiew@gmail.com>
@pull pull bot locked and limited conversation to collaborators Apr 7, 2026
@pull pull bot added the ⤵️ pull label Apr 7, 2026
@pull pull bot merged commit 0b8c4c5 into buraksenn:main Apr 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants