简体   繁体   中英

MySQL commenting out alter table partition statement

I have a table that is empty for now but will be loaded with hundreds of millions of records. Before I do this load, I want to create some partitions on the table to improve query performance and to enable better deletion later on (just truncate an entire partition).

The alter table code I am using is:

ALTER TABLE `TABLE_NAME` 
 PARTITION BY RANGE (YEAR(DATE_FIELD)) (
 PARTITION y1 VALUES LESS THAN (2017),
 PARTITION y2 VALUES LESS THAN (2018),
 PARTITION y3 VALUES LESS THAN (2019),
 PARTITION ymax VALUES LESS THAN (2050)
 );

When I run the code in MySQL Workbench, it executes fine without any errors. when I inspect the table, the partitions do not show up in the list: 在此处输入图片说明

and in the auto generated DDL, the partition is commented out:

CREATE TABLE `TABLE_NAME` (
  `field1` decimal(5,2) DEFAULT NULL,
  `field2` decimal(5,2) DEFAULT NULL,
  `DATE_FIELD` date NOT NULL,
  `field3` float DEFAULT NULL,
  `field4` float DEFAULT NULL,
  `field5` datetime DEFAULT NULL,
  `field6` varchar(50) NOT NULL,
  PRIMARY KEY (`field6`,`DATE_FIELD`),
  KEY `dd_IDX1` (`DATE_FIELD`,`field1`,`field2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (year(`DATE_FIELD`))
(PARTITION y1 VALUES LESS THAN (2017) ENGINE = InnoDB,
 PARTITION y2 VALUES LESS THAN (2018) ENGINE = InnoDB,
 PARTITION y3 VALUES LESS THAN (2019) ENGINE = InnoDB,
 PARTITION ymax VALUES LESS THAN (2050) ENGINE = InnoDB) */

I cannot figure out why this would be. I loaded some fake records to see if the lack of data was causing the issue. I also tried commenting out the partitions and created a new table with no luck.

After more research, I am going to chalk up the fact that the partitions do not show up in the Partitions screen when clicking Table Inspector to a bug in the GUI. When you select Alter Table and look at the partitioning tab, they show up there. Additionally, when checking the PARTITIONS information table the partitions show up there as well. See Rick James answer to understand the comment syntax.

/*!50100 ... */ is a special type of comment. It says "If the version is 5.1.0 or later, include the text as real; else leave it as just a comment.

So, if you ran this on a 5.0 server, it would not have partitions. (5.0 did not have PARTITIONs implemented.) But 5.1 and later will.

You will see variations on this in mysqldump output.

Meanwhile, you will probably find that you gain no performance by using PARTITIONing . What were you hoping for?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM