Skip to content

Commit f20e3e6

Browse files
authored
Merge branch 'postgres:master' into master
2 parents fc605a4 + 9016fa7 commit f20e3e6

File tree

12 files changed

+64
-43
lines changed

12 files changed

+64
-43
lines changed

doc/src/sgml/xfunc.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,11 +3668,14 @@ LWLockRelease(AddinShmemInitLock);
36683668
</programlisting>
36693669
<literal>shmem_startup_hook</literal> provides a convenient place for the
36703670
initialization code, but it is not strictly required that all such code
3671-
be placed in this hook. Each backend will execute the registered
3672-
<literal>shmem_startup_hook</literal> shortly after it attaches to shared
3673-
memory. Note that add-ins should still acquire
3671+
be placed in this hook. On Windows (and anywhere else where
3672+
<literal>EXEC_BACKEND</literal> is defined), each backend executes the
3673+
registered <literal>shmem_startup_hook</literal> shortly after it
3674+
attaches to shared memory, so add-ins should still acquire
36743675
<function>AddinShmemInitLock</function> within this hook, as shown in the
3675-
example above.
3676+
example above. On other platforms, only the postmaster process executes
3677+
the <literal>shmem_startup_hook</literal>, and each backend automatically
3678+
inherits the pointers to shared memory.
36763679
</para>
36773680

36783681
<para>

src/backend/access/transam/xlog.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8385,6 +8385,14 @@ xlog_redo(XLogReaderState *record)
83858385
checkPoint.ThisTimeLineID, replayTLI)));
83868386

83878387
RecoveryRestartPoint(&checkPoint, record);
8388+
8389+
/*
8390+
* After replaying a checkpoint record, free all smgr objects.
8391+
* Otherwise we would never do so for dropped relations, as the
8392+
* startup does not process shared invalidation messages or call
8393+
* AtEOXact_SMgr().
8394+
*/
8395+
smgrdestroyall();
83888396
}
83898397
else if (info == XLOG_CHECKPOINT_ONLINE)
83908398
{
@@ -8438,6 +8446,14 @@ xlog_redo(XLogReaderState *record)
84388446
checkPoint.ThisTimeLineID, replayTLI)));
84398447

84408448
RecoveryRestartPoint(&checkPoint, record);
8449+
8450+
/*
8451+
* After replaying a checkpoint record, free all smgr objects.
8452+
* Otherwise we would never do so for dropped relations, as the
8453+
* startup does not process shared invalidation messages or call
8454+
* AtEOXact_SMgr().
8455+
*/
8456+
smgrdestroyall();
84418457
}
84428458
else if (info == XLOG_OVERWRITE_CONTRECORD)
84438459
{

src/backend/executor/nodeAgg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@
267267
#include "utils/acl.h"
268268
#include "utils/builtins.h"
269269
#include "utils/datum.h"
270-
#include "utils/dynahash.h"
271270
#include "utils/expandeddatum.h"
272271
#include "utils/injection_point.h"
273272
#include "utils/logtape.h"
@@ -2115,7 +2114,7 @@ hash_choose_num_partitions(double input_groups, double hashentrysize,
21152114
npartitions = (int) dpartitions;
21162115

21172116
/* ceil(log2(npartitions)) */
2118-
partition_bits = my_log2(npartitions);
2117+
partition_bits = pg_ceil_log2_32(npartitions);
21192118

21202119
/* make sure that we don't exhaust the hash bits */
21212120
if (partition_bits + used_bits >= 32)

src/backend/executor/nodeHash.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "executor/nodeHashjoin.h"
3737
#include "miscadmin.h"
3838
#include "port/pg_bitutils.h"
39-
#include "utils/dynahash.h"
4039
#include "utils/lsyscache.h"
4140
#include "utils/memutils.h"
4241
#include "utils/syscache.h"
@@ -340,7 +339,7 @@ MultiExecParallelHash(HashState *node)
340339
*/
341340
hashtable->curbatch = -1;
342341
hashtable->nbuckets = pstate->nbuckets;
343-
hashtable->log2_nbuckets = my_log2(hashtable->nbuckets);
342+
hashtable->log2_nbuckets = pg_ceil_log2_32(hashtable->nbuckets);
344343
hashtable->totalTuples = pstate->total_tuples;
345344

346345
/*
@@ -480,7 +479,7 @@ ExecHashTableCreate(HashState *state)
480479
&nbuckets, &nbatch, &num_skew_mcvs);
481480

482481
/* nbuckets must be a power of 2 */
483-
log2_nbuckets = my_log2(nbuckets);
482+
log2_nbuckets = pg_ceil_log2_32(nbuckets);
484483
Assert(nbuckets == (1 << log2_nbuckets));
485484

486485
/*
@@ -3499,7 +3498,7 @@ ExecParallelHashTableSetCurrentBatch(HashJoinTable hashtable, int batchno)
34993498
dsa_get_address(hashtable->area,
35003499
hashtable->batches[batchno].shared->buckets);
35013500
hashtable->nbuckets = hashtable->parallel_state->nbuckets;
3502-
hashtable->log2_nbuckets = my_log2(hashtable->nbuckets);
3501+
hashtable->log2_nbuckets = pg_ceil_log2_32(hashtable->nbuckets);
35033502
hashtable->current_chunk = NULL;
35043503
hashtable->current_chunk_shared = InvalidDsaPointer;
35053504
hashtable->batches[batchno].at_least_one_chunk = false;

src/backend/parser/parse_utilcmd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,6 @@ expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
14611461
char *ccname = constr->check[ccnum].ccname;
14621462
char *ccbin = constr->check[ccnum].ccbin;
14631463
bool ccenforced = constr->check[ccnum].ccenforced;
1464-
bool ccvalid = constr->check[ccnum].ccvalid;
14651464
bool ccnoinherit = constr->check[ccnum].ccnoinherit;
14661465
Node *ccbin_node;
14671466
bool found_whole_row;
@@ -1492,7 +1491,7 @@ expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
14921491
n->conname = pstrdup(ccname);
14931492
n->location = -1;
14941493
n->is_enforced = ccenforced;
1495-
n->initially_valid = ccvalid;
1494+
n->initially_valid = ccenforced; /* sic */
14961495
n->is_no_inherit = ccnoinherit;
14971496
n->raw_expr = NULL;
14981497
n->cooked_expr = nodeToString(ccbin_node);

src/backend/replication/logical/worker.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@
276276
#include "storage/procarray.h"
277277
#include "tcop/tcopprot.h"
278278
#include "utils/acl.h"
279-
#include "utils/dynahash.h"
280279
#include "utils/guc.h"
281280
#include "utils/inval.h"
282281
#include "utils/lsyscache.h"
@@ -5115,7 +5114,7 @@ subxact_info_read(Oid subid, TransactionId xid)
51155114
len = sizeof(SubXactInfo) * subxact_data.nsubxacts;
51165115

51175116
/* we keep the maximum as a power of 2 */
5118-
subxact_data.nsubxacts_max = 1 << my_log2(subxact_data.nsubxacts);
5117+
subxact_data.nsubxacts_max = 1 << pg_ceil_log2_32(subxact_data.nsubxacts);
51195118

51205119
/*
51215120
* Allocate subxact information in the logical streaming context. We need

src/backend/utils/adt/meson.build

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Copyright (c) 2022-2025, PostgreSQL Global Development Group
22

3+
# Some code in numeric.c benefits from auto-vectorization
4+
numeric_backend_lib = static_library('numeric_backend_lib',
5+
'numeric.c',
6+
dependencies: backend_build_deps,
7+
kwargs: internal_lib_args,
8+
c_args: vectorize_cflags,
9+
)
10+
11+
backend_link_with += numeric_backend_lib
12+
313
backend_sources += files(
414
'acl.c',
515
'amutils.c',
@@ -61,7 +71,6 @@ backend_sources += files(
6171
'network_gist.c',
6272
'network_selfuncs.c',
6373
'network_spgist.c',
64-
'numeric.c',
6574
'numutils.c',
6675
'oid.c',
6776
'oracle_compat.c',

src/backend/utils/hash/dynahash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
#include "port/pg_bitutils.h"
103103
#include "storage/shmem.h"
104104
#include "storage/spin.h"
105-
#include "utils/dynahash.h"
106105
#include "utils/memutils.h"
107106

108107

@@ -281,6 +280,7 @@ static bool init_htab(HTAB *hashp, int64 nelem);
281280
pg_noreturn static void hash_corrupted(HTAB *hashp);
282281
static uint32 hash_initial_lookup(HTAB *hashp, uint32 hashvalue,
283282
HASHBUCKET **bucketptr);
283+
static int my_log2(int64 num);
284284
static int64 next_pow2_int64(int64 num);
285285
static int next_pow2_int(int64 num);
286286
static void register_seq_scan(HTAB *hashp);
@@ -1813,7 +1813,7 @@ hash_corrupted(HTAB *hashp)
18131813
}
18141814

18151815
/* calculate ceil(log base 2) of num */
1816-
int
1816+
static int
18171817
my_log2(int64 num)
18181818
{
18191819
/*

src/include/utils/dynahash.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/test/modules/test_slru/test_slru.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ test_slru_shmem_startup(void)
219219
*/
220220
const bool long_segment_names = true;
221221
const char slru_dir_name[] = "pg_test_slru";
222-
int test_tranche_id;
223-
int test_buffer_tranche_id;
222+
int test_tranche_id = -1;
223+
int test_buffer_tranche_id = -1;
224224

225225
if (prev_shmem_startup_hook)
226226
prev_shmem_startup_hook();
@@ -231,10 +231,18 @@ test_slru_shmem_startup(void)
231231
*/
232232
(void) MakePGDirectory(slru_dir_name);
233233

234-
/* initialize the SLRU facility */
235-
test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
236-
237-
test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
234+
/*
235+
* Initialize the SLRU facility. In EXEC_BACKEND builds, the
236+
* shmem_startup_hook is called in the postmaster and in each backend, but
237+
* we only need to generate the LWLock tranches once. Note that these
238+
* tranche ID variables are not used by SimpleLruInit() when
239+
* IsUnderPostmaster is true.
240+
*/
241+
if (!IsUnderPostmaster)
242+
{
243+
test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
244+
test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
245+
}
238246

239247
TestSlruCtl->PagePrecedes = test_slru_page_precedes_logically;
240248
SimpleLruInit(TestSlruCtl, "TestSLRU",

0 commit comments

Comments
 (0)