MySQL Forums
Forum List  »  Partitioning

Re: No other way than delete primary key to create partitions by single datetime columns?
Posted by: Jonathan Stephens
Date: August 21, 2015 02:53AM

Every column referenced in a table's partitioning expression must be part of that table's PK/UKs. Since you've only the single PK, any columns used in your partitioning expression must also be part of that PK (and we needn't worry about it being part of any unique keys as well).

Make createDate part of the table's PK. Then you can use it in the partitioning expression, like so:

mysql> CREATE TABLE t1 (
    ->   id VARCHAR(64) NOT NULL,
    ->   createDate DATETIME DEFAULT NULL,
    ->   col3 INT(11) DEFAULT NULL,
    ->   col4 INT(11) DEFAULT NULL,
    ->   PRIMARY KEY (id, createDate)
    -> ) 
    ->   PARTITION p20150601 VALUES LESS THAN ('2015-06-01'),
    ->   PARTITION p20150701 VALUES LESS THAN ('2015-07-01'),
    -> ); 
Query OK, 0 rows affected (0.74 sec)

As you can see, you do not need to include every column from the PK in the partitioning key.

See for more info and examples.

Good luck!

Jon Stephens
MySQL Documentation Team @ Oracle
Stockholm, Sweden

MySQL Dev Zone
MySQL Server Documentation

Edited 1 time(s). Last edit at 08/21/2015 03:59AM by Jonathan Stephens.

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.