Skip to content

Commit 2dafe4a

Browse files
author
Alexander Korotkov
committed
Replace dynahash optimization by Alexander Alexeev with one committed to 9.6.
1 parent e74705d commit 2dafe4a

File tree

9 files changed

+125
-83
lines changed

9 files changed

+125
-83
lines changed

contrib/pg_pathman/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ create_relations_hashtable()
254254
if (relations != NULL)
255255
hash_destroy(relations);
256256

257-
relations = ShmemInitHash("Partitioning relation info", 1024, &ctl, HASH_ELEM | HASH_BLOBS);
257+
relations = ShmemInitHash("Partitioning relation info", 1024, 1024, &ctl, HASH_ELEM | HASH_BLOBS);
258258
}
259259

260260
/*
@@ -551,7 +551,7 @@ create_range_restrictions_hashtable()
551551
ctl.keysize = sizeof(RelationKey);
552552
ctl.entrysize = sizeof(RangeRelation);
553553
range_restrictions = ShmemInitHash("pg_pathman range restrictions",
554-
1024, &ctl, HASH_ELEM | HASH_BLOBS);
554+
1024, 1024, &ctl, HASH_ELEM | HASH_BLOBS);
555555
}
556556

557557
/*

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pgss_shmem_startup(void)
496496
info.hash = pgss_hash_fn;
497497
info.match = pgss_match_fn;
498498
pgss_hash = ShmemInitHash("pg_stat_statements hash",
499-
pgss_max,
499+
pgss_max, pgss_max,
500500
&info,
501501
HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
502502

src/backend/storage/buffer/buf_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ InitBufTable(int size)
6363
info.num_partitions = NUM_BUFFER_PARTITIONS;
6464

6565
SharedBufHash = ShmemInitHash("Shared Buffer Lookup Table",
66-
size,
66+
size, size,
6767
&info,
6868
HASH_ELEM | HASH_BLOBS | HASH_PARTITION);
6969
}

src/backend/storage/ipc/shmem.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ InitShmemIndex(void)
241241
hash_flags = HASH_ELEM;
242242

243243
ShmemIndex = ShmemInitHash("ShmemIndex",
244-
SHMEM_INDEX_SIZE,
244+
SHMEM_INDEX_SIZE, SHMEM_INDEX_SIZE,
245245
&info, hash_flags);
246246
}
247247

@@ -259,12 +259,17 @@ InitShmemIndex(void)
259259
* exceeded substantially (since it's used to compute directory size and
260260
* the hash table buckets will get overfull).
261261
*
262+
* init_size is the number of hashtable entries to preallocate. For a table
263+
* whose maximum size is certain, this should be equal to max_size; that
264+
* ensures that no run-time out-of-shared-memory failures can occur.
265+
*
262266
* Note: before Postgres 9.0, this function returned NULL for some failure
263267
* cases. Now, it always throws error instead, so callers need not check
264268
* for NULL.
265269
*/
266270
HTAB *
267271
ShmemInitHash(const char *name, /* table string name for shmem index */
272+
long init_size, /* initial table size */
268273
long max_size, /* max size of the table */
269274
HASHCTL *infoP, /* info about key and bucket size */
270275
int hash_flags) /* info about infoP */
@@ -298,7 +303,7 @@ ShmemInitHash(const char *name, /* table string name for shmem index */
298303
/* Pass location of hashtable header to hash_create */
299304
infoP->hctl = (HASHHDR *) location;
300305

301-
return hash_create(name, max_size, infoP, hash_flags);
306+
return hash_create(name, init_size, infoP, hash_flags);
302307
}
303308

304309
/*

src/backend/storage/lmgr/lock.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,16 @@ void
374374
InitLocks(void)
375375
{
376376
HASHCTL info;
377-
long max_table_size;
377+
long init_table_size,
378+
max_table_size;
378379
bool found;
379380

380381
/*
381382
* Compute init/max size to request for lock hashtables. Note these
382383
* calculations must agree with LockShmemSize!
383384
*/
384385
max_table_size = NLOCKENTS();
386+
init_table_size = max_table_size / 2;
385387

386388
/*
387389
* Allocate hash table for LOCK structs. This stores per-locked-object
@@ -393,12 +395,14 @@ InitLocks(void)
393395
info.num_partitions = NUM_LOCK_PARTITIONS;
394396

395397
LockMethodLockHash = ShmemInitHash("LOCK hash",
398+
init_table_size,
396399
max_table_size,
397400
&info,
398401
HASH_ELEM | HASH_BLOBS | HASH_PARTITION);
399402

400403
/* Assume an average of 2 holders per lock */
401404
max_table_size *= 2;
405+
init_table_size *= 2;
402406

403407
/*
404408
* Allocate hash table for PROCLOCK structs. This stores
@@ -410,6 +414,7 @@ InitLocks(void)
410414
info.num_partitions = NUM_LOCK_PARTITIONS;
411415

412416
LockMethodProcLockHash = ShmemInitHash("PROCLOCK hash",
417+
init_table_size,
413418
max_table_size,
414419
&info,
415420
HASH_ELEM | HASH_FUNCTION | HASH_PARTITION);

src/backend/storage/lmgr/predicate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ InitPredicateLocks(void)
11171117
info.num_partitions = NUM_PREDICATELOCK_PARTITIONS;
11181118

11191119
PredicateLockTargetHash = ShmemInitHash("PREDICATELOCKTARGET hash",
1120+
max_table_size,
11201121
max_table_size,
11211122
&info,
11221123
HASH_ELEM | HASH_BLOBS |
@@ -1144,6 +1145,7 @@ InitPredicateLocks(void)
11441145
info.num_partitions = NUM_PREDICATELOCK_PARTITIONS;
11451146

11461147
PredicateLockHash = ShmemInitHash("PREDICATELOCK hash",
1148+
max_table_size,
11471149
max_table_size,
11481150
&info,
11491151
HASH_ELEM | HASH_FUNCTION |
@@ -1224,6 +1226,7 @@ InitPredicateLocks(void)
12241226
info.entrysize = sizeof(SERIALIZABLEXID);
12251227

12261228
SerializableXidHash = ShmemInitHash("SERIALIZABLEXID hash",
1229+
max_table_size,
12271230
max_table_size,
12281231
&info,
12291232
HASH_ELEM | HASH_BLOBS |

0 commit comments

Comments
 (0)