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: add partition compatibility for temporary table #24406

Merged
merged 33 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e0469fc
Merge pull request #1 from pingcap/master
Howie59 Mar 15, 2021
7d60de6
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Mar 18, 2021
0297c4a
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/Pingcap/tidb
Howie59 Apr 1, 2021
d4aa60c
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/Pingcap/tidb
Howie59 Apr 5, 2021
0362a4b
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 8, 2021
382f2ce
Merge branch 'master' of https://github.com/pingcap/tidb
Howie59 Apr 15, 2021
1108209
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 16, 2021
bf43b07
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 17, 2021
9e41542
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 19, 2021
dfc62d3
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 20, 2021
27572fa
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 23, 2021
b74d2d5
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 23, 2021
9f13862
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 27, 2021
6a86dcd
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 Apr 28, 2021
cd9321c
raise err when partition in temporary mode
Howie59 Apr 28, 2021
765208a
change pos
Howie59 May 2, 2021
bb4b31a
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb i…
Howie59 May 2, 2021
1c2aedd
add tests
Howie59 May 2, 2021
ce12242
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb
Howie59 May 2, 2021
9cbc9e0
Merge branch 'master' into check-partition
Howie59 May 2, 2021
899a34a
fix test panic
Howie59 May 2, 2021
63ead9b
add errors toml
Howie59 May 3, 2021
db713e3
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/pingcap/tidb i…
Howie59 May 3, 2021
779ee45
add tests
Howie59 May 6, 2021
d20651b
alter tests
Howie59 May 6, 2021
f7d70ae
Merge branch 'master' of https://github.saobby.my.eu.org.cnpmjs.org/Pingcap/tidb i…
Howie59 May 6, 2021
1f0b18b
Merge branch 'master' into check-partition
Howie59 May 6, 2021
951e24d
add tests
Howie59 May 6, 2021
6892896
Merge branch 'check-partition' of https://github.saobby.my.eu.org.cnpmjs.org/Howie…
Howie59 May 6, 2021
9b198b5
Merge branch 'master' into check-partition
ti-chi-bot May 6, 2021
f783c18
Merge branch 'master' into check-partition
Howie59 May 6, 2021
12ce8f7
Merge branch 'master' into check-partition
ti-chi-bot May 6, 2021
d16ac29
Merge branch 'master' into check-partition
ti-chi-bot May 6, 2021
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
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)
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
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;")
Howie59 marked this conversation as resolved.
Show resolved Hide resolved
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