active_sample icon indicating copy to clipboard operation
active_sample copied to clipboard

Scaling problem.

Open kenn opened this issue 9 years ago • 0 comments

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().

kenn avatar May 07 '16 02:05 kenn