Selecting random rows efficiently - Mailing list pgsql-performance

From Richard Jones
Subject Selecting random rows efficiently
Date
Msg-id 200308301309.03412.rj@last.fm
Whole thread Raw
In response to Re: Hardware recommendations to scale to silly load  (Ron Johnson <ron.l.johnson@cox.net>)
Responses Re: Selecting random rows efficiently
Re: Selecting random rows efficiently
List pgsql-performance
Hi,
i have a table of around 3 million rows from which i regularly (twice a second
at the moment) need to select a random row from

currently i'm doing "order by rand() limit 1" - but i suspect this is
responsible for the large load on my db server - i guess that PG is doing far
too much work just to pick one row.

one way i can think of is to read in all the primary keys from my table, and
select one of the keys at random then directly fetch that row.

are there any other ways to do this? i need to keep the load down :)

Thanks,
Richard

pgsql-performance by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Hardware recommendations to scale to silly load
Next
From: Jeff
Date:
Subject: Re: Selecting random rows efficiently