Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zabetak
Copy link
Member

@zabetak zabetak commented Dec 20, 2024

What changes were proposed in this pull request?

Enhance HiveRelFieldTrimmer to remove the maximum number of redundant columns from the GROUP BY clause.

Why are the changes needed?

  1. Generate more efficient plans by pruning as many columns as possible (less CPU/IO/network cost).
  2. Avoid missing optimization opportunities by examining all candidates.

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?

mvn test -Dtest=TestMiniLlapLocalCliDriver.java -Dqfile="cbo_groupby_remove_key.q"

Copy link

@zabetak zabetak marked this pull request as ready for review December 31, 2024 16:09
if (aggregate.getGroupSet().contains(key)) {
groupByUniqueKey = key;
break;
ImmutableBitSet removableCols = originalGroupSet.except(key).except(fieldsUsed);
Copy link
Contributor

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 excepts will still yield the same resulting set.

Copy link
Contributor

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)

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants