We have a simple query that looks like:
SELECT a,b,c,d FROM table WHERE a=1 and b IN ('aaa', 'bbb', 'ccc', ...)
No joins at all, 5000 contsant values in the IN clause.
Now, this query takes 1-20 seconds to run on a very strong (16 core) server. The table has an index on (a,b), and we also tried reversing the index to (b,a). The server has tons of memory, and nobody is writing to this table - just 5 processes running selects like I described above.
We did some profiling and saw that some queries spend 3.5 seconds in "JOIN::optimize" (.\sql_select.cc 977). I remind you, the queries do not use joins at all.
What could be the cause for this large time spent optimizing joins on a join-less table?
Here is the result of EXPLAIN SELECT:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE table range IX_A_B IX_A_B 65 \N 5000 Using where