Skip to content

Planner: Run full partition pruning if convertToPointGet converted keys to SortKey #59918

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

Merged
merged 16 commits into from
Mar 12, 2025

Conversation

mjonss
Copy link
Contributor

@mjonss mjonss commented Mar 5, 2025

What problem does this PR solve?

Issue Number: close #59827

Problem Summary:
When PointGetPlan is created by convertToPointGet, the IndexValues comes from the Range optimizer, and if any of the LIST/RANGE COLUMNS has a non-binary collation, they conditions values are converted to SortKey, which does not work with the LIST/RANGE COLUMNS partitioning pruning code, since they will unconditionally convert it again to SortKey, which may fail finding a matching partition.

NOTE: This only affects PointGet, since BatchPointGet is not supported yet.

What changed and how does it work?

If the IndexValues are already converted, run the normal partition pruning code on the conditions, to find the matching partition.

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.

Partition Pruning could fail and choose 'TableDual', i.e. no matching partition, in case the optimizer could convert the query to PointGet (if not using the FastPlan) and any LIST COLUMNS or RANGE COLUMNS had non-binary collation.

Copy link

ti-chi-bot bot commented Mar 5, 2025

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

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 5, 2025
Copy link

tiprow bot commented Mar 5, 2025

Hi @mjonss. 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-sigs/prow repository.

@mjonss
Copy link
Contributor Author

mjonss commented Mar 5, 2025

/test all

Copy link

tiprow bot commented Mar 5, 2025

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

In response to this:

/test all

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-sigs/prow repository.

@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 6, 2025
@mjonss
Copy link
Contributor Author

mjonss commented Mar 6, 2025

/retest

Copy link

tiprow bot commented Mar 6, 2025

@mjonss: 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-sigs/prow repository.

Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 63.30275% with 40 lines in your changes missing coverage. Please review.

Project coverage is 73.2799%. Comparing base (d392685) to head (7f64780).
Report is 97 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #59918        +/-   ##
================================================
+ Coverage   72.9654%   73.2799%   +0.3145%     
================================================
  Files          1699       1703         +4     
  Lines        469477     476770      +7293     
================================================
+ Hits         342556     349377      +6821     
- Misses       105828     106093       +265     
- Partials      21093      21300       +207     
Flag Coverage Δ
integration 42.7406% <30.2752%> (?)
unit 72.6821% <62.3853%> (+0.2289%) ⬆️

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

Components Coverage Δ
dumpling ∅ <ø> (∅)
parser ∅ <ø> (∅)
br 46.1044% <ø> (-0.3110%) ⬇️
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mjonss
Copy link
Contributor Author

mjonss commented Mar 6, 2025

KEY partitioning does not seem to be affected, since it is using val.ToHashKey() which is using the value's collation, meaning that if it already is converted to binary SortKey, it will get the same hash/key partition as if it is a non-converted values with the original collation, which will be converted in val.ToHashKey()

@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 6, 2025
@mjonss mjonss marked this pull request as ready for review March 6, 2025 18:08
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 6, 2025
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. 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 10, 2025
@mjonss mjonss requested a review from qw4990 March 10, 2025 13:13
Comment on lines +361 to +387
// TODO: Is there a simpler way, or existing function for this?!?
tblCols := make([]*expression.Column, 0, len(indexInfo.Columns))
var partNameSlice types.NameSlice
for _, tblCol := range tblInfo.Columns {
found := false
for _, idxCol := range indexCols {
if idxCol.ID == tblCol.ID {
tblCols = append(tblCols, idxCol)
found = true
break
}
}
partNameSlice = append(partNameSlice, &types.FieldName{
ColName: tblCol.Name,
TblName: tblInfo.Name,
DBName: ast.NewCIStr(dbName),
OrigTblName: tblInfo.Name,
OrigColName: tblCol.Name,
})
if !found {
tblCols = append(tblCols, &expression.Column{
ID: tblCol.ID,
OrigName: tblCol.Name.O,
RetType: tblCol.FieldType.Clone(),
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this operations common for partitioning tables? If Yes, could we wrap this operation as a separate function in partition_prune.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried using ColumnInfos2ColumnsAndNames() but there were test failures. So I'm keeping this code for now.

Copy link

ti-chi-bot bot commented Mar 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Defined2014, qw4990

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 Mar 12, 2025
Copy link

ti-chi-bot bot commented Mar 12, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-03-10 09:52:41.19161533 +0000 UTC m=+176716.797144257: ☑️ agreed by Defined2014.
  • 2025-03-12 00:41:23.919209587 +0000 UTC m=+316439.524738509: ☑️ agreed by qw4990.

@qw4990
Copy link
Contributor

qw4990 commented Mar 12, 2025

/test unit-test

Copy link

tiprow bot commented Mar 12, 2025

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

In response to this:

/test unit-test

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-sigs/prow repository.

Copy link

tiprow bot commented Mar 12, 2025

@mjonss: 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
fast_test_tiprow 7f64780 link true /test fast_test_tiprow

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

@ti-chi-bot ti-chi-bot bot merged commit 89cab6a into pingcap:master Mar 12, 2025
23 of 24 checks passed
@mjonss mjonss deleted the partition-point-get-prune-59827 branch March 12, 2025 08:03
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-9.0-beta.1: #60161.

@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Mar 19, 2025
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Mar 19, 2025
@ti-chi-bot
Copy link
Member

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

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-8.5 Should cherry pick this PR to release-8.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner 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.

Wrong Ranges for partition pruning
4 participants