the it-madness

MySQL Select performance – zufällige Ergebnisse

by on Jul.26, 2011, under Technik

Das sieht doch gleich viel besser aus (ca 1M Einträge in der Datenbank):

SELECT sender_ip FROM archive ORDER BY RAND(20090301) LIMIT 10;
-> 10 rows in set (10.00 sec)
-> 10 rows in set (10.54 sec)

SELECT sender_ip FROM ( SELECT  @cnt := COUNT(*) + 1, @lim := 10 FROM archive ) vars STRAIGHT_JOIN ( SELECT  r.*, @lim := @lim – 1 FROM archive r WHERE (@cnt := @cnt – 1) AND RAND(20090301) < @lim / @cnt ) i;
-> 10 rows in set (2.84 sec)
-> 10 rows in set (2.77 sec)

:

Leave a Reply

Spam protection by WP Captcha-Free

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...