I have this central table in my schema that is getting slow to query since it hits ~6M rows. I'm planning to alter some indexes, to this on the example, to try to better fit the queries needs.
I'm also considering partitioning the table to let newst records separate from the old ones. The system oftem needs to query the last 3 months of records. The older records may be required evetually or in reports. But keep all of then is important to not allow the same records (UNIQUE KEY) to enter the system again by costumer mistake (and they try to do this every day).
- How do I compose the partition expression since I have a PK and an UNIQUE KEY?
- How much partitions seens a good start point?
- Partitioning this table seees like a good idea at all?
Example table:
- The real table have 3 times more columns and some other indexes.
- Like 7 other tables with FK pointing to this table's id.
- A simple mysqldump of this table ganerates a 2.3GB file.
- Now it is getting ~1M rows bigger each month.
- mysql Ver 14.14 Distrib 5.1.73, for debian-linux-gnu (x86_64) using readline 6.1
CREATE TABLE `docs` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`taxId` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`creator` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`model` int(2) NOT NULL,
`serie` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
`num` varchar(9) COLLATE utf8_unicode_ci NOT NULL,
`creationDt` datetime NOT NULL,
`modificationDt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `main` (`taxId`,`model`,`serie`,`num`,`creator`),
KEY `cdt` (`creationDt`, `model`, `taxId`),
KEY `mdt` (`modificationDt`, `model`, `taxId`)
) ENGINE=InnoDB AUTO_INCREMENT=7412843 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci