1997-04-27 20:13:54 +02:00
|
|
|
--
|
2000-01-06 07:41:55 +01:00
|
|
|
-- RANDOM
|
|
|
|
-- Test the random function
|
1997-04-27 20:13:54 +02:00
|
|
|
--
|
2000-01-06 07:41:55 +01:00
|
|
|
|
2004-03-15 16:46:25 +01:00
|
|
|
-- count the number of tuples originally, should be 1000
|
1997-04-27 20:13:54 +02:00
|
|
|
SELECT count(*) FROM onek;
|
|
|
|
|
2004-03-15 16:46:25 +01:00
|
|
|
-- pick three random rows, they shouldn't match
|
|
|
|
(SELECT unique1 AS random
|
|
|
|
FROM onek ORDER BY random() LIMIT 1)
|
|
|
|
INTERSECT
|
|
|
|
(SELECT unique1 AS random
|
|
|
|
FROM onek ORDER BY random() LIMIT 1)
|
|
|
|
INTERSECT
|
|
|
|
(SELECT unique1 AS random
|
|
|
|
FROM onek ORDER BY random() LIMIT 1);
|
|
|
|
|
|
|
|
-- count roughly 1/10 of the tuples
|
1998-08-17 18:11:35 +02:00
|
|
|
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;
|
1997-04-27 20:13:54 +02:00
|
|
|
|
|
|
|
-- select again, the count should be different
|
1998-08-17 18:11:35 +02:00
|
|
|
INSERT INTO RANDOM_TBL (random)
|
|
|
|
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;
|
1998-08-17 18:11:35 +02:00
|
|
|
|
2004-03-15 16:46:25 +01:00
|
|
|
-- select again, the count should be different
|
|
|
|
INSERT INTO RANDOM_TBL (random)
|
|
|
|
SELECT count(*)
|
|
|
|
FROM onek WHERE random() < 1.0/10;
|
|
|
|
|
|
|
|
-- select again, the count should be different
|
|
|
|
INSERT INTO RANDOM_TBL (random)
|
|
|
|
SELECT count(*)
|
|
|
|
FROM onek WHERE random() < 1.0/10;
|
|
|
|
|
|
|
|
-- now test that they are different counts
|
1998-08-17 18:11:35 +02:00
|
|
|
SELECT random, count(random) FROM RANDOM_TBL
|
2004-03-15 16:46:25 +01:00
|
|
|
GROUP BY random HAVING count(random) > 3;
|
1998-08-17 18:11:35 +02:00
|
|
|
|
2004-03-15 16:46:25 +01:00
|
|
|
SELECT AVG(random) FROM RANDOM_TBL
|
|
|
|
HAVING AVG(random) NOT BETWEEN 80 AND 120;
|
1997-04-27 20:13:54 +02:00
|
|
|
|