Will code 1 be slower than code 2 ?
Code: Select all
SELECT * FROM `tableName` WHERE UserId='5'Code: Select all
SELECT * FROM `tableName` WHERE UserId='5' LIMIT 0,1Thanks
Moderator: General Moderators
Code: Select all
SELECT * FROM `tableName` WHERE UserId='5'Code: Select all
SELECT * FROM `tableName` WHERE UserId='5' LIMIT 0,1The HAVING clause is applied nearly last, just before items are sent to the client, with no optimization. (LIMIT is applied after HAVING.)
Posted by [name withheld] on March 29 2003 2:49am [Delete] [Edit]
when selecting a single random row you have to use a query like this: SELECT ... FROM my_table ORDER BY RAND() LIMIT 1.
as explain shows, mysql optimizes this VERY badly (or may be better said, doens't optimize it at all): it uses an temporary table and an extra filesort.
couldn't this be optimized?!
if not, may be add a syntax like SELECT RANDOM_ROW .... FROM my_table ..