I have a query in MySQL (used in a stored procedure) that searches by name and another field. When I use different combinations of these search parameters, I get quick results (from 1 to 2 s), but with some specific values, I get a query that takes 9 s to return the results on the production website. Here is what I got from the EXPLAIN instruction:
id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
--------------------------------------------
1, SIMPLE, Names, ref, IX_Name, IX_Name, 17, const, 3173, Using where
The name is declared as varchar (40) and the other field is Unsigned smallint (6). I use the index for the first 15 characters of the name (IX_Name), which is used in the query. I see that slow queries get enough rows to check the "rows" column of EXPLAIN output.
I'm not sure what I can do to improve performance. Is there anything noticeable with the EXPLAIN output above?
Thanks Tim
Timothy Mifsud
source
share