Skip to content

Commit

Permalink
ddl: check only the range type partition (#7599)
Browse files Browse the repository at this point in the history
ddl: check only the range type partition
  • Loading branch information
ciscoxll authored Sep 6, 2018
1 parent 5dc1dbd commit 7c6c279
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 18 deletions.
49 changes: 49 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,55 @@ func (s *testDBSuite) TestCreateTableWithPartition(c *C) {
partition p3 values less than (18446744073709551000 + 1),
partition p4 values less than (18446744073709551000 + 10)
);`)

// Only range type partition is now supported, range columns partition only implements the parser, so it will not be checked.
// So the following SQL statements can be executed successfully.
s.tk.MustExec(`create table t29 (
a decimal
)
partition by range columns (a)
(partition p0 values less than (0));`)
}

func (s *testDBSuite) TestCreateTableWithHashPartition(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test;")
s.tk.MustExec("drop table if exists employees;")
s.tk.MustExec(`
create table employees (
id int not null,
fname varchar(30),
lname varchar(30),
hired date not null default '1970-01-01',
separated date not null default '9999-12-31',
job_code int,
store_id int
)
partition by hash(store_id) partitions 4;`)

s.tk.MustExec("drop table if exists employees;")
s.tk.MustExec(`
create table employees (
id int not null,
fname varchar(30),
lname varchar(30),
hired date not null default '1970-01-01',
separated date not null default '9999-12-31',
job_code int,
store_id int
)
partition by hash( year(hired) ) partitions 4;`)
}

func (s *testDBSuite) TestCreateTableWithKeyPartition(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test;")
s.tk.MustExec("drop table if exists tm1;")
s.tk.MustExec(`create table tm1
(
s1 char(32) primary key
)
partition by key(s1) partitions 10;`)
}

func (s *testDBSuite) TestTableDDLWithFloatType(c *C) {
Expand Down
40 changes: 22 additions & 18 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,29 +907,33 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e
return errors.Trace(err)
}

if pi != nil {
if err = checkPartitionNameUnique(tbInfo, pi); err != nil {
return errors.Trace(err)
}
if pi != nil && pi.Type == model.PartitionTypeRange {
// Only range type partition is now supported.
// Range columns partition only implements the parser, so it will not be checked.
if s.Partition.ColumnNames == nil {
if err = checkPartitionNameUnique(tbInfo, pi); err != nil {
return errors.Trace(err)
}

if err = checkCreatePartitionValue(ctx, tbInfo, pi, cols); err != nil {
return errors.Trace(err)
}
if err = checkCreatePartitionValue(ctx, tbInfo, pi, cols); err != nil {
return errors.Trace(err)
}

if err = checkAddPartitionTooManyPartitions(len(pi.Definitions)); err != nil {
return errors.Trace(err)
}
if err = checkAddPartitionTooManyPartitions(len(pi.Definitions)); err != nil {
return errors.Trace(err)
}

if err = checkPartitionFuncValid(ctx, tbInfo, s.Partition.Expr); err != nil {
return errors.Trace(err)
}
if err = checkPartitionFuncValid(ctx, tbInfo, s.Partition.Expr); err != nil {
return errors.Trace(err)
}

if err = checkPartitionFuncType(ctx, s, cols, tbInfo); err != nil {
return errors.Trace(err)
}
if err = checkPartitionFuncType(ctx, s, cols, tbInfo); err != nil {
return errors.Trace(err)
}

if err = checkRangePartitioningKeysConstraints(ctx, s, tbInfo, newConstraints); err != nil {
return errors.Trace(err)
if err = checkRangePartitioningKeysConstraints(ctx, s, tbInfo, newConstraints); err != nil {
return errors.Trace(err)
}
}
tbInfo.Partition = pi
}
Expand Down

0 comments on commit 7c6c279

Please sign in to comment.