mysql 按日期分区

mysql partitioning by date

我正在尝试在 mysql 中的日期列 MV_DATE 中创建分区 DATE

这是查询-

ALTER TABLE table_name PARTITION BY RANGE (TO_DAYS(MV_DATE))(PARTITION p0 VALUES LESS THAN (TO_DAYS('2015-08-31')));

我收到错误 A PRIMARY KEY must include all columns in the table's partitioning function

MV_DATE 不是我的 table 的主键。

我也试过 ALTER TABLE JOB_VOL_SWH PARTITION BY RANGE ((MV_DATE))(PARTITION p0 VALUES LESS THAN (TO_DAYS('2015-08-31'))); 抛出错误 ERROR 1659 (HY000): Field 'JB_DATE' is of a not allowed type for this type of partitioning

我已经尝试了几个选项,但 none 似乎有效。

是否有特殊的方法可以按日期范围创建分区? MYSQL table 有近十亿行数据,这几乎意味着我的查询根本没有 return(实际上)。因此,希望对 tables.

进行分区

19.6.1 Partitioning Keys, Primary Keys, and Unique Keys

This section discusses the relationship of partitioning keys with primary keys and unique keys. The rule governing this relationship can be expressed as follows: All columns used in the partitioning expression for a partitioned table must be part of every unique key that the table may have.

In other words, every unique key on the table must use every column in the table's partitioning expression. (This also includes the table's primary key, since it is by definition a unique key. This particular case is discussed later in this section.) For example, each of the following table creation statements is invalid:

参考:

https://dev.mysql.com/doc/refman/5.7/en/partitioning-limitations-partitioning-keys-unique-keys.html