mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
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
This commit is contained in:
parent
8195f8f042
commit
6cb1f4fe44
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.138 2003/02/06 20:25:31 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.139 2003/02/13 05:24:01 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -682,14 +682,15 @@ PostgreSQL documentation
|
|||||||
<entry><literal>round(42.4382, 2)</literal></entry>
|
<entry><literal>round(42.4382, 2)</literal></entry>
|
||||||
<entry>42.44</entry>
|
<entry>42.44</entry>
|
||||||
</row>
|
</row>
|
||||||
<!--
|
|
||||||
<row>
|
<row>
|
||||||
<entry><function>setseed</function>(<replaceable>new-seed</replaceable>)</entry>
|
<entry><function>setseed</function>(<type>dp</type>)</entry>
|
||||||
<entry>set seed for subsequent random() calls</entry>
|
<entry><type>int32</type></entry>
|
||||||
<entry><literal>setseed(0.54823)</literal></entry>
|
<entry>set seed for subsequent random() calls</entry>
|
||||||
<entry></entry>
|
<entry><literal>setseed(0.54823)</literal></entry>
|
||||||
</row>
|
<entry>1177314959</entry>
|
||||||
-->
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><function>sign</function>(<type>dp</type> or <type>numeric</type>)</entry>
|
<entry><function>sign</function>(<type>dp</type> or <type>numeric</type>)</entry>
|
||||||
<entry>(same as input)</entry>
|
<entry>(same as input)</entry>
|
||||||
@ -955,7 +956,8 @@ PostgreSQL documentation
|
|||||||
<entry><function>substring</function>(<parameter>string</parameter> from <replaceable>pattern</replaceable> for <replaceable>escape</replaceable>)</entry>
|
<entry><function>substring</function>(<parameter>string</parameter> from <replaceable>pattern</replaceable> for <replaceable>escape</replaceable>)</entry>
|
||||||
<entry><type>text</type></entry>
|
<entry><type>text</type></entry>
|
||||||
<entry>
|
<entry>
|
||||||
Extract substring matching SQL regular expression
|
Extract substring matching <acronym>SQL</acronym> regular
|
||||||
|
expression
|
||||||
<indexterm>
|
<indexterm>
|
||||||
<primary>substring</primary>
|
<primary>substring</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
@ -1168,7 +1170,7 @@ PostgreSQL documentation
|
|||||||
<entry><type>text</type></entry>
|
<entry><type>text</type></entry>
|
||||||
<entry>
|
<entry>
|
||||||
Return the given string suitably quoted to be used as an identifier
|
Return the given string suitably quoted to be used as an identifier
|
||||||
in an SQL query string.
|
in an <acronym>SQL</acronym> query string.
|
||||||
Quotes are added only if necessary (i.e., if the string contains
|
Quotes are added only if necessary (i.e., if the string contains
|
||||||
non-identifier characters or would be case-folded).
|
non-identifier characters or would be case-folded).
|
||||||
Embedded quotes are properly doubled.
|
Embedded quotes are properly doubled.
|
||||||
@ -1182,7 +1184,7 @@ PostgreSQL documentation
|
|||||||
<entry><type>text</type></entry>
|
<entry><type>text</type></entry>
|
||||||
<entry>
|
<entry>
|
||||||
Return the given string suitably quoted to be used as a literal
|
Return the given string suitably quoted to be used as a literal
|
||||||
in an SQL query string.
|
in an <acronym>SQL</acronym> query string.
|
||||||
Embedded quotes and backslashes are properly doubled.
|
Embedded quotes and backslashes are properly doubled.
|
||||||
</entry>
|
</entry>
|
||||||
<entry><literal>quote_literal('O\'Reilly')</literal></entry>
|
<entry><literal>quote_literal('O\'Reilly')</literal></entry>
|
||||||
@ -2511,14 +2513,15 @@ PostgreSQL documentation
|
|||||||
<function>SUBSTRING(<parameter>string</parameter> FROM
|
<function>SUBSTRING(<parameter>string</parameter> FROM
|
||||||
<replaceable>pattern</replaceable> FOR
|
<replaceable>pattern</replaceable> FOR
|
||||||
<replaceable>escape</replaceable>)</function>, provides
|
<replaceable>escape</replaceable>)</function>, provides
|
||||||
extraction of a substring that matches a SQL99 regular expression
|
extraction of a substring that matches a <acronym>SQL99</acronym>
|
||||||
pattern. As with <literal>SIMILAR TO</>, the specified pattern
|
regular expression pattern. As with <literal>SIMILAR TO</>, the
|
||||||
must match to the entire data string, else the function fails and
|
specified pattern must match to the entire data string, else the
|
||||||
returns null. To indicate the part of the pattern that should be
|
function fails and returns null. To indicate the part of the
|
||||||
returned on success, SQL99 specifies that the pattern must
|
pattern that should be returned on success,
|
||||||
contain two occurrences of the escape character followed by
|
<acronym>SQL99</acronym> specifies that the pattern must contain
|
||||||
double quote (<literal>"</>). The text matching the portion of
|
two occurrences of the escape character followed by double quote
|
||||||
the pattern between these markers is returned.
|
(<literal>"</>). The text matching the portion of the pattern
|
||||||
|
between these markers is returned.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -6025,11 +6028,11 @@ SELECT TIMESTAMP 'now';
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
For largely historical reasons, the sequence to be operated on by
|
For largely historical reasons, the sequence to be operated on by a
|
||||||
a sequence-function call is specified by a text-string argument.
|
sequence-function call is specified by a text-string argument. To
|
||||||
To achieve some compatibility with the handling of ordinary SQL
|
achieve some compatibility with the handling of ordinary
|
||||||
names, the sequence functions convert their argument to lower case
|
<acronym>SQL</acronym> names, the sequence functions convert their
|
||||||
unless the string is double-quoted. Thus
|
argument to lower case unless the string is double-quoted. Thus
|
||||||
<programlisting>
|
<programlisting>
|
||||||
nextval('foo') <lineannotation>operates on sequence <literal>foo</literal></>
|
nextval('foo') <lineannotation>operates on sequence <literal>foo</literal></>
|
||||||
nextval('FOO') <lineannotation>operates on sequence <literal>foo</literal></>
|
nextval('FOO') <lineannotation>operates on sequence <literal>foo</literal></>
|
||||||
@ -6480,7 +6483,8 @@ SELECT NULLIF(value, '(none)') ...
|
|||||||
<para>
|
<para>
|
||||||
The <function>current_setting</function> is used to obtain the current
|
The <function>current_setting</function> is used to obtain the current
|
||||||
value of the <parameter>setting_name</parameter> setting, as a query
|
value of the <parameter>setting_name</parameter> setting, as a query
|
||||||
result. It is the equivalent to the SQL <command>SHOW</command> command.
|
result. It is the equivalent to the <acronym>SQL</acronym>
|
||||||
|
<command>SHOW</command> command.
|
||||||
For example:
|
For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
select current_setting('DateStyle');
|
select current_setting('DateStyle');
|
||||||
@ -6497,8 +6501,8 @@ select current_setting('DateStyle');
|
|||||||
If <parameter>is_local</parameter> is set to <literal>true</literal>,
|
If <parameter>is_local</parameter> is set to <literal>true</literal>,
|
||||||
the new value will only apply to the current transaction. If you want
|
the new value will only apply to the current transaction. If you want
|
||||||
the new value to apply for the current session, use
|
the new value to apply for the current session, use
|
||||||
<literal>false</literal> instead. It is the equivalent to the SQL
|
<literal>false</literal> instead. It is the equivalent to the
|
||||||
<command>SET</command> command. For example:
|
<acronym>SQL</acronym> <command>SET</command> command. For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
select set_config('show_statement_stats','off','f');
|
select set_config('show_statement_stats','off','f');
|
||||||
set_config
|
set_config
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -43,75 +43,6 @@ nonnullvalue(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_BOOL(true);
|
PG_RETURN_BOOL(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* 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()
|
* current_database()
|
||||||
* Expose the current database to the user
|
* Expose the current database to the user
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: catversion.h,v 1.175 2003/02/03 21:15:44 tgl Exp $
|
* $Id: catversion.h,v 1.176 2003/02/13 05:24:02 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 200302031
|
#define CATALOG_VERSION_NO 200302131
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pg_proc.h,v 1.282 2003/01/28 22:13:36 tgl Exp $
|
* $Id: pg_proc.h,v 1.283 2003/02/13 05:24:02 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The script catalog/genbki.sh reads this file and generates .bki
|
* The script catalog/genbki.sh reads this file and generates .bki
|
||||||
@ -944,12 +944,6 @@ DESCR("greater-than");
|
|||||||
/* OIDS 700 - 799 */
|
/* OIDS 700 - 799 */
|
||||||
DATA(insert OID = 710 ( getpgusername PGNSP PGUID 12 f f t f s 0 19 "" current_user - _null_ ));
|
DATA(insert OID = 710 ( getpgusername PGNSP PGUID 12 f f t f s 0 19 "" current_user - _null_ ));
|
||||||
DESCR("deprecated -- use current_user");
|
DESCR("deprecated -- use current_user");
|
||||||
DATA(insert OID = 711 ( userfntest PGNSP PGUID 12 f f t f i 1 23 "23" userfntest - _null_ ));
|
|
||||||
DESCR("");
|
|
||||||
DATA(insert OID = 713 ( oidrand PGNSP PGUID 12 f f t f v 2 16 "26 23" oidrand - _null_ ));
|
|
||||||
DESCR("random");
|
|
||||||
DATA(insert OID = 715 ( oidsrand PGNSP PGUID 12 f f t f v 1 16 "23" oidsrand - _null_ ));
|
|
||||||
DESCR("seed random number generator");
|
|
||||||
DATA(insert OID = 716 ( oidlt PGNSP PGUID 12 f f t f i 2 16 "26 26" oidlt - _null_ ));
|
DATA(insert OID = 716 ( oidlt PGNSP PGUID 12 f f t f i 2 16 "26 26" oidlt - _null_ ));
|
||||||
DESCR("less-than");
|
DESCR("less-than");
|
||||||
DATA(insert OID = 717 ( oidle PGNSP PGUID 12 f f t f i 2 16 "26 26" oidle - _null_ ));
|
DATA(insert OID = 717 ( oidle PGNSP PGUID 12 f f t f i 2 16 "26 26" oidle - _null_ ));
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: builtins.h,v 1.207 2003/02/06 20:25:33 tgl Exp $
|
* $Id: builtins.h,v 1.208 2003/02/13 05:24:04 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -315,9 +315,6 @@ extern Datum float84ge(PG_FUNCTION_ARGS);
|
|||||||
/* misc.c */
|
/* misc.c */
|
||||||
extern Datum nullvalue(PG_FUNCTION_ARGS);
|
extern Datum nullvalue(PG_FUNCTION_ARGS);
|
||||||
extern Datum nonnullvalue(PG_FUNCTION_ARGS);
|
extern Datum nonnullvalue(PG_FUNCTION_ARGS);
|
||||||
extern Datum oidrand(PG_FUNCTION_ARGS);
|
|
||||||
extern Datum oidsrand(PG_FUNCTION_ARGS);
|
|
||||||
extern Datum userfntest(PG_FUNCTION_ARGS);
|
|
||||||
extern Datum current_database(PG_FUNCTION_ARGS);
|
extern Datum current_database(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
/* not_in.c */
|
/* not_in.c */
|
||||||
|
@ -15,11 +15,11 @@ SELECT count(*) FROM onek;
|
|||||||
-- have a regression test which can pass/fail
|
-- have a regression test which can pass/fail
|
||||||
-- - thomas 1998-08-17
|
-- - thomas 1998-08-17
|
||||||
SELECT count(*) AS random INTO RANDOM_TBL
|
SELECT count(*) AS random INTO RANDOM_TBL
|
||||||
FROM onek WHERE oidrand(onek.oid, 10);
|
FROM onek WHERE random() < 1.0/10;
|
||||||
-- select again, the count should be different
|
-- select again, the count should be different
|
||||||
INSERT INTO RANDOM_TBL (random)
|
INSERT INTO RANDOM_TBL (random)
|
||||||
SELECT count(*)
|
SELECT count(*)
|
||||||
FROM onek WHERE oidrand(onek.oid, 10);
|
FROM onek WHERE random() < 1.0/10;
|
||||||
-- now test the results for randomness in the correct range
|
-- now test the results for randomness in the correct range
|
||||||
SELECT random, count(random) FROM RANDOM_TBL
|
SELECT random, count(random) FROM RANDOM_TBL
|
||||||
GROUP BY random HAVING count(random) > 1;
|
GROUP BY random HAVING count(random) > 1;
|
||||||
|
@ -12,12 +12,12 @@ SELECT count(*) FROM onek;
|
|||||||
-- have a regression test which can pass/fail
|
-- have a regression test which can pass/fail
|
||||||
-- - thomas 1998-08-17
|
-- - thomas 1998-08-17
|
||||||
SELECT count(*) AS random INTO RANDOM_TBL
|
SELECT count(*) AS random INTO RANDOM_TBL
|
||||||
FROM onek WHERE oidrand(onek.oid, 10);
|
FROM onek WHERE random() < 1.0/10;
|
||||||
|
|
||||||
-- select again, the count should be different
|
-- select again, the count should be different
|
||||||
INSERT INTO RANDOM_TBL (random)
|
INSERT INTO RANDOM_TBL (random)
|
||||||
SELECT count(*)
|
SELECT count(*)
|
||||||
FROM onek WHERE oidrand(onek.oid, 10);
|
FROM onek WHERE random() < 1.0/10;
|
||||||
|
|
||||||
-- now test the results for randomness in the correct range
|
-- now test the results for randomness in the correct range
|
||||||
SELECT random, count(random) FROM RANDOM_TBL
|
SELECT random, count(random) FROM RANDOM_TBL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user