We are running MySQL/ISAM database with a following table:
create table measurements (
`tm_stamp` int(11) NOT NULL DEFAULT '0',
`fk_channel` int(11) NOT NULL DEFAULT '0',
`value` int(11) DEFAULT NULL,
PRIMARY KEY (`tm_stamp`,`fk_channel`)
);
The tm_stamp
-fk_channel
combination is required unique, hence the compound primary key. Now, for certain irrelevant reason, the database will be migrated to InnoDB engine. Upon googling something about it, i found out that the key will dictate the physical ordering of the data on the disk. 90% of the queries currently go as follows:
SELECT value FROM measurements
WHERE fk_channel=A AND tm_stamp>=B and tm_stamp<=C
ORDER BY tm_stamp ASC
Inserts are 99% in order of tm_stamp
, it's a storage for dataloggers network. The table has low millions of rows but growing steadily. The questions are
- Should the sole change of storage engine result in any significant performance change, better or worse?
- Does the order of columns in the index matter with regards to the most popular SELECT? This blog suggest something along that line.
- Thanks to the nature of clustered index, may we perhaps leave out the ORDER BY clause and gain some performance?