3 ms·
> But ORDER BY random() will scan the whole table and assign values. Er, no, it will assign values to the result set, which may not involve a full table scan.
by cryptonector 3y ago
> But ORDER BY random() will scan the whole table and assign values.
Er, no, it will assign values to the result set, which may not involve a full table scan.
- acatton 3y agoGood point, but in the case of OP, without condition, it will do a full table scan. Also, any case of "WHERE filter ORDER BY random() LIMIT n" means "I want a tiny sample from a broad filter". So it might not be a full table scan, but it will still assign value to a lot of rows.
- cryptonector 3y ago> Good point, but in the case of OP, without condition, it will do a full table scan. And that has nothing to do with the ORDER BY random().
- tremon 3y agoYes it does, because of LIMIT N. An unordered result set will stop after the first N matches.
- cryptonector 3y agoNow that is correct.