Skip to content

Commit

Permalink
cherry pick pingcap#16194 to release-3.0
Browse files Browse the repository at this point in the history
Signed-off-by: sre-bot <[email protected]>
  • Loading branch information
tiancaiamao authored and sre-bot committed Apr 9, 2020
1 parent 2ade419 commit 53aa99a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ func (s *testIntegrationSuite7) TestCreateTableWithHashPartition(c *C) {
store_id int
)
partition by hash( year(hired) ) partitions 4;`)

// This query makes tidb OOM without partition count check.
tk.MustGetErrCode(`CREATE TABLE employees (
id INT NOT NULL,
fname VARCHAR(30),
lname VARCHAR(30),
hired DATE NOT NULL DEFAULT '1970-01-01',
separated DATE NOT NULL DEFAULT '9999-12-31',
job_code INT,
store_id INT
) PARTITION BY HASH(store_id) PARTITIONS 102400000000;`, tmysql.ErrTooManyPartitions)
}

func (s *testIntegrationSuite10) TestCreateTableWithRangeColumnPartition(c *C) {
Expand Down
8 changes: 8 additions & 0 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,19 @@ func buildTablePartitionInfo(ctx sessionctx.Context, d *ddl, s *ast.CreateTableS
return pi, nil
}

<<<<<<< HEAD
func buildHashPartitionDefinitions(ctx sessionctx.Context, d *ddl, s *ast.CreateTableStmt, pi *model.PartitionInfo) error {
genIDs, err := d.genGlobalIDs(int(pi.Num))
if err != nil {
return errors.Trace(err)
}
=======
func buildHashPartitionDefinitions(ctx sessionctx.Context, s *ast.CreateTableStmt, pi *model.PartitionInfo) error {
if err := checkAddPartitionTooManyPartitions(pi.Num); err != nil {
return err
}

>>>>>>> 4a803b1... ddl: fix create hash partition table makes tidb OOM (#16194)
defs := make([]model.PartitionDefinition, pi.Num)
for i := 0; i < len(defs); i++ {
defs[i].ID = genIDs[i]
Expand Down

0 comments on commit 53aa99a

Please sign in to comment.