I have the following table in a MySQL database:
CREATE TABLE `secondary_images` (
`imgId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`primaryId` int(10) unsigned DEFAULT NULL,
`view` varchar(255) DEFAULT NULL,
`imgURL` varchar(255) DEFAULT NULL,
`imgDate` datetime DEFAULT NULL,
PRIMARY KEY (`imgId`),
KEY `primaryId` (`primaryId`),
KEY `imgDate` (`imgDate`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
The SQL will be the following:
SELECT imgURL, view FROM secondary_images
WHERE primaryId={$imgId} ORDER BY imgDate DESC
As you can see I made both the primaryId
and imgDate
, Index Keys. My thinking behind that was because the WHERE
clause queries results using the primaryId
, and the ORDER
clause uses imgDate
.
My question is, would it be better to use Multiple Indexes as I am right now? Or should I a Multiple Column Index (something I don't understand all too well at the moment)?
This is what I get from EXPLAIN:
id = 1
select_type = simple
table = secondary_images
type = ref
possible_keys = primaryId
key = primaryId
key_len = 5
ref = const
rows = 1
extra = Using where; Using filesort
NOTE: This is not using a Multiple Column Index, it is the result from using the above table description.