Skip to content

Columns: optimize ColumnString filter when selectivity is high#9987

Merged
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
Lloyd-Pottiger:optimize-column-filter
Mar 12, 2025
Merged

Columns: optimize ColumnString filter when selectivity is high#9987
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
Lloyd-Pottiger:optimize-column-filter

Conversation

@Lloyd-Pottiger
Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger commented Mar 11, 2025

What problem does this PR solve?

Issue Number: ref #9699, close #10029

Problem Summary:

What is changed and how it works?

following optimization of #9670

optimize the performance of ColumnString filter when the selectivity of filter is high:

For example, when filter is `0111111111111111011111111111111101111111111111110111111111111111`, 
the mask will be `11111111111111110111111111111111101111111111111111011111111111111110`, 
since it does not be `[0]*[1]+` or `[1]+[0]*`, we need to copy each selected row one by one.

Now, we can copy 15 rows at once.

The total elapsed time of TPC-H 50 reduce from 42.9s to 41.1s.

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

Optimize the performance of ColumnString filter when the selectivity of filter is high. The total elapsed time of TPC-H 50 reduce 4%.

Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 11, 2025
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 11, 2025
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 12, 2025
Comment on lines +250 to +251
if (index + length == FILTER_SIMD_BYTES)
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding a predefined mask table?

constexpr uint64_t MASKS[65] = [] {
    uint64_t masks[65] = {};
    for (int i = 0; i < 64; ++i) {
        masks[i] = ~((1ULL << i) - 1);
    }
    masks[64] = 0;
    return masks;
}();
mast &= MASKS[index + length];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Mar 12, 2025
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.

Do we have some existing test for this?

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Mar 12, 2025
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
@ti-chi-bot ti-chi-bot 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 Mar 12, 2025
@Lloyd-Pottiger Lloyd-Pottiger changed the title Columns: optimize filter when selectivity is high Columns: optimize ColumnString filter when selectivity is high Mar 12, 2025
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
Copy link
Contributor

ti-chi-bot bot commented Mar 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gengliqi, windtalker

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [gengliqi,windtalker]

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 12, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Mar 12, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-03-12 05:58:31.082884421 +0000 UTC m=+335466.688413344: ☑️ agreed by gengliqi.
  • 2025-03-12 09:14:18.258360856 +0000 UTC m=+347213.863889783: ☑️ agreed by windtalker.

@ti-chi-bot ti-chi-bot bot merged commit 6dbd149 into pingcap:master Mar 12, 2025
5 checks passed
@Lloyd-Pottiger Lloyd-Pottiger deleted the optimize-column-filter branch March 12, 2025 10:06
@JaySon-Huang
Copy link
Contributor

/cherry-pick release-9.0-beta.1

@ti-chi-bot
Copy link
Member

@JaySon-Huang: new pull request created to branch release-9.0-beta.1: #10036.

Details

In response to this:

/cherry-pick release-9.0-beta.1

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 bot pushed a commit that referenced this pull request Mar 26, 2025
#10036)

ref #9699, close #10029

optimize the performance of ColumnString filter when the selectivity of filter is high:

For example, when filter is `0111111111111111011111111111111101111111111111110111111111111111`, 
the mask will be `11111111111111110111111111111111101111111111111111011111111111111110`, 
since it does not be `[0]*[1]+` or `[1]+[0]*`, we need to copy each selected row one by one.

Now, we can copy 15 rows at once.

The total elapsed time of TPC-H 50 reduce from 42.9s to 41.1s.

Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>

Co-authored-by: Lloyd-Pottiger <yan1579196623@gmail.com>
Co-authored-by: Lloyd-Pottiger <60744015+Lloyd-Pottiger@users.noreply.github.com>
Co-authored-by: JaySon-Huang <tshent@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Compared with v8.5.1, v9.0.0-beta1 olap has a 9.1% performance regression in ossinxxx-x86 workload

5 participants