]> granicus.if.org Git - postgresql/commitdiff
Add pow(), aka power(), function to pgbench.
authorRobert Haas <rhaas@postgresql.org>
Wed, 27 Dec 2017 18:24:33 +0000 (10:24 -0800)
committerRobert Haas <rhaas@postgresql.org>
Wed, 27 Dec 2017 18:45:45 +0000 (10:45 -0800)
Raúl Marín Rodríguez, reviewed by Fabien Coelho and Michael Paquier,
with a minor fix by me.

Discussion: http://postgr.es/m/CAM6_UM4XiA14y9HnDqu9kAAOtwMhHZxW--q_ZACZW9Hsrsf-tg@mail.gmail.com

doc/src/sgml/ref/pgbench.sgml
src/bin/pgbench/exprparse.y
src/bin/pgbench/pgbench.c
src/bin/pgbench/pgbench.h
src/bin/pgbench/t/001_pgbench_with_server.pl

index 4431fc3eb741945e2cdcb824b3ac2b6f83146331..1519fe78ef95a8684bc1f9f5e689b567de8b911a 100644 (file)
@@ -1069,6 +1069,13 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
        <entry><literal>pi()</literal></entry>
        <entry><literal>3.14159265358979323846</literal></entry>
       </row>
+      <row>
+       <entry><literal><function>pow(<replaceable>x</replaceable>, <replaceable>y</replaceable>)</function>, <function>power(<replaceable>x</replaceable>, <replaceable>y</replaceable>)</function></literal></entry>
+       <entry>double</entry>
+       <entry>exponentiation</entry>
+       <entry><literal>pow(2.0, 10)</literal>, <literal>power(2.0, 10)</literal></entry>
+       <entry><literal>1024.0</literal></entry>
+      </row>
       <row>
        <entry><literal><function>random(<replaceable>lb</replaceable>, <replaceable>ub</replaceable>)</function></literal></entry>
        <entry>integer</entry>
index 25d5ad48e55a32b55b92390d671727dc2cb40c1a..74ffe5e7a7bb694a98a3fa6438c48908399d831b 100644 (file)
@@ -194,6 +194,12 @@ static const struct
        {
                "random_zipfian", 3, PGBENCH_RANDOM_ZIPFIAN
        },
+       {
+               "pow", 2, PGBENCH_POW
+       },
+       {
+               "power", 2, PGBENCH_POW
+       },
        /* keep as last array element */
        {
                NULL, 0, 0
index 7ce6f607f5cb386d694bcb4a94f13e0fc916a3c6..e065f7bedc7c5358db8b228a1c94e81dd6f92fe8 100644 (file)
@@ -1850,6 +1850,24 @@ evalFunc(TState *thread, CState *st,
                                return true;
                        }
 
+               case PGBENCH_POW:
+                       {
+                               PgBenchValue *lval = &vargs[0];
+                               PgBenchValue *rval = &vargs[1];
+                               double          ld,
+                                                       rd;
+
+                               Assert(nargs == 2);
+
+                               if (!coerceToDouble(lval, &ld) ||
+                                       !coerceToDouble(rval, &rd))
+                                       return false;
+
+                               setDoubleValue(retval, pow(ld, rd));
+
+                               return true;
+                       }
+
                default:
                        /* cannot get here */
                        Assert(0);
index 83fee1ae74560dc73be0a5de1bbd9d11a10137c0..0e92882a4c3e0c7c381c9de9ebbc21e5fe853adf 100644 (file)
@@ -76,7 +76,8 @@ typedef enum PgBenchFunction
        PGBENCH_RANDOM,
        PGBENCH_RANDOM_GAUSSIAN,
        PGBENCH_RANDOM_EXPONENTIAL,
-       PGBENCH_RANDOM_ZIPFIAN
+       PGBENCH_RANDOM_ZIPFIAN,
+       PGBENCH_POW
 } PgBenchFunction;
 
 typedef struct PgBenchExpr PgBenchExpr;
index e3cdf28628ca229b9318780459c2bcba4ee5607f..9cbeb2fc111f937c702e01849bdda8525e38c36e 100644 (file)
@@ -232,7 +232,17 @@ pgbench(
                qr{command=19.: double 19\b},
                qr{command=20.: double 20\b},
                qr{command=21.: int 9223372036854775807\b},
-               qr{command=23.: int [1-9]\b}, ],
+               qr{command=23.: int [1-9]\b},
+               qr{command=24.: double -27\b},
+               qr{command=25.: double 1024\b},
+               qr{command=26.: double 1\b},
+               qr{command=27.: double 1\b},
+               qr{command=28.: double -0.125\b},
+               qr{command=29.: double -0.125\b},
+               qr{command=30.: double -0.00032\b},
+               qr{command=31.: double 8.50705917302346e\+37\b},
+               qr{command=32.: double 1e\+30\b},
+       ],
        'pgbench expressions',
        {   '001_pgbench_expressions' => q{-- integer functions
 \set i1 debug(random(1, 100))
@@ -264,6 +274,16 @@ pgbench(
 \set i1 0
 -- yet another integer function
 \set id debug(random_zipfian(1, 9, 1.3))
+--- pow and power
+\set poweri debug(pow(-3,3))
+\set powerd debug(pow(2.0,10))
+\set poweriz debug(pow(0,0))
+\set powerdz debug(pow(0.0,0.0))
+\set powernegi debug(pow(-2,-3))
+\set powernegd debug(pow(-2.0,-3.0))
+\set powernegd2 debug(power(-5.0,-5.0))
+\set powerov debug(pow(9223372036854775807, 2))
+\set powerov2 debug(pow(10,30))
 } });
 
 # backslash commands