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: support drop sequence in TiDB #14442

Merged
merged 14 commits into from
Jan 20, 2020
Merged

ddl: support drop sequence in TiDB #14442

merged 14 commits into from
Jan 20, 2020

Conversation

AilinKid
Copy link
Contributor

support drop sequence in TiDB.

DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_name [, sequence_name] ...

What problem does this PR solve?

What is changed and how it works?

  1. drop sequence share many logic code with dropTableOrView, so I merge them together.
  2. drop sequence will also delete the sequence value kv pair (drop table and drop table will also do this. But don't worry, HDel() won't take effect if the sequence kv-pair is not exist in case of drop table/view)

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has exported function/method change
  • Has interface methods change

Related changes

  • Need to update the documentation

Release note

  • ddl: Support drop sequence in TiDB.

@AilinKid AilinKid requested a review from a team as a code owner January 10, 2020 08:59
@ghost ghost requested review from francis0407 and alivxxx and removed request for a team January 10, 2020 09:28
@AilinKid AilinKid requested review from zimulala, bb7133 and djshow832 and removed request for francis0407 and alivxxx January 10, 2020 10:16
ddl/ddl_api.go Show resolved Hide resolved
@@ -84,3 +84,37 @@ func (s *testSequenceSuite) TestCreateSequence(c *C) {
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[planner:1142]CREATE command denied to user 'localhost'@'myuser' for table 'my_seq'")
}

func (s *testSequenceSuite) TestDropSequence(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
Copy link
Member

Choose a reason for hiding this comment

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

Please add the test case for drop table SEQUCNE_NAME, 'drop view SEQUCNE_NAME`.

Also, we need to test the behavior for drop sequence TABLE_NAME, drop sequence VIEW_NAME, but not in this function. You can find a suitable place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch.

@bb7133 bb7133 changed the title ddl: Support drop sequence in TiDB. ddl: support drop sequence in TiDB Jan 11, 2020
@wwar
Copy link

wwar commented Jan 12, 2020

It does not look like privilege checks are being done here. I assume it will be handled in a followup PR?

@AilinKid
Copy link
Contributor Author

It does not look like privilege checks are being done here. I assume it will be handled in a followup PR?

Good catch! thanks for reminding me.

@bb7133 bb7133 added this to the v4.0.0 milestone Jan 16, 2020
executor/ddl.go Outdated

}

func (e *DDLExec) dropTableViewSequence(objects []*ast.TableName, obt objectType, ifExists bool) error {
Copy link
Member

Choose a reason for hiding this comment

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

The naming is weird. How about renaming it to dropTableObject and add some comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice, addressed.

executor/ddl.go Outdated
viewObject
sequenceObject
)

func (e *DDLExec) executeDropTableOrView(s *ast.DropTableStmt) error {
Copy link
Member

Choose a reason for hiding this comment

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

Please separate this function to executeDropTable and executeDropView(just what you did for Sequences).

Both of them can simply call dropTableViewSequence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, addressed.

@AilinKid
Copy link
Contributor Author

It does not look like privilege checks are being done here. I assume it will be handled in a followup PR?

I've added the check, please take a look~

@AilinKid
Copy link
Contributor Author

/build

Copy link
Contributor

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

ddl/sequence_test.go Outdated Show resolved Hide resolved
ddl/sequence_test.go Show resolved Hide resolved
@AilinKid
Copy link
Contributor Author

In MariaDB,

mariadb root@172.17.0.3:test> show create table t
1 row in set
Time: 0.006s
+-------+----------------------------------------+
| Table | Create Table                           |
+-------+----------------------------------------+
| t     | CREATE TABLE `t` (                     |
|       |   `a` int(11) DEFAULT NULL             |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------+
mariadb root@172.17.0.3:test> drop sequence if exists t
Query OK, 0 rows affected
Time: 0.001s

Perhaps skip ErrWrongObject if if exists is specified.

Exactly right, I've fixed it, PTAL

@AilinKid AilinKid requested review from tangenta and zimulala and removed request for zimulala January 19, 2020 12:31
Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

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

LGTM

@tangenta tangenta added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 19, 2020
meta/meta.go Outdated Show resolved Hide resolved
@AilinKid
Copy link
Contributor Author

/run-unit-test

@AilinKid
Copy link
Contributor Author

/run-unit-test

@AilinKid
Copy link
Contributor Author

/run-all-tests

@AilinKid
Copy link
Contributor Author

/rebuild

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@AilinKid AilinKid added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Jan 20, 2020
@bb7133
Copy link
Member

bb7133 commented Jan 20, 2020

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 20, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Jan 20, 2020

/run-all-tests

@sre-bot sre-bot merged commit b25c824 into pingcap:master Jan 20, 2020
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
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.

7 participants