Re: Selecting random rows efficiently

From: "Russell Garrett" <rg(at)tcslon(dot)com>
To: "PgSQL Performance ML" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Selecting random rows efficiently
Date: 2003-08-30 17:43:22
Message-ID: MKEGJINFADFODDNOKEJCGEGOEAAA.rg@tcslon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

Considering that we'd have to index the random field too, it'd be neater in
the long term to re-number the primary key. Although, being a primary key,
that's foreign-keyed from absolutely everywhere, so that'd probably take an
amusingly long time.

...and no we're not from Micronesia, we're from ever so slightly less exotic
London. Though Micronesia might be nice...

Russ (also from last.fm but without the fancy address)

pgsql-performance-owner(at)postgresql(dot)org wrote:
> On Sat, 2003-08-30 at 09:01, Rod Taylor wrote:
>>> i was hoping there was some trickery with sequences that would
>>> allow me to easily pick a random valid sequence number..?
>>
>> I would suggest renumbering the data.
>>
>> ALTER SEQUENCE ... RESTART WITH 1;
>> UPDATE table SET pkey = DEFAULT;
>>
>> Of course, PostgreSQL may have trouble with that update due to
>> evaluation of the unique constraint immediately -- so drop the
>> primary key first, and add it back after.
>
> And if there are child tables, they'd all have to be updated, too.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-08-30 17:47:19 Re: [HACKERS] What goes into the security doc?
Previous Message Jonathan Gardner 2003-08-30 17:30:28 Re: ALTER TABLE ... TO ... to change related names

Browse pgsql-performance by date

  From Date Subject
Next Message Rob Nagler 2003-08-30 20:42:09 Re: How to force Nested Loop plan?
Previous Message Bruce Momjian 2003-08-30 16:47:53 Re: PostgreSQL HDD Grow capacity