diff options
author | Bruce Momjian <bruce@momjian.us> | 2003-02-13 05:24:04 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2003-02-13 05:24:04 +0000 |
commit | 6cb1f4fe44a92aa97fbfd0c26ebbb8842349d90d (patch) | |
tree | 228d6d973ec607fe0c171319b84b9d8cfd10fd58 /src/backend/utils/adt/misc.c | |
parent | 8195f8f0427e0387f595ca951e4dcc257655e891 (diff) | |
download | postgresql-6cb1f4fe44a92aa97fbfd0c26ebbb8842349d90d.tar.gz postgresql-6cb1f4fe44a92aa97fbfd0c26ebbb8842349d90d.zip |
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).
Ok, this patch removes oidrand(), oidsrand(), and userfntest(), and
improves the SGML docs a little bit (un-commenting the setseed()
documentation).
Neil Conway
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r-- | src/backend/utils/adt/misc.c | 71 |
1 files changed, 1 insertions, 70 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 6b105fdef4d..1f85e4f4992 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.27 2002/09/04 20:31:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.28 2003/02/13 05:24:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -44,75 +44,6 @@ nonnullvalue(PG_FUNCTION_ARGS) } /* - * oidrand (oid o, int4 X)- - * Takes in an oid and a int4 X, and will return 'true' about 1/X of - * the time. If X == 0, this will always return true. - * Useful for doing random sampling or subsetting. - * - * Example use: - * select * from TEMP where oidrand(TEMP.oid, 10) - * will return about 1/10 of the tuples in TEMP - * - * NOTE: the OID input is not used at all. It is there just because of - * an old optimizer bug: a qual expression containing no variables was - * mistakenly assumed to be a constant. Pretending to access the row's OID - * prevented the optimizer from treating the oidrand() result as constant. - */ - -static bool random_initialized = false; - -Datum -oidrand(PG_FUNCTION_ARGS) -{ -#ifdef NOT_USED - Oid o = PG_GETARG_OID(0); -#endif - int32 X = PG_GETARG_INT32(1); - bool result; - - if (X == 0) - PG_RETURN_BOOL(true); - - /* - * We do this because the cancel key is actually a random, so we don't - * want them to be able to request random numbers using our postmaster - * seeded value. - */ - if (!random_initialized) - { - srandom((unsigned int) time(NULL)); - random_initialized = true; - } - - result = (random() % X == 0); - PG_RETURN_BOOL(result); -} - -/* - oidsrand(int32 X) - - seeds the random number generator - always returns true -*/ -Datum -oidsrand(PG_FUNCTION_ARGS) -{ - int32 X = PG_GETARG_INT32(0); - - srandom((unsigned int) X); - random_initialized = true; - PG_RETURN_BOOL(true); -} - - -Datum -userfntest(PG_FUNCTION_ARGS) -{ - int32 i = PG_GETARG_INT32(0); - - PG_RETURN_INT32(i); -} - -/* * current_database() * Expose the current database to the user */ |