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

Commitad95664

Browse files
committed
pgbench: Remove \setrandom.
You can now do the same thing via \set using the appropriate function,either random(), random_gaussian(), or random_exponential(), dependingon the desired distribution. This is not backward-compatible, but perdiscussion, it's worth it to avoid having the old syntax hang aroundforever.Fabien Coelho, reviewed by Michael Paquier, and adjusted by me.
1 parent7abc157 commitad95664

File tree

2 files changed

+2
-233
lines changed

2 files changed

+2
-233
lines changed

‎doc/src/sgml/ref/pgbench.sgml

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -836,60 +836,6 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
836836
</listitem>
837837
</varlistentry>
838838

839-
<varlistentry>
840-
<term>
841-
<literal>\setrandom <replaceable>varname</> <replaceable>min</> <replaceable>max</> [ uniform | { gaussian | exponential } <replaceable>parameter</> ]</literal>
842-
</term>
843-
844-
<listitem>
845-
<para>
846-
Sets variable <replaceable>varname</> to a random integer value
847-
between the limits <replaceable>min</> and <replaceable>max</> inclusive.
848-
Each limit can be either an integer constant or a
849-
<literal>:</><replaceable>variablename</> reference to a variable
850-
having an integer value.
851-
</para>
852-
853-
<para>
854-
<itemizedlist>
855-
<listitem>
856-
<para>
857-
<literal>\setrandom n 1 10</> or <literal>\setrandom n 1 10 uniform</>
858-
is equivalent to <literal>\set n random(1, 10)</> and uses a uniform
859-
distribution.
860-
</para>
861-
</listitem>
862-
863-
<listitem>
864-
<para>
865-
<literal>\setrandom n 1 10 exponential 3.0</> is equivalent to
866-
<literal>\set n random_exponential(1, 10, 3.0)</> and uses an
867-
exponential distribution.
868-
</para>
869-
</listitem>
870-
871-
<listitem>
872-
<para>
873-
<literal>\setrandom n 1 10 gaussian 2.0</> is equivalent to
874-
<literal>\set n random_gaussian(1, 10, 2.0)</>, and uses a gaussian
875-
distribution.
876-
</para>
877-
</listitem>
878-
</itemizedlist>
879-
880-
See the documentation of these functions below for further information
881-
about the precise shape of these distributions, depending on the value
882-
of the parameter.
883-
</para>
884-
885-
<para>
886-
Example:
887-
<programlisting>
888-
\setrandom aid 1 :naccounts gaussian 5.0
889-
</programlisting></para>
890-
</listitem>
891-
</varlistentry>
892-
893839
<varlistentry>
894840
<term>
895841
<literal>\sleep <replaceable>number</> [ us | ms | s ]</literal>

‎src/bin/pgbench/pgbench.c

Lines changed: 2 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,148 +1941,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
19411941
fprintf(stderr,"\n");
19421942
}
19431943

1944-
/*
1945-
* Note: this section could be removed, as the same functionnality
1946-
* is available through \set xxx random_gaussian(...)
1947-
*/
1948-
if (pg_strcasecmp(argv[0],"setrandom")==0)
1949-
{
1950-
char*var;
1951-
int64min,
1952-
max;
1953-
doubleparameter=0;
1954-
charres[64];
1955-
1956-
if (*argv[2]==':')
1957-
{
1958-
if ((var=getVariable(st,argv[2]+1))==NULL)
1959-
{
1960-
fprintf(stderr,"%s: undefined variable \"%s\"\n",
1961-
argv[0],argv[2]);
1962-
st->ecnt++;
1963-
return true;
1964-
}
1965-
min=strtoint64(var);
1966-
}
1967-
else
1968-
min=strtoint64(argv[2]);
1969-
1970-
if (*argv[3]==':')
1971-
{
1972-
if ((var=getVariable(st,argv[3]+1))==NULL)
1973-
{
1974-
fprintf(stderr,"%s: undefined variable \"%s\"\n",
1975-
argv[0],argv[3]);
1976-
st->ecnt++;
1977-
return true;
1978-
}
1979-
max=strtoint64(var);
1980-
}
1981-
else
1982-
max=strtoint64(argv[3]);
1983-
1984-
if (max<min)
1985-
{
1986-
fprintf(stderr,"%s: \\setrandom maximum is less than minimum\n",
1987-
argv[0]);
1988-
st->ecnt++;
1989-
return true;
1990-
}
1991-
1992-
/*
1993-
* Generate random number functions need to be able to subtract
1994-
* max from min and add one to the result without overflowing.
1995-
* Since we know max > min, we can detect overflow just by
1996-
* checking for a negative result. But we must check both that the
1997-
* subtraction doesn't overflow, and that adding one to the result
1998-
* doesn't overflow either.
1999-
*/
2000-
if (max-min<0|| (max-min)+1<0)
2001-
{
2002-
fprintf(stderr,"%s: \\setrandom range is too large\n",
2003-
argv[0]);
2004-
st->ecnt++;
2005-
return true;
2006-
}
2007-
2008-
if (argc==4||/* uniform without or with "uniform" keyword */
2009-
(argc==5&&pg_strcasecmp(argv[4],"uniform")==0))
2010-
{
2011-
#ifdefDEBUG
2012-
printf("min: "INT64_FORMAT" max: "INT64_FORMAT" random: "INT64_FORMAT"\n",min,max,getrand(thread,min,max));
2013-
#endif
2014-
snprintf(res,sizeof(res),INT64_FORMAT,getrand(thread,min,max));
2015-
}
2016-
elseif (argc==6&&
2017-
((pg_strcasecmp(argv[4],"gaussian")==0)||
2018-
(pg_strcasecmp(argv[4],"exponential")==0)))
2019-
{
2020-
if (*argv[5]==':')
2021-
{
2022-
if ((var=getVariable(st,argv[5]+1))==NULL)
2023-
{
2024-
fprintf(stderr,"%s: invalid parameter: \"%s\"\n",
2025-
argv[0],argv[5]);
2026-
st->ecnt++;
2027-
return true;
2028-
}
2029-
parameter=strtod(var,NULL);
2030-
}
2031-
else
2032-
parameter=strtod(argv[5],NULL);
2033-
2034-
if (pg_strcasecmp(argv[4],"gaussian")==0)
2035-
{
2036-
if (parameter<MIN_GAUSSIAN_PARAM)
2037-
{
2038-
fprintf(stderr,"gaussian parameter must be at least %f (not \"%s\")\n",MIN_GAUSSIAN_PARAM,argv[5]);
2039-
st->ecnt++;
2040-
return true;
2041-
}
2042-
#ifdefDEBUG
2043-
printf("min: "INT64_FORMAT" max: "INT64_FORMAT" random: "INT64_FORMAT"\n",
2044-
min,max,
2045-
getGaussianRand(thread,min,max,parameter));
2046-
#endif
2047-
snprintf(res,sizeof(res),INT64_FORMAT,
2048-
getGaussianRand(thread,min,max,parameter));
2049-
}
2050-
elseif (pg_strcasecmp(argv[4],"exponential")==0)
2051-
{
2052-
if (parameter <=0.0)
2053-
{
2054-
fprintf(stderr,
2055-
"exponential parameter must be greater than zero (not \"%s\")\n",
2056-
argv[5]);
2057-
st->ecnt++;
2058-
return true;
2059-
}
2060-
#ifdefDEBUG
2061-
printf("min: "INT64_FORMAT" max: "INT64_FORMAT" random: "INT64_FORMAT"\n",
2062-
min,max,
2063-
getExponentialRand(thread,min,max,parameter));
2064-
#endif
2065-
snprintf(res,sizeof(res),INT64_FORMAT,
2066-
getExponentialRand(thread,min,max,parameter));
2067-
}
2068-
}
2069-
else/* this means an error somewhere in the parsing phase... */
2070-
{
2071-
fprintf(stderr,"%s: invalid arguments for \\setrandom\n",
2072-
argv[0]);
2073-
st->ecnt++;
2074-
return true;
2075-
}
2076-
2077-
if (!putVariable(st,argv[0],argv[1],res))
2078-
{
2079-
st->ecnt++;
2080-
return true;
2081-
}
2082-
2083-
st->listen= true;
2084-
}
2085-
elseif (pg_strcasecmp(argv[0],"set")==0)
1944+
if (pg_strcasecmp(argv[0],"set")==0)
20861945
{
20871946
charres[64];
20881947
PgBenchExpr*expr=commands[st->state]->expr;
@@ -2880,43 +2739,7 @@ process_backslash_command(PsqlScanState sstate, const char *source)
28802739
start_offset,
28812740
end_offset);
28822741

2883-
if (pg_strcasecmp(my_command->argv[0],"setrandom")==0)
2884-
{
2885-
/*--------
2886-
* parsing:
2887-
* \setrandom variable min max [uniform]
2888-
* \setrandom variable min max (gaussian|exponential) parameter
2889-
*/
2890-
2891-
if (my_command->argc<4)
2892-
syntax_error(source,lineno,my_command->line,my_command->argv[0],
2893-
"missing arguments",NULL,-1);
2894-
2895-
if (my_command->argc==4||/* uniform without/with "uniform"
2896-
* keyword */
2897-
(my_command->argc==5&&
2898-
pg_strcasecmp(my_command->argv[4],"uniform")==0))
2899-
{
2900-
/* nothing to do */
2901-
}
2902-
elseif (/* argc >= 5 */
2903-
(pg_strcasecmp(my_command->argv[4],"gaussian")==0)||
2904-
(pg_strcasecmp(my_command->argv[4],"exponential")==0))
2905-
{
2906-
if (my_command->argc<6)
2907-
syntax_error(source,lineno,my_command->line,my_command->argv[0],
2908-
"missing parameter",NULL,-1);
2909-
elseif (my_command->argc>6)
2910-
syntax_error(source,lineno,my_command->line,my_command->argv[0],
2911-
"too many arguments",NULL,
2912-
offsets[6]-start_offset);
2913-
}
2914-
else/* unrecognized distribution argument */
2915-
syntax_error(source,lineno,my_command->line,my_command->argv[0],
2916-
"unexpected argument",my_command->argv[4],
2917-
offsets[4]-start_offset);
2918-
}
2919-
elseif (pg_strcasecmp(my_command->argv[0],"sleep")==0)
2742+
if (pg_strcasecmp(my_command->argv[0],"sleep")==0)
29202743
{
29212744
if (my_command->argc<2)
29222745
syntax_error(source,lineno,my_command->line,my_command->argv[0],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp