HIVE-29368: limiting the NDV fix to the CASE clause handler only#6308
Open
konstantinb wants to merge 2 commits intoapache:masterfrom
Open
HIVE-29368: limiting the NDV fix to the CASE clause handler only#6308konstantinb wants to merge 2 commits intoapache:masterfrom
konstantinb wants to merge 2 commits intoapache:masterfrom
Conversation
|
Contributor
Author
|
CC @okumin |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



What changes were proposed in this pull request?
HIVE-29368: perform more accurate NDV estimations for CASE/WHEN clauses with multiple constant branches
If the resulting NDV off PessimisticStatCombiner is smaller than the number of const branches, use the number of const branches as the expression NDV
Why are the changes needed?
The original code uses PessimisticStatCombiner to combine stats of all branches of a CASE/WHEN clause. Since every const branch has a natural NDV of 1, the resulting NDV estimate of even very large clauses is also 1 (PessimisticStatCombiner calculates MAX NDV of all branches). If such a column is subsequently used in a GROUP BY, especially multiple time, this under-estimation might lead to pretty bad exscution plan decisions. E.g. a 20x under-estimation alone could be not so bad, but when this happens 3x times in one query, then the underestimation of 111 = 1 could quickly grow up to 202020 = 8000x times row count underestimation
Does this PR introduce any user-facing change?
No
How was this patch tested?
See the .q file in the PR; also extensively tested in a private custom installation