MySQL Forums
Forum List  »  Performance

"limit 1" on a primary key - any point?
Posted by: Geoff
Date: November 10, 2005 11:39AM

I suspect I know the answer to this question already but I'd just like to check ;)

I have a web application where speed is critical. Given a table that is indexed thus:

CREATE TABLE `counts` (
`uid` varchar(20) NOT NULL default '',
`iid` bigint(10) NOT NULL default '0',
`count` int(10) NOT NULL default '0',
[...],
PRIMARY KEY (`uid`,`iid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1

my usual select statement is of the form:
SELECT count from counts WHERE uid='xxxxxxxx' AND iid='xxxxxxxxxx';

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)?

Geoff

Options: ReplyQuote


Subject
Views
Written By
Posted
"limit 1" on a primary key - any point?
1768
November 10, 2005 11:39AM
1055
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.