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

planner: add optimizer trace framework for logicalOptimize #29559

Merged
merged 5 commits into from
Nov 12, 2021

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Nov 8, 2021

What problem does this PR solve?

ref #29661

Add optimize trace framework for logicalOptimize. In this pr, we do the following work.

  1. use stmtCtx.EnableOptimizeTrace to indicate whether the statement should be enabled optimizer trace
  2. add optimize trace common framework into logical optimize processing.

Issue Number: close #xxx

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 8, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • AilinKid
  • rebelice

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 8, 2021
@Yisaer Yisaer marked this pull request as ready for review November 10, 2021 07:25
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 10, 2021
@Yisaer Yisaer mentioned this pull request Nov 10, 2021
19 tasks
planner/core/optimizer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rebelice rebelice left a comment

Choose a reason for hiding this comment

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

rest LGTM

planner/core/optimizer.go Outdated Show resolved Hide resolved
@@ -179,25 +179,25 @@ func wrapCastFunction(ctx sessionctx.Context, arg expression.Expression, targetT
return expression.BuildCastFunction(ctx, arg, targetTp)
}

func (a *aggregationEliminator) optimize(ctx context.Context, p LogicalPlan) (LogicalPlan, error) {
func (a *aggregationEliminator) optimize(ctx context.Context, p LogicalPlan, opts ...logicalOptimizeOption) (*logicalOptimizeReturn, error) {
newChildren := make([]LogicalPlan, 0, len(p.Children()))
for _, child := range p.Children() {
newChild, err := a.optimize(ctx, child)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add opts here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently we only implement framework for rule.optimize. In future we will implement specific logical code for each rule during optimize. Thus no need to add opts here for now.

planner/core/rule_decorrelate.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 11, 2021
@AilinKid AilinKid changed the title planner: add optimize trace framework for logicalOptimize planner: add optimizer trace framework for logicalOptimize Nov 11, 2021
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@@ -377,6 +381,15 @@ func (p *baseLogicalPlan) ExplainInfo() string {
return ""
}

// buildLogicalPlanTrace implements LogicalPlan
func (p *baseLogicalPlan) buildLogicalPlanTrace() tracing.LogicalPlanTrace {
Copy link
Contributor

Choose a reason for hiding this comment

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

need pointer here? func (p *baseLogicalPlan) buildLogicalPlanTrace() *tracing.LogicalPlanTrace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

@@ -377,6 +381,15 @@ func (p *baseLogicalPlan) ExplainInfo() string {
return ""
}

// buildLogicalPlanTrace implements LogicalPlan
func (p *baseLogicalPlan) buildLogicalPlanTrace() tracing.LogicalPlanTrace {
planTrace := tracing.LogicalPlanTrace{ID: p.ID(), TP: p.TP()}
Copy link
Contributor

Choose a reason for hiding this comment

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

explainInfo will be filled next?

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, explainInfo will be implemented by specific logical operator.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 11, 2021
@AilinKid
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 7a7aaa242575391a7b8892f1e1a3dc2691c3962d

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 11, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 11, 2021

/merge

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 11, 2021

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 11, 2021
planner/core/optimizer.go Outdated Show resolved Hide resolved
// The order of flags is same as the order of optRule in the list.
// We use a bitmask to record which opt rules should be used. If the i-th bit is 1, it means we should
// apply i-th optimizing rule.
if flag&(1<<uint(i)) == 0 || isLogicalRuleDisabled(rule) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is duplicated with the original one, you can align. Please think about minimizing changes to original codes to make tracer work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

// logicalOptRule means a logical optimizing rule, which contains decorrelate, ppd, column pruning, etc.
type logicalOptRule interface {
optimize(context.Context, LogicalPlan) (LogicalPlan, error)
optimize(context.Context, LogicalPlan, ...logicalOptimizeOption) (*logicalOptimizeReturn, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add one rule implementation to show how this framework works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in aggregationEliminateChecker.

@ti-chi-bot
Copy link
Member

@chrysan: Request changes is only allowed for the reviewers in list.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 11, 2021

/hold

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Nov 11, 2021
Signed-off-by: yisaer <[email protected]>
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 11, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/hold cancel

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 12, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: dbb28ee

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 12, 2021
return op
}

func (op *logicalOptimizeOp) appendRuleTracerBeforeRuleOptimize(name string, before LogicalPlan) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want logicalOptimizeOp to be generic not only for tracer, you'd better set the func name more generic without word "tracer".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 12, 2021
Signed-off-by: yisaer <[email protected]>
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Nov 12, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/hold cancel

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 12, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 10ae26b

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 12, 2021
@ti-chi-bot
Copy link
Member

@Yisaer: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/run_check_dev_2

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/run_check_dev

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/run_all_tests

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/run-all-tests

@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/run-check_dev_2

1 similar comment
@Yisaer
Copy link
Contributor Author

Yisaer commented Nov 12, 2021

/run-check_dev_2

@ti-chi-bot ti-chi-bot merged commit a4bd02e into pingcap:master Nov 12, 2021
@Yisaer Yisaer added the sig/planner SIG: Planner label Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants