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

Fix logging of plan optimizer #21226

Merged
merged 1 commit into from
Oct 26, 2023
Merged

Conversation

feilong-liu
Copy link
Contributor

@feilong-liu feilong-liu commented Oct 23, 2023

Description

Change the result type of PlanOptimizer, so that it not only returns the new plan node, but also returns whether the optimizer is triggered or not.

Motivation and Context

Currently, the logging of PlanOptimizer is to compare the old and new plan root with the equal operator. However, this leads to false positives, where any non meaningful changes (for example reorder of outputs etc) will show as optimizer triggered. It also relies on proper equal() override for all data structures in query plans.

In this PR, I change the PlanOptimizer to explicitly return whether an optimizer is triggered or not. I've implemented them for all existing plan optimizers.

Impact

Fix logging of optimizers, and eliminate false positives.

Test Plan

Existing unit tests.

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* Fix logging of optimizer triggering, eliminating false positives where optimizer is logged as triggered but actually not. The PlanOptimizer now return both result plan and whether the plan changed or not.

@feilong-liu feilong-liu requested a review from a team as a code owner October 23, 2023 21:36
@feilong-liu feilong-liu marked this pull request as draft October 23, 2023 21:36
@feilong-liu feilong-liu force-pushed the fix_log branch 4 times, most recently from 2542e12 to 2e67c57 Compare October 23, 2023 23:12
@feilong-liu feilong-liu marked this pull request as ready for review October 23, 2023 23:12
@mlyublena
Copy link
Contributor

Thanks for fixing these!

{
PlanWithProperties result = new Rewriter(idAllocator, variableAllocator, session, partitioningProviderManager).accept(plan, PreferredProperties.any());
return result.getNode();
boolean optimizerTriggered = PlanNodeSearcher.searchFrom(result.getNode()).where(node -> node instanceof ExchangeNode && ((ExchangeNode) node).getScope().isRemote()).findFirst().isPresent();
Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure that this optimizer added the exchange node and it wasn't there before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we only have this optimizer to add remote exchange node.

{
if (optimizer instanceof IterativeOptimizer) {
// iterative optimizers do their own recording of what rules got triggered
return;
}

String optimizerName = optimizer.getClass().getSimpleName();
boolean isTriggered = (oldNode != newNode);
boolean isTriggered = planOptimizerResult.isOptimizerTriggered();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of comparing plan node, now the optimizer returns whether the plan is changed or not.

Change the result type of PlanOptimizer, so that it not only returns the new plan node, but also returns whether the optimizer is triggered or not.
Copy link
Contributor

@pranjalssh pranjalssh left a comment

Choose a reason for hiding this comment

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

Will all new optimizers will have to implement isOptimizerTriggered method. So all spi optimizers and our internal optimizers api might change. Please add that in release notes

@feilong-liu feilong-liu merged commit 82a3bc8 into prestodb:master Oct 26, 2023
@feilong-liu feilong-liu deleted the fix_log branch October 26, 2023 22:06
@wanglinsong wanglinsong mentioned this pull request Dec 8, 2023
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants