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

schemadiff: support for RangeRotationStrategy diff hint #10131

Merged

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Apr 24, 2022

Description

Diffing partitions is a complex topic. There can be scenarios where a change of partitioning scheme required an entire rebuild of the table (e.g. change of number of HASH partitions), and cases where optimally one could get by with only modifying some of the partitions (e.g. COALESCE two partitions into one).

Normally, when we see a diff of partitions, we just invoke an ALTER TABLE... PARTITION BY... with the entire new partitioning scheme. The idea? Even a COALESCE for two partitions out of 200 is a blocking schema change. As we push forward Online DDL, we are opinionated that it's better to rebuild the entire table, online, than just 2 partitions out of 200, in a blocking operation.

However, there are exceptions to this.

A common partitioning scheme that does not require blocking: rotation of range partitioning. The classic example is, say, partitioning by day, such that every day we add a new partition; and possibly every day we also purge an old partition.
We could be adding a bunch of partitions at a time, or drop a bunch of partitions at a time.
Adding new partitions is super cheap, and dropping old partitions can be cheap or expensive, depending on the size of dropped partition and version of MySQL.

In this PR schemadiff identifies a rotating range partitioning scheme: two tables that are partitioned by RANGE, share exactly one consecutive non-empty sequence of partitions (i.e., the two tables have some partitions in common), and possibly:

  • 1st table (aka "old" table) does not have some newer partitions (these have just been rotated in), and
  • 2nd table (aka "new" table) does not have some older partitions (they have been rotated away)

As of this PR schemadiff supports a RangeRotationStrategy, of the following values:

  • RangeRotationFullSpec: generate a full partitioning spec, meaning do not optimize for partition rotation; this behavior is the same as before this PR
  • RangeRotationIgnore: consider this as a non-diff. This is similar in concept to ignoring an AUTO_INCREMENT increase.
  • RangeRotationStatements NOT YET IMPLEMENTED. Will throw an error. Once implemented, will return the proper DROP PARTITION ... and ADD PARTITION ... statements that perform the rotation.

Checklist

  • "Backport me!" label has been added if this change should be backported
  • Tests were added or are not required
  • Documentation was added or is not required

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving release notes none labels Apr 24, 2022
@shlomi-noach
Copy link
Contributor Author

To support RangeRotationStatements we'd first need an AddPartition and DropPartition statements in AST, that implement AlterOption via iAlterOption().

@shlomi-noach shlomi-noach requested a review from a team April 25, 2022 08:40
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

It looks good to me! What might be worth noting is that, we are expanding the parsing support for partition definitions (#10127 ) along with sub partitions (soon to follow).

@shlomi-noach
Copy link
Contributor Author

What might be worth noting is that, we are expanding the parsing support for partition definitions (#10127 ) along with sub partitions

Oh wonderful! Do you think we might be able to then have:

AddPartition and DropPartition statements in AST, that implement AlterOption via iAlterOption().

?

@GuptaManan100
Copy link
Member

Oh wonderful! Do you think we might be able to then have:

AddPartition and DropPartition statements in AST, that implement AlterOption via iAlterOption().

?

Yes! Most definitely. We can work on that before subpartitions, since I see you need it for completing this work!

@shlomi-noach shlomi-noach merged commit 2f7eb97 into vitessio:main Apr 25, 2022
@shlomi-noach shlomi-noach deleted the schemadiff-range-partition-rotation branch April 25, 2022 16:38
@shlomi-noach
Copy link
Contributor Author

@GuptaManan100 thank you! There is no urgency for this work.

@GuptaManan100
Copy link
Member

@shlomi-noach I checked, and apparently we already have parsing support for ADD PARTITION, DROP PARTITION, etc already. It was added way back in #7199. These don't implement the AlterOption interface and instead are specified in PartitionSpec in the AlterTable field. I don't remember exactly why I implemented it this way but my guess would be, we did this because there can be multiple alter options, but only 1 partition alter in a statement. This is written at the end of the doc here - https://dev.mysql.com/doc/refman/8.0/en/alter-table.html

@GuptaManan100
Copy link
Member

With this we augmented the partition definition, which also added that additional parsing to ADD PARTITION so we should be good there too

@shlomi-noach
Copy link
Contributor Author

@GuptaManan100 ahhh, that's right! Now I see it. Thank you.

@shlomi-noach
Copy link
Contributor Author

Tracking issue: #10203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants