pgbench_pow_v2_pgbench-more-ops-funcs-14.patch
text/x-patch
Filename: pgbench_pow_v2_pgbench-more-ops-funcs-14.patch
Type: text/x-patch
Part: 0
Message:
Re: pow support for pgbench
Patch
Format: format-patch
Series: patch v2
Subject: Add pow() support to pgbench
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/pgbench.sgml | 7 | 0 |
| src/bin/pgbench/exprparse.y | 3 | 0 |
| src/bin/pgbench/pgbench.c | 9 | 0 |
| src/bin/pgbench/pgbench.h | 2 | 1 |
| src/bin/pgbench/t/001_pgbench_with_server.pl | 5 | 0 |
From a6eecfe6637bdb0cbb02a9eda7b88d9c4325bb51 Mon Sep 17 00:00:00 2001
From: Raul Marin <rmrodriguez@cartodb.com>
Date: Fri, 13 Oct 2017 17:42:23 +0200
Subject: [PATCH] Add pow() support to pgbench
---
doc/src/sgml/ref/pgbench.sgml | 7 +++++++
src/bin/pgbench/exprparse.y | 3 +++
src/bin/pgbench/pgbench.c | 9 +++++++++
src/bin/pgbench/pgbench.h | 3 ++-
src/bin/pgbench/t/001_pgbench_with_server.pl | 5 +++++
5 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 1f55967e40a..2e913dfcfd6 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -1233,6 +1233,13 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
<entry><literal>sqrt(2.0)</literal></entry>
<entry><literal>1.414213562</literal></entry>
</row>
+ <row>
+ <entry><literal><function>pow(<replaceable>x</replaceable>, <replaceable>y</replaceable>)</function></literal></entry>
+ <entry>double if <replaceable>x</replaceable> or <replaceable>y</replaceable> are doubles, else integer</entry>
+ <entry>Numeric exponentiation</entry>
+ <entry><literal>pow(2.0, 10)</literal></entry>
+ <entry><literal>1024.0/<literal></entry>
+ </row>
</tbody>
</tgroup>
</table>
diff --git a/src/bin/pgbench/exprparse.y b/src/bin/pgbench/exprparse.y
index 770be981f06..290bca99d12 100644
--- a/src/bin/pgbench/exprparse.y
+++ b/src/bin/pgbench/exprparse.y
@@ -334,6 +334,9 @@ static const struct
{
"!case_end", -2, PGBENCH_CASE
},
+ {
+ "pow", 2, PGBENCH_POW
+ },
/* keep as last array element */
{
NULL, 0, 0
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index add653bf90c..b2bab9b8239 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -1474,6 +1474,7 @@ evalFunc(TState *thread, CState *st,
case PGBENCH_NE:
case PGBENCH_LE:
case PGBENCH_LT:
+ case PGBENCH_POW:
{
PgBenchValue *lval = &vargs[0],
*rval = &vargs[1];
@@ -1525,6 +1526,10 @@ evalFunc(TState *thread, CState *st,
setBoolValue(retval, ld < rd);
return true;
+ case PGBENCH_POW:
+ setDoubleValue(retval, pow(ld, rd));
+ return true;
+
default:
/* cannot get here */
Assert(0);
@@ -1602,6 +1607,10 @@ evalFunc(TState *thread, CState *st,
return true;
+ case PGBENCH_POW:
+ setIntValue(retval, pow(li, ri));
+ return true;
+
default:
/* cannot get here */
Assert(0);
diff --git a/src/bin/pgbench/pgbench.h b/src/bin/pgbench/pgbench.h
index e1277a1dde6..9f26af92bf6 100644
--- a/src/bin/pgbench/pgbench.h
+++ b/src/bin/pgbench/pgbench.h
@@ -94,7 +94,8 @@ typedef enum PgBenchFunction
PGBENCH_LE,
PGBENCH_LT,
PGBENCH_IS,
- PGBENCH_CASE
+ PGBENCH_CASE,
+ PGBENCH_POW
} PgBenchFunction;
typedef struct PgBenchExpr PgBenchExpr;
diff --git a/src/bin/pgbench/t/001_pgbench_with_server.pl b/src/bin/pgbench/t/001_pgbench_with_server.pl
index 8e19bbd3f45..81b7ce4dfcc 100644
--- a/src/bin/pgbench/t/001_pgbench_with_server.pl
+++ b/src/bin/pgbench/t/001_pgbench_with_server.pl
@@ -237,6 +237,8 @@ sub pgbench
qr{command=36.: int 36\b},
qr{command=37.: boolean true\b},
qr{command=38.: boolean true\b},
+ qr{command=44.: int -27\b},
+ qr{command=45.: double 1024\b},
],
'pgbench expressions',
{ '001_pgbench_expressions' => q{-- integer functions
@@ -299,6 +301,9 @@ sub pgbench
\set v2 5432
\set v3 -54.21E-2
SELECT :v0, :v1, :v2, :v3;
+--- pow() operator
+\set poweri debug(pow(-3,3))
+\set powerd debug(pow(2.0,10))
} });
=head