pgsql: Replace random(), pg_erand48(), etc with a better PRNG API and a

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Replace random(), pg_erand48(), etc with a better PRNG API and a
Date: 2021-11-29 02:33:45
Message-ID: E1mrWUD-000235-Hq@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2021-11-29 03:47:48 Re: pgsql: Replace random(), pg_erand48(), etc with a better PRNG API and a
Previous Message Michael Paquier 2021-11-29 01:40:58 pgsql: Improve psql tab completion for views, FDWs, sequences and trans