Re: pgbench - add pseudo-random permutation function

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Hironobu SUZUKI <hironobu(at)interdb(dot)jp>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: pgbench - add pseudo-random permutation function
Date: 2019-07-16 04:47:55
Message-ID: CA+hUKGJexK+xNCyY6xmg+NcMjHBX-+eoW7bWzzv3c6xb=EYL6Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, May 24, 2019 at 2:46 AM Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> wrote:
> Here is a v15 which is a rebase, plus a large simplification of the modmul
> function if an int128 type is available, which is probably always…

> > Function nbits(), which was previously discussed, has been simplified by
> > using the function pg_popcount64().

Hi Fabien, Suzuki-san,

I am not smart enough to commit this or judge its value for
benchmarking, but I have a few trivial comments on the language:

+ It allows to mix the output of non uniform random functions so that

"It allows the output of non-uniform random functions to be mixed so that"

+ ensures that a perfect permutation is applied: there are no collisions
+ nor holes in the output values.

"neither collisions nor holes", or "no collisions or holes"

+ The function errors if size is not positive.

"raises an error"

+ * 24 bits mega primes from https://primes.utm.edu/lists/small/millions/

"24 bit mega primes"

+/* length of n binary representation */
+static int
+nbits(uint64 n)
+{
+ /* set lower bits to 1 and count them */
+ return pg_popcount64(compute_mask(n));
+}

I suppose you could use n == 0 ? 0 : pg_leftmost_one_pos64(n) + 1, and then...

+/* return smallest mask holding n */
+static uint64
+compute_mask(uint64 n)
+{
+ n |= n >> 1;
+ n |= n >> 2;
+ n |= n >> 4;
+ n |= n >> 8;
+ n |= n >> 16;
+ n |= n >> 32;
+ return n;
+}

... here you could use 1 << nbits(n)) - 1. I have no idea if doing it
that way around is better, it's just a thought and removes a few lines
of bit-swizzling code.

--
Thomas Munro
https://enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2019-07-16 05:01:24 Re: make \d pg_toast.foo show its indices ; and, \d toast show its main table ; and \d relkind=I show its partitions (and tablespace)
Previous Message Amit Kapila 2019-07-16 04:32:45 Re: POC: Cleaning up orphaned files using undo logs