2000-01-06 07:40:54 +01:00
|
|
|
--
|
|
|
|
-- RANDOM
|
|
|
|
-- Test the random function
|
|
|
|
--
|
|
|
|
-- count the number of tuples originally
|
|
|
|
SELECT count(*) FROM onek;
|
|
|
|
count
|
|
|
|
-------
|
|
|
|
1000
|
1997-04-29 16:23:51 +02:00
|
|
|
(1 row)
|
|
|
|
|
2000-01-06 07:40:54 +01:00
|
|
|
-- select roughly 1/10 of the tuples
|
|
|
|
-- Assume that the "onek" table has 1000 tuples
|
|
|
|
-- and try to bracket the correct number so we
|
|
|
|
-- have a regression test which can pass/fail
|
|
|
|
-- - thomas 1998-08-17
|
|
|
|
SELECT count(*) AS random INTO RANDOM_TBL
|
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
2003-02-13 06:24:04 +01:00
|
|
|
FROM onek WHERE random() < 1.0/10;
|
2000-01-06 07:40:54 +01:00
|
|
|
-- select again, the count should be different
|
|
|
|
INSERT INTO RANDOM_TBL (random)
|
1998-08-17 18:11:35 +02:00
|
|
|
SELECT count(*)
|
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
2003-02-13 06:24:04 +01:00
|
|
|
FROM onek WHERE random() < 1.0/10;
|
2000-01-06 07:40:54 +01:00
|
|
|
-- now test the results for randomness in the correct range
|
|
|
|
SELECT random, count(random) FROM RANDOM_TBL
|
1998-08-17 18:11:35 +02:00
|
|
|
GROUP BY random HAVING count(random) > 1;
|
2000-01-06 07:40:54 +01:00
|
|
|
random | count
|
|
|
|
--------+-------
|
1998-08-17 18:11:35 +02:00
|
|
|
(0 rows)
|
1997-04-29 16:23:51 +02:00
|
|
|
|
2000-01-06 07:40:54 +01:00
|
|
|
SELECT random FROM RANDOM_TBL
|
1998-08-17 18:11:35 +02:00
|
|
|
WHERE random NOT BETWEEN 80 AND 120;
|
2000-01-06 07:40:54 +01:00
|
|
|
random
|
|
|
|
--------
|
1998-08-17 18:11:35 +02:00
|
|
|
(0 rows)
|
1997-04-29 16:23:51 +02:00
|
|
|
|