Re: add modulo (%) operator to pgbench

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: add modulo (%) operator to pgbench
Date: 2014-09-23 18:15:38
Message-ID: alpine.DEB.2.10.1409232001580.3297@sto
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> So my opinion is that this small modulo operator patch is both useful and
>> harmless, so it should be committed.
> You've really failed to make that case --- in particular, AFAICS there is
> not even consensus on the exact semantics that the operator should have.

There is. Basically whatever with a positive remainder when the divisor is
positive is fine. The only one to avoid is the dividend signed version,
which happen to be the one of C and SQL, a very unfortunate choice in both
case as soon as you have negative numbers.

> So I'm inclined to reject rather than put in something that may cause
> surprises down the road. The usefulness doesn't seem great enough to
> take that risk.

If you reject it, you can also remove the gaussian and exponential random
distribution which is near useless without a mean to add a minimal
pseudo-random stage, for which "(x * something) % size" is a reasonable
approximation, hence the modulo submission.

> The way forward, if we think there is enough value in it (I'm not
> sure there is), would be to build enough expression infrastructure
> so that we could inexpensively add both operators and functions.

The modulo patch is basically 10 lines of code, I would not call that

As I explained earlier, it would NOT be any different with an "expression
infrastructure", as you would have to add a lex for the operator, then a
yacc rule for the construction, the operator would need to be represented
in a data structure, and the executor should be able to handle the case
including errors... there is no way that this would be less that 10 lines
of code. It would basically include the very same lines for the executor

> Then we could add a modulo operator with whatever semantics seem
> most popular, and some function(s) for the other semantics, and
> there would not be so much riding on choosing the "right" semantics.

The semantics is clear. I just choose the wrong one in the first patch:-)


In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-09-23 18:24:22 Replication identifiers, take 3
Previous Message Alvaro Herrera 2014-09-23 18:04:09 Re: BRIN indexes - TRAP: BadArgument