C
C
coderisimo2015-12-19 18:12:46
MySQL
coderisimo, 2015-12-19 18:12:46

How to optimize query speed using MySQL indexes?

There is a monstrous request which it would be good to optimize. There is no way to rewrite the query itself, but adding the necessary indexes would be very helpful.
Here's an example:
indexes2.jpg
p .`id_product` is used here, but as we can see this column does not have an independent index. It is used in a composite :
indexes1.jpg
am I correct in assuming that we need to create an index here specifically for `id_product` ?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2015-12-19
@coderisimo

No, a separate index by id_product will not be used. Why take an index, find values ​​by it and then look for them by the primary key (in innodb, clustering by the primary key), if you can search immediately by the primary key?
Now, if the primary index were id_shop & id_product - then yes, an index on id_product would be useful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question