Re: pgbench - add pseudo-random permutation function

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
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 14:44:00
Message-ID: 20210313144400.GA23514@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

On 2021-Mar-13, Fabien COELHO wrote:

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

Yeah, we rely on those being available elsewhere.

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

Clearly we got rid of a lot of code. About the tests, maybe the easiest
thing to do is "skip ... if $Config{'osname'} eq 'MSWin32'".

One comment in pseudorandom_perm talks about "whitening" while the other
talks about "scramble". I think they should both use the same term to
ease understanding.

You kept routine nbits() which is unneeded now.

pgbench.c gains too many includes for my taste. Can we put
pseudorandom_perm() in a separate file?

The function name pr_perm() is much too short; I think we should use a
more descriptive name; maybe \prand_perm is sufficient? Though I admit
the abbreviation "perm" evokes "permission" more than "permutation" to
me, so maybe \prand_permutation is better? (If you're inclined to
abbreviate permutation, maybe \prand_permut?)

I think the reference docs are not clear enough. What do you think of
something like this?

> + <row>
> + <entry role="func_table_entry"><para role="func_signature">
> + <function>pr_perm</function> ( <parameter>i</parameter>, <parameter>size</parameter> [, <parameter>seed</parameter> ] )
> + <returnvalue>integer</returnvalue>
> + </para>
> + <para>
> + i'th pseudo-random permutation in <literal>[0,size)</literal>
> + <!-- "The i'th value of the pseudo-random permutation in the interval [0,size)"? -->
> + </para>
> + <para>
> + <literal>pr_perm(2, 4)</literal>
> + <returnvalue>the 2nd integer between 0 and (4-1)</returnvalue>
> + </para></entry>
> + </row>

--
Álvaro Herrera Valdivia, Chile

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-03-13 14:50:54 Re: pg_amcheck contrib application
Previous Message Robert Haas 2021-03-13 13:49:50 Re: pg_amcheck contrib application