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 adding/dropping the primary key by a configuration #13229

Merged
merged 13 commits into from
Nov 14, 2019

Conversation

zimulala
Copy link
Contributor

@zimulala zimulala commented Nov 7, 2019

What problem does this PR solve?

Support adding/dropping the primary key by a configuration.

What is changed and how it works?

Using enable-pk-is-handle to control alter primary key feature. The default is true, which means that the alter primary key feature is disabled.
If we set this configuration item to false, we can add a primary key through "alter table", but we may not be able to drop the primary key. In order to support the "drop primary key" operation, this configuration must be false, and the table does not have the pkIsHandle flag.

Its implementation is similar to the "add/drop index" except that "add primary key" requires an additional check for not null.

Related PR pingcap/parser#617

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Support adding/dropping the primary key by the configuration of enable-pk-is-handle.

@zimulala
Copy link
Contributor Author

zimulala commented Nov 7, 2019

PTAL @crazycs520 @bb7133 @jackysp

@zimulala zimulala requested a review from bb7133 November 7, 2019 02:32
@@ -68,6 +82,205 @@ func (s *testSerialSuite) TearDownSuite(c *C) {
}
}

func (s *testSerialSuite) TestPrimaryKey(c *C) {
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 new tests for this file come from db_integration_test.go because they require newCfg.EnablePKIsHandle = true.

@codecov
Copy link

codecov bot commented Nov 7, 2019

Codecov Report

Merging #13229 into master will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master    #13229   +/-   ##
=========================================
  Coverage   80.504%   80.504%           
=========================================
  Files          472       472           
  Lines       115711    115711           
=========================================
  Hits         93152     93152           
  Misses       15382     15382           
  Partials      7177      7177

@zimulala
Copy link
Contributor Author

zimulala commented Nov 7, 2019

PTAL @eurekaka @winoros @lamxTyler

@zimulala zimulala requested a review from a team as a code owner November 7, 2019 05:26
@ghost ghost requested review from wshwsh12 and XuHuaiyu and removed request for a team November 7, 2019 05:26
@@ -66,6 +66,11 @@ delay-clean-table-lock = 0
# Maximum number of the splitting region, which is used by the split region statement.
split-region-max-num = 1000

# enable-pk-is-handle is used to control alter primary key feature. Default is true, indicate the alter primary key feature is disabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks really confused here. Why true means disable since the name is enableXXX. And the name makes me wondering enable pk to do what.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any advice?

Copy link
Member

Choose a reason for hiding this comment

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

How about change-primary-key?
There may be a potential problem when each TiDB configuration is not the same. But considering that this may be a temporary solution, it should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly, if this configuration allows, but the table's pkIsHandle is true, we also do not support drop the primary key. I think it still a little different. @jackysp @lamxTyler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly, if this configuration allows, but the table's pkIsHandle is true, we also do not support drop the primary key. I think it still a little different. @jackysp @lamxTyler

Copy link
Member

Choose a reason for hiding this comment

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

I think this difference can be explained in comments and documentation. pk-is-handle is not easy for users to understand the meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I change it to enable-alter-primary-key. @jackysp @lamxTyler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussing with PM, I change it to alter-primary-key.

@zimulala zimulala added needs-cherry-pick-3.1 status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Nov 14, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 14, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Nov 14, 2019

@zimulala merge failed.

@ericsyh
Copy link
Member

ericsyh commented Nov 14, 2019

/run-all-tests

@zimulala
Copy link
Contributor Author

/run-common-test tidb-test=pr/948
/run-integration-common-test tidb-test=pr/948
/run-unit-test

@jackysp
Copy link
Member

jackysp commented Nov 14, 2019

/merge

@sre-bot
Copy link
Contributor

sre-bot commented Nov 14, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Nov 14, 2019

@zimulala merge failed.

@zimulala
Copy link
Contributor Author

/run-common-test tidb-test=pr/948
/run-integration-common-test tidb-test=pr/948

1 similar comment
@bb7133
Copy link
Member

bb7133 commented Nov 14, 2019

/run-common-test tidb-test=pr/948
/run-integration-common-test tidb-test=pr/948

@bb7133 bb7133 merged commit df1baca into pingcap:master Nov 14, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 14, 2019

cherry pick to release-3.0 failed

@sre-bot
Copy link
Contributor

sre-bot commented Nov 14, 2019

cherry pick to release-3.1 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants