max or not max?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a question about the use of the function "max" and the use of index.
I have a table with primary key "nr" (DataType Integer).

when i do

desc select max(nr) from data_sales

the result is:

id: 1
select_type: SIMPLE
table: NULL
type: NULL
possible_keys NULL
key: NULL
key_len: NULL
ref: NULL
rows: NULL
Extra Select tables optimized away

if i rewrite my query to:

desc select nr from data_sales order by nr desc limit 1

the result is:
table: data_sales
type: index
possible_keys: NULL
rows: Using index

Does this mean the second query is better? or is "max" otherwise optimized?


Re: max or not max?

Mark wrote:

Quoted text here. Click to load it

AFAIK max() is optimized internally. Use it instead of custom queries.

Site Timeline