What is the most efficent method to extract 1000 random rows from a table with 100.000.000 of records without a numeric primary key?
Using ORDER BY RAND() is excluded because highly inefficent.
Looking around the best method i found is the following:
SELECT key FROM (
SELECT @cnt := COUNT( * ) +1, @lim := 1000 FROM table
)vars STRAIGHT_JOIN (
SELECT r . * , @lim := @lim -1
FROM table r
WHERE (
@cnt := @cnt -1
)
AND RAND( ) < @lim / @cnt
)i
is this the best possible method using MySQL 5 or is it possible to use more efficent code?