PDA

View Full Version : Mysql not using correct indexes and may be a bug


cobaku
11-13-2009, 09:45 PM
SELECT threadid, title, prefixid, lastpost, replycount FROM thread AS thread WHERE forumid = 1393 AND visible = 1 AND open <> 10 ORDER BY dateline DESC LIMIT 6960,87;
when i execute this query mysql uses a random index named forumid
and
the query executes in 10.17 sec

when i force an index like below

SELECT threadid, title, prefixid, lastpost, replycount FROM thread AS thread FORCE INDEX(zarchivethread) WHERE forumid = 1393 AND visible = 1 AND open <> 10 ORDER BY dateline DESC LIMIT 6960,87;

when i do above and force index
the query executes in 0.17 sec


My question is is there any way in mysql to chose correct index (automaticly) i dont want to change php 1 by 1

this is really important for me, i would be happy if i get an answer.
thanks alot.