Re: extend pgbench expressions with functions - Mailing list pgsql-hackers

From Shulgin, Oleksandr
Subject Re: extend pgbench expressions with functions
Date
Msg-id CACACo5SXL02Vw=aOk_24Qt1H_pZgxj5RO1qvzTB3SnfAZueyGA@mail.gmail.com
Whole thread Raw
In response to Re: extend pgbench expressions with functions  (Fabien COELHO <coelho@cri.ensmp.fr>)
Responses Re: extend pgbench expressions with functions  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
On Fri, Sep 18, 2015 at 10:21 AM, Fabien COELHO <coelho@cri.ensmp.fr> wrote:

Hello Kyotaro-san,

My description should have been obscure. Indeed the call tree is
finite for *sane* expression node. But it makes infinit call for
a value of expr->etype unknown by both evalDouble and
evalInt.

Such issue would be detected if the function is actually tested, hopefully this should be the case... :-)

However I agree that relying implicitely on the "default" case is not very good practice, so I updated the code in the attached v11 to fail explicitely on such errors.

I also attached a small test script, which exercises most (all?) functions:

  ./pgbench -f functions.sql -t 1

A short review from me:

1. Patch applies cleanly on current HEAD.
2. It compiles without errors or warnings.
3. The attached test case can be executed w/o symptoms of any problem and it produces meaningful results.

Should we not allow for functions taking 0 arguments?  Since we're already into some math here, how about pi()? ;-)

I understand requiring at least 1 arg simplifies the code a bit, but right now it reports syntax error for "random()", while it correctly reports unexpected number of arguments for "random(1,2,3)".  We would need another check for min() and max() which expect >=1 arguments, but it's easy to add.

I would also argue that we should rename "random" to "rand" here to avoid confusion with the familiar SQL function "random()" that doesn't take arguments.

--
Alex

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Move PinBuffer and UnpinBuffer to atomics
Next
From: Oleg Bartunov
Date:
Subject: Re: Did the "Full-text search in PostgreSQL in milliseconds" patches land?