I have two MySQL queries which I use to help me arrange news on my website. All the fields here indicated are numeric (int or tinyint) and all have an index on them. Can somebody help me build the multi column indexes which will speed up the two queries please?
SELECT MAX(content_time) AS content_time
FROM cm_data
WHERE content_time < UNIX_TIMESTAMP()
AND page = '1'
AND (content_type = '1' OR content_type = '5')
SELECT content_id
FROM cm_data
WHERE (content_time < UNIX_TIMESTAMP()
OR (hp_time >= UNIX_TIMESTAMP() AND content_time < UNIX_TIMESTAMP()
)
)
AND page = '1'
AND (content_type = '1' OR content_type = '5')
ORDER BY hp_time DESC
, content_time DESC
LIMIT 20
And here is the DB schema:
CREATE TABLE IF NOT EXISTS `cm_data` (
`content_id` mediumint(8) NOT NULL AUTO_INCREMENT,
`content_time` int(11) DEFAULT NULL,
`hp_time` int(11) NOT NULL DEFAULT '0',
`content_type` tinyint(2) DEFAULT NULL,
`page` tinyint(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`content_id`),
KEY `content_time` (`content_time`),
KEY `content_type` (`content_type`),
KEY `page` (`page`),
);