pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Replace random(), pg_erand48(), etc with a better PRNG API and a
Date: Mon, 29 Nov 2021 02:33:45 +0000
Message-ID: <E1mrWUD-000235-Hq@gemulon.postgresql.org> (raw)

Replace random(), pg_erand48(), etc with a better PRNG API and algorithm.

Standardize on xoroshiro128** as our basic PRNG algorithm, eliminating
a bunch of platform dependencies as well as fundamentally-obsolete PRNG
code.  In addition, this API replacement will ease replacing the
algorithm again in future, should that become necessary.

xoroshiro128** is a few percent slower than the drand48 family,
but it can produce full-width 64-bit random values not only 48-bit,
and it should be much more trustworthy.  It's likely to be noticeably
faster than the platform's random(), depending on which platform you
are thinking about; and we can have non-global state vectors easily,
unlike with random().  It is not cryptographically strong, but neither
are the functions it replaces.

Fabien Coelho, reviewed by Dean Rasheed, Aleksander Alekseev, and myself

Discussion: https://postgr.es/m/alpine.DEB.2.22.394.2105241211230.165418@pseudo

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3804539e48e794781c6145c7f988f5d507418fa8

Modified Files
--------------
configure                                          |  26 ---
configure.ac                                       |   2 -
contrib/amcheck/verify_nbtree.c                    |   5 +-
contrib/auto_explain/auto_explain.c                |   4 +-
contrib/file_fdw/file_fdw.c                        |   2 +-
contrib/postgres_fdw/postgres_fdw.c                |   2 +-
contrib/tablefunc/tablefunc.c                      |   5 +-
contrib/tsm_system_rows/tsm_system_rows.c          |  12 +-
contrib/tsm_system_time/tsm_system_time.c          |  12 +-
src/backend/access/gin/ginget.c                    |   3 +-
src/backend/access/gist/gistutil.c                 |   5 +-
src/backend/access/nbtree/nbtinsert.c              |   3 +-
src/backend/access/spgist/spgdoinsert.c            |   5 +-
src/backend/access/transam/xact.c                  |   3 +-
src/backend/commands/analyze.c                     |   7 +-
src/backend/executor/nodeSamplescan.c              |   3 +-
src/backend/lib/bloomfilter.c                      |   3 +-
src/backend/optimizer/geqo/geqo_random.c           |  23 +-
src/backend/optimizer/geqo/geqo_selection.c        |  14 +-
src/backend/postmaster/postmaster.c                |  20 +-
src/backend/storage/file/fd.c                      |   4 +-
src/backend/storage/ipc/dsm.c                      |   9 +-
src/backend/storage/lmgr/Makefile                  |   5 +-
src/backend/storage/lmgr/s_lock.c                  |   5 +-
src/backend/tcop/postgres.c                        |   7 +-
src/backend/utils/adt/float.c                      |  20 +-
src/backend/utils/misc/sampling.c                  |  52 +++--
src/bin/initdb/initdb.c                            |   8 +-
src/bin/pg_test_fsync/pg_test_fsync.c              |   5 +-
src/bin/pgbench/pgbench.c                          | 122 ++++------
src/bin/pgbench/t/001_pgbench_with_server.pl       |  23 +-
src/common/Makefile                                |   1 +
src/common/pg_prng.c                               | 247 +++++++++++++++++++++
src/include/common/pg_prng.h                       |  60 +++++
src/include/optimizer/geqo.h                       |   3 +-
src/include/optimizer/geqo_random.h                |   5 +-
src/include/pg_config.h.in                         |   6 -
src/include/pg_config_manual.h                     |  11 -
src/include/port.h                                 |  13 --
src/include/utils/sampling.h                       |  15 +-
src/port/Makefile                                  |   1 -
src/port/erand48.c                                 | 136 ------------
src/port/random.c                                  |  25 ---
src/port/srandom.c                                 |  25 ---
.../modules/test_bloomfilter/test_bloomfilter.c    |   4 +-
src/test/modules/test_integerset/test_integerset.c |   6 +-
src/test/modules/test_rbtree/test_rbtree.c         |   5 +-
src/tools/msvc/Mkvcbuild.pm                        |  12 +-
src/tools/msvc/Solution.pm                         |   2 -
src/tools/testint128.c                             |  29 +--
50 files changed, 544 insertions(+), 481 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1mrWUD-000235-Hq@gemulon.postgresql.org>
Permalink:  ../E1mrWUD-000235-Hq@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1mrWUD-000235-Hq@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Replace random(), pg_erand48(), etc with a better PRNG API and a
  In-Reply-To: <E1mrWUD-000235-Hq@gemulon.postgresql.org>
  References: <E1mrWUD-000235-Hq@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox