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

Closed
wants to merge 2 commits into 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"

@zabetak zabetak marked this pull request as ready for review December 31, 2024 16:09
Copy link

sonarqubecloud bot commented Jan 3, 2025

Copy link
Contributor

@soumyakanti3578 soumyakanti3578 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ramesh0201
Copy link
Contributor

ramesh0201 commented Jan 3, 2025

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;
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change the aggregate function the query changes as well.

If we assume that the set of redundant columns remains the same after changing the aggregate function (e.g., MAX(fname)) then it's always a good idea to drop unnecessary processing so grouping on fname, lname is the best option.

If the set of redundant columns changes (e.g., MAX(passport)) then this optimization will not trigger in the same way (passport column cannot be dropped).

@zabetak zabetak closed this in b7a3e8b Jan 6, 2025
@zabetak zabetak deleted the gby_remove branch January 6, 2025 09:56
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