Skip to content

Instantly share code, notes, and snippets.

View BurntBrunch's full-sized avatar

Delyan Kratunov BurntBrunch

  • San Francisco, CA
  • 15:18 (UTC -07:00)
View GitHub Profile
@BurntBrunch
BurntBrunch / gist:1868909
Created February 20, 2012 11:49
ORDER BY RANDOM() vs random offsets
== 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)