Page 1 of 1
best query for mysql speed
Posted: Mon Jul 20, 2009 11:00 am
by sn4k3
what will be more fast to mysql execute
DB: InnoDB
Primary Index: id
Code: Select all
SELECT * FROM table WHERE id = some_int LIMIT 1ORSELECT * FROM table LIMIT some_int , 1
Thanks
Re: best query for mysql speed
Posted: Mon Jul 20, 2009 2:51 pm
by Darhazer
You always can test them both and compare the results. It's not that hard. The first one should be faster.
And by the way, the 2 queries can return different row... You do not guarantee in any way that with the second you will retrieve the record with id = some_int
Re: best query for mysql speed
Posted: Mon Jul 20, 2009 9:47 pm
by Benjamin
They would be the same speed unless a field in the where clause is indexed and reduced the cardinality. (The number of records to check). In that case, the first query would be faster. If the field in the where clause is NOT indexed and MySQL needs to perform a table scan the second query would be faster. Also just to clarify, by same speed I mean the difference wouldn't make a difference, performance wise.