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: fix create hash partition table makes tidb OOM (#16194) #16219

Merged
merged 1 commit into from
Apr 9, 2020
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
ddl: fix create hash partition table makes tidb OOM (#16194)
  • Loading branch information
tiancaiamao authored and sre-bot committed Apr 9, 2020
commit 2de5533a2005d3f54d19c96a49b35e4c3e25cbf1
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
4 changes: 4 additions & 0 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.CreateTableStmt) (*m
}

func buildHashPartitionDefinitions(ctx sessionctx.Context, s *ast.CreateTableStmt, pi *model.PartitionInfo) error {
if err := checkAddPartitionTooManyPartitions(pi.Num); err != nil {
return err
}

defs := make([]model.PartitionDefinition, pi.Num)
for i := 0; i < len(defs); i++ {
if len(s.Partition.Definitions) == 0 {
Expand Down