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

ddl, table: improve the efficiency of adding index #48184

Merged
merged 24 commits into from
Nov 2, 2023

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Nov 1, 2023

What problem does this PR solve?

Issue Number: ref #47757

Problem Summary:

See #47757.

What is changed and how it works?

This PR contains multiple optimizations:

  • Change MergeSortOverlapThreshold to 8000 to increase the threshold to trigger merge-sort step.
  • Optimize extractDatumByOffsets by decoding value into the datum directly instead of copying.
    BenchmarkExtractDatumByOffsets-10    	126919888	         9.298 ns/op
    BenchmarkExtractDatumByOffsets-10    	164564930	         7.231 ns/op
    
  • Add index value buffer as a parameter to GenIndexValue() to avoid memory allocation.
  • Change table.IndexIter from interface to struct so that it is not escaping to heap anymore.
     9601753               129.6 ns/op           138 B/op          4 allocs/op
    18007044                66.81 ns/op           17 B/op          2 allocs/op
    
  • Adopt the fast path for GenIndexKey to reduce overhead.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 1, 2023
@tangenta tangenta changed the title ddl,table: reduce memory allocation ddl, table: reduce memory allocation Nov 1, 2023
Copy link

tiprow bot commented Nov 1, 2023

Hi @tangenta. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@tangenta tangenta changed the title ddl, table: reduce memory allocation ddl, table: improve the efficiency of adding index Nov 1, 2023
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Merging #48184 (eea4b78) into master (028d7b8) will increase coverage by 1.2621%.
Report is 9 commits behind head on master.
The diff coverage is 87.8787%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #48184        +/-   ##
================================================
+ Coverage   71.5384%   72.8006%   +1.2621%     
================================================
  Files          1402       1425        +23     
  Lines        406159     413058      +6899     
================================================
+ Hits         290560     300709     +10149     
+ Misses        95775      93430      -2345     
+ Partials      19824      18919       -905     
Flag Coverage Δ
integration 42.8453% <65.6565%> (?)
unit 71.4896% <87.8787%> (-0.0489%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9874% <ø> (ø)
parser ∅ <ø> (∅)
br 48.6817% <100.0000%> (-4.2133%) ⬇️

pkg/ddl/index.go Outdated Show resolved Hide resolved
@@ -470,23 +439,9 @@ func (w *Writer) flushKVs(ctx context.Context, fromClose bool) (err error) {
}()

sortStart := time.Now()
if w.shareMu != nil {
sorty.MaxGor = min(8, uint64(variable.GetDDLReorgWorkerCounter()))
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need sorty library? It has better performance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean setting sorty.MaxGor to 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tangenta
Copy link
Contributor Author

tangenta commented Nov 2, 2023

/retest

Copy link

tiprow bot commented Nov 2, 2023

@tangenta: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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 bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 2, 2023
Copy link
Contributor

@lance6716 lance6716 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

pkg/table/index.go Outdated Show resolved Hide resolved
// Valid returns true if the generator is exhausted.
func (iter *IndexKVGenerator) Valid() bool {
if len(iter.allIdxVals) == 0 {
return iter.i == 0
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 Valid() before the first Next() call?

Copy link
Contributor Author

@tangenta tangenta Nov 2, 2023

Choose a reason for hiding this comment

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

Yes. For non multi-value indexes, there is only one index kv per row.

Co-authored-by: lance6716 <lance6716@gmail.com>
Copy link

ti-chi-bot bot commented Nov 2, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lance6716, wjhuang2016

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 2, 2023
Copy link

ti-chi-bot bot commented Nov 2, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-11-02 11:40:24.423277431 +0000 UTC m=+3126022.010387575: ☑️ agreed by wjhuang2016.
  • 2023-11-02 13:24:58.166446584 +0000 UTC m=+3132295.753556731: ☑️ agreed by lance6716.

Copy link

tiprow bot commented Nov 2, 2023

@tangenta: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
tiprow_fast_test eea4b78 link true /test tiprow_fast_test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot bot merged commit c1e28f3 into pingcap:master Nov 2, 2023
16 of 24 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #48250.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 2, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note-none Denotes a PR that doesn't merit a release note. 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.

6 participants