Re: extend pgbench expressions with functions

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: extend pgbench expressions with functions
Date: 2015-11-05 21:19:36
Message-ID: CA+TgmoZh+q+zbZtzvHb7sfGkLQCpfybNNkDF_bDfgLYKxvoOHw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 5, 2015 at 3:33 PM, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> wrote:
> For the '+' overload operator with conversions there are 4 cases (2
> arguments ** 2 types) to handle. For all 5 binary operators (+ - * / %).
> that makes 20 cases to handle. Then for every function, you have to deal
> with type conversion as well, each function times number of arguments **
> number of types. That is 2 cases for abs, 4 cases for random, 8 cases for
> each random_exp*, 8 for random_gaus*, and so on. Some thinking would be
> required for n-ary functions (min & max).
>
> Basically, it can be done, no technical issue, it is just a matter of
> writing a *lot* of repetitive code, hundreds of lines of them. As I think it
> does not bring any value for pgbench purpose, I used the other approach
> which reduces the code size by avoiding the combinatorial "cross-type"
> conversions.

Those can be avoided in other ways. For example:

if (x->type == PGBT_INTEGER && y->type == PGBT_INTEGER)
{
result->type = PGBT_INTEGER;
result->u.ival = x->u.ival + y->u.ival;
}
else
{
result->type = PGBT_DOUBLE;
result->u.ival = coerceToDouble(x) + coerceToDouble(y);
}

coerceToDouble can re-used for every arithmetic operator and can throw
an error if the input type is not coercible. Yet, we still return an
exact integer answer when possible.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2015-11-05 21:23:29 Re: proposal: multiple psql option -c
Previous Message Adrian.Vondendriesch 2015-11-05 21:19:34 Re: [BUGS] BUG #12989: pg_size_pretty with negative values