Answer the question
In order to leave comments, you need to log in
What indexes to make for such a query in mysql?
explain select * from class_actions where type like 'newad' or type like 'renewad' and object_id=335046;
There is already an index on the type field and double on the type + object_id
explain fields shows that the indexes do not work.
Answer the question
In order to leave comments, you need to log in
where type in ('newad','renewad') and object_id=335046
Here at such request the index on object_id & type will be used.
It is rather obvious that it is necessary to hang up an index on object_id.
If your type is text (otherwise why like), then it definitely makes sense to change it to enum, then the composite (type + object_id) can start working (only the query will need to be rewritten from like to in ('newad','renewad')
The sequence of columns in the index is exactly (1) type, (2) object_id?
For the sake of testing, I put two indexes on type (VARCHAR), object_id (int):
type + object_id and object_id + type - explain shows that the first one works.
like 'newad' or type like 'renewad'
sorry, but there are no wildcards here, if it's a full match, wouldn't it be better to use =?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question