MySQL Forums
Forum List  »  Optimizer & Parser

Re: sometimes, mysql don't use an existing index
Posted by: Toa Sty
Date: September 11, 2006 06:29AM

Hi there,

With your first statement my guess is that the condition on the timestamp is not selective enough to warrant using index lookups. i.e. I guess that mysql considers it more efficient to just table scan in this case, because there is such a large proportion of matching rows.

In your second example the condition on the timestamp *is* selective enough to warrant using index lookups, so that's what mysql does.


I don't know your data distribution but I would imagine that you'll get much better results by getting the query to use a trace.customerID index rather than the timestamp one as I imagine it's much more selective.
(how many rows would you expect a particular customerID to match? Not that many I guess)

Try adding an index on the trace table on (customerID, timestamp) and see what the explain plan for the query then looks like. (and post it here)

There may be more (or better) things that can be done, but let's see what difference this makes. I suspect it will make quite a lot.

BTW it may take a while to add on a table of 50M rows so it's probably do it on a non-live db :)

HTH,
Toasty

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: sometimes, mysql don't use an existing index
2788
September 11, 2006 06:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.