Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cb1f4f

Browse files
committed
The "random" regression test uses a function called oidrand(), which
takes two parameters, an OID x and an integer y, and returns "true" withprobability 1/y (the OID argument is ignored). This can be useful -- forexample, it can be used to select a random sampling of the rows in atable (which is what the "random" regression test uses it for).This patch removes that function, because it was old and messy. The oldfunction 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 awaycalls to the function; AFAIK marking the function as 'volatile' sufficesnowadays)- it used a different random-number generation technique than the otherPSRNG-related functions in the backend do (it called random() like theydo, but it had its own logic for setting a set and deciding when toreseed the RNG).Ok, this patch removes oidrand(), oidsrand(), and userfntest(), andimproves the SGML docs a little bit (un-commenting the setseed()documentation).Neil Conway
1 parent8195f8f commit6cb1f4f

File tree

7 files changed

+41
-115
lines changed

7 files changed

+41
-115
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.138 2003/02/06 20:25:31 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.139 2003/02/13 05:24:01 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -682,14 +682,15 @@ PostgreSQL documentation
682682
<entry><literal>round(42.4382, 2)</literal></entry>
683683
<entry>42.44</entry>
684684
</row>
685-
<!--
686-
<row>
687-
<entry><function>setseed</function>(<replaceable>new-seed</replaceable>)</entry>
688-
<entry>set seed for subsequent random() calls</entry>
689-
<entry><literal>setseed(0.54823)</literal></entry>
690-
<entry></entry>
691-
</row>
692-
-->
685+
686+
<row>
687+
<entry><function>setseed</function>(<type>dp</type>)</entry>
688+
<entry><type>int32</type></entry>
689+
<entry>set seed for subsequent random() calls</entry>
690+
<entry><literal>setseed(0.54823)</literal></entry>
691+
<entry>1177314959</entry>
692+
</row>
693+
693694
<row>
694695
<entry><function>sign</function>(<type>dp</type> or <type>numeric</type>)</entry>
695696
<entry>(same as input)</entry>
@@ -955,7 +956,8 @@ PostgreSQL documentation
955956
<entry><function>substring</function>(<parameter>string</parameter> from <replaceable>pattern</replaceable> for <replaceable>escape</replaceable>)</entry>
956957
<entry><type>text</type></entry>
957958
<entry>
958-
Extract substring matching SQL regular expression
959+
Extract substring matching <acronym>SQL</acronym> regular
960+
expression
959961
<indexterm>
960962
<primary>substring</primary>
961963
</indexterm>
@@ -1168,7 +1170,7 @@ PostgreSQL documentation
11681170
<entry><type>text</type></entry>
11691171
<entry>
11701172
Return the given string suitably quoted to be used as an identifier
1171-
in an SQL query string.
1173+
in an<acronym>SQL</acronym> query string.
11721174
Quotes are added only if necessary (i.e., if the string contains
11731175
non-identifier characters or would be case-folded).
11741176
Embedded quotes are properly doubled.
@@ -1182,7 +1184,7 @@ PostgreSQL documentation
11821184
<entry><type>text</type></entry>
11831185
<entry>
11841186
Return the given string suitably quoted to be used as a literal
1185-
in an SQL query string.
1187+
in an<acronym>SQL</acronym> query string.
11861188
Embedded quotes and backslashes are properly doubled.
11871189
</entry>
11881190
<entry><literal>quote_literal('O\'Reilly')</literal></entry>
@@ -2511,14 +2513,15 @@ PostgreSQL documentation
25112513
<function>SUBSTRING(<parameter>string</parameter> FROM
25122514
<replaceable>pattern</replaceable> FOR
25132515
<replaceable>escape</replaceable>)</function>, provides
2514-
extraction of a substring that matches a SQL99 regular expression
2515-
pattern. As with <literal>SIMILAR TO</>, the specified pattern
2516-
must match to the entire data string, else the function fails and
2517-
returns null. To indicate the part of the pattern that should be
2518-
returned on success, SQL99 specifies that the pattern must
2519-
contain two occurrences of the escape character followed by
2520-
double quote (<literal>"</>). The text matching the portion of
2521-
the pattern between these markers is returned.
2516+
extraction of a substring that matches a <acronym>SQL99</acronym>
2517+
regular expression pattern. As with <literal>SIMILAR TO</>, the
2518+
specified pattern must match to the entire data string, else the
2519+
function fails and returns null. To indicate the part of the
2520+
pattern that should be returned on success,
2521+
<acronym>SQL99</acronym> specifies that the pattern must contain
2522+
two occurrences of the escape character followed by double quote
2523+
(<literal>"</>). The text matching the portion of the pattern
2524+
between these markers is returned.
25222525
</para>
25232526

25242527
<para>
@@ -6025,11 +6028,11 @@ SELECT TIMESTAMP 'now';
60256028
</table>
60266029

60276030
<para>
6028-
For largely historical reasons, the sequence to be operated on by
6029-
asequence-function call is specified by a text-string argument.
6030-
Toachieve some compatibility with the handling of ordinary SQL
6031-
names, the sequence functions convert their argument to lower case
6032-
unless the string is double-quoted. Thus
6031+
For largely historical reasons, the sequence to be operated on by a
6032+
sequence-function call is specified by a text-string argument. To
6033+
achieve some compatibility with the handling of ordinary
6034+
<acronym>SQL</acronym>names, the sequence functions convert their
6035+
argument to lower caseunless the string is double-quoted. Thus
60336036
<programlisting>
60346037
nextval('foo') <lineannotation>operates on sequence <literal>foo</literal></>
60356038
nextval('FOO') <lineannotation>operates on sequence <literal>foo</literal></>
@@ -6480,7 +6483,8 @@ SELECT NULLIF(value, '(none)') ...
64806483
<para>
64816484
The <function>current_setting</function> is used to obtain the current
64826485
value of the <parameter>setting_name</parameter> setting, as a query
6483-
result. It is the equivalent to the SQL <command>SHOW</command> command.
6486+
result. It is the equivalent to the <acronym>SQL</acronym>
6487+
<command>SHOW</command> command.
64846488
For example:
64856489
<programlisting>
64866490
select current_setting('DateStyle');
@@ -6497,8 +6501,8 @@ select current_setting('DateStyle');
64976501
If <parameter>is_local</parameter> is set to <literal>true</literal>,
64986502
the new value will only apply to the current transaction. If you want
64996503
the new value to apply for the current session, use
6500-
<literal>false</literal> instead. It is the equivalent to the SQL
6501-
<command>SET</command> command. For example:
6504+
<literal>false</literal> instead. It is the equivalent to the
6505+
<acronym>SQL</acronym> <command>SET</command> command. For example:
65026506
<programlisting>
65036507
select set_config('show_statement_stats','off','f');
65046508
set_config

‎src/backend/utils/adt/misc.c

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.27 2002/09/04 20:31:28 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.28 2003/02/13 05:24:02 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -43,75 +43,6 @@ nonnullvalue(PG_FUNCTION_ARGS)
4343
PG_RETURN_BOOL(true);
4444
}
4545

46-
/*
47-
* oidrand (oid o, int4 X)-
48-
* Takes in an oid and a int4 X, and will return 'true' about 1/X of
49-
* the time. If X == 0, this will always return true.
50-
* Useful for doing random sampling or subsetting.
51-
*
52-
* Example use:
53-
* select * from TEMP where oidrand(TEMP.oid, 10)
54-
* will return about 1/10 of the tuples in TEMP
55-
*
56-
* NOTE: the OID input is not used at all.It is there just because of
57-
* an old optimizer bug: a qual expression containing no variables was
58-
* mistakenly assumed to be a constant. Pretending to access the row's OID
59-
* prevented the optimizer from treating the oidrand() result as constant.
60-
*/
61-
62-
staticboolrandom_initialized= false;
63-
64-
Datum
65-
oidrand(PG_FUNCTION_ARGS)
66-
{
67-
#ifdefNOT_USED
68-
Oido=PG_GETARG_OID(0);
69-
#endif
70-
int32X=PG_GETARG_INT32(1);
71-
boolresult;
72-
73-
if (X==0)
74-
PG_RETURN_BOOL(true);
75-
76-
/*
77-
* We do this because the cancel key is actually a random, so we don't
78-
* want them to be able to request random numbers using our postmaster
79-
* seeded value.
80-
*/
81-
if (!random_initialized)
82-
{
83-
srandom((unsignedint)time(NULL));
84-
random_initialized= true;
85-
}
86-
87-
result= (random() %X==0);
88-
PG_RETURN_BOOL(result);
89-
}
90-
91-
/*
92-
oidsrand(int32 X) -
93-
seeds the random number generator
94-
always returns true
95-
*/
96-
Datum
97-
oidsrand(PG_FUNCTION_ARGS)
98-
{
99-
int32X=PG_GETARG_INT32(0);
100-
101-
srandom((unsignedint)X);
102-
random_initialized= true;
103-
PG_RETURN_BOOL(true);
104-
}
105-
106-
107-
Datum
108-
userfntest(PG_FUNCTION_ARGS)
109-
{
110-
int32i=PG_GETARG_INT32(0);
111-
112-
PG_RETURN_INT32(i);
113-
}
114-
11546
/*
11647
* current_database()
11748
*Expose the current database to the user

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.175 2003/02/03 21:15:44 tgl Exp $
40+
* $Id: catversion.h,v 1.176 2003/02/13 05:24:02 momjian Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200302031
56+
#defineCATALOG_VERSION_NO200302131
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.282 2003/01/28 22:13:36 tgl Exp $
10+
* $Id: pg_proc.h,v 1.283 2003/02/13 05:24:02 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -944,12 +944,6 @@ DESCR("greater-than");
944944
/* OIDS 700 - 799 */
945945
DATA(insertOID=710 (getpgusernamePGNSPPGUID12fftfs019""current_user-_null_ ));
946946
DESCR("deprecated -- use current_user");
947-
DATA(insertOID=711 (userfntestPGNSPPGUID12fftfi123"23"userfntest-_null_ ));
948-
DESCR("");
949-
DATA(insertOID=713 (oidrandPGNSPPGUID12fftfv216"26 23"oidrand-_null_ ));
950-
DESCR("random");
951-
DATA(insertOID=715 (oidsrandPGNSPPGUID12fftfv116"23"oidsrand-_null_ ));
952-
DESCR("seed random number generator");
953947
DATA(insertOID=716 (oidltPGNSPPGUID12fftfi216"26 26"oidlt-_null_ ));
954948
DESCR("less-than");
955949
DATA(insertOID=717 (oidlePGNSPPGUID12fftfi216"26 26"oidle-_null_ ));

‎src/include/utils/builtins.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.207 2003/02/06 20:25:33 tgl Exp $
10+
* $Id: builtins.h,v 1.208 2003/02/13 05:24:04 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -315,9 +315,6 @@ extern Datum float84ge(PG_FUNCTION_ARGS);
315315
/* misc.c */
316316
externDatumnullvalue(PG_FUNCTION_ARGS);
317317
externDatumnonnullvalue(PG_FUNCTION_ARGS);
318-
externDatumoidrand(PG_FUNCTION_ARGS);
319-
externDatumoidsrand(PG_FUNCTION_ARGS);
320-
externDatumuserfntest(PG_FUNCTION_ARGS);
321318
externDatumcurrent_database(PG_FUNCTION_ARGS);
322319

323320
/* not_in.c */

‎src/test/regress/expected/random.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ SELECT count(*) FROM onek;
1515
-- have a regression test which can pass/fail
1616
-- - thomas 1998-08-17
1717
SELECT count(*) AS random INTO RANDOM_TBL
18-
FROM onek WHEREoidrand(onek.oid, 10);
18+
FROM onek WHERErandom() < 1.0/10;
1919
-- select again, the count should be different
2020
INSERT INTO RANDOM_TBL (random)
2121
SELECT count(*)
22-
FROM onek WHEREoidrand(onek.oid, 10);
22+
FROM onek WHERErandom() < 1.0/10;
2323
-- now test the results for randomness in the correct range
2424
SELECT random, count(random) FROM RANDOM_TBL
2525
GROUP BY random HAVING count(random) > 1;

‎src/test/regress/sql/random.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ SELECT count(*) FROM onek;
1212
-- have a regression test which can pass/fail
1313
-- - thomas 1998-08-17
1414
SELECTcount(*)AS random INTO RANDOM_TBL
15-
FROM onekWHEREoidrand(onek.oid,10);
15+
FROM onekWHERErandom()<1.0/10;
1616

1717
-- select again, the count should be different
1818
INSERT INTO RANDOM_TBL (random)
1919
SELECTcount(*)
20-
FROM onekWHEREoidrand(onek.oid,10);
20+
FROM onekWHERErandom()<1.0/10;
2121

2222
-- now test the results for randomness in the correct range
2323
SELECT random,count(random)FROM RANDOM_TBL

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp