S
S
starkos2015-05-26 09:27:01
MySQL
starkos, 2015-05-26 09:27:01

Partitioning a MySql table by two fields?

There is a table:
CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP,
`updated` datetime DEFAULT ON UPDATE CURRENT_TIMESTAMP,
`status` tinyint(1) NOT NULL DEFAULT 0,
.. ..
PRIMARY KEY (`id`),
....
) ENGINE=InnoDB DEFAULT CHARSET=utf8 It is
necessary to partition this table by two fields: updated and status
Moreover, by the updated field, for example, by quarterly or by year, and by the status field, for example, from value equal to 2
Need an example of this breakdown into partitions according to the above criteria...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
egor_nullptr, 2015-05-26
@egor_nullptr

https://dev.mysql.com/doc/refman/5.6/en/partitioni...

PARTITION BY RANGE(YEAR(updated))
SUBPARTITION BY HASH(status)
SUBPARTITIONS 4 (
        PARTITION p0 VALUES LESS THAN (2000),
        PARTITION p1 VALUES LESS THAN (2010),
        PARTITION p2 VALUES LESS THAN MAXVALUE
);

The number of SUBPARTITIONS (4 in the example) is equal to the number of distinct values ​​in the status field.

S
starkos, 2015-05-26
@starkos

Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question