pgsql: Improve style of pg_lfind32().

2024-03-27 Thread Nathan Bossart
Improve style of pg_lfind32().

This commit simplifies pg_lfind32() a bit by moving the standard
one-by-one linear search code to an inline helper function.

Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/20240327013616.GA3940109%40nathanxps13

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/7188a7806d208430aa5c717a1aefdf4980ed3d4d

Modified Files
--
src/include/port/pg_lfind.h | 62 +++--
1 file changed, 26 insertions(+), 36 deletions(-)



pgsql: Rethink create and attach APIs of shared TidStore.

2024-03-27 Thread Masahiko Sawada
Rethink create and attach APIs of shared TidStore.

Previously, the behavior of TidStoreCreate() was inconsistent between
local and shared TidStore instances in terms of memory limitation. For
local TidStore, a memory context was created with initial and maximum
memory block sizes, as well as a minimum memory context size, based on
the specified max_bytes values. However, for shared TidStore, the
provided DSA area was used for TID storage. Although commit bb952c8c8b
allowed specifying the initial and maximum DSA segment sizes, callers
would have needed to clamp their own limits, which was not consistent
and user-friendly.

With this commit, when creating a shared TidStore, a dedicated DSA
area is created for TID storage instead of using a provided DSA
area. The initial and maximum DSA segment sizes are chosen based on
the specified max_bytes. Other processes can attach to the shared
TidStore using the handle of the created DSA returned by the new
TidStoreGetDSA() function and the DSA pointer returned by
TidStoreGetHandle(). The created DSA has the same lifetime as the
shared TidStore and is deleted when all processes detach from it.

To improve clarity, the TidStoreCreate() function has been divided
into two separate functions: TidStoreCreateLocal() and
TidStoreCreateShared().

Reviewed-by: John Naylor
Discussion: 
https://postgr.es/m/CAD21AoAyc1j%3DBCdUqZfk6qbdjZ68UgRx1Gkpk0oah4K7S0Ri9g%40mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/2d8f56dabbfd2f85da9a4e0fe4a4b4d6654864f1

Modified Files
--
src/backend/access/common/tidstore.c   | 107 +++--
src/include/access/tidstore.h  |   7 +-
src/test/modules/test_tidstore/test_tidstore.c |  14 +---
3 files changed, 89 insertions(+), 39 deletions(-)



pgsql: doc: fix CREATE ROLE typo

2024-03-27 Thread Bruce Momjian
doc:  fix CREATE ROLE typo

This wording typo was added in PG 16.

Reported-by: s.bai...@chorusintel.com

Discussion: 
https://postgr.es/m/171150077554.7105.801523271545956...@wrigleys.postgresql.org

Backpatch-through: 16

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/d1cf5319e9ae16435e5ca416c06c2290bfca000e

Modified Files
--
doc/src/sgml/ref/create_role.sgml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: doc: fix CREATE ROLE typo

2024-03-27 Thread Bruce Momjian
doc:  fix CREATE ROLE typo

This wording typo was added in PG 16.

Reported-by: s.bai...@chorusintel.com

Discussion: 
https://postgr.es/m/171150077554.7105.801523271545956...@wrigleys.postgresql.org

Backpatch-through: 16

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/ca4c60e05f81c57b4d72da867173fc524c76aa71

Modified Files
--
doc/src/sgml/ref/create_role.sgml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: Run perltidy on generate-unicode_version.pl.

2024-03-27 Thread Jeff Davis
Run perltidy on generate-unicode_version.pl.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/b0be28761ec5958bb7bbf9a03d94ee6e1bc59849

Modified Files
--
src/common/unicode/generate-unicode_version.pl | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



pgsql: Fix unnecessary use of moving-aggregate mode with non-moving fra

2024-03-27 Thread Tom Lane
Fix unnecessary use of moving-aggregate mode with non-moving frame.

When a plain aggregate is used as a window function, and the window
frame start is specified as UNBOUNDED PRECEDING, the frame's head
cannot move so we do not need to use moving-aggregate mode.  The check
for that was put into initialize_peragg(), failing to notice that
ExecInitWindowAgg() calls that function before it's filled in
winstate->frameOptions.  Since makeNode() would have zeroed the field,
this didn't provoke uninitialized-value complaints, nor would the
erroneous decision have resulted in more than a little inefficiency.
Still, it's wrong, so move the initialization of
winstate->frameOptions earlier to make it work properly.

While here, also fix a thinko in a comment.  Both errors crept in in
commit a9d9acbf2 which introduced the moving-aggregate mode.

Spotted by Vallimaharajan G.  Back-patch to all supported branches.

Discussion: 
https://postgr.es/m/18e7f2a5167.fe36253866818.977923893562469...@zohocorp.com

Branch
--
REL_12_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/25675c474292dca71470ef17ea8a53c150eb0e0a

Modified Files
--
src/backend/executor/nodeWindowAgg.c | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Fix unnecessary use of moving-aggregate mode with non-moving fra

2024-03-27 Thread Tom Lane
Fix unnecessary use of moving-aggregate mode with non-moving frame.

When a plain aggregate is used as a window function, and the window
frame start is specified as UNBOUNDED PRECEDING, the frame's head
cannot move so we do not need to use moving-aggregate mode.  The check
for that was put into initialize_peragg(), failing to notice that
ExecInitWindowAgg() calls that function before it's filled in
winstate->frameOptions.  Since makeNode() would have zeroed the field,
this didn't provoke uninitialized-value complaints, nor would the
erroneous decision have resulted in more than a little inefficiency.
Still, it's wrong, so move the initialization of
winstate->frameOptions earlier to make it work properly.

While here, also fix a thinko in a comment.  Both errors crept in in
commit a9d9acbf2 which introduced the moving-aggregate mode.

Spotted by Vallimaharajan G.  Back-patch to all supported branches.

Discussion: 
https://postgr.es/m/18e7f2a5167.fe36253866818.977923893562469...@zohocorp.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a767cdc84c9a4cba1f92854de55fb8b5f2de4598

Modified Files
--
src/backend/executor/nodeWindowAgg.c | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Fix unnecessary use of moving-aggregate mode with non-moving fra

2024-03-27 Thread Tom Lane
Fix unnecessary use of moving-aggregate mode with non-moving frame.

When a plain aggregate is used as a window function, and the window
frame start is specified as UNBOUNDED PRECEDING, the frame's head
cannot move so we do not need to use moving-aggregate mode.  The check
for that was put into initialize_peragg(), failing to notice that
ExecInitWindowAgg() calls that function before it's filled in
winstate->frameOptions.  Since makeNode() would have zeroed the field,
this didn't provoke uninitialized-value complaints, nor would the
erroneous decision have resulted in more than a little inefficiency.
Still, it's wrong, so move the initialization of
winstate->frameOptions earlier to make it work properly.

While here, also fix a thinko in a comment.  Both errors crept in in
commit a9d9acbf2 which introduced the moving-aggregate mode.

Spotted by Vallimaharajan G.  Back-patch to all supported branches.

Discussion: 
https://postgr.es/m/18e7f2a5167.fe36253866818.977923893562469...@zohocorp.com

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/0d30e48c2578a6857aa2869f1b2696b6eb5fef68

Modified Files
--
src/backend/executor/nodeWindowAgg.c | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Fix unnecessary use of moving-aggregate mode with non-moving fra

2024-03-27 Thread Tom Lane
Fix unnecessary use of moving-aggregate mode with non-moving frame.

When a plain aggregate is used as a window function, and the window
frame start is specified as UNBOUNDED PRECEDING, the frame's head
cannot move so we do not need to use moving-aggregate mode.  The check
for that was put into initialize_peragg(), failing to notice that
ExecInitWindowAgg() calls that function before it's filled in
winstate->frameOptions.  Since makeNode() would have zeroed the field,
this didn't provoke uninitialized-value complaints, nor would the
erroneous decision have resulted in more than a little inefficiency.
Still, it's wrong, so move the initialization of
winstate->frameOptions earlier to make it work properly.

While here, also fix a thinko in a comment.  Both errors crept in in
commit a9d9acbf2 which introduced the moving-aggregate mode.

Spotted by Vallimaharajan G.  Back-patch to all supported branches.

Discussion: 
https://postgr.es/m/18e7f2a5167.fe36253866818.977923893562469...@zohocorp.com

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/03561a6c7bbfe305b941d46f7bafb3cdd4793982

Modified Files
--
src/backend/executor/nodeWindowAgg.c | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Fix unnecessary use of moving-aggregate mode with non-moving fra

2024-03-27 Thread Tom Lane
Fix unnecessary use of moving-aggregate mode with non-moving frame.

When a plain aggregate is used as a window function, and the window
frame start is specified as UNBOUNDED PRECEDING, the frame's head
cannot move so we do not need to use moving-aggregate mode.  The check
for that was put into initialize_peragg(), failing to notice that
ExecInitWindowAgg() calls that function before it's filled in
winstate->frameOptions.  Since makeNode() would have zeroed the field,
this didn't provoke uninitialized-value complaints, nor would the
erroneous decision have resulted in more than a little inefficiency.
Still, it's wrong, so move the initialization of
winstate->frameOptions earlier to make it work properly.

While here, also fix a thinko in a comment.  Both errors crept in in
commit a9d9acbf2 which introduced the moving-aggregate mode.

Spotted by Vallimaharajan G.  Back-patch to all supported branches.

Discussion: 
https://postgr.es/m/18e7f2a5167.fe36253866818.977923893562469...@zohocorp.com

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/a94f51a7bfc9e65ce3799d8cb12945bd596c5ba8

Modified Files
--
src/backend/executor/nodeWindowAgg.c | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Fix unnecessary use of moving-aggregate mode with non-moving fra

2024-03-27 Thread Tom Lane
Fix unnecessary use of moving-aggregate mode with non-moving frame.

When a plain aggregate is used as a window function, and the window
frame start is specified as UNBOUNDED PRECEDING, the frame's head
cannot move so we do not need to use moving-aggregate mode.  The check
for that was put into initialize_peragg(), failing to notice that
ExecInitWindowAgg() calls that function before it's filled in
winstate->frameOptions.  Since makeNode() would have zeroed the field,
this didn't provoke uninitialized-value complaints, nor would the
erroneous decision have resulted in more than a little inefficiency.
Still, it's wrong, so move the initialization of
winstate->frameOptions earlier to make it work properly.

While here, also fix a thinko in a comment.  Both errors crept in in
commit a9d9acbf2 which introduced the moving-aggregate mode.

Spotted by Vallimaharajan G.  Back-patch to all supported branches.

Discussion: 
https://postgr.es/m/18e7f2a5167.fe36253866818.977923893562469...@zohocorp.com

Branch
--
REL_13_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/de3c5b18729a234df0b9203e195a2a5c168ef1cd

Modified Files
--
src/backend/executor/nodeWindowAgg.c | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Adjust documentation for syncfs().

2024-03-27 Thread Nathan Bossart
Adjust documentation for syncfs().

Commit 8c16ad3b43 created a new appendix for syncfs(), which is
excessive for such a small amount of content.  This commit moves
the description of the caveats to be aware of when using syncfs()
back to the documentation for recovery_init_sync_method.  The
documentation for the other utilities with syncfs() support now
directs readers to recovery_init_sync_method for information about
these caveats.

Reported-by: Peter Eisentraut, Robert Haas
Suggested-by: Robert Haas
Reviewed-by: Robert Haas
Discussion: 
https://postgr.es/m/42804669-7063-1320-ed37-3226d5f1067d%40eisentraut.org
Discussion: 
https://postgr.es/m/CA%2BTgmobUiqKr%2BZMCLc5Qap-sXBnjfGUU%2BZBmzYEjUuWyjsGr1g%40mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/44a4cca9913bae8557c31207adb97b94e6e60603

Modified Files
--
doc/src/sgml/config.sgml   | 12 +---
doc/src/sgml/filelist.sgml |  1 -
doc/src/sgml/postgres.sgml |  1 -
doc/src/sgml/ref/initdb.sgml   |  4 ++--
doc/src/sgml/ref/pg_basebackup.sgml|  4 ++--
doc/src/sgml/ref/pg_checksums.sgml |  4 ++--
doc/src/sgml/ref/pg_combinebackup.sgml |  4 ++--
doc/src/sgml/ref/pg_dump.sgml  |  5 +++--
doc/src/sgml/ref/pg_rewind.sgml|  4 ++--
doc/src/sgml/ref/pgupgrade.sgml|  4 ++--
doc/src/sgml/syncfs.sgml   | 36 --
11 files changed, 24 insertions(+), 55 deletions(-)



pgsql: Rename COMPAT_OPTIONS_CLIENT to COMPAT_OPTIONS_OTHER.

2024-03-27 Thread Robert Haas
Rename COMPAT_OPTIONS_CLIENT to COMPAT_OPTIONS_OTHER.

The user-facing name is "Other Platforms and Clients", but the
internal name seems too focused on clients specifically, especially
given the plan to add a new setting to this session that is about
platform or deployment model compatibility rather than client
compatibility.

Jelte Fennema-Nio

Discussion: 
http://postgr.es/m/cageczqtfmbdim6w3av+3wesnhxjvpmutecjxvvst91sqbdo...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/de7e96bd0fc620715fa1c7bd9985463c358664cf

Modified Files
--
src/backend/utils/misc/guc_tables.c | 4 ++--
src/include/utils/guc_tables.h  | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)



pgsql: Fix unstable aggregate regression test

2024-03-27 Thread David Rowley
Fix unstable aggregate regression test

Buildfarm member avocet has shown a plan change by switching the
finalize aggregate stage to use a GroupAggregate rather than a
HashAggregate.  This is consistent with autovacuum having triggered on
the table, per analysis by Alexander Lakhin.

Fix this by disabling autovacuum on the table.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/d4493a28-589a-5328-fed5-250f2d7d3...@gmail.com
Backpatch-through: 16, where this test was added.

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/f5d0e866404a249d3a87a016e3ec562ab2dc6706

Modified Files
--
src/test/regress/expected/aggregates.out | 2 +-
src/test/regress/sql/aggregates.sql  | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)



pgsql: Fix unstable aggregate regression test

2024-03-27 Thread David Rowley
Fix unstable aggregate regression test

Buildfarm member avocet has shown a plan change by switching the
finalize aggregate stage to use a GroupAggregate rather than a
HashAggregate.  This is consistent with autovacuum having triggered on
the table, per analysis by Alexander Lakhin.

Fix this by disabling autovacuum on the table.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/d4493a28-589a-5328-fed5-250f2d7d3...@gmail.com
Backpatch-through: 16, where this test was added.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/d6a6957d53e3de9982b076b6ddd703be3d0ae30a

Modified Files
--
src/test/regress/expected/aggregates.out | 2 +-
src/test/regress/sql/aggregates.sql  | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)



pgsql: Add functions to generate random numbers in a specified range.

2024-03-27 Thread Dean Rasheed
Add functions to generate random numbers in a specified range.

This adds 3 new variants of the random() function:

random(min integer, max integer) returns integer
random(min bigint, max bigint) returns bigint
random(min numeric, max numeric) returns numeric

Each returns a random number x in the range min <= x <= max.

For the numeric function, the number of digits after the decimal point
is equal to the number of digits that "min" or "max" has after the
decimal point, whichever has more.

The main entry points for these functions are in a new C source file.
The existing random(), random_normal(), and setseed() functions are
moved there too, so that they can all share the same PRNG state, which
is kept private to that file.

Dean Rasheed, reviewed by Jian He, David Zhang, Aleksander Alekseev,
and Tomas Vondra.

Discussion: 
https://postgr.es/m/caezatcv89vxuq93xqdmc0t-0y2zeenqtdsjbmv7dyfbpykb...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/e6341323a8da64b18e9af3e75a4578230702d61c

Modified Files
--
doc/src/sgml/func.sgml|  43 +++-
src/backend/utils/adt/Makefile|   1 +
src/backend/utils/adt/float.c |  95 
src/backend/utils/adt/meson.build |   1 +
src/backend/utils/adt/numeric.c   | 219 ++
src/backend/utils/adt/pseudorandomfuncs.c | 185 +++
src/common/pg_prng.c  |  36 +++
src/include/catalog/catversion.h  |   2 +-
src/include/catalog/pg_proc.dat   |  12 +
src/include/common/pg_prng.h  |   1 +
src/include/utils/numeric.h   |   4 +
src/test/regress/expected/random.out  | 360 ++
src/test/regress/sql/random.sql   | 164 ++
13 files changed, 1022 insertions(+), 101 deletions(-)



pgsql: Fix some typos and grammar issues from commit 87985cc92522

2024-03-27 Thread Alexander Korotkov
Fix some typos and grammar issues from commit 87985cc92522

Reported-by: Alexander Lakhin

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/818861eb578663a0d4d8d7dc4e18c96a148b3c75

Modified Files
--
src/backend/access/heap/heapam.c | 2 +-
src/backend/commands/trigger.c   | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)



pgsql: Fix random failure in 004_subscription.

2024-03-27 Thread Amit Kapila
Fix random failure in 004_subscription.

After the upgrade, the failed test was ensuring that the changes made on
the publisher should be replicated to the subscriber. We missed waiting
for one of the subscriptions to catch up.

Per buildfarm

Author: Vignesh C
Reviewed-by: Kuroda Hayato
Discussion: 
https://postgr.es/m/CALDaNm0z=fLtio1h50K8WossUGXU+gy0H9y9=ryh1ddziq2...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/677a45c4ae165f86b4a7b8562795f19f1ed480cf

Modified Files
--
src/bin/pg_upgrade/t/004_subscription.pl | 3 +++
1 file changed, 3 insertions(+)