pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.32k stars 5.72k forks source link

util/ranger: support use `like` to build range for new collation columns | tidb-test=pr/2247 #48522

Closed time-and-fate closed 5 months ago

time-and-fate commented 6 months ago

What problem does this PR solve?

Issue Number: close #48181 close #49138

What is changed and how it works?

  1. For the builder in pkg/util/ranger/points.go, we provide a new parameter convertToSortKey bool. If it's true, we can build ranges for new collation columns in newBuildFromPatternLike. The user of builder should specify if it should convert the string values to the sort key or keep the original value.
    • Here we use KeyWithoutTrimRightSpace() and then +1 to calculate the end key. The KeyWithoutTrimRightSpace prevents regression compared to the existing behavior for binary collations. For other details, please see the comments.
  2. Add two functions pointsConvertToSortKey, and pointConvertToSortKey to do the conversion work.
    • Previously, the convertPoint happens before converting to the sort key. Specifically, it's called in points2Ranges, appendPoints2Ranges, and points2TableRanges, which are right after build(). Now we try to keep this logic unchanged. So we do a convertPoint inside these two functions before the conversion to the sort key.
    • To implement 2., we need to pass the newTp into the builder. Therefore I merged it with the previous Collator parameter for the build().
  3. The previous convertPoint is not removed because it's needed to handle non-string cases. In such a case, we need to make the existing convertPoint able to correctly handle the new sort key cases. Specifically, we need to use the binary collation instead of the collation of the column for the FieldType passed into convertPoint.
    • I also added a convertStringFTToBinaryCollate() to reduce some repeated code.
  4. In pkg/util/ranger/checker.go, remove the limitation that we can't use LIKE function on new collation column to build ranges.

Check List

Tests

Side effects

Documentation

Release note

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

Support using Range Scan on non-binary collation columns for `LIKE` functions.
ti-chi-bot[bot] commented 6 months ago

Skipping CI for Draft Pull Request. If you want CI signal for your change, please convert it to an actual PR. You can still manually trigger a test run with /test all

tiprow[bot] commented 6 months ago

Skipping CI for Draft Pull Request. If you want CI signal for your change, please convert it to an actual PR. You can still manually trigger a test run with /test all

time-and-fate commented 6 months ago

/test all

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

codecov[bot] commented 6 months ago

Codecov Report

Merging #48522 (06ee151) into master (ca9f4d3) will increase coverage by 1.1230%. Report is 4 commits behind head on master. The diff coverage is 77.2455%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #48522 +/- ## ================================================ + Coverage 71.0446% 72.1677% +1.1230% ================================================ Files 1368 1405 +37 Lines 402955 414519 +11564 ================================================ + Hits 286278 299149 +12871 + Misses 96736 96533 -203 + Partials 19941 18837 -1104 ``` | [Flag](https://app.codecov.io/gh/pingcap/tidb/pull/48522/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | Coverage Δ | | |---|---|---| | [integration](https://app.codecov.io/gh/pingcap/tidb/pull/48522/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `43.8865% <77.2455%> (?)` | | | [unit](https://app.codecov.io/gh/pingcap/tidb/pull/48522/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `71.0426% <ø> (-0.0020%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap#carryforward-flags-in-the-pull-request-comment) to find out more. | [Components](https://app.codecov.io/gh/pingcap/tidb/pull/48522/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | Coverage Δ | | |---|---|---| | [dumpling](https://app.codecov.io/gh/pingcap/tidb/pull/48522/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `53.9663% <ø> (ø)` | | | [parser](https://app.codecov.io/gh/pingcap/tidb/pull/48522/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `∅ <ø> (∅)` | | | [br](https://app.codecov.io/gh/pingcap/tidb/pull/48522/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap) | `48.3829% <ø> (-4.5858%)` | :arrow_down: |
time-and-fate commented 6 months ago

/test all

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/test unit-test

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1813616844): >/test unit-test Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/test unit-test

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1813791866): >/test unit-test Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/test mysql-test

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1813886192): >/test mysql-test Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/test mysql-test

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1818976148): >/test mysql-test Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/test mysql-test

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1819123829): >/test mysql-test Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/test check-dev2

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1819276717): >/test check-dev2 Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago
/test mysql-test
time-and-fate commented 6 months ago

/test mysql-test

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1820700987): >/test mysql-test Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/test unit-test

tiprow[bot] commented 6 months ago

@time-and-fate: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

Use /test all to run all jobs.

In response to [this](https://github.com/pingcap/tidb/pull/48522#issuecomment-1821351688): >/test unit-test Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest

time-and-fate commented 6 months ago

/retest