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

Support add/drop attributes for table or partition #1271

Merged
merged 9 commits into from
Jul 28, 2021

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented Jul 8, 2021

What problem does this PR solve?

It's used for the region label feature. Closes #1288.

What is changed and how it works?

This PR is going to support

ALTER TABLE t ATTRIBUTES="attr1,attr2,...,attrn"
ALTER TABLE t PARTITION p ATTRIBUTES="attr1,attr2,...,attrn"

to change the attributes of a table or a partition.

And use the following syntax to reset all attributes for a table or a partition:

ALTER TABLE t ATTRIBUTES=default
ALTER TABLE t PARTITION p ATTRIBUTES=default

Check List

Tests

  • Unit test

Related changes

  • Need to update the documentation
  • Need to be included in the release note

@CLAassistant
Copy link

CLAassistant commented Jul 8, 2021

CLA assistant check
All committers have signed the CLA.

@kennytm
Copy link
Contributor

kennytm commented Jul 8, 2021

what is the difference between this and PLACEMENT POLICY?

@morgo morgo self-requested a review July 8, 2021 05:04
ast/ddl.go Outdated
@@ -2648,6 +2651,19 @@ func (n *AlterTableSpec) Restore(ctx *format.RestoreCtx) error {
return errors.Annotatef(err, "An error occurred while restore AlterTableSpec.PlacementSpecs[%d]", i)
}
}
case AlterTableAlterPartitionAttributes:
if len(n.PartitionNames) != 1 {
return errors.Errorf("Maybe partition options are combined.")
Copy link
Member

Choose a reason for hiding this comment

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

This error message indicates the number of partion names is over 1, what about zero?

@rleungx
Copy link
Member Author

rleungx commented Jul 8, 2021

what is the difference between this and PLACEMENT POLICY?

We are going to add some attributes to a table/partition to solve some specified problems. e.g., notmerge attribute means don't merge a table. It's different from the placement rule which mainly focuses on data placement.

@morgo morgo removed their request for review July 8, 2021 21:26
@rleungx rleungx force-pushed the support-region-label branch from 143e065 to 6ebf0e8 Compare July 13, 2021 05:57
@tangenta
Copy link
Contributor

@rleungx We may also need to consider the removal syntax for attributes. Anyway, it would be better if there is a detailed design document.

@rleungx
Copy link
Member Author

rleungx commented Jul 27, 2021

PTAL @djshow832 @xhebox, thanks.

@rleungx
Copy link
Member Author

rleungx commented Jul 27, 2021

@rleungx We may also need to consider the removal syntax for attributes. Anyway, it would be better if there is a detailed design document.

How about using alter table t attributes=default for removing all attributes?

@rleungx rleungx force-pushed the support-region-label branch from ea7714f to 4d99cd9 Compare July 27, 2021 09:56
parser.y Outdated
$$ = &ast.AlterTableSpec{
Tp: ast.AlterTablePartition,
Partition: $1.(*ast.PartitionOptions),
if alterTableSpec, ok := $1.(*ast.AlterTableSpec); ok {
Copy link
Contributor

@xhebox xhebox Jul 27, 2021

Choose a reason for hiding this comment

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

I suggest adding a new term ATTRIBUTES : "ATTRIBUTES" "=" stringLit | "DEFAULT", which will return the attributes spec, to reuse and write less code.

And the change here is not elegant for me. It is strange if PartitionOpt did not return PartitionOptions.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jul 28, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • djshow832
  • xhebox

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.

Copy link
Member

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

@nolouch: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

lgtm

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.

{"ALTER TABLE t ATTRIBUTES='str1,str2'", true, "ALTER TABLE `t` ATTRIBUTES='str1,str2'"},
{"ALTER TABLE t ATTRIBUTES=DEFAULT", true, "ALTER TABLE `t` ATTRIBUTES=DEFAULT"},
{"ALTER TABLE t ATTRIBUTES=default", true, "ALTER TABLE `t` ATTRIBUTES=DEFAULT"},
{"ALTER TABLE t ATTRIBUTES=DeFaUlT", true, "ALTER TABLE `t` ATTRIBUTES=DEFAULT"},
Copy link
Member

Choose a reason for hiding this comment

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

BTW, Default meaning empty or may have some default attributes?

Copy link
Member Author

@rleungx rleungx Jul 28, 2021

Choose a reason for hiding this comment

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

It will reset the attributes. And since we don't have the default attributes for now, it can be regarded as empty.

rleungx added 5 commits July 28, 2021 14:54
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
rleungx added 3 commits July 28, 2021 14:55
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: Ryan Leung <rleungx@gmail.com>
@rleungx rleungx force-pushed the support-region-label branch from c731350 to ad6dc6b Compare July 28, 2021 06:59
Copy link
Contributor

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

parser.y Outdated
Comment on lines 1592 to 1600
"ATTRIBUTES" "=" "DEFAULT"
{
$$ = &ast.AttributesSpec{Default: true}
}
| "ATTRIBUTES" "=" stringLit
{
$$ = &ast.AttributesSpec{Default: false, Attributes: $3}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

As I recall, = is optional in all table options in MySQL.

@@ -2783,6 +2783,20 @@ func (s *testParserSuite) TestDDL(c *C) {
{"ALTER TABLE t ALTER PLACEMENT POLICY CONSTRAINTS='str' ROLE=leader REPLICAS=1", true, "ALTER TABLE `t` ALTER PLACEMENT POLICY CONSTRAINTS='str' ROLE=LEADER REPLICAS=1"},
{"ALTER TABLE t ADD PLACEMENT POLICY CONSTRAINTS='str1' ROLE=leader REPLICAS=1, ADD PLACEMENT POLICY CONSTRAINTS='str2' ROLE=leader REPLICAS=1", true, "ALTER TABLE `t` ADD PLACEMENT POLICY CONSTRAINTS='str1' ROLE=LEADER REPLICAS=1, ADD PLACEMENT POLICY CONSTRAINTS='str2' ROLE=LEADER REPLICAS=1"},

// alter attributes
{"ALTER TABLE t ATTRIBUTES='str'", true, "ALTER TABLE `t` ATTRIBUTES='str'"},
{"ALTER TABLE t ATTRIBUTES='str1,str2'", true, "ALTER TABLE `t` ATTRIBUTES='str1,str2'"},
Copy link
Contributor

Choose a reason for hiding this comment

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

How about double quotation marks, like "str1, str2"?

Signed-off-by: Ryan Leung <rleungx@gmail.com>
@ti-chi-bot ti-chi-bot added status/LGT2 LGT2 and removed status/LGT1 LGT1 labels Jul 28, 2021
@djshow832
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 8938372

@ti-chi-bot ti-chi-bot merged commit 915a010 into pingcap:master Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support attributes syntax for alter table/partition operations
9 participants