active_sample
active_sample copied to clipboard
Scaling problem.
It is not scalable when you have millions of records. An array with millions of elements would go out of memory, and moreover it's prohibitively slow on the DB as it compares millions of IDs per record as you scan the table - it's called O(N^2) problem.
ORDER BY RAND() LIMIT 10 is a workable alternative, which is order of magnitude faster, but still slow given the millions.
Oh and if you want the random order, not just ids, ORDER BY FIELD().