[
https://issues.apache.org/jira/browse/CALCITE-4132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17161693#comment-17161693
]
Liya Fan commented on CALCITE-4132:
-----------------------------------
[~julianhyde] Thanks a lot for your good suggestions.
I have revised the title accordingly, and added an example to the description.
Please check.
I agree with you that for some scenarios, "without-replacement" should be more
appropriate. Maybe we need a case-by-case analysis.
For the "without-replacement" scenario, I think we have two sub-cases to
consider:
1. We suppose all elements in the unverse set are distinct. In this case, we
get n distinct values with n selections, so there is no need for an estimation.
2. We suppose there are k distinct values in the set, with n1, n2, ... , nk
items respectively. For such a case, the formula for the number of distinct
values should be extremely complicated (involving the multi-nomial formula),
and the computational cost would be high as well.
> Estimate the number of distinct values more accurately
> ------------------------------------------------------
>
> Key: CALCITE-4132
> URL: https://issues.apache.org/jira/browse/CALCITE-4132
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Liya Fan
> Assignee: Liya Fan
> Priority: Major
> Labels: pull-request-available
> Time Spent: 40m
> Remaining Estimate: 0h
>
> Currently, we estimate the NDV of many operators based on the
> RelMdUtil#numDistinctVals method. This method estimates the expected number
> of distinct values selected n times (with replacement) from a collection with
> N distinct values. The estimation is based on the approximation when N
> approaches infinity.
> However, when N is not a large number, the difference between the approximate
> and exact values can be notabe. In addtion, the error can be magnified by
> different combinations of N and n, which can lead the optimizer to make wrong
> decisions.
> For example, when we select one element from a table with a 4-value enum, we
> expect to get one distinct value according to common sense. However, the
> current implementation gives 0.88, which is counter-intuitive, and leads to a
> 10+% error.
> Therefore, we give the exact estimation based on the unbiased estimator (The
> proof is given in the comment).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)