Handle cardinality estimation for disjoint inner and outer joins #3848
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.
Which issue does this PR close?
Closes #3802 .
Rationale for this change
When we know for a fact that an inner join is disjoint, we can estimate the cardinality of an inner join with (at least) one disjoint column as
0
. From there, we can derive the cardinality of a left/right and full outer joins.What changes are included in this PR?
We now take an
is_exact
flag inestimate_join_cardinality
which is onlytrue
when both left and right are originating directly from table providers (which might change in the future if we collect more statistics during materialization points both in DF and Ballista, and somehow adaptively optimize the parent plans according to that). If thatis_exact
flag is true and if we identify a disjoint column when calculating the inner join cardinality, we now infer the cardinality of an inner join as 0.Since the cardinality of left/right/full outer joins can be derived from the inner join's cardinality (e.g. a disjoint left outer join would result with the number of rows from the left side), this PR also adds support for inferring their cardinality.
Are there any user-facing changes?
No.