MySQL Forums
Forum List  »  Optimizer & Parser

min() vs limit optimization
Posted by: Paul Medynski
Date: July 02, 2006 05:34PM

So which of these is faster:

select min(StuffId) from Stuff where StuffId > X;

select StuffId from Stuff where StuffId > X limit 1;

where StuffId is the primary key of the Stuff table, and X is some variable. In my tests using an InnoDB table, both of these queries return the same result.

I read in the 5.1 Manual (Section 7.4.5) that min() is optimized when its argument has a unique key used in the where clause, but it only showed an example using equals (=). I need to know if that optimization holds true when using greater-than (>). In Sybase, min() is brain-dead, and using the limit is extremely fast.

-Paul

Options: ReplyQuote


Subject
Views
Written By
Posted
min() vs limit optimization
5514
July 02, 2006 05:34PM
2215
July 02, 2006 08:26PM
2157
July 03, 2006 05:22PM
2311
July 04, 2006 06:51AM


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.