3 ms·
Why was the random function done this way? Is it not possible to index into a database table at a random position?
by t0astbread 4y ago
Why was the random function done this way? Is it not possible to index into a database table at a random position?
- bombcar 4y agoI assume it's for performance reasons, a "select next greater than X" being faster than "get a random row" - not sure if databases even have the concept of returning a random row, or how performant it is.
- K2L8M11N2 4y agoI can't think of a reason why getting an article with ID of randomIntBetween(0, count(articles)) would be slow (maybe UUID primary keys?)
- Sohcahtoa82 4y agoEven if you used UUIDs, couldn't you just "select count(id) from articles" to get the list of articles, generate a random number between 0 and the count, then "select id from articles offset {index}"?