Skip to content

Statistics: Implement SampledDistribution variant to Distribution to … #16614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

cj-zhukov
Copy link
Contributor

…support estimated distributions (#14897)

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Jun 29, 2025
@github-actions github-actions bot added the physical-expr Changes to the physical-expr crates label Jun 29, 2025
@alamb
Copy link
Contributor

alamb commented Jun 30, 2025

Thanks @cj-zhukov !

I think it would be super helpful to make an example / test showing how to use this new distribution to estimate cardinality

For example perhaps you could set up a SampledDistribition like

[0, 10]: 100 samples
[20,30]: 200 samples

And then estimate the cardinality of a predicate like x > 25

I would expect the estimate to be 1/3 (half of the 20-30 bucket and none of the 1-10 bucket)

@alamb
Copy link
Contributor

alamb commented Jun 30, 2025

FYI @ozankabak and @berkaysynnada as you may be interested in this feature too

@cj-zhukov
Copy link
Contributor Author

Thanks @cj-zhukov !

I think it would be super helpful to make an example / test showing how to use this new distribution to estimate cardinality

For example perhaps you could set up a SampledDistribition like

[0, 10]: 100 samples
[20,30]: 200 samples

And then estimate the cardinality of a predicate like x > 25

I would expect the estimate to be 1/3 (half of the 20-30 bucket and none of the 1-10 bucket)

hi @alamb , I wanted to clarify one thing . I implemented general-purpose methods like mean(), median(), and variance() for SampledDistribution, similar to other Distribution variants. These are designed to summarize the entire distribution. To answer your question about estimating cardinality for predicates like x > 25, I implemented a separate method estimate_selectivity_gt() that works specifically for that use case — it calculates how many values match the condition based on the bin layout and counts. Let me know if you think those general-purpose methods should be reused here, or if you’d prefer to keep predicate-based estimation separate. Happy to adjust based on your guidance.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Statistics: Implement SampledDistribution variant to Distribution to support estimated distributions
2 participants