Re: selecting random rows - Mailing list pgsql-general

From Joseph Shraibman
Subject Re: selecting random rows
Date
Msg-id 3F6114F9.4010104@selectacast.net
Whole thread Raw
In response to Re: selecting random rows  (Dennis Gearon <gearond@fireserve.net>)
Responses Re: selecting random rows  (Dennis Gearon <gearond@fireserve.net>)
List pgsql-general
Dennis Gearon wrote:
> If you have a nice small Primary key on the table, you can so something
> like this:
>
> SELECT field_list
> FROM table
> WHERE primary_key IN(
>     SELECT primary_key,
>     FROM table
>     ORDER by RANDOM()
>     LIMIT your_limit);
>
> This may not be the exact sequence, and there is some workarounds for
> some slowness in the IN() keyword. Others may comment at will, and
> polish this up?
>
What exactly does that do for me?  Postgres still has to go over the whole table to get
the primary keys.


pgsql-general by date:

Previous
From: Dennis Gearon
Date:
Subject: Re: selecting random rows
Next
From: Joseph Shraibman
Date:
Subject: Re: NFS performance tuning