-
Notifications
You must be signed in to change notification settings - Fork 6k
planner: fix PointGetPlan.PrunePartitions
function works with non-binary collate
#62002
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
Conversation
Hi @Defined2014. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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. |
There was a problem hiding this 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
toDetachCondAndBuildRange
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
tohasNonBinaryCollate
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 thatDetachCondAndBuildRange
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.
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
/retest |
@Defined2014: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
/retest |
@Defined2014: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
There was a problem hiding this 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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 typeexpression.Column
, while the IDs frompt.GetPartitionColumnIDs()
are derived fromt.Cols()
which type istable.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`) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
/retest |
@Defined2014: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
/retest |
@Defined2014: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
[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 |
[LGTM Timeline notifier]Timeline:
|
/unhold |
/cherry-pick-release-8.5 |
/cherry-pick release-8.5 |
Signed-off-by: ti-chi-bot <[email protected]>
@Defined2014: new pull request created to branch In response to this:
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. |
What problem does this PR solve?
Issue Number: close #61965, close #59827
Problem Summary:
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.