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

*: Modify tidb/executor to implement plan recreator #26381

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

zhuo-zhi
Copy link
Contributor

@zhuo-zhi zhuo-zhi commented Jul 20, 2021

What problem does this PR solve?

Issue Number: close #26335, subitem of #26325

Problem Summary:

  • Subtask of Plan Recreator.
  • Modify tidb/executor to implement plan recreator

What is changed and how it works?

  • Modify executor to support plan recreator's dumping files of a single SQL statement.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

  • Modify tidb/executor to implement plan recreator

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

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 the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 20, 2021
@ti-srebot
Copy link
Contributor

@zhuo-zhi zhuo-zhi marked this pull request as draft July 20, 2021 09:34
@ti-chi-bot ti-chi-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 20, 2021
@github-actions github-actions bot added sig/execution SIG execution sig/sql-infra SIG: SQL Infra labels Jul 20, 2021
@ti-srebot
Copy link
Contributor

@ti-srebot
Copy link
Contributor

@zhuo-zhi
Copy link
Contributor Author

Blocked by parser pull request.


// Dump bindings
normSql, _ := parser.NormalizeDigest(e.ExecStmt.Text())
recordSets, err = e.Ctx.(sqlexec.SQLExecutor).Execute(context.TODO(), fmt.Sprintf("show bindings where Original_sql='%s'", normSql))
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 we‘d better dump all bindings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in the new commit.

@zhuo-zhi zhuo-zhi marked this pull request as ready for review July 28, 2021 07:58
@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 Jul 28, 2021
@ti-chi-bot
Copy link
Member

@zhuo-zhi: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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 kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Jul 28, 2021
@zhuo-zhi
Copy link
Contributor Author

Moved some code to pr #26700

@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 30, 2021
return sRows, nil
}

func getRows4Test(ctx context.Context, rs sqlexec.RecordSet) ([]chunk.Row, error) {
Copy link
Member

@time-and-fate time-and-fate Jul 30, 2021

Choose a reason for hiding this comment

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

Can we use DrainRecordSet() directly? I think they're similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's only used for oom action.

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 30, 2021
executor/plan_recreator.go Outdated Show resolved Hide resolved
executor/plan_recreator.go Show resolved Hide resolved
@zhouqiang-cl zhouqiang-cl removed the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Aug 4, 2021
Co-authored-by: Zhou Kunqin <25057648+time-and-fate@users.noreply.github.com>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 4, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 4, 2021
@qw4990 qw4990 self-requested a review August 5, 2021 06:59
}
return in, true
}

// planRecreatorVarKeyType is a dummy type to avoid naming collision in context.
type planRecreatorVarKeyType int
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this variable be removed?

Comment on lines +139 to +141
result := newFirstChunk(e)
result.AppendString(0, res)
req.Append(result, 0, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can directly use req.AppendString(0, res) here.

}

// Create zip file
startTime := time.Now()
fileName := fmt.Sprintf("recreator_single_%v.zip", startTime.UnixNano())
zf, err := os.Create(recreatorPath + "/" + fileName)
zf, err := os.Create(path + "/" + fileName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use filepath.Join(path, fileName) here, which is safer than path + "/" + fileName.

@@ -145,7 +177,7 @@ func (e *PlanRecreatorSingleInfo) dumpSingle() (string, error) {
TList := val.(fileList).TokenMap
for k, v := range Flist {
if time.Since(v.StartTime).Minutes() > remainedInterval {
err := os.Remove(recreatorPath + "/" + k)
err := os.Remove(path + "/" + k)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

Please add some test cases for this feature, you can refer to select ... into outfile TestSelectIntoOutfileFromTable.

Comment on lines +1149 to +1152
ExecStmt ast.StmtNode
Analyze bool
Load bool
File string
Copy link
Contributor

Choose a reason for hiding this comment

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

These fields seem not be used?

Comment on lines +2260 to +2262
if s.Value(executor.PlanRecreatorFileList) != nil {
executor.CleanUpPlanRecreatorFile(s.GetSessionVars().ConnectionID)
}
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean if the client closed this session, the file would be no longer available? Is this expected?

return nil
}

func resultSetToStringSlice(ctx context.Context, rs sqlexec.RecordSet) ([][]string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems we can directly use ResultSetToStringSlice from the session package?

@time-and-fate
Copy link
Member

Also please fix the lint error.

@ti-chi-bot
Copy link
Member

@zhuo-zhi: PR needs rebase.

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 kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. sig/execution SIG execution sig/sql-infra SIG: SQL Infra size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add plan replayer GC
7 participants