-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ddl: Coalesce partition | tidb-test=pr/2111 #42476
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Skipping CI for Draft Pull Request. |
/test all |
/retest |
1 similar comment
/retest |
@@ -3868,6 +3868,19 @@ func (d *ddl) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, spec * | |||
if pi == nil { | |||
return errors.Trace(dbterror.ErrPartitionMgmtOnNonpartitioned) | |||
} | |||
if pi.Type == model.PartitionTypeHash || pi.Type == model.PartitionTypeKey { | |||
// Add partition for hash/key is actually a reorganize partition |
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.
// Add partition for hash/key is actually a reorganize partition | |
// Adding partition for hash/key is actually a reorganize partition |
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 command is 'ADD PARTITION', so that is what I used here, but I don't mind changing the comment if you want?
ddl/partition.go
Outdated
// So start by re-using the existing ones | ||
// For COALESCE, it will copy the remaining ones | ||
// For ADD it will copy the existing ones | ||
copy(definitions, tbInfo.Partition.Definitions) |
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 run the sql alter table t add partition partitions 3
and alter table t coalesce partition 8
, no one can get here.
What's the scenes when len(defs) != 0
?
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.
If you specify the partition definitions in CREATE or ADD PARTITION, you will have definitions, not just a number.
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.
Like:
ALTER TABLE t ADD PARTITION
(PARTITION pWithName1 COMMENT = 'Not really useful, but can be used for placement rules',
PARTITION pWithName2);
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.
But I don't understand the comment "So start by re-using the existing ones".
In the past, we don't copy the entire information from tbInfo.Partition.Definitions, only set Name
, Comment
,Policy
. Why do we need copy the entire information now ?
/retest |
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 resolve comment from the others, rest looks good to me.
} | ||
} | ||
|
||
return d.ReorganizePartitions(sctx, ident, &newSpec) |
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.
So this line is all the real changes for this functionality ...
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.
Correct, it is reusing the heavy lifting done and tested in Reorganize Partition (copy row data between partitions and recreating the indexes on each new partition).
/retest |
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.
LGTM
ddl/partition.go
Outdated
// So start by re-using the existing ones | ||
// For COALESCE, it will copy the remaining ones | ||
// For ADD it will copy the existing ones | ||
copy(definitions, tbInfo.Partition.Definitions) |
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.
But I don't understand the comment "So start by re-using the existing ones".
In the past, we don't copy the entire information from tbInfo.Partition.Definitions, only set Name
, Comment
,Policy
. Why do we need copy the entire information now ?
ddl/partition.go
Outdated
|
||
// ADD PARTITION needs to add the new partitions | ||
for i := offset; i < numParts; i++ { | ||
if (i - offset) < uint64(len(defs)) { |
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.
Is there any case which will cover the if (i - offset) < uint64(len(defs))...
code block and else
code block at the same time. If no, why dont' separate the two from loop.
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.
There should not be, since number of partitions partitions N
and partition definitions (partition p1 ..., ...)
are mutual exclusive.
But I rewrote it slightly to avoid copying all information, and only copying name, comment and placement rules.
LGTM |
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.
LGTM
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 2e248a3
|
/retest |
What problem does this PR solve?
Issue Number: close #15002
Problem Summary:
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.