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

Commit7a622b2

Browse files
committed
Rename pgbench min/max to least/greatest, and fix handling of double args.
These functions behave like the backend's least/greatest functions,not like min/max, so the originally-chosen names invite confusion.Per discussion, rename to least/greatest.I also took it upon myself to make them return double if any input isdouble. The previous behavior of silently coercing all inputs to intsurely does not meet the principle of least astonishment.Copy-edit some of the other new functions' documentation, too.
1 parentc311f78 commit7a622b2

File tree

4 files changed

+67
-34
lines changed

4 files changed

+67
-34
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -935,14 +935,15 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
935935
<row>
936936
<entry><literal><function>abs(<replaceable>a</>)</></></>
937937
<entry>same as <replaceable>a</></>
938-
<entry>integer or doubleabsolute value</>
938+
<entry>absolute value</>
939939
<entry><literal>abs(-17)</></>
940940
<entry><literal>17</></>
941941
</row>
942942
<row>
943943
<entry><literal><function>debug(<replaceable>a</>)</></></>
944944
<entry>same as <replaceable>a</> </>
945-
<entry>print to <systemitem>stderr</systemitem> the given argument</>
945+
<entry>print <replaceable>a</> to <systemitem>stderr</systemitem>,
946+
and return <replaceable>a</></>
946947
<entry><literal>debug(5432.1)</></>
947948
<entry><literal>5432.1</></>
948949
</row>
@@ -961,23 +962,23 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
961962
<entry><literal>9</></>
962963
</row>
963964
<row>
964-
<entry><literal><function>max(<replaceable>i</> [, <replaceable>...</> ] )</></></>
965-
<entry>integer</>
966-
<entry>maximum value</>
967-
<entry><literal>max(5, 4, 3, 2)</></>
965+
<entry><literal><function>greatest(<replaceable>a</> [, <replaceable>...</> ] )</></></>
966+
<entry>double if any <replaceable>a</> is double, elseinteger</>
967+
<entry>largest value among arguments</>
968+
<entry><literal>greatest(5, 4, 3, 2)</></>
968969
<entry><literal>5</></>
969970
</row>
970971
<row>
971-
<entry><literal><function>min(<replaceable>i</> [, <replaceable>...</> ] )</></></>
972-
<entry>integer</>
973-
<entry>minimum value</>
974-
<entry><literal>min(5, 4, 3, 2)</></>
975-
<entry><literal>2</></>
972+
<entry><literal><function>least(<replaceable>a</> [, <replaceable>...</> ] )</></></>
973+
<entry>double if any <replaceable>a</> is double, elseinteger</>
974+
<entry>smallest value among arguments</>
975+
<entry><literal>least(5, 4, 3, 2.1)</></>
976+
<entry><literal>2.1</></>
976977
</row>
977978
<row>
978979
<entry><literal><function>pi()</></></>
979980
<entry>double</>
980-
<entry>value of thePIconstant</>
981+
<entry>value of the constant PI</>
981982
<entry><literal>pi()</></>
982983
<entry><literal>3.14159265358979323846</></>
983984
</row>

‎src/bin/pgbench/exprparse.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ make_op(yyscan_t yyscanner, const char *operator,
131131
* List of available functions:
132132
* - fname: function name
133133
* - nargs: number of arguments
134-
*-1 is a special value formin &max meaning #args >= 1
134+
*-1 is a special value forleast &greatest meaning #args >= 1
135135
* - tag: function identifier from PgBenchFunction enum
136136
*/
137137
staticconststruct
@@ -162,10 +162,10 @@ static const struct
162162
"abs",1, PGBENCH_ABS
163163
},
164164
{
165-
"min", -1,PGBENCH_MIN
165+
"least", -1,PGBENCH_LEAST
166166
},
167167
{
168-
"max", -1,PGBENCH_MAX
168+
"greatest", -1,PGBENCH_GREATEST
169169
},
170170
{
171171
"debug",1, PGBENCH_DEBUG
@@ -274,7 +274,7 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
274274
expr_yyerror_more(yyscanner,"unexpected number of arguments",
275275
PGBENCH_FUNCTIONS[fnumber].fname);
276276

277-
/* check at least one arg formin &max*/
277+
/* check at least one arg forleast &greatest*/
278278
if (PGBENCH_FUNCTIONS[fnumber].nargs == -1 &&
279279
elist_length(args) ==0)
280280
expr_yyerror_more(yyscanner,"at least one argument expected",

‎src/bin/pgbench/pgbench.c

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,31 +1298,63 @@ evalFunc(TState *thread, CState *st,
12981298
return true;
12991299
}
13001300

1301-
/* variable number ofintarguments */
1302-
casePGBENCH_MIN:
1303-
casePGBENCH_MAX:
1301+
/* variable number of arguments */
1302+
casePGBENCH_LEAST:
1303+
casePGBENCH_GREATEST:
13041304
{
1305-
int64extremum;
1305+
boolhavedouble;
13061306
inti;
1307-
Assert(nargs >=1);
13081307

1309-
if (!coerceToInt(&vargs[0],&extremum))
1310-
return false;
1308+
Assert(nargs >=1);
13111309

1312-
for (i=1;i<nargs;i++)
1310+
/* need double result if any input is double */
1311+
havedouble= false;
1312+
for (i=0;i<nargs;i++)
13131313
{
1314-
int64ival;
1314+
if (vargs[i].type==PGBT_DOUBLE)
1315+
{
1316+
havedouble= true;
1317+
break;
1318+
}
1319+
}
1320+
if (havedouble)
1321+
{
1322+
doubleextremum;
13151323

1316-
if (!coerceToInt(&vargs[i],&ival))
1324+
if (!coerceToDouble(&vargs[0],&extremum))
13171325
return false;
1318-
1319-
if (func==PGBENCH_MIN)
1320-
extremum=extremum<ival ?extremum :ival;
1321-
elseif (func==PGBENCH_MAX)
1322-
extremum=extremum>ival ?extremum :ival;
1326+
for (i=1;i<nargs;i++)
1327+
{
1328+
doubledval;
1329+
1330+
if (!coerceToDouble(&vargs[i],&dval))
1331+
return false;
1332+
if (func==PGBENCH_LEAST)
1333+
extremum=Min(extremum,dval);
1334+
else
1335+
extremum=Max(extremum,dval);
1336+
}
1337+
setDoubleValue(retval,extremum);
13231338
}
1339+
else
1340+
{
1341+
int64extremum;
13241342

1325-
setIntValue(retval,extremum);
1343+
if (!coerceToInt(&vargs[0],&extremum))
1344+
return false;
1345+
for (i=1;i<nargs;i++)
1346+
{
1347+
int64ival;
1348+
1349+
if (!coerceToInt(&vargs[i],&ival))
1350+
return false;
1351+
if (func==PGBENCH_LEAST)
1352+
extremum=Min(extremum,ival);
1353+
else
1354+
extremum=Max(extremum,ival);
1355+
}
1356+
setIntValue(retval,extremum);
1357+
}
13261358
return true;
13271359
}
13281360

‎src/bin/pgbench/pgbench.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ typedef enum PgBenchFunction
6767
PGBENCH_MOD,
6868
PGBENCH_DEBUG,
6969
PGBENCH_ABS,
70-
PGBENCH_MIN,
71-
PGBENCH_MAX,
70+
PGBENCH_LEAST,
71+
PGBENCH_GREATEST,
7272
PGBENCH_INT,
7373
PGBENCH_DOUBLE,
7474
PGBENCH_PI,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp