-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
HIVE-28675: Maximize the removal of redundant columns from GROUP BY clauses #5586
base: master
Are you sure you want to change the base?
Conversation
if (aggregate.getGroupSet().contains(key)) { | ||
groupByUniqueKey = key; | ||
break; | ||
ImmutableBitSet removableCols = originalGroupSet.except(key).except(fieldsUsed); |
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.
Is it possible to compute except(fieldsUsed)
outside the loop? I believe changing the order of except
s will still yield the same resulting set.
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.
Yes we can do this, but just want to be careful that if there is no uniquekey match then we should not remove any columns at all(should skip the except in the return statement below in that case)
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.
Just realized that we only update columnsToRemove when there is atleast one match. So I think yes we can move the except(fieldsUsed) outside the for loop.
Also is it efficient to loop the fieldsUsed(and then check if there is a field that is a unique key and part of aggregate keys to retain only fieldsUsed) vs looping uniquekeys? Mostly depends on size of fieldsUsed vs uniqueKeys. I will probably leave it upto you to decide on that.
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.
Yes, it is possible to compute except(fieldsUsed)
outside the loop. I applied the suggestion in e89386d.
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.
Comparing the efficiency of the iteration between fieldsUsed
and uniqueKeys
is not possible because the semantics are different. The uniqueKeys
variable is a set of sets (Set<ImmutableBitSet>
) while fieldsUsed
is a single set (ImmutableBitSet
). Note that a key
is not necessarily a single column but a set of columns (composite key).
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.
Thank you for your explanation. Makes sense to me.
Quality Gate passedIssues Measures |
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.
LGTM!
LGTM +1. Just left a minor comment for my understanding, please feel free to merge if this question is irrelevant. :) |
EXPLAIN CBO SELECT passport, COUNT(1) FROM passenger GROUP BY id, fname, lname, passport; | ||
EXPLAIN CBO SELECT fname, COUNT(1) FROM passenger GROUP BY id, fname, lname, passport; | ||
EXPLAIN CBO SELECT lname, COUNT(1) FROM passenger GROUP BY id, fname, lname, passport; | ||
EXPLAIN CBO SELECT fname, lname, COUNT(1) FROM passenger GROUP BY id, fname, lname, passport; |
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.
In this case, is having group by fname,lname always a better plan? -- even if there is a different aggregate function?
What changes were proposed in this pull request?
Enhance
HiveRelFieldTrimmer
to remove the maximum number of redundant columns from theGROUP BY
clause.Why are the changes needed?
For more see HIVE-28675.
Does this PR introduce any user-facing change?
More efficient query plans.
Is the change a dependency upgrade?
No
How was this patch tested?