Skip to content

Commit

Permalink
ddl: add partition compatibility for temporary table (#24406)
Browse files Browse the repository at this point in the history
  • Loading branch information
Howie59 authored May 6, 2021
1 parent a57dc3a commit bc4a38c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/testutil"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
tmysql "github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
Expand Down Expand Up @@ -3385,3 +3386,31 @@ func (s *testIntegrationSuite7) TestPartitionListWithNewCollation(c *C) {
str := tk.MustQuery(`desc select * from t11 where a = 'b';`).Rows()[0][3].(string)
c.Assert(strings.Contains(str, "partition:p0"), IsTrue)
}

func (s *testIntegrationSuite7) TestAddTableWithPartition(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists global_partition_table;")
tk.MustGetErrCode("create global temporary table global_partition_table (a int, b int) partition by hash(a) partitions 3 ON COMMIT DELETE ROWS;", errno.ErrPartitionNoTemporary)
tk.MustExec("drop table if exists global_partition_table;")
tk.MustExec("drop table if exists partition_table;")
_, err := tk.Exec("create table partition_table (a int, b int) partition by hash(a) partitions 3;")
c.Assert(err, IsNil)
tk.MustExec("drop table if exists partition_table;")
tk.MustExec("drop table if exists partition_range_table;")
tk.MustGetErrCode(`create global temporary table partition_range_table (c1 smallint(6) not null, c2 char(5) default null) partition by range ( c1 ) (
partition p0 values less than (10),
partition p1 values less than (20),
partition p2 values less than (30),
partition p3 values less than (MAXVALUE)
) ON COMMIT DELETE ROWS;`, errno.ErrPartitionNoTemporary)
tk.MustExec("drop table if exists partition_range_table;")
tk.MustExec("drop table if exists partition_list_table;")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustGetErrCode(`create global temporary table partition_list_table (id int) partition by list (id) (
partition p0 values in (1,2),
partition p1 values in (3,4),
partition p3 values in (5,null)
) ON COMMIT DELETE ROWS;`, errno.ErrPartitionNoTemporary)
tk.MustExec("drop table if exists partition_list_table;")
}
3 changes: 3 additions & 0 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,7 @@ var (
ErrUnknownEngine = dbterror.ClassDDL.NewStd(mysql.ErrUnknownStorageEngine)

errExchangePartitionDisabled = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("Exchange Partition is disabled, please set 'tidb_enable_exchange_partition' if you need to need to enable it", nil))

// ErrPartitionNoTemporary returns when partition at temporary mode
ErrPartitionNoTemporary = dbterror.ClassDDL.NewStd(mysql.ErrPartitionNoTemporary)
)
5 changes: 5 additions & 0 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error)
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}
if tbInfo.Partition != nil && (tbInfo.TempTableType == model.TempTableGlobal || tbInfo.TempTableType == model.TempTableLocal) {
// unsupported ddl, cancel this job.
job.State = model.JobStateCancelled
return ver, errors.Trace(ErrPartitionNoTemporary)
}

tbInfo.State = model.StateNone
err := checkTableNotExists(d, t, schemaID, tbInfo.Name.L)
Expand Down
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ error = '''
Duplicate partition name %-.192s
'''

["ddl:1562"]
error = '''
Cannot create temporary table with partitions
'''

["ddl:1563"]
error = '''
Partition constant is out of partition function domain
Expand Down

0 comments on commit bc4a38c

Please sign in to comment.