Skip to content

Add Optimizer for validating and optimizing#19050

Merged
jainxrohit merged 1 commit intoprestodb:masterfrom
jainxrohit:rj_plan
Feb 15, 2023
Merged

Add Optimizer for validating and optimizing#19050
jainxrohit merged 1 commit intoprestodb:masterfrom
jainxrohit:rj_plan

Conversation

@jainxrohit
Copy link
Contributor

@jainxrohit jainxrohit commented Feb 13, 2023

The LogicalPlanner performs various functions including creating, validating, and optimizing plan nodes. The creation of plan nodes are dependent on the analyzer artifacts, while validation and optimization are core engine responsibilities.

To separate these responsibilities, we are introducing an optimizer class to manage the validation and optimization of plan nodes.

This change also adds a runtime stats (optimizerTime) for measuring time taken to validate and optimize plan nodes.

== RELEASE NOTES ==

General Changes
* Added a new runtime metric ``optimizerTimeNanos`` to measure time taken by optimizers. The time taken by optimizers has been removed from runtime metric ``logicalPlannerTimeNanos``.

@jainxrohit jainxrohit force-pushed the rj_plan branch 4 times, most recently from 70aef3d to 4202c5e Compare February 13, 2023 19:27
@jainxrohit jainxrohit changed the title commit1 Add Optimizer for validating and optimizing Feb 13, 2023
@jainxrohit jainxrohit marked this pull request as ready for review February 13, 2023 19:31
@jainxrohit jainxrohit requested a review from a team as a code owner February 13, 2023 19:31
@jainxrohit jainxrohit marked this pull request as draft February 13, 2023 21:01
@jainxrohit jainxrohit marked this pull request as ready for review February 13, 2023 21:25
The LogicalPlanner performs various functions including creating,
validating, and optimizing plan nodes. The creation of plan nodes
are dependent on the analyzer artifacts, while validation and
optimization are core engine responsibilities.
To separate these responsibilities, we are introducing an optimizer
class to manage the validation and optimization of plan nodes.

This change also adds a runtime stats optimizerTime for measuring
time taken to validate and optimize plannodes.
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public class Optimizer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not really a fan of this name. As this class is also validating plans. I wonder what could be a good name for this class. e.g. QueryPlanner? suggestions? @rschlussel @mlyublena

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the name is ok wrt to the fact that it both optimizes and validates.
I think there might be some confusion between Optimizer and PlanOptimizer, but if anything, PlanOptimizer is the confusing one (as it describes a single optimization rule vs the whole process of query optimization)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just call it OpitmizerDriver or OptimizeAndValidate - Optimizer definitely looks wrong to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wanted to add more context. In my later PR, the logical planner related usage would be abstracted behind analyzer interfaces. Only Optimizer class would be used by the SQLQueryExecution

Copy link
Contributor

Choose a reason for hiding this comment

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

Driver that runs optimizers one by one - more apt name for this class. This is definitely not an opitmizer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay will change it to OptimizerDriver.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm maybe Optimizer is OK - let me think more.

metadata,
planVariableAllocator);

PlanNode planNode = getSession().getRuntimeStats().profileNanos(
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps call this logicalPlanNode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel planNode is sufficient, and its used at many other places. If we want to use logicalPlanNode then it would be better to change all other places as well. I will keep it planNode as of now, let me know if you feel strongly about it.

metadata,
planVariableAllocator);

PlanNode planNode = session.getRuntimeStats().profileNanos(
Copy link
Contributor

Choose a reason for hiding this comment

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

logicalPlanNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above.

@rschlussel
Copy link
Contributor

I think this needs a release note because LOGICAL_PLANNER_TIME_NANOS used to include optimization time, and now they are being split apart.

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public class Optimizer
Copy link
Contributor

Choose a reason for hiding this comment

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

Driver that runs optimizers one by one - more apt name for this class. This is definitely not an opitmizer

Copy link
Contributor

@kaikalur kaikalur left a comment

Choose a reason for hiding this comment

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

I take back that comment - after thinking more - it's not as bad as I initially felt - analyzer/planner/optimizer as high level APIs is OK

@jainxrohit jainxrohit merged commit c79a269 into prestodb:master Feb 15, 2023
@wanglinsong wanglinsong mentioned this pull request Feb 25, 2023
12 tasks
@jainxrohit jainxrohit deleted the rj_plan branch February 26, 2023 20:23
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.

4 participants