简体   繁体   English

MySQL注释掉Alter表分区语句

[英]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代码是:

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. 当我在MySQL Workbench中运行代码时,它执行得很好,没有任何错误。 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: 在自动生成的DDL中,该分区被注释掉:

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. 经过更多研究,我将总结一个事实,即在Table Inspector中单击GUI中的错误时,分区不会显示在“分区”屏幕中。 When you select Alter Table and look at the partitioning tab, they show up there. 当您选择“ Alter Table”并查看“分区”选项卡时,它们会显示在此处。 Additionally, when checking the PARTITIONS information table the partitions show up there as well. 此外,当检查PARTITIONS信息表时,分区也会显示在此处。 See Rick James answer to understand the comment syntax. 请参阅Rick James答案以了解注释语法。

/*!50100 ... */ is a special type of comment. /*!50100 ... */是一种特殊的注释。 It says "If the version is 5.1.0 or later, include the text as real; else leave it as just a comment. 它说:“如果版本是5.1.0或更高版本,则以真实文本包含;否则保留为注释。

So, if you ran this on a 5.0 server, it would not have partitions. 因此,如果您在5.0服务器上运行它,它将没有分区。 (5.0 did not have PARTITIONs implemented.) But 5.1 and later will. (5.0尚未实现PARTITIONs 。)但是5.1及更高版本会实现。

You will see variations on this in mysqldump output. 您将在mysqldump输出中看到此变化。

Meanwhile, you will probably find that you gain no performance by using PARTITIONing . 同时,您可能会发现使用PARTITIONing不会获得任何性能。 What were you hoping for? 你想要什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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