Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking? - Mailing list pgsql-general

From Craig Ringer
Subject Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?
Date
Msg-id 49FD24E5.3090509@postnewspapers.com.au
Whole thread Raw
In response to Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?  (Jasen Betts <jasen@xnet.co.nz>)
List pgsql-general
Jasen Betts wrote:

> That means storing a long list of numbers and doing queries similar to
> the following to get ne next value for the sequence.
>
> select id from idtable
>   order by id
>   limit 1
>   offset random(0, (select count (*) from idtable)
>
> a ramdom-looking  1:1 mapping is potentially much more efficient.

You'd probably be better off generating it with something like:

CREATE TABLE shuffled AS (n integer, s integer)
AS SELECT n, NULL FROM generate_series(0, max_value) AS n;

SELECT shuffle(); -- sets `s' for each `n'

... then querying it with:

SELECT s FROM shuffled WHERE n = <value-wanted>;

... but you still have to generate, shuffle, and store a huge collection
of values.

--
Craig Ringer

pgsql-general by date:

Previous
From: Jasen Betts
Date:
Subject: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?
Next
From: Craig Ringer
Date:
Subject: Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?