pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron Johnson <ron.l.johnson@cox.net>
To: PgSQL Performance ML <pgsql-performance@postgresql.org>
Subject: Re: Selecting random rows efficiently
Date: Sat, 30 Aug 2003 09:04:01 -0500
Message-ID: <1062252240.667.453.camel@haggis> (raw)
In-Reply-To: <200308301309.03412.rj@last.fm>
References: <200308300244.h7U2i4S12751@candle.pha.pa.us>
	<1062220877.669.406.camel@haggis>
	<200308301309.03412.rj@last.fm>

On Sat, 2003-08-30 at 08:09, Richard Jones wrote:
> 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.

What datatype is the selected by key?

Also, where is rand() defined?  Is that a UDF?

Could it be that there is a type mismatch?

> 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 

Are you really in Micronesia?

-- 
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

"The greatest dangers to liberty lurk in insidious encroachment 
by men of zeal, well-meaning, but without understanding."
Justice Louis Brandeis, dissenting, Olmstead v US (1928)




view thread (10+ messages)  latest in thread

Message-ID: <1062252240.667.453.camel@haggis>
Permalink:  ../1062252240.667.453.camel@haggis/
Also on:    postgresql.org/message-id/1062252240.667.453.camel@haggis

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: ron.l.johnson@cox.net
  Subject: Re: Selecting random rows efficiently
  In-Reply-To: <1062252240.667.453.camel@haggis>
  References: <200308300244.h7U2i4S12751@candle.pha.pa.us> <1062220877.669.406.camel@haggis> <200308301309.03412.rj@last.fm> <1062252240.667.453.camel@haggis>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox