Hi,
i have a table with INT columns id,key,b1,b2,c1,c2, having 1.500.000
rows. 'key' and 'id' are indexed (Kardinality 385381) and id
(Kardinality 1541525).
Performing a
SELECT * FROM table WHERE key IN (10,11,12) OR key BETWEEN 20000 AND
28000 AND b1<4500000 AND b2>3954545 AND c1<4543554 AND c2>4400000
ORDER BY id LIMIT 0,100000
on that table (linux) results in ca. 100 lines within 70..80 ms (like
expected), but sometimes it takes 10 sec(!) and more although an
EXPLAIN SELECT tells me that the index of 'key' will be used:
table type possible_keys key key_len ref rows Extra
table range key key 5 NULL 11393 Using where;
Using filesort
Doing the SELECT with changing one of the IN()-values results
afterwards is quite fast SELECT's, seems that the caching of the
underlying file system is responsible for the faster speed.
2 Questions:
1. Why are there so big time differencies SELECT's like above
_although_ the 'key' index is used ?
2. How can one optimize mysql SELECTS for the table above? Are there
optimizations in mysql´s ini file for large tables (small tables dont
show such speed diefferencies) ?
thank you. Sven