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 truncate partition all support #23040

Merged
merged 6 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6592,3 +6592,16 @@ func (s *testSerialDBSuite) TestIssue22819(c *C) {
_, err := tk1.Exec("commit")
c.Assert(err, ErrorMatches, ".*8028.*Information schema is changed during the execution of the statement.*")
}

func (s *testSerialSuite) TestTruncateAllPartitions(c *C) {
tk1 := testkit.NewTestKit(c, s.store)
tk1.MustExec("use test;")
tk1.MustExec("drop table if exists partition_table;")
defer func() {
tk1.MustExec("drop table if exists partition_table;")
}()
tk1.MustExec("create table partition_table (v int) partition by hash (v) partitions 10;")
tk1.MustExec("insert into partition_table values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10);")
tk1.MustExec("alter table partition_table truncate partition all;")
tk1.MustQuery("select count(*) from partition_table;").Check(testkit.Rows("0"))
}
17 changes: 12 additions & 5 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2971,12 +2971,19 @@ func (d *ddl) TruncateTablePartition(ctx sessionctx.Context, ident ast.Ident, sp
}

pids := make([]int64, len(spec.PartitionNames))
for i, name := range spec.PartitionNames {
pid, err := tables.FindPartitionByName(meta, name.L)
if err != nil {
return errors.Trace(err)
if spec.OnAllPartitions {
pids = make([]int64, len(meta.GetPartitionInfo().Definitions))
for i, def := range meta.GetPartitionInfo().Definitions {
pids[i] = def.ID
}
} else {
for i, name := range spec.PartitionNames {
pid, err := tables.FindPartitionByName(meta, name.L)
if err != nil {
return errors.Trace(err)
}
pids[i] = pid
}
pids[i] = pid
}

job := &model.Job{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20210308063835-39b884695fb8
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8
github.com/pingcap/parser v0.0.0-20210311132237-9841cb715606
github.com/pingcap/parser v0.0.0-20210314080929-ed8900c94180
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99
github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible
github.com/pingcap/tipb v0.0.0-20210309080453-72c4feaa6da7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIf
github.com/pingcap/log v0.0.0-20200511115504-543df19646ad/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8 h1:M+DNpOu/I3uDmwee6vcnoPd6GgSMqND4gxvDQ/W584U=
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/parser v0.0.0-20210311132237-9841cb715606 h1:/d3CdGzpfCRbdKn38gYH4FGEXgTJCzfI8yroEfKcwbA=
github.com/pingcap/parser v0.0.0-20210311132237-9841cb715606/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE=
github.com/pingcap/parser v0.0.0-20210314080929-ed8900c94180 h1:pnTbjUpOib2uhBfm9R9P6n1huAvl5a9CtMysvI493hQ=
github.com/pingcap/parser v0.0.0-20210314080929-ed8900c94180/go.mod h1:GbEr2PgY72/4XqPZzmzstlOU/+il/wrjeTNFs6ihsSE=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99 h1:/ogXgm4guJzow4UafiyXZ6ciAIPzxImaXYiFvTpKzKY=
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
Expand Down