Skip to content
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

Merged
merged 17 commits into from
Apr 17, 2023

Conversation

mjonss
Copy link
Contributor

@mjonss mjonss commented Mar 22, 2023

What problem does this PR solve?

Issue Number: close #15002

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

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
Copy link
Member

ti-chi-bot commented Mar 22, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • TonsnakeLin
  • crazycs520

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot
Copy link
Member

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 added do-not-merge/needs-linked-issue 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 22, 2023
@mjonss
Copy link
Contributor Author

mjonss commented Mar 22, 2023

/test all

@mjonss mjonss mentioned this pull request Mar 29, 2023
12 tasks
@mjonss mjonss mentioned this pull request Mar 31, 2023
5 tasks
@mjonss mjonss marked this pull request as ready for review April 3, 2023 09:53
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 3, 2023
@mjonss mjonss changed the title ddl: Coalesce partition ddl: Coalesce partition | tidb-test=pr/2111 Apr 3, 2023
@mjonss
Copy link
Contributor Author

mjonss commented Apr 4, 2023

/retest

1 similar comment
@mjonss
Copy link
Contributor Author

mjonss commented Apr 5, 2023

/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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Add partition for hash/key is actually a reorganize partition
// Adding partition for hash/key is actually a reorganize partition

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 command is 'ADD PARTITION', so that is what I used here, but I don't mind changing the comment if you want?

ddl/ddl_api.go Show resolved Hide resolved
ddl/ddl_api.go Show resolved Hide resolved
ddl/ddl_api.go Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
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)
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);

Copy link
Contributor

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/ddl_api.go Outdated Show resolved Hide resolved
@mjonss
Copy link
Contributor Author

mjonss commented Apr 9, 2023

/retest

ddl/partition.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tiancaiamao tiancaiamao left a 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)
Copy link
Contributor

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 ...

Copy link
Contributor Author

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).

@mjonss
Copy link
Contributor Author

mjonss commented Apr 12, 2023

/retest

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 12, 2023
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)
Copy link
Contributor

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)) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@TonsnakeLin
Copy link
Contributor

LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 17, 2023
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@bb7133
Copy link
Member

bb7133 commented Apr 17, 2023

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 2e248a3

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 17, 2023
@hawkingrei
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot merged commit 4878ed3 into pingcap:master Apr 17, 2023
@mjonss mjonss deleted the coalesce-partition branch May 8, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support COALESCE PARTITION for hash partitioned table
7 participants