Merged
Conversation
) ## 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 : )