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: check no partitions error when create partition table (#9531) #9663

Merged
merged 7 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,8 @@ func (s *testDBSuite) TestCreateTableWithPartition(c *C) {
)
partition by range columns (a)
(partition p0 values less than (0));`)

s.testErrorCode(c, `create table t31 (a int not null) partition by range( a );`, tmysql.ErrPartitionsMustBeDefined)
}

func (s *testDBSuite) TestCreateTableWithHashPartition(c *C) {
Expand Down
4 changes: 4 additions & 0 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ var (
ErrDropLastPartition = terror.ClassDDL.New(codeDropLastPartition, mysql.MySQLErrName[mysql.ErrDropLastPartition])
//ErrTooManyPartitions returns too many partitions were defined.
ErrTooManyPartitions = terror.ClassDDL.New(codeTooManyPartitions, mysql.MySQLErrName[mysql.ErrTooManyPartitions])
//ErrNoParts returns no partition were defined.
ErrNoParts = terror.ClassDDL.New(codeNoParts, mysql.MySQLErrName[mysql.ErrNoParts])
//ErrPartitionFunctionIsNotAllowed returns this partition function is not allowed.
ErrPartitionFunctionIsNotAllowed = terror.ClassDDL.New(codePartitionFunctionIsNotAllowed, mysql.MySQLErrName[mysql.ErrPartitionFunctionIsNotAllowed])
// ErrPartitionFuncNotAllowed returns partition function returns the wrong type.
Expand Down Expand Up @@ -618,6 +620,7 @@ const (
codeErrTooManyValues = terror.ErrCode(mysql.ErrTooManyValues)
codeDropLastPartition = terror.ErrCode(mysql.ErrDropLastPartition)
codeTooManyPartitions = terror.ErrCode(mysql.ErrTooManyPartitions)
codeNoParts = terror.ErrCode(mysql.ErrNoParts)
codePartitionFunctionIsNotAllowed = terror.ErrCode(mysql.ErrPartitionFunctionIsNotAllowed)
codeErrPartitionFuncNotAllowed = terror.ErrCode(mysql.ErrPartitionFuncNotAllowed)
codeErrFieldTypeNotAllowedAsPartitionField = terror.ErrCode(mysql.ErrFieldTypeNotAllowedAsPartitionField)
Expand Down Expand Up @@ -666,6 +669,7 @@ func init() {
codeErrTooManyValues: mysql.ErrTooManyValues,
codeDropLastPartition: mysql.ErrDropLastPartition,
codeTooManyPartitions: mysql.ErrTooManyPartitions,
codeNoParts: mysql.ErrNoParts,
codePartitionFunctionIsNotAllowed: mysql.ErrPartitionFunctionIsNotAllowed,
codeErrPartitionFuncNotAllowed: mysql.ErrPartitionFuncNotAllowed,
codeErrFieldTypeNotAllowedAsPartitionField: mysql.ErrFieldTypeNotAllowedAsPartitionField,
Expand Down
4 changes: 4 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,10 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e
return errors.Trace(err)
}

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

if err = checkPartitionFuncValid(ctx, tbInfo, s.Partition.Expr); err != nil {
return errors.Trace(err)
}
Expand Down
7 changes: 7 additions & 0 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ func checkAddPartitionTooManyPartitions(piDefs uint64) error {
return nil
}

func checkNoRangePartitions(partitionNum int) error {
if partitionNum == 0 {
return errors.Trace(ErrPartitionsMustBeDefined)
}
return nil
}

func getPartitionIDs(table *model.TableInfo) []int64 {
if table.GetPartitionInfo() == nil {
return []int64{}
Expand Down