Equivalent expressions

Given a primary key field `RecNo` -

Are there any performance reasons to favor one of these two otherwise
equivalant expressions?

SELECT MAX(RecNo)
FROM SomeTable;

SELECT RecNo
FROM SomeTable
ORDER BY RecNo DESC
LIMIT 1;

Just curious.
Thomas Bartkus
Thomas Bartkus [ Di, 22 August 2006 20:29 ] [ ID #1439575 ]

Re: Equivalent expressions

Thomas Bartkus wrote:
> Given a primary key field `RecNo` -
>
> Are there any performance reasons to favor one of these two otherwise
> equivalant expressions?
>
> SELECT MAX(RecNo)
> FROM SomeTable;
>
> SELECT RecNo
> FROM SomeTable
> ORDER BY RecNo DESC
> LIMIT 1;
>
> Just curious.
> Thomas Bartkus

I think the performance differences (if any) would be easy enough to
test yourself.
Note though that there are at least a couple of situations where these
queries are not equivalent: If, for instance, a NULL value was provided
then this would appear at the top of the second query.
zac.carey [ Mi, 23 August 2006 02:38 ] [ ID #1441331 ]
Datenbanken » mailing.database.mysql » Equivalent expressions

Vorheriges Thema: newbie question: performance of large table
Nächstes Thema: how to escape mysql_connect() DNS caching?