Skip to content

Conversation

Defined2014
Copy link
Contributor

@Defined2014 Defined2014 commented Jun 25, 2025

What problem does this PR solve?

Issue Number: close #61965, close #59827

Problem Summary:

What changed and how does it work?

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 the release-note-none Denotes a PR that doesn't merit a release note. label Jun 25, 2025
@Defined2014 Defined2014 requested a review from Copilot June 25, 2025 09:30
@ti-chi-bot ti-chi-bot bot added sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 25, 2025
Copy link

tiprow bot commented Jun 25, 2025

Hi @Defined2014. 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.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors partition pruning in PointGetPlan to correctly handle non-binary collations and exports the range detachment function for broader use.

  • Export and rename detachCondAndBuildRange to DetachCondAndBuildRange in pkg/util/ranger.
  • Update PointGetPlan.PrunePartitions to detect non-binary collations, rebuild a single-point range via the new API, and use its low values for partition pruning.
  • Refactor getNameValuePairs control flow from if/else to switch for improved clarity.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/util/ranger/detacher.go Renamed and exported the DetachCondAndBuildRange function and updated callers.
pkg/planner/core/point_get_plan.go Replaced the old needsPartitionPruning with non-binary-collation logic using ranger.DetachCondAndBuildRange; refactored getNameValuePairs.
Comments suppressed due to low confidence (2)

pkg/planner/core/point_get_plan.go:389

  • [nitpick] Consider renaming containsNonBinaryCollate to hasNonBinaryCollate to align with common boolean variable naming conventions and improve readability.
		containsNonBinaryCollate := false

pkg/planner/core/point_get_plan.go:397

  • Add unit or integration tests covering the non-binary collation branch in PrunePartitions, verifying that DetachCondAndBuildRange produces exactly one point range and the subsequent partition pruning behaves correctly.
		// If a non-binary collation is used, the values in `p.IndexValues` are sort keys and cannot be used for partition pruning.

Copy link

codecov bot commented Jun 25, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 73.5680%. Comparing base (a7465f4) to head (dd2c350).
Report is 16 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #62002        +/-   ##
================================================
+ Coverage   72.9452%   73.5680%   +0.6228%     
================================================
  Files          1735       1737         +2     
  Lines        482252     490630      +8378     
================================================
+ Hits         351780     360947      +9167     
+ Misses       108880     108009       -871     
- Partials      21592      21674        +82     
Flag Coverage Δ
integration 42.5936% <80.0000%> (?)
unit 72.4942% <80.0000%> (+0.2929%) ⬆️

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

Components Coverage Δ
dumpling 52.7804% <ø> (ø)
parser ∅ <ø> (∅)
br 46.3331% <ø> (-0.3390%) ⬇️
🚀 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.

@Defined2014
Copy link
Contributor Author

/retest

@Defined2014 Defined2014 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Jun 25, 2025
Copy link

tiprow bot commented Jun 25, 2025

@Defined2014: 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.

@Defined2014
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jun 25, 2025

@Defined2014: 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.

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 26, 2025
Copy link
Contributor

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

idx := -1
p.PartitionIdx = &idx
return true, nil
if len(r.Ranges) != 1 || !r.Ranges[0].IsPoint(sctx.GetRangerCtx()) {
Copy link
Contributor

@mjonss mjonss Jun 26, 2025

Choose a reason for hiding this comment

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

Please add a test where len(r.Ranges) == 0. Like RANGE partition without MAXVALUE and a condition for value greater than last partition.
I would assume it should return true, nil in such case and use table DUAL.

Copy link
Contributor Author

@Defined2014 Defined2014 Jun 27, 2025

Choose a reason for hiding this comment

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

This function isn't related to partition tables — it only processes the AccessConditions and returns the ranger. So even it's not meet any exists partition, the len(r.Ranges) also should equals to 1.

The pruning stage is handled separately here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The root cause of these problems is that the planner uses a different function from this one, and the results of the two are not always consistent. To ensure correctness, we should use the same function here.

for _, col := range p.IdxCols {
if !collate.IsBinCollation(col.GetType(evalCtx).GetCollate()) {
// If a non-binary collation is used, the values in `p.IndexValues` are sort keys and cannot be used for partition pruning.
r, err := ranger.DetachCondAndBuildRangeForPartition(sctx.GetRangerCtx(), p.AccessConditions, p.IdxCols, p.IdxColLens, sctx.GetSessionVars().RangeMaxSize)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we looping on p.IdxCols and doing this for the full conditions, and all columns (p.IdxCols)?
Should we also check if the column is part of the partitioning expression and then check if binary collation?

Copy link
Contributor Author

@Defined2014 Defined2014 Jun 27, 2025

Choose a reason for hiding this comment

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

I added a comments here, I think it's not easy to do this right now. And this part will not affect the performance very much.

However, we currently don't have a safe and reliable way to do that. col is of type expression.Column, while the IDs from pt.GetPartitionColumnIDs() are derived from t.Cols() which type is table.Column. It's not always correctly to compare them.

`col_95` char(181) COLLATE gbk_bin NOT NULL DEFAULT 'SaMKHTyg+nlID-X3Y',
PRIMARY KEY (`col_95`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_bin
PARTITION BY RANGE COLUMNS(`col_95`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to test other partitioning schemes as well? Like RANGE COLUMNS, LIST [COLUMNS] and KEY?

Copy link
Contributor Author

@Defined2014 Defined2014 Jun 27, 2025

Choose a reason for hiding this comment

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

I don't think this is related to partition types. And also I think the test cases have already been added in PR #59918.

@Defined2014
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jun 27, 2025

@Defined2014: 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.

@Defined2014
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jun 27, 2025

@Defined2014: 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.

@Defined2014 Defined2014 added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 27, 2025
Copy link

ti-chi-bot bot commented Jun 27, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, hawkingrei

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 27, 2025
Copy link

ti-chi-bot bot commented Jun 27, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-26 07:48:39.954342007 +0000 UTC m=+949172.677520984: ☑️ agreed by hawkingrei.
  • 2025-06-27 09:47:15.123250116 +0000 UTC m=+1042687.846429095: ☑️ agreed by AilinKid.

@Defined2014
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 28, 2025
@ti-chi-bot ti-chi-bot bot merged commit ce538d6 into pingcap:master Jun 28, 2025
22 checks passed
@Defined2014
Copy link
Contributor Author

/cherry-pick-release-8.5

@Defined2014
Copy link
Contributor Author

/cherry-pick release-8.5

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 30, 2025
@ti-chi-bot
Copy link
Member

@Defined2014: new pull request created to branch release-8.5: #62082.
But this PR has conflicts, please resolve them!

In response to this:

/cherry-pick release-8.5

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.

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-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report too many partitions matching for PointGetPlan for range partition Wrong Ranges for partition pruning
5 participants