2 ms·
Generate a temp table with a sufficient number of random values and join. Add an ORDER BY RANDOM() to those results to subsample. Another approach would be to
by kwillets 5y ago
Generate a temp table with a sufficient number of random values and join. Add an ORDER BY RANDOM() to those results to subsample.
Another approach would be to create a table with a small sample of the main one and refresh it periodically -- each query just needs to do a random reordering on the small sample, and the results will be truly random over time.