replace oidrand() with random_sample()

From: Neil Conway <neilc(at)samurai(dot)com>
To: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: replace oidrand() with random_sample()
Date: 2003-01-15 23:15:14
Message-ID: 1042672514.20006.29.camel@tokyo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)samurai(dot)com> || PGP Key ID: DB3C29FC

Attachment Content-Type Size
random_sample-1.patch text/x-patch 17.3 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2003-01-16 00:55:20 Re: fix broken regression tests
Previous Message Gavin Sherry 2003-01-15 22:28:35 Re: fix broken regression tests