-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29556: do not adjust "unknown" NDVs in extractNDVGroupingColumns #6418
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
konstantinb
wants to merge
4
commits into
apache:master
Choose a base branch
from
konstantinb:HIVE-29556
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1e903bb
HIVE-29556: do not adjust "unknown" NDVs in extractNDVGroupingColumns
konstantinb d873d6f
HIVE-29556: can't elegantly resolve "const NULL" columns without a ne…
konstantinb 297cab5
HIVE-29556: one more file's plan has been positively impacted, plus o…
konstantinb 11800bf
HIVE-29556: more explicit and "future-proof" NDV sssignment for const…
konstantinb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| -- HIVE-29556: GROUP BY of a column with unknown NDV (NDV=0 sentinel + numNulls>0) | ||
| -- must not collapse to "1 row" estimate. Both probes feed a join sized so that | ||
| -- master's bogus 1-row estimate triggers Map Join while the heuristic fallback | ||
| -- forces Merge Join. | ||
|
|
||
| SET hive.auto.convert.join=true; | ||
|
|
||
| CREATE TABLE big (k BIGINT); | ||
| CREATE TABLE small (id BIGINT, name STRING); | ||
|
|
||
| ALTER TABLE big UPDATE STATISTICS SET('numRows'='100000000'); | ||
| ALTER TABLE big UPDATE STATISTICS for column k SET ('numDVs'='0','numNulls'='100000000'); | ||
|
|
||
| ALTER TABLE small UPDATE STATISTICS SET('numRows'='1000000'); | ||
| ALTER TABLE small UPDATE STATISTICS for column id SET ('numDVs'='1000000','numNulls'='0'); | ||
| ALTER TABLE small UPDATE STATISTICS for column name SET ('numDVs'='1000000','numNulls'='0','avgColLen'='100','maxColLen'='100'); | ||
|
|
||
| -- U1: direct column with unknown NDV. | ||
| EXPLAIN | ||
| SELECT s.name, g.cnt | ||
| FROM (SELECT k, COUNT(*) AS cnt FROM big GROUP BY k) g | ||
| JOIN small s ON g.cnt = s.id; | ||
|
|
||
| -- U2: PessimisticStatCombiner output for CASE WHEN with one NULL branch. | ||
| EXPLAIN | ||
| SELECT s.name, g.cnt | ||
| FROM (SELECT x, COUNT(*) AS cnt | ||
| FROM (SELECT CASE WHEN k > 0 THEN k ELSE cast(NULL AS BIGINT) END AS x FROM big) t | ||
| GROUP BY x) g | ||
| JOIN small s ON g.cnt = s.id; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we know that a column is a constant then shouldn't
ndv = 1? Why do we want to do +1 ? Why do we care about the number of nulls?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The
+1accounts for NULL being its own GROUP BY bucket — that's whynumNulls > 0gates it for the non-const case. The|| cs.isConst()clause was specifically to handle the all-NULLconst case (
countDistint=0, numNulls>0) where we still want one bucket.But you're right that
ndv = 1is the cleaner way to express it. The current form works only because all threesetConst(true)sites today satisfy the invariant!(countDistint>0 && numNulls>0)— that's implicit and would silently give the wrong answer (2 buckets) if some future code path marked a column const while preserving both a non-null distinct count and nulls (although this would also completely redefine what an NDV of a "const" means).
I'll switch to a much more readable variant: