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

Optimize string sort for default collation UTF8MB4_BIN #5375

Merged
merged 19 commits into from
Jul 21, 2022

Conversation

solotzg
Copy link
Contributor

@solotzg solotzg commented Jul 15, 2022

What problem does this PR solve?

Issue Number: close #5366 ref #5294

Problem Summary:

What is changed and how it works?

  • devirtualize function call when collation is UTF8MB4_BIN, which is the default one.

Tail '\0' doesn't be removed in those parts.

auto sort_key = collator->sortKey(reinterpret_cast<const char *>(&chars[offset]), string_size, sort_key_container);

auto sort_key = collator->sortKey(reinterpret_cast<const char *>(&chars[offset]), string_size, sort_key_container);

reinterpret_cast<const char *>(&parent.chars[parent.offsetAt(lhs)]), parent.sizeAt(lhs),
reinterpret_cast<const char *>(&parent.chars[parent.offsetAt(rhs)]), parent.sizeAt(rhs));

Benchmark

ENV:

  • tpch100
  • 1 tiflash
  • limit cpu up to 200%
  • original commit: 97342db

SQL

select min(L_SHIPMODE) from lineitem;
Time(s) Original Optimized NoCollation    
  11.35 9.98 9.81    
  11.33 9.98 9.88    
  11.23 10 9.84    
  11.22 9.82 9.73 NoCollation : Original 15.22%
  11.58 9.95 9.96 Optimized : Original 14.04%
AVG 11.342 9.946 9.844 NoCollation : Optimized 1.04%

SQL

select max(L_SHIPMODE) from lineitem;
Time(s) Original Optimized NoCollation    
  13.56 12.62 12.77    
  13.74 12.51 12.27    
  13.35 12.61 12.32    
  13.63 12.63 12.45 NoCollation : Original 9.13%
  13.52 12.66 12.32 Optimized : Original 7.57%
AVG 13.56 12.606 12.426 NoCollation : Optimized 1.45%

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

None

@solotzg solotzg added the type/enhancement The issue or PR belongs to an enhancement. label Jul 15, 2022
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jul 15, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • windtalker
  • zanmato1984

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 release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 15, 2022
@solotzg solotzg added type/performance type/bugfix This PR fixes a bug. labels Jul 15, 2022
dbms/src/Storages/Transaction/Collator.h Outdated Show resolved Hide resolved
dbms/src/Storages/Transaction/Collator.h Outdated Show resolved Hide resolved
@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 20, 2022
@solotzg solotzg requested a review from windtalker July 20, 2022 12:56
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 20, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 21, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Jul 21, 2022

/run-all-tests

@pingcap pingcap deleted a comment from sre-bot Jul 21, 2022
@pingcap pingcap deleted a comment from sre-bot Jul 21, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented Jul 21, 2022

Coverage for changed files

Filename                                               Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Columns/ColumnString.cpp                                   161                79    50.93%          24                15    37.50%         343               198    42.27%          88                43    51.14%
Columns/ColumnString.h                                      67                15    77.61%          32                 8    75.00%         167                49    70.66%          24                 6    75.00%
Functions/CollationOperatorOptimized.h                      26                20    23.08%           6                 4    33.33%         100                82    18.00%          16                10    37.50%
Interpreters/AggregationCommon.h                            65                43    33.85%          10                 8    20.00%         190               131    31.05%          46                30    34.78%
Interpreters/SetVariants.h                                   1                 1     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
Storages/Transaction/Collator.cpp                          194                52    73.20%          32                 5    84.38%         416               124    70.19%         168                70    58.33%
Storages/Transaction/CollatorUtils.h                        26                 8    69.23%           9                 2    77.78%          42                 8    80.95%          10                 3    70.00%
Storages/Transaction/tests/gtest_tidb_collator.cpp          69                 9    86.96%           6                 0   100.00%          48                 0   100.00%          26                 9    65.38%
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                      609               227    62.73%         120                43    64.17%        1307               593    54.63%         378               171    54.76%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18639      9397             49.58%    212524  94895        55.35%

full coverage report (for internal network access only)

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 21, 2022
Copy link
Contributor

@zanmato1984 zanmato1984 left a comment

Choose a reason for hiding this comment

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

LGTM

@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 Jul 21, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Jul 21, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and 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.

If you have any questions about the PR merge process, please refer to pr process.

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.

@ti-chi-bot
Copy link
Member

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

Commit hash: 9359dbb

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 21, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented Jul 21, 2022

Coverage for changed files

Filename                                               Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Columns/ColumnString.cpp                                   161                80    50.31%          24                15    37.50%         343               200    41.69%          88                44    50.00%
Columns/ColumnString.h                                      67                13    80.60%          32                 6    81.25%         167                39    76.65%          24                 6    75.00%
Functions/CollationOperatorOptimized.h                      26                20    23.08%           6                 4    33.33%         100                82    18.00%          16                10    37.50%
Interpreters/AggregationCommon.h                            65                43    33.85%          10                 8    20.00%         190               131    31.05%          46                30    34.78%
Interpreters/SetVariants.h                                   1                 1     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
Storages/Transaction/Collator.cpp                          188                46    75.53%          32                 5    84.38%         411               118    71.29%         162                64    60.49%
Storages/Transaction/CollatorUtils.h                        26                 8    69.23%           9                 2    77.78%          42                 8    80.95%          10                 3    70.00%
Storages/Transaction/tests/gtest_tidb_collator.cpp          69                 9    86.96%           6                 0   100.00%          48                 0   100.00%          26                 9    65.38%
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                      603               220    63.52%         120                41    65.83%        1302               579    55.53%         372               166    55.38%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18780      9449             49.69%    213985  95464        55.39%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot merged commit d61c1df into pingcap:master Jul 21, 2022
@solotzg solotzg deleted the optimize-sort branch July 21, 2022 09:21
@solotzg solotzg removed the type/bugfix This PR fixes a bug. label Jul 21, 2022
solotzg added a commit to solotzg/tiflash that referenced this pull request Sep 19, 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. 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. type/enhancement The issue or PR belongs to an enhancement. type/performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong behavior when handle strcmp with default collation
5 participants