Skip to content

Instantly share code, notes, and snippets.

@BurntBrunch
BurntBrunch / gist:1868909
Created Feb 20, 2012
ORDER BY RANDOM() vs random offsets
View gist:1868909
== ORDER BY RANDOM() ==
hs=> explain analyze select * from requests_request order by random() limit 1;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
Limit (cost=21.12..21.13 rows=1 width=242) (actual time=1.447..1.448 rows=1 loops=1)
-> Sort (cost=21.12..22.00 rows=350 width=242) (actual time=1.445..1.445 rows=1 loops=1)
Sort Key: (random())
Sort Method: top-N heapsort Memory: 18kB
-> Seq Scan on requests_request (cost=0.00..19.38 rows=350 width=242) (actual time=0.014..0.743 rows=352 loops=1)