Re: pgbench - add pseudo-random permutation function

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Hironobu SUZUKI <hironobu(at)interdb(dot)jp>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgbench - add pseudo-random permutation function
Date: 2021-03-13 08:49:53
Message-ID: alpine.DEB.2.22.394.2103130910470.771005@pseudo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello Alvaro,

>> That doesn't sound like a bad option to me, if it makes this much
>> simpler. The main modern system without it seems to be MSVC. The
>> Linux, BSD, Apple, illumos, AIX systems using Clang/GCC with
>> Intel/AMD/ARM/PowerPC CPUs have it, and the Windows systems using open
>> source compilers have it.
>
> Hmm. Can we go a bit further, and say that if you don't have 128-bit
> ints, then you can use pr_perm but only to a maximum of 32-bit ints?
> Then you can do the calculations in 64-bit ints. That's much less bad
> than desupporting the feature altogether.

This looks like a good compromise, which can even be a little better
because we still have 64 bits ints.

As there is already a performance shortcut in the code relying on the fact
that x is 24 bits and that no overflow occurs if y & m are up to 48 bits
(we are using unsigned int), the simplification is just to abort if int128
is not available, because we would have called the function only if it was
really needed.

Attached a simplified patch which does that, removing 1/3 of the code.
What do you think?

Note that this creates one issue though: tests now fail if 128 bits ints
are not available. I'm not sure how to detect & skip that from the tap
tests. I'm not keen on removing the tests either. Will give it some
thoughts if you want to proceed in that direction.

--
Fabien.

Attachment Content-Type Size
pgbench-prp-func-21.patch text/x-diff 16.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Julien Rouhaud 2021-03-13 08:53:51 Re: pl/pgsql feature request: shorthand for argument and local variable references
Previous Message Fabien COELHO 2021-03-13 08:08:31 Re: pgbench: option delaying queries till connections establishment?