The table contains about 40,000,000 records having:
CREATE TABLE `event` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`some_other_id_not_fk` int(10) unsigned default NOT NULL,
`event_time` datetime NOT NULL,
`radius` float default NULL,
`how_heavy` smallint(6) default NULL,
PRIMARY KEY (`id`),
KEY `event_some_other_id_not_fk` (`some_other_id_not_fk`),
KEY `event_event_time` (`event_time`)
) ENGINE=MyISAM AUTO_INCREMENT=6506226 DEFAULT CHARSET=utf8
You should know that some_other_id_not_fk
column is not big, it contains distinctively only 7 different numbers. The real pain is the event_time
datetime column, as it contains extremely large amounts of different datetime's, and basicly everything is allowed: duplicates as well as unpredictably large time intervals without records to 'cover' them. You should also know that (some_other_id_not_fk
,event_time
) pair must be allowed to have duplicates either :( I know this causes even more problems :(
I've had some experience in optimizing MySQL tables, but such a huge pain had never appeared on my horizon :/
The current state of 'the things' is:
- The selects by
event_time
between date1 and date2 (which I need to do) are satisfactorily fast. :) - My inserts are slow, I mean really SLOW!!! more then a 30 secs, and even worse: LOAD DATA procedures that temporary DISABLE and ENABLE KEYS are EXTREMELY slow(several hours), mainly on ENABLE keys operation.
- The size of the index on the disk is 7 times bigger then the size of the data
I would have tried several different combinations of re-indexing till now, but the size of that data really prevents me from experimenting on indexes and columns drop/create at will.
Please help anyone had managed this ? Should using timestamp instead of datetime solve my problem? Or maybe I should add additional columns for day
, year
,... etc and index on them ?