MySQL Forums
Forum List  »  InnoDB

Re: Slow Performance / Index not used
Posted by: Rick James
Date: August 30, 2008 12:31AM

Were your timings run twice? The first run is likely to be I/O bound; the second is likely to be at least partially cached.

PK can, and should, be used in many situations. Some simple examples:
* SELECT * FROM tbl WHERE id = 123 -- fetch one row very efficiently.
* SELECT * FROM tbl WHERE id BETWEEN 123 AND 234 -- fetch consecutive rows very efficiently
* SELECT ... FROM a, b WHERE a... AND b.id=a.id -- after deciding on which rows from 'a' to fetch, then drill directly into 'b' to find the rest of the stuff.

An example of where having a clustered PK is less efficient (as in InnoDB, vs MyISAM):
SELECT id FROM tbl WHERE id BETWEEN 123 AND 234
Now it is doing as you fear -- stepping over whole records to get just the id. On the other hand, if "id" were a secondary key, this would be more efficient and the EXPLAIN would say "Using index".

Options: ReplyQuote


Subject
Views
Written By
Posted
2810
August 28, 2008 08:46AM
1766
August 28, 2008 11:12PM
Re: Slow Performance / Index not used
1663
August 30, 2008 12:31AM


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.