replace oidrand() with random_sample() - Mailing list pgsql-patches

From Neil Conway
Subject replace oidrand() with random_sample()
Date
Msg-id 1042672514.20006.29.camel@tokyo
Whole thread Raw
Responses Re: replace oidrand() with random_sample()
List pgsql-patches
The "random" regression test uses a function called oidrand(), which
takes two parameters, an OID x and an integer y, and returns "true" with
probability 1/y (the OID argument is ignored). This can be useful -- for
example, it can be used to select a random sampling of the rows in a
table (which is what the "random" regression test uses it for).

This patch removes that function, because it was old and messy. The old
function had the following problems:

- it was undocumented

- it was poorly named

- it was designed to workaround an optimizer bug that no longer exists
(the OID argument is to ensure that the optimizer won't optimize away
calls to the function; AFAIK marking the function as 'volatile' suffices
nowadays)

- it used a different random-number generation technique than the other
PSRNG-related functions in the backend do (it called random() like they
do, but it had its own logic for setting a set and deciding when to
reseed the RNG).

This patch implements a new version of the function, called
"random_sample" (if you think that's not a good name, please suggest an
improvement). It corrects the problems mentioned above.

I also documented the setseed() function: there were some SGML docs for
it, but they were commented out (Peter E. removed them revision 1.41 of
func.sgml, without explaining why).

Finally, I removed the oidsrand() and userfntest() functions: the former
was only for use with oidrand(), and the later has no value AFAICS (I
checked with Bruce, and he agreed with me).

Initdb required.

Cheers,

Neil
--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC



Attachment

pgsql-patches by date:

Previous
From: Rod Taylor
Date:
Subject: Re: ALTER TABLE .. SET WITHOUT OIDS -- ROUND 2
Next
From: Tom Lane
Date:
Subject: Re: replace oidrand() with random_sample()