Implement Archiving In Mysql

Partitioning is a way in which a database (MySQL in this case) splits its actual data down into separate tables, but still get treated as a single table by the SQL layer
When partitioning is good:
INSERTs to the partitioned table go faster.  As InnoDB tables get big, their PK-based B-Trees can get very "deep", meaning large-volume INSERTs can get progressively slower.  Partitioning slows down this process.
When partitioning is bad:
If you have a lot of secondary indexes on a table, partitioning won't improve performance and may actually hurt it, particularly if you're doing searches that end up needing to visit many or sometimes all the partitions through the secondary index
Partitioning is done by several ways like Date,Id,Status etc.
Create Table
CREATE TABLE `test` (
   `id` bigint unsigned NOT NULL AUTO_INCREMENT,
   `dateCreated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `status` int default 1,
   `txt` text,
   PRIMARY KEY (`id`,`dateCreated`)
 )
Partitioning By Date
 alter table test partition by RANGE(YEAR(dateCreated)) (
 PARTITION p2016 VALUES LESS THAN (2017),
 PARTITION p2017 VALUES LESS THAN (2018),
 PARTITION p2018 VALUES LESS THAN (2019),
 PARTITION pmax VALUES LESS THAN MAXVALUE);

Comments