From c0ad9605bdf83db9614ac4636e652d5440c943fb Mon Sep 17 00:00:00 2001 From: winkyao Date: Mon, 13 Aug 2018 12:14:45 +0800 Subject: [PATCH] ddl: fix panic when create table patition by range columns --- ddl/ddl_api.go | 3 ++- ddl/ddl_db_test.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 62192a19b2868..85f715161dd6a 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -803,7 +803,8 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e if err != nil { return errors.Trace(err) } - if s.Partition != nil { + // TODO: Remove the test 's.Partition.Expr != nil' when we support 'PARTITION BY RANGE COLUMNS' + if s.Partition != nil && s.Partition.Expr != nil { pi := &model.PartitionInfo{ Type: s.Partition.Tp, Expr: s.Partition.Expr.Text(), diff --git a/ddl/ddl_db_test.go b/ddl/ddl_db_test.go index 10e0efd2d15c8..9aafaf4312449 100644 --- a/ddl/ddl_db_test.go +++ b/ddl/ddl_db_test.go @@ -1469,6 +1469,9 @@ func (s *testDBSuite) TestCreateTableWithPartition(c *C) { c.Assert(part.Definitions[1].Name, Equals, "p1") c.Assert(part.Definitions[2].MaxValue, IsTrue) c.Assert(part.Definitions[2].Name, Equals, "p2") + + // Fix issue 7362. + s.tk.MustExec("create table test_partition(id bigint, name varchar(255), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION BY RANGE COLUMNS(id) (PARTITION p1 VALUES LESS THAN (10) ENGINE = InnoDB);") } func (s *testDBSuite) TestTruncateTable(c *C) {