I have the following table:
CREATE TABLE `CustomerRatings` (
`movie_id` int NOT NULL,
`category_id` int NOT NULL,
`customer_score` double NOT NULL,
`num_of_theaters` double NOT NULL DEFAULT '0',
PRIMARY KEY (`movie_id`,`category_id`)
)
I'd like to be able to do efficient queries having num_of_theaters
as part of the WHERE
condition (along with movie_id and category_id).
I think that if I add a new index as follows:
`KEY (`movie_id`,`category_id`,`num_of_theaters`)
that should help but I am not sure if the cardinality of the columns matter in this case.
The category_id
has much lower cardinality (very small range of values) than num_of_theaters
. Would that affect the index and should the order of the cols in the index definition be different? Or is there another more efficient approach?
Note: In case it matters the most common condition would be num_of_theaters > 0
or num_of_theaters <> 0