MySQL Forums
Forum List  »  Performance

Re: "limit 1" on a primary key - any point?
Posted by: Jay Pipes
Date: November 11, 2005 01:53PM

Geoff wrote:
> Is there any advantage in specifying "limit 1" or
> is that implicit in MySQL's analysis of the
> statement? i.e. does MySQL know that the primary
> key must be unique so it automatically stops after
> the first hit and doesn't go on to search for any
> other rows (even if "limit 1" is not specified)?

No. It will be optimized away by mysql and you shall see in the results of EXPLAIN SELECT that mysql is using a (const,const) primary key lookup with 1 row returned.

BTW, if speed is indeed critical, I would recommend trimming your data types to the INT column type instead of BIGINT. That is unless you *really* will be using > 4 billion unique iid values...

Jay Pipes
Community Relations Manager, North America, MySQL Inc.

Got Cluster? http://www.mysql.com/cluster
Personal: http://jpipes.com

Options: ReplyQuote


Subject
Views
Written By
Posted
1755
November 10, 2005 11:39AM
Re: "limit 1" on a primary key - any point?
1238
November 11, 2005 01:53PM
1048
November 12, 2005 06:20AM


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.