Answer the question
In order to leave comments, you need to log in
Why is a composite index in MySQL not fully utilized?
There is a similar table:
CREATE TABLE `test` (
`id` int(10) unsigned,
`price` int(10) NOT NULL,
`product_id` int(10),
KEY `IdxProductIdPrice` (`product_id`,`price`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SELECT `price`, `id`, `product_id`
FROM `test`
WHERE `product_id` = 1100
ORDER BY `price` ASC;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE test ref IdxProductIdPrice IdxProductIdPrice 5 const 38000 Using where
Answer the question
In order to leave comments, you need to log in
The index is stored in a B-tree .
When =
you find the right entry is very easy.
With >
finding the desired branch is much longer, but still faster than without an index.
With order by
all the same it is necessary to touch EVERYTHING. And it's easier to do without an index.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question