PostgreSQL Source Code  git master
hsearch.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  HASHELEMENT
 
struct  HASHCTL
 
struct  HASH_SEQ_STATUS
 

Macros

#define HASH_PARTITION   0x0001 /* Hashtable is used w/partitioned locking */
 
#define HASH_SEGMENT   0x0002 /* Set segment size */
 
#define HASH_DIRSIZE   0x0004 /* Set directory size (initial and max) */
 
#define HASH_FFACTOR   0x0008 /* Set fill factor */
 
#define HASH_ELEM   0x0010 /* Set keysize and entrysize */
 
#define HASH_BLOBS   0x0020 /* Select support functions for binary keys */
 
#define HASH_FUNCTION   0x0040 /* Set user defined hash function */
 
#define HASH_COMPARE   0x0080 /* Set user defined comparison function */
 
#define HASH_KEYCOPY   0x0100 /* Set user defined key-copying function */
 
#define HASH_ALLOC   0x0200 /* Set memory allocator */
 
#define HASH_CONTEXT   0x0400 /* Set memory allocation context */
 
#define HASH_SHARED_MEM   0x0800 /* Hashtable is in shared memory */
 
#define HASH_ATTACH   0x1000 /* Do not initialize hctl */
 
#define HASH_FIXED_SIZE   0x2000 /* Initial size is a hard limit */
 
#define NO_MAX_DSIZE   (-1)
 

Typedefs

typedef uint32(* HashValueFunc) (const void *key, Size keysize)
 
typedef int(* HashCompareFunc) (const void *key1, const void *key2, Size keysize)
 
typedef void *(* HashCopyFunc) (void *dest, const void *src, Size keysize)
 
typedef void *(* HashAllocFunc) (Size request)
 
typedef struct HASHELEMENT HASHELEMENT
 
typedef struct HASHHDR HASHHDR
 
typedef struct HTAB HTAB
 
typedef struct HASHCTL HASHCTL
 

Enumerations

enum  HASHACTION { HASH_FIND, HASH_ENTER, HASH_REMOVE, HASH_ENTER_NULL }
 

Functions

HTABhash_create (const char *tabname, long nelem, HASHCTL *info, int flags)
 
void hash_destroy (HTAB *hashp)
 
void hash_stats (const char *where, HTAB *hashp)
 
void * hash_search (HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
 
uint32 get_hash_value (HTAB *hashp, const void *keyPtr)
 
void * hash_search_with_hash_value (HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
 
bool hash_update_hash_key (HTAB *hashp, void *existingEntry, const void *newKeyPtr)
 
long hash_get_num_entries (HTAB *hashp)
 
void hash_seq_init (HASH_SEQ_STATUS *status, HTAB *hashp)
 
void * hash_seq_search (HASH_SEQ_STATUS *status)
 
void hash_seq_term (HASH_SEQ_STATUS *status)
 
void hash_freeze (HTAB *hashp)
 
Size hash_estimate_size (long num_entries, Size entrysize)
 
long hash_select_dirsize (long num_entries)
 
Size hash_get_shared_size (HASHCTL *info, int flags)
 
void AtEOXact_HashTables (bool isCommit)
 
void AtEOSubXact_HashTables (bool isCommit, int nestDepth)
 

Macro Definition Documentation

◆ HASH_ALLOC

#define HASH_ALLOC   0x0200 /* Set memory allocator */

Definition at line 92 of file hsearch.h.

Referenced by hash_create(), and ShmemInitHash().

◆ HASH_ATTACH

#define HASH_ATTACH   0x1000 /* Do not initialize hctl */

Definition at line 95 of file hsearch.h.

Referenced by hash_create(), and ShmemInitHash().

◆ HASH_BLOBS

#define HASH_BLOBS   0x0020 /* Select support functions for binary keys */

Definition at line 88 of file hsearch.h.

Referenced by _hash_finish_split(), _PG_init(), AddPendingSync(), begin_heap_rewrite(), BuildEventTriggerCache(), CompactCheckpointerRequestQueue(), compute_array_stats(), create_seq_hashtable(), CreateLocalPredicateLockHash(), CreatePartitionDirectory(), do_autovacuum(), ExecHashSubPlanResultRelsByOid(), find_all_inheritors(), find_oper_cache_entry(), get_tabstat_entry(), GetComboCommandId(), GetConnection(), gistInitBuildBuffers(), gistInitParentMap(), hash_create(), init_enum_blacklist(), init_procedure_caches(), init_rel_sync_cache(), init_ts_config_cache(), InitBufferPoolAccess(), InitBufTable(), InitializeAttoptCache(), InitializeRelfilenodeMap(), InitializeShippableCache(), InitializeTableSpaceCache(), InitLocalBuffers(), InitLocks(), InitPredicateLocks(), InitRecoveryTransactionEnvironment(), InitSync(), log_invalid_page(), logical_begin_heap_rewrite(), logicalrep_partmap_init(), logicalrep_relmap_init(), lookup_collation_cache(), lookup_proof_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupOpclassInfo(), pgss_shmem_startup(), pgstat_collect_oids(), pgstat_init_function_usage(), pgstat_read_statsfiles(), plpgsql_estate_setup(), plpgsql_HashTableInit(), PLy_add_exceptions(), process_syncing_tables_for_apply(), rebuild_database_list(), record_C_func(), RelationCacheInitialize(), ReorderBufferAllocate(), ReorderBufferBuildTupleCidHash(), ReorderBufferToastInitHash(), reset_dbentry_counters(), ri_InitHashTables(), SerializePendingSyncs(), smgropen(), and transformGraph().

◆ HASH_COMPARE

#define HASH_COMPARE   0x0080 /* Set user defined comparison function */

◆ HASH_CONTEXT

◆ HASH_DIRSIZE

#define HASH_DIRSIZE   0x0004 /* Set directory size (initial and max) */

Definition at line 85 of file hsearch.h.

Referenced by hash_create(), hash_get_shared_size(), and ShmemInitHash().

◆ HASH_ELEM

#define HASH_ELEM   0x0010 /* Set keysize and entrysize */

Definition at line 87 of file hsearch.h.

Referenced by _hash_finish_split(), _PG_init(), AddEventToPendingNotifies(), AddPendingSync(), assign_record_type_typmod(), begin_heap_rewrite(), build_join_rel_hash(), BuildEventTriggerCache(), CompactCheckpointerRequestQueue(), compute_array_stats(), compute_tsvector_stats(), create_seq_hashtable(), createConnHash(), CreateLocalPredicateLockHash(), CreatePartitionDirectory(), do_autovacuum(), EnablePortalManager(), ExecHashSubPlanResultRelsByOid(), find_all_inheritors(), find_oper_cache_entry(), find_rendezvous_variable(), get_json_object_as_hash(), get_tabstat_entry(), GetComboCommandId(), GetConnection(), gistInitBuildBuffers(), gistInitParentMap(), hash_create(), init_enum_blacklist(), init_procedure_caches(), init_rel_sync_cache(), init_timezone_hashtable(), init_ts_config_cache(), InitBufferPoolAccess(), InitBufTable(), InitializeAttoptCache(), InitializeRelfilenodeMap(), InitializeShippableCache(), InitializeTableSpaceCache(), InitLocalBuffers(), InitLocks(), InitPredicateLocks(), InitQueryHashTable(), InitRecoveryTransactionEnvironment(), InitShmemIndex(), InitSync(), load_categories_hash(), log_invalid_page(), logical_begin_heap_rewrite(), logicalrep_partmap_init(), logicalrep_relmap_init(), lookup_collation_cache(), lookup_proof_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupOpclassInfo(), pgss_shmem_startup(), pgstat_collect_oids(), pgstat_init_function_usage(), pgstat_read_statsfiles(), plpgsql_estate_setup(), plpgsql_HashTableInit(), PLy_add_exceptions(), populate_recordset_object_start(), process_syncing_tables_for_apply(), rebuild_database_list(), record_C_func(), RegisterExtensibleNodeEntry(), RelationCacheInitialize(), ReorderBufferAllocate(), ReorderBufferBuildTupleCidHash(), ReorderBufferToastInitHash(), reset_dbentry_counters(), ResetUnloggedRelationsInDbspaceDir(), ri_InitHashTables(), select_perl_context(), SerializePendingSyncs(), set_rtable_names(), smgropen(), and transformGraph().

◆ HASH_FFACTOR

#define HASH_FFACTOR   0x0008 /* Set fill factor */

Definition at line 86 of file hsearch.h.

Referenced by hash_create().

◆ HASH_FIXED_SIZE

#define HASH_FIXED_SIZE   0x2000 /* Initial size is a hard limit */

Definition at line 96 of file hsearch.h.

Referenced by hash_create(), and InitPredicateLocks().

◆ HASH_FUNCTION

#define HASH_FUNCTION   0x0040 /* Set user defined hash function */

◆ HASH_KEYCOPY

#define HASH_KEYCOPY   0x0100 /* Set user defined key-copying function */

Definition at line 91 of file hsearch.h.

Referenced by hash_create().

◆ HASH_PARTITION

#define HASH_PARTITION   0x0001 /* Hashtable is used w/partitioned locking */

Definition at line 83 of file hsearch.h.

Referenced by hash_create(), InitBufTable(), InitLocks(), and InitPredicateLocks().

◆ HASH_SEGMENT

#define HASH_SEGMENT   0x0002 /* Set segment size */

Definition at line 84 of file hsearch.h.

Referenced by hash_create().

◆ HASH_SHARED_MEM

#define HASH_SHARED_MEM   0x0800 /* Hashtable is in shared memory */

Definition at line 94 of file hsearch.h.

Referenced by hash_create(), and ShmemInitHash().

◆ NO_MAX_DSIZE

#define NO_MAX_DSIZE   (-1)

Definition at line 100 of file hsearch.h.

Referenced by dir_realloc(), and hdefault().

Typedef Documentation

◆ HashAllocFunc

typedef void*(* HashAllocFunc) (Size request)

Definition at line 44 of file hsearch.h.

◆ HashCompareFunc

typedef int(* HashCompareFunc) (const void *key1, const void *key2, Size keysize)

Definition at line 29 of file hsearch.h.

◆ HashCopyFunc

typedef void*(* HashCopyFunc) (void *dest, const void *src, Size keysize)

Definition at line 37 of file hsearch.h.

◆ HASHCTL

typedef struct HASHCTL HASHCTL

◆ HASHELEMENT

typedef struct HASHELEMENT HASHELEMENT

◆ HASHHDR

typedef struct HASHHDR HASHHDR

Definition at line 58 of file hsearch.h.

◆ HashValueFunc

typedef uint32(* HashValueFunc) (const void *key, Size keysize)

Definition at line 21 of file hsearch.h.

◆ HTAB

typedef struct HTAB HTAB

Definition at line 61 of file hsearch.h.

Enumeration Type Documentation

◆ HASHACTION

enum HASHACTION
Enumerator
HASH_FIND 
HASH_ENTER 
HASH_REMOVE 
HASH_ENTER_NULL 

Definition at line 103 of file hsearch.h.

104 {
105  HASH_FIND,
106  HASH_ENTER,
107  HASH_REMOVE,
109 } HASHACTION;
HASHACTION
Definition: hsearch.h:103

Function Documentation

◆ AtEOSubXact_HashTables()

void AtEOSubXact_HashTables ( bool  isCommit,
int  nestDepth 
)

Definition at line 1883 of file dynahash.c.

References elog, i, num_seq_scans, seq_scan_level, and WARNING.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

1884 {
1885  int i;
1886 
1887  /*
1888  * Search backward to make cleanup easy. Note we must check all entries,
1889  * not only those at the end of the array, because deletion technique
1890  * doesn't keep them in order.
1891  */
1892  for (i = num_seq_scans - 1; i >= 0; i--)
1893  {
1894  if (seq_scan_level[i] >= nestDepth)
1895  {
1896  if (isCommit)
1897  elog(WARNING, "leaked hash_seq_search scan for hash table %p",
1898  seq_scan_tables[i]);
1901  num_seq_scans--;
1902  }
1903  }
1904 }
static int seq_scan_level[MAX_SEQ_SCANS]
Definition: dynahash.c:1804
#define WARNING
Definition: elog.h:40
static int num_seq_scans
Definition: dynahash.c:1805
static HTAB * seq_scan_tables[MAX_SEQ_SCANS]
Definition: dynahash.c:1803
#define elog(elevel,...)
Definition: elog.h:214
int i

◆ AtEOXact_HashTables()

void AtEOXact_HashTables ( bool  isCommit)

Definition at line 1857 of file dynahash.c.

References elog, i, num_seq_scans, and WARNING.

Referenced by AbortTransaction(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), CommitTransaction(), PrepareTransaction(), and WalWriterMain().

1858 {
1859  /*
1860  * During abort cleanup, open scans are expected; just silently clean 'em
1861  * out. An open scan at commit means someone forgot a hash_seq_term()
1862  * call, so complain.
1863  *
1864  * Note: it's tempting to try to print the tabname here, but refrain for
1865  * fear of touching deallocated memory. This isn't a user-facing message
1866  * anyway, so it needn't be pretty.
1867  */
1868  if (isCommit)
1869  {
1870  int i;
1871 
1872  for (i = 0; i < num_seq_scans; i++)
1873  {
1874  elog(WARNING, "leaked hash_seq_search scan for hash table %p",
1875  seq_scan_tables[i]);
1876  }
1877  }
1878  num_seq_scans = 0;
1879 }
#define WARNING
Definition: elog.h:40
static int num_seq_scans
Definition: dynahash.c:1805
static HTAB * seq_scan_tables[MAX_SEQ_SCANS]
Definition: dynahash.c:1803
#define elog(elevel,...)
Definition: elog.h:214
int i

◆ get_hash_value()

uint32 get_hash_value ( HTAB hashp,
const void *  keyPtr 
)

Definition at line 881 of file dynahash.c.

References HTAB::hash, and HTAB::keysize.

Referenced by BufTableHashCode(), and LockTagHashCode().

882 {
883  return hashp->hash(keyPtr, hashp->keysize);
884 }
Size keysize
Definition: dynahash.c:237
HashValueFunc hash
Definition: dynahash.c:224

◆ hash_create()

HTAB* hash_create ( const char *  tabname,
long  nelem,
HASHCTL info,
int  flags 
)

Definition at line 328 of file dynahash.c.

References HASHCTL::alloc, HTAB::alloc, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, CurrentDynaHashCxt, HTAB::dir, HASHCTL::dsize, HASHHDR::dsize, DynaHashAlloc(), element_alloc(), elog, HASHCTL::entrysize, HASHHDR::entrysize, ereport, errcode(), errmsg(), ERROR, HASHCTL::ffactor, HASHHDR::ffactor, HTAB::frozen, HASHCTL::hash, HTAB::hash, HASH_ALLOC, HASH_ATTACH, HASH_BLOBS, HASH_COMPARE, HASH_CONTEXT, HASH_DIRSIZE, HASH_ELEM, HASH_FFACTOR, HASH_FIXED_SIZE, HASH_FUNCTION, HASH_KEYCOPY, HASH_PARTITION, HASH_SEGMENT, HASH_SHARED_MEM, HASHCTL::hctl, HTAB::hctl, HASHCTL::hcxt, HTAB::hcxt, hdefault(), i, init_htab(), IS_PARTITIONED, HTAB::isfixed, HTAB::isshared, HASHCTL::keycopy, HTAB::keycopy, HASHCTL::keysize, HASHHDR::keysize, HTAB::keysize, HASHCTL::match, HTAB::match, HASHCTL::max_dsize, HASHHDR::max_dsize, MemoryContextSetIdentifier(), MemSet, my_log2(), HASHHDR::nelem_alloc, next_pow2_int(), NUM_FREELISTS, HASHCTL::num_partitions, HASHHDR::num_partitions, HASHHDR::sshift, HTAB::sshift, HASHCTL::ssize, HASHHDR::ssize, HTAB::ssize, string_compare(), string_hash(), strlcpy(), HTAB::tabname, tag_hash(), TopMemoryContext, and uint32_hash().

Referenced by _hash_finish_split(), _PG_init(), AddEventToPendingNotifies(), AddPendingSync(), assign_record_type_typmod(), begin_heap_rewrite(), build_join_rel_hash(), BuildEventTriggerCache(), CompactCheckpointerRequestQueue(), compute_array_stats(), compute_tsvector_stats(), create_seq_hashtable(), createConnHash(), CreateLocalPredicateLockHash(), CreatePartitionDirectory(), do_autovacuum(), EnablePortalManager(), ExecHashSubPlanResultRelsByOid(), find_all_inheritors(), find_oper_cache_entry(), find_rendezvous_variable(), get_json_object_as_hash(), get_tabstat_entry(), GetComboCommandId(), GetConnection(), gistInitBuildBuffers(), gistInitParentMap(), init_enum_blacklist(), init_procedure_caches(), init_rel_sync_cache(), init_timezone_hashtable(), init_ts_config_cache(), InitBufferPoolAccess(), InitializeAttoptCache(), InitializeRelfilenodeMap(), InitializeShippableCache(), InitializeTableSpaceCache(), InitLocalBuffers(), InitLocks(), InitQueryHashTable(), InitRecoveryTransactionEnvironment(), InitSync(), load_categories_hash(), log_invalid_page(), logical_begin_heap_rewrite(), logicalrep_partmap_init(), logicalrep_relmap_init(), lookup_collation_cache(), lookup_proof_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupOpclassInfo(), pgstat_collect_oids(), pgstat_init_function_usage(), pgstat_read_statsfiles(), plpgsql_estate_setup(), plpgsql_HashTableInit(), PLy_add_exceptions(), populate_recordset_object_start(), process_syncing_tables_for_apply(), rebuild_database_list(), record_C_func(), RegisterExtensibleNodeEntry(), RelationCacheInitialize(), ReorderBufferAllocate(), ReorderBufferBuildTupleCidHash(), ReorderBufferToastInitHash(), reset_dbentry_counters(), ResetUnloggedRelationsInDbspaceDir(), ri_InitHashTables(), select_perl_context(), SerializePendingSyncs(), set_rtable_names(), ShmemInitHash(), smgropen(), and transformGraph().

329 {
330  HTAB *hashp;
331  HASHHDR *hctl;
332 
333  /*
334  * For shared hash tables, we have a local hash header (HTAB struct) that
335  * we allocate in TopMemoryContext; all else is in shared memory.
336  *
337  * For non-shared hash tables, everything including the hash header is in
338  * a memory context created specially for the hash table --- this makes
339  * hash_destroy very simple. The memory context is made a child of either
340  * a context specified by the caller, or TopMemoryContext if nothing is
341  * specified.
342  */
343  if (flags & HASH_SHARED_MEM)
344  {
345  /* Set up to allocate the hash header */
347  }
348  else
349  {
350  /* Create the hash table's private memory context */
351  if (flags & HASH_CONTEXT)
352  CurrentDynaHashCxt = info->hcxt;
353  else
356  "dynahash",
358  }
359 
360  /* Initialize the hash header, plus a copy of the table name */
361  hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) + 1);
362  MemSet(hashp, 0, sizeof(HTAB));
363 
364  hashp->tabname = (char *) (hashp + 1);
365  strcpy(hashp->tabname, tabname);
366 
367  /* If we have a private context, label it with hashtable's name */
368  if (!(flags & HASH_SHARED_MEM))
370 
371  /*
372  * Select the appropriate hash function (see comments at head of file).
373  */
374  if (flags & HASH_FUNCTION)
375  hashp->hash = info->hash;
376  else if (flags & HASH_BLOBS)
377  {
378  /* We can optimize hashing for common key sizes */
380  if (info->keysize == sizeof(uint32))
381  hashp->hash = uint32_hash;
382  else
383  hashp->hash = tag_hash;
384  }
385  else
386  hashp->hash = string_hash; /* default hash function */
387 
388  /*
389  * If you don't specify a match function, it defaults to string_compare if
390  * you used string_hash (either explicitly or by default) and to memcmp
391  * otherwise.
392  *
393  * Note: explicitly specifying string_hash is deprecated, because this
394  * might not work for callers in loadable modules on some platforms due to
395  * referencing a trampoline instead of the string_hash function proper.
396  * Just let it default, eh?
397  */
398  if (flags & HASH_COMPARE)
399  hashp->match = info->match;
400  else if (hashp->hash == string_hash)
402  else
403  hashp->match = memcmp;
404 
405  /*
406  * Similarly, the key-copying function defaults to strlcpy or memcpy.
407  */
408  if (flags & HASH_KEYCOPY)
409  hashp->keycopy = info->keycopy;
410  else if (hashp->hash == string_hash)
411  {
412  /*
413  * The signature of keycopy is meant for memcpy(), which returns
414  * void*, but strlcpy() returns size_t. Since we never use the return
415  * value of keycopy, and size_t is pretty much always the same size as
416  * void *, this should be safe. The extra cast in the middle is to
417  * avoid warnings from -Wcast-function-type.
418  */
420  }
421  else
422  hashp->keycopy = memcpy;
423 
424  /* And select the entry allocation function, too. */
425  if (flags & HASH_ALLOC)
426  hashp->alloc = info->alloc;
427  else
428  hashp->alloc = DynaHashAlloc;
429 
430  if (flags & HASH_SHARED_MEM)
431  {
432  /*
433  * ctl structure and directory are preallocated for shared memory
434  * tables. Note that HASH_DIRSIZE and HASH_ALLOC had better be set as
435  * well.
436  */
437  hashp->hctl = info->hctl;
438  hashp->dir = (HASHSEGMENT *) (((char *) info->hctl) + sizeof(HASHHDR));
439  hashp->hcxt = NULL;
440  hashp->isshared = true;
441 
442  /* hash table already exists, we're just attaching to it */
443  if (flags & HASH_ATTACH)
444  {
445  /* make local copies of some heavily-used values */
446  hctl = hashp->hctl;
447  hashp->keysize = hctl->keysize;
448  hashp->ssize = hctl->ssize;
449  hashp->sshift = hctl->sshift;
450 
451  return hashp;
452  }
453  }
454  else
455  {
456  /* setup hash table defaults */
457  hashp->hctl = NULL;
458  hashp->dir = NULL;
459  hashp->hcxt = CurrentDynaHashCxt;
460  hashp->isshared = false;
461  }
462 
463  if (!hashp->hctl)
464  {
465  hashp->hctl = (HASHHDR *) hashp->alloc(sizeof(HASHHDR));
466  if (!hashp->hctl)
467  ereport(ERROR,
468  (errcode(ERRCODE_OUT_OF_MEMORY),
469  errmsg("out of memory")));
470  }
471 
472  hashp->frozen = false;
473 
474  hdefault(hashp);
475 
476  hctl = hashp->hctl;
477 
478  if (flags & HASH_PARTITION)
479  {
480  /* Doesn't make sense to partition a local hash table */
481  Assert(flags & HASH_SHARED_MEM);
482 
483  /*
484  * The number of partitions had better be a power of 2. Also, it must
485  * be less than INT_MAX (see init_htab()), so call the int version of
486  * next_pow2.
487  */
489 
490  hctl->num_partitions = info->num_partitions;
491  }
492 
493  if (flags & HASH_SEGMENT)
494  {
495  hctl->ssize = info->ssize;
496  hctl->sshift = my_log2(info->ssize);
497  /* ssize had better be a power of 2 */
498  Assert(hctl->ssize == (1L << hctl->sshift));
499  }
500  if (flags & HASH_FFACTOR)
501  hctl->ffactor = info->ffactor;
502 
503  /*
504  * SHM hash tables have fixed directory size passed by the caller.
505  */
506  if (flags & HASH_DIRSIZE)
507  {
508  hctl->max_dsize = info->max_dsize;
509  hctl->dsize = info->dsize;
510  }
511 
512  /*
513  * hash table now allocates space for key and data but you have to say how
514  * much space to allocate
515  */
516  if (flags & HASH_ELEM)
517  {
518  Assert(info->entrysize >= info->keysize);
519  hctl->keysize = info->keysize;
520  hctl->entrysize = info->entrysize;
521  }
522 
523  /* make local copies of heavily-used constant fields */
524  hashp->keysize = hctl->keysize;
525  hashp->ssize = hctl->ssize;
526  hashp->sshift = hctl->sshift;
527 
528  /* Build the hash directory structure */
529  if (!init_htab(hashp, nelem))
530  elog(ERROR, "failed to initialize hash table \"%s\"", hashp->tabname);
531 
532  /*
533  * For a shared hash table, preallocate the requested number of elements.
534  * This reduces problems with run-time out-of-shared-memory conditions.
535  *
536  * For a non-shared hash table, preallocate the requested number of
537  * elements if it's less than our chosen nelem_alloc. This avoids wasting
538  * space if the caller correctly estimates a small table size.
539  */
540  if ((flags & HASH_SHARED_MEM) ||
541  nelem < hctl->nelem_alloc)
542  {
543  int i,
544  freelist_partitions,
545  nelem_alloc,
546  nelem_alloc_first;
547 
548  /*
549  * If hash table is partitioned, give each freelist an equal share of
550  * the initial allocation. Otherwise only freeList[0] is used.
551  */
552  if (IS_PARTITIONED(hashp->hctl))
553  freelist_partitions = NUM_FREELISTS;
554  else
555  freelist_partitions = 1;
556 
557  nelem_alloc = nelem / freelist_partitions;
558  if (nelem_alloc <= 0)
559  nelem_alloc = 1;
560 
561  /*
562  * Make sure we'll allocate all the requested elements; freeList[0]
563  * gets the excess if the request isn't divisible by NUM_FREELISTS.
564  */
565  if (nelem_alloc * freelist_partitions < nelem)
566  nelem_alloc_first =
567  nelem - nelem_alloc * (freelist_partitions - 1);
568  else
569  nelem_alloc_first = nelem_alloc;
570 
571  for (i = 0; i < freelist_partitions; i++)
572  {
573  int temp = (i == 0) ? nelem_alloc_first : nelem_alloc;
574 
575  if (!element_alloc(hashp, temp, i))
576  ereport(ERROR,
577  (errcode(ERRCODE_OUT_OF_MEMORY),
578  errmsg("out of memory")));
579  }
580  }
581 
582  if (flags & HASH_FIXED_SIZE)
583  hashp->isfixed = true;
584  return hashp;
585 }
int(* HashCompareFunc)(const void *key1, const void *key2, Size keysize)
Definition: hsearch.h:29
Size keysize
Definition: dynahash.c:191
Size keysize
Definition: dynahash.c:237
long dsize
Definition: dynahash.c:184
#define AllocSetContextCreate
Definition: memutils.h:170
#define HASH_CONTEXT
Definition: hsearch.h:93
#define HASH_ELEM
Definition: hsearch.h:87
MemoryContext hcxt
Definition: hsearch.h:78
long ssize
Definition: hsearch.h:68
HashCopyFunc keycopy
Definition: hsearch.h:76
Size entrysize
Definition: dynahash.c:192
#define IS_PARTITIONED(hctl)
Definition: dynahash.c:211
uint32 string_hash(const void *key, Size keysize)
Definition: hashfn.c:660
long num_partitions
Definition: dynahash.c:193
Size entrysize
Definition: hsearch.h:73
#define NUM_FREELISTS
Definition: dynahash.c:128
int errcode(int sqlerrcode)
Definition: elog.c:610
HashAllocFunc alloc
Definition: dynahash.c:227
#define MemSet(start, val, len)
Definition: c.h:949
#define HASH_SHARED_MEM
Definition: hsearch.h:94
static int string_compare(const char *key1, const char *key2, Size keysize)
Definition: dynahash.c:305
long dsize
Definition: hsearch.h:69
uint32 uint32_hash(const void *key, Size keysize)
Definition: hashfn.c:688
#define HASH_PARTITION
Definition: hsearch.h:83
#define HASH_ATTACH
Definition: hsearch.h:95
long ffactor
Definition: dynahash.c:194
HashValueFunc hash
Definition: dynahash.c:224
Definition: dynahash.c:220
long max_dsize
Definition: hsearch.h:70
long ssize
Definition: dynahash.c:238
#define ERROR
Definition: elog.h:43
long num_partitions
Definition: hsearch.h:67
int sshift
Definition: dynahash.c:239
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
HashAllocFunc alloc
Definition: hsearch.h:77
#define HASH_KEYCOPY
Definition: hsearch.h:91
long max_dsize
Definition: dynahash.c:195
static void hdefault(HTAB *hashp)
Definition: dynahash.c:591
HASHHDR * hctl
Definition: dynahash.c:222
unsigned int uint32
Definition: c.h:374
static bool init_htab(HTAB *hashp, long nelem)
Definition: dynahash.c:657
MemoryContext TopMemoryContext
Definition: mcxt.c:44
int my_log2(long num)
Definition: dynahash.c:1739
HashCompareFunc match
Definition: dynahash.c:225
static int next_pow2_int(long num)
Definition: dynahash.c:1765
bool isshared
Definition: dynahash.c:230
#define HASH_BLOBS
Definition: hsearch.h:88
bool frozen
Definition: dynahash.c:234
uint32 tag_hash(const void *key, Size keysize)
Definition: hashfn.c:677
long ssize
Definition: dynahash.c:196
Size keysize
Definition: hsearch.h:72
void *(* HashCopyFunc)(void *dest, const void *src, Size keysize)
Definition: hsearch.h:37
HashCompareFunc match
Definition: hsearch.h:75
MemoryContext hcxt
Definition: dynahash.c:228
#define ereport(elevel,...)
Definition: elog.h:144
HashCopyFunc keycopy
Definition: dynahash.c:226
#define HASH_SEGMENT
Definition: hsearch.h:84
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define Assert(condition)
Definition: c.h:745
#define HASH_COMPARE
Definition: hsearch.h:90
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
Definition: mcxt.c:329
HASHHDR * hctl
Definition: hsearch.h:79
long ffactor
Definition: hsearch.h:71
char * tabname
Definition: dynahash.c:229
#define HASH_FIXED_SIZE
Definition: hsearch.h:96
bool isfixed
Definition: dynahash.c:231
#define HASH_FFACTOR
Definition: hsearch.h:86
static void * DynaHashAlloc(Size size)
Definition: dynahash.c:290
#define HASH_DIRSIZE
Definition: hsearch.h:85
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
static MemoryContext CurrentDynaHashCxt
Definition: dynahash.c:287
int i
#define HASH_ALLOC
Definition: hsearch.h:92
void(* pg_funcptr_t)(void)
Definition: c.h:273
HASHSEGMENT * dir
Definition: dynahash.c:223
static bool element_alloc(HTAB *hashp, int nelem, int freelist_idx)
Definition: dynahash.c:1678
int sshift
Definition: dynahash.c:197
HashValueFunc hash
Definition: hsearch.h:74
#define HASH_FUNCTION
Definition: hsearch.h:89

◆ hash_destroy()

void hash_destroy ( HTAB hashp)

Definition at line 835 of file dynahash.c.

References HTAB::alloc, Assert, DynaHashAlloc(), hash_stats(), HTAB::hcxt, and MemoryContextDelete().

Referenced by _hash_finish_split(), clear_external_function_hash(), CompactCheckpointerRequestQueue(), EnableSyncRequestForwarding(), find_all_inheritors(), InitLocks(), pgoutput_shutdown(), pgstat_recv_dropdb(), pgstat_recv_resetcounter(), pgstat_report_stat(), pgstat_vacuum_stat(), populate_recordset_object_end(), PostPrepare_PredicateLocks(), process_syncing_tables_for_apply(), ReleasePredicateLocksLocal(), ReorderBufferReturnTXN(), ReorderBufferToastReset(), ReorderBufferTruncateTXN(), ResetSequenceCaches(), ResetUnloggedRelationsInDbspaceDir(), SerializePendingSyncs(), set_rtable_names(), ShutdownRecoveryTransactionEnvironment(), and XLogCheckInvalidPages().

836 {
837  if (hashp != NULL)
838  {
839  /* allocation method must be one we know how to free, too */
840  Assert(hashp->alloc == DynaHashAlloc);
841  /* so this hashtable must have its own context */
842  Assert(hashp->hcxt != NULL);
843 
844  hash_stats("destroy", hashp);
845 
846  /*
847  * Free everything by destroying the hash table's memory context.
848  */
849  MemoryContextDelete(hashp->hcxt);
850  }
851 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
void hash_stats(const char *where, HTAB *hashp)
Definition: dynahash.c:854
HashAllocFunc alloc
Definition: dynahash.c:227
MemoryContext hcxt
Definition: dynahash.c:228
#define Assert(condition)
Definition: c.h:745
static void * DynaHashAlloc(Size size)
Definition: dynahash.c:290

◆ hash_estimate_size()

Size hash_estimate_size ( long  num_entries,
Size  entrysize 
)

Definition at line 753 of file dynahash.c.

References add_size(), choose_nelem_alloc(), DEF_DIRSIZE, DEF_FFACTOR, DEF_SEGSIZE, MAXALIGN, mul_size(), and next_pow2_long().

Referenced by BufTableShmemSize(), CreateSharedMemoryAndSemaphores(), LockShmemSize(), pgss_memsize(), and PredicateLockShmemSize().

754 {
755  Size size;
756  long nBuckets,
757  nSegments,
758  nDirEntries,
759  nElementAllocs,
760  elementSize,
761  elementAllocCnt;
762 
763  /* estimate number of buckets wanted */
764  nBuckets = next_pow2_long((num_entries - 1) / DEF_FFACTOR + 1);
765  /* # of segments needed for nBuckets */
766  nSegments = next_pow2_long((nBuckets - 1) / DEF_SEGSIZE + 1);
767  /* directory entries */
768  nDirEntries = DEF_DIRSIZE;
769  while (nDirEntries < nSegments)
770  nDirEntries <<= 1; /* dir_alloc doubles dsize at each call */
771 
772  /* fixed control info */
773  size = MAXALIGN(sizeof(HASHHDR)); /* but not HTAB, per above */
774  /* directory */
775  size = add_size(size, mul_size(nDirEntries, sizeof(HASHSEGMENT)));
776  /* segments */
777  size = add_size(size, mul_size(nSegments,
778  MAXALIGN(DEF_SEGSIZE * sizeof(HASHBUCKET))));
779  /* elements --- allocated in groups of choose_nelem_alloc() entries */
780  elementAllocCnt = choose_nelem_alloc(entrysize);
781  nElementAllocs = (num_entries - 1) / elementAllocCnt + 1;
782  elementSize = MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(entrysize);
783  size = add_size(size,
784  mul_size(nElementAllocs,
785  mul_size(elementAllocCnt, elementSize)));
786 
787  return size;
788 }
static long next_pow2_long(long num)
Definition: dynahash.c:1757
Size mul_size(Size s1, Size s2)
Definition: shmem.c:515
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:473
#define MAXALIGN(LEN)
Definition: c.h:698
static int choose_nelem_alloc(Size entrysize)
Definition: dynahash.c:624
#define DEF_FFACTOR
Definition: dynahash.c:125
#define DEF_SEGSIZE
Definition: dynahash.c:122
#define DEF_DIRSIZE
Definition: dynahash.c:124

◆ hash_freeze()

void hash_freeze ( HTAB hashp)

Definition at line 1506 of file dynahash.c.

References elog, ERROR, HTAB::frozen, has_seq_scans(), HTAB::isshared, and HTAB::tabname.

1507 {
1508  if (hashp->isshared)
1509  elog(ERROR, "cannot freeze shared hashtable \"%s\"", hashp->tabname);
1510  if (!hashp->frozen && has_seq_scans(hashp))
1511  elog(ERROR, "cannot freeze hashtable \"%s\" because it has active scans",
1512  hashp->tabname);
1513  hashp->frozen = true;
1514 }
#define ERROR
Definition: elog.h:43
static bool has_seq_scans(HTAB *hashp)
Definition: dynahash.c:1843
bool isshared
Definition: dynahash.c:230
bool frozen
Definition: dynahash.c:234
char * tabname
Definition: dynahash.c:229
#define elog(elevel,...)
Definition: elog.h:214

◆ hash_get_num_entries()

long hash_get_num_entries ( HTAB hashp)

Definition at line 1356 of file dynahash.c.

References HASHHDR::freeList, HTAB::hctl, i, IS_PARTITIONED, FreeListData::nentries, and NUM_FREELISTS.

Referenced by compute_array_stats(), compute_tsvector_stats(), entry_alloc(), entry_dealloc(), entry_reset(), EstimateEnumBlacklistSpace(), EstimatePendingSyncsSpace(), get_crosstab_tuplestore(), GetLockStatusData(), GetPredicateLockStatusData(), GetRunningTransactionLocks(), hash_stats(), pgss_shmem_shutdown(), pgstat_vacuum_stat(), ResetUnloggedRelationsInDbspaceDir(), SerializePendingSyncs(), transformGraph(), and XLogHaveInvalidPages().

1357 {
1358  int i;
1359  long sum = hashp->hctl->freeList[0].nentries;
1360 
1361  /*
1362  * We currently don't bother with acquiring the mutexes; it's only
1363  * sensible to call this function if you've got lock on all partitions of
1364  * the table.
1365  */
1366  if (IS_PARTITIONED(hashp->hctl))
1367  {
1368  for (i = 1; i < NUM_FREELISTS; i++)
1369  sum += hashp->hctl->freeList[i].nentries;
1370  }
1371 
1372  return sum;
1373 }
#define IS_PARTITIONED(hctl)
Definition: dynahash.c:211
#define NUM_FREELISTS
Definition: dynahash.c:128
HASHHDR * hctl
Definition: dynahash.c:222
long nentries
Definition: dynahash.c:156
FreeListData freeList[NUM_FREELISTS]
Definition: dynahash.c:180
int i

◆ hash_get_shared_size()

Size hash_get_shared_size ( HASHCTL info,
int  flags 
)

Definition at line 824 of file dynahash.c.

References Assert, HASHCTL::dsize, HASH_DIRSIZE, and HASHCTL::max_dsize.

Referenced by ShmemInitHash().

825 {
827  Assert(info->dsize == info->max_dsize);
828  return sizeof(HASHHDR) + info->dsize * sizeof(HASHSEGMENT);
829 }
long dsize
Definition: hsearch.h:69
long max_dsize
Definition: hsearch.h:70
struct HASHHDR HASHHDR
Definition: hsearch.h:58
#define Assert(condition)
Definition: c.h:745
#define HASH_DIRSIZE
Definition: hsearch.h:85

◆ hash_search()

void* hash_search ( HTAB hashp,
const void *  keyPtr,
HASHACTION  action,
bool foundPtr 
)

Definition at line 927 of file dynahash.c.

References generate_unaccent_rules::action, HTAB::hash, hash_search_with_hash_value(), and HTAB::keysize.

Referenced by _hash_finish_split(), _hash_splitbucket(), add_join_rel(), AddEnumLabel(), AddEventToPendingNotifies(), AddPendingSync(), ApplyLogicalMappingFile(), assign_record_type_typmod(), AsyncExistsPendingNotify(), AtEOSubXact_RelationCache(), AtEOXact_RelationCache(), build_join_rel_hash(), BuildEventTriggerCache(), CheckAndPromotePredicateLockRequest(), CheckForSerializableConflictOut(), CompactCheckpointerRequestQueue(), compile_plperl_function(), compile_pltcl_function(), compute_array_stats(), compute_tsvector_stats(), createNewConnection(), deleteConnection(), do_autovacuum(), DropAllPredicateLocksFromTable(), DropAllPreparedStatements(), DropPreparedStatement(), DropRelFileNodeAllLocalBuffers(), DropRelFileNodeLocalBuffers(), entry_alloc(), entry_dealloc(), entry_reset(), EnumBlacklisted(), EventCacheLookup(), ExecCleanupTupleRouting(), ExecFindPartition(), ExecHashSubPlanResultRelsByOid(), FetchPreparedStatement(), find_all_inheritors(), find_funcstat_entry(), find_join_rel(), find_oper_cache_entry(), find_rendezvous_variable(), find_tabstat_entry(), forget_invalid_pages(), forget_invalid_pages_db(), ForgetPrivateRefCountEntry(), get_attribute_options(), get_cast_hashentry(), get_pgstat_tabentry_relid(), get_rel_sync_entry(), get_tablespace(), get_tabstat_entry(), GetComboCommandId(), GetConnection(), getConnectionByName(), GetExtensibleNodeEntry(), GetPrivateRefCountEntry(), getState(), gistGetNodeBuffer(), gistGetParent(), gistMemorizeParent(), gistRelocateBuildBuffersOnSplit(), hash_object_field_end(), init_sequence(), InitPredicateLocks(), InvalidateAttoptCacheCallback(), InvalidateOprCacheCallBack(), InvalidateShippableCacheCallback(), InvalidateTableSpaceCacheCallback(), is_shippable(), JsObjectGetField(), LocalBufferAlloc(), LockAcquireExtended(), LockHasWaiters(), LockHeldByMe(), LockRelease(), log_invalid_page(), logical_rewrite_log_mapping(), logicalrep_partition_open(), logicalrep_rel_open(), logicalrep_relmap_update(), logicalrep_typmap_gettypname(), logicalrep_typmap_update(), lookup_C_func(), lookup_collation_cache(), lookup_proof_cache(), lookup_ts_config_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupOpclassInfo(), make_oper_cache_entry(), PartitionDirectoryLookup(), pg_tzset(), pgss_store(), pgstat_collect_oids(), pgstat_fetch_stat_dbentry(), pgstat_fetch_stat_funcentry(), pgstat_fetch_stat_tabentry(), pgstat_get_db_entry(), pgstat_get_tab_entry(), pgstat_init_function_usage(), pgstat_read_db_statsfile(), pgstat_read_statsfiles(), pgstat_recv_dropdb(), pgstat_recv_funcpurge(), pgstat_recv_funcstat(), pgstat_recv_resetsinglecounter(), pgstat_recv_tabpurge(), pgstat_recv_tabstat(), pgstat_vacuum_stat(), plperl_spi_exec_prepared(), plperl_spi_freeplan(), plperl_spi_prepare(), plperl_spi_query_prepared(), plpgsql_HashTableDelete(), plpgsql_HashTableInsert(), plpgsql_HashTableLookup(), pltcl_fetch_interp(), PLy_generate_spi_exceptions(), PLy_procedure_get(), PLy_spi_subtransaction_abort(), populate_recordset_object_field_end(), predicatelock_twophase_recover(), PredicateLockExists(), PredicateLockTwoPhaseFinish(), PrefetchLocalBuffer(), process_syncing_tables_for_apply(), ProcessSyncRequests(), prune_element_hashtable(), prune_lexemes_hashtable(), rebuild_database_list(), record_C_func(), RegisterExtensibleNodeEntry(), RegisterPredicateLockingXid(), rel_sync_cache_relation_cb(), RelationPreTruncate(), ReleaseOneSerializableXact(), RelfilenodeMapInvalidateCallback(), RelFileNodeSkippingWAL(), RelidByRelfilenode(), RememberSyncRequest(), RemoveLocalLock(), ReorderBufferBuildTupleCidHash(), ReorderBufferCleanupTXN(), ReorderBufferToastAppendChunk(), ReorderBufferToastReplace(), ReorderBufferTXNByXid(), ReservePrivateRefCountEntry(), ResetUnloggedRelationsInDbspaceDir(), ResolveCminCmaxDuringDecoding(), RestoreEnumBlacklist(), rewrite_heap_dead_tuple(), rewrite_heap_tuple(), ri_FetchPreparedPlan(), ri_HashCompareOp(), ri_HashPreparedPlan(), ri_LoadConstraintInfo(), select_perl_context(), SerializePendingSyncs(), set_rtable_names(), ShmemInitStruct(), smgrclose(), smgrclosenode(), smgrDoPendingSyncs(), smgropen(), StandbyAcquireAccessExclusiveLock(), StandbyReleaseAllLocks(), StandbyReleaseLocks(), StandbyReleaseOldLocks(), StorePreparedStatement(), and table_recheck_autovac().

931 {
932  return hash_search_with_hash_value(hashp,
933  keyPtr,
934  hashp->hash(keyPtr, hashp->keysize),
935  action,
936  foundPtr);
937 }
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:940
Size keysize
Definition: dynahash.c:237
HashValueFunc hash
Definition: dynahash.c:224

◆ hash_search_with_hash_value()

void* hash_search_with_hash_value ( HTAB hashp,
const void *  keyPtr,
uint32  hashvalue,
HASHACTION  action,
bool foundPtr 
)

Definition at line 940 of file dynahash.c.

References HTAB::alloc, Assert, calc_bucket(), HTAB::dir, DynaHashAlloc(), ELEMENTKEY, elog, ereport, errcode(), errmsg(), ERROR, expand_table(), HASHHDR::ffactor, FreeListData::freeList, HASHHDR::freeList, FREELIST_IDX, HTAB::frozen, get_hash_entry(), has_seq_scans(), hash_corrupted(), HASH_ENTER, HASH_ENTER_NULL, HASH_FIND, HASH_REMOVE, HASHELEMENT::hashvalue, HTAB::hctl, IS_PARTITIONED, HTAB::isshared, HTAB::keycopy, HASHHDR::keysize, HTAB::keysize, HASHELEMENT::link, HTAB::match, HASHHDR::max_bucket, MOD, FreeListData::mutex, FreeListData::nentries, SpinLockAcquire, SpinLockRelease, HTAB::sshift, HTAB::ssize, and HTAB::tabname.

Referenced by BufTableDelete(), BufTableInsert(), BufTableLookup(), CheckTargetForConflictsIn(), CleanUpLock(), ClearOldPredicateLocks(), CreatePredicateLock(), DecrementParentLocks(), DeleteChildTargetLocks(), DeleteLockTarget(), DropAllPredicateLocksFromTable(), FastPathGetRelationLockEntry(), GetLockConflicts(), hash_search(), lock_twophase_recover(), LockAcquireExtended(), LockRefindAndRelease(), LockRelease(), LockWaiterCount(), PageIsPredicateLocked(), PredicateLockAcquire(), ReleaseOneSerializableXact(), RemoveScratchTarget(), RemoveTargetIfNoLongerUsed(), RestoreScratchTarget(), SetupLockInTable(), and TransferPredicateLocksToNewTarget().

945 {
946  HASHHDR *hctl = hashp->hctl;
947  int freelist_idx = FREELIST_IDX(hctl, hashvalue);
948  Size keysize;
949  uint32 bucket;
950  long segment_num;
951  long segment_ndx;
952  HASHSEGMENT segp;
953  HASHBUCKET currBucket;
954  HASHBUCKET *prevBucketPtr;
955  HashCompareFunc match;
956 
957 #ifdef HASH_STATISTICS
958  hash_accesses++;
959  hctl->accesses++;
960 #endif
961 
962  /*
963  * If inserting, check if it is time to split a bucket.
964  *
965  * NOTE: failure to expand table is not a fatal error, it just means we
966  * have to run at higher fill factor than we wanted. However, if we're
967  * using the palloc allocator then it will throw error anyway on
968  * out-of-memory, so we must do this before modifying the table.
969  */
971  {
972  /*
973  * Can't split if running in partitioned mode, nor if frozen, nor if
974  * table is the subject of any active hash_seq_search scans. Strange
975  * order of these tests is to try to check cheaper conditions first.
976  */
977  if (!IS_PARTITIONED(hctl) && !hashp->frozen &&
978  hctl->freeList[0].nentries / (long) (hctl->max_bucket + 1) >= hctl->ffactor &&
979  !has_seq_scans(hashp))
980  (void) expand_table(hashp);
981  }
982 
983  /*
984  * Do the initial lookup
985  */
986  bucket = calc_bucket(hctl, hashvalue);
987 
988  segment_num = bucket >> hashp->sshift;
989  segment_ndx = MOD(bucket, hashp->ssize);
990 
991  segp = hashp->dir[segment_num];
992 
993  if (segp == NULL)
994  hash_corrupted(hashp);
995 
996  prevBucketPtr = &segp[segment_ndx];
997  currBucket = *prevBucketPtr;
998 
999  /*
1000  * Follow collision chain looking for matching key
1001  */
1002  match = hashp->match; /* save one fetch in inner loop */
1003  keysize = hashp->keysize; /* ditto */
1004 
1005  while (currBucket != NULL)
1006  {
1007  if (currBucket->hashvalue == hashvalue &&
1008  match(ELEMENTKEY(currBucket), keyPtr, keysize) == 0)
1009  break;
1010  prevBucketPtr = &(currBucket->link);
1011  currBucket = *prevBucketPtr;
1012 #ifdef HASH_STATISTICS
1013  hash_collisions++;
1014  hctl->collisions++;
1015 #endif
1016  }
1017 
1018  if (foundPtr)
1019  *foundPtr = (bool) (currBucket != NULL);
1020 
1021  /*
1022  * OK, now what?
1023  */
1024  switch (action)
1025  {
1026  case HASH_FIND:
1027  if (currBucket != NULL)
1028  return (void *) ELEMENTKEY(currBucket);
1029  return NULL;
1030 
1031  case HASH_REMOVE:
1032  if (currBucket != NULL)
1033  {
1034  /* if partitioned, must lock to touch nentries and freeList */
1035  if (IS_PARTITIONED(hctl))
1036  SpinLockAcquire(&(hctl->freeList[freelist_idx].mutex));
1037 
1038  /* delete the record from the appropriate nentries counter. */
1039  Assert(hctl->freeList[freelist_idx].nentries > 0);
1040  hctl->freeList[freelist_idx].nentries--;
1041 
1042  /* remove record from hash bucket's chain. */
1043  *prevBucketPtr = currBucket->link;
1044 
1045  /* add the record to the appropriate freelist. */
1046  currBucket->link = hctl->freeList[freelist_idx].freeList;
1047  hctl->freeList[freelist_idx].freeList = currBucket;
1048 
1049  if (IS_PARTITIONED(hctl))
1050  SpinLockRelease(&hctl->freeList[freelist_idx].mutex);
1051 
1052  /*
1053  * better hope the caller is synchronizing access to this
1054  * element, because someone else is going to reuse it the next
1055  * time something is added to the table
1056  */
1057  return (void *) ELEMENTKEY(currBucket);
1058  }
1059  return NULL;
1060 
1061  case HASH_ENTER_NULL:
1062  /* ENTER_NULL does not work with palloc-based allocator */
1063  Assert(hashp->alloc != DynaHashAlloc);
1064  /* FALL THRU */
1065 
1066  case HASH_ENTER:
1067  /* Return existing element if found, else create one */
1068  if (currBucket != NULL)
1069  return (void *) ELEMENTKEY(currBucket);
1070 
1071  /* disallow inserts if frozen */
1072  if (hashp->frozen)
1073  elog(ERROR, "cannot insert into frozen hashtable \"%s\"",
1074  hashp->tabname);
1075 
1076  currBucket = get_hash_entry(hashp, freelist_idx);
1077  if (currBucket == NULL)
1078  {
1079  /* out of memory */
1080  if (action == HASH_ENTER_NULL)
1081  return NULL;
1082  /* report a generic message */
1083  if (hashp->isshared)
1084  ereport(ERROR,
1085  (errcode(ERRCODE_OUT_OF_MEMORY),
1086  errmsg("out of shared memory")));
1087  else
1088  ereport(ERROR,
1089  (errcode(ERRCODE_OUT_OF_MEMORY),
1090  errmsg("out of memory")));
1091  }
1092 
1093  /* link into hashbucket chain */
1094  *prevBucketPtr = currBucket;
1095  currBucket->link = NULL;
1096 
1097  /* copy key into record */
1098  currBucket->hashvalue = hashvalue;
1099  hashp->keycopy(ELEMENTKEY(currBucket), keyPtr, keysize);
1100 
1101  /*
1102  * Caller is expected to fill the data field on return. DO NOT
1103  * insert any code that could possibly throw error here, as doing
1104  * so would leave the table entry incomplete and hence corrupt the
1105  * caller's data structure.
1106  */
1107 
1108  return (void *) ELEMENTKEY(currBucket);
1109  }
1110 
1111  elog(ERROR, "unrecognized hash action code: %d", (int) action);
1112 
1113  return NULL; /* keep compiler quiet */
1114 }
int(* HashCompareFunc)(const void *key1, const void *key2, Size keysize)
Definition: hsearch.h:29
Size keysize
Definition: dynahash.c:237
uint32 max_bucket
Definition: dynahash.c:186
static uint32 calc_bucket(HASHHDR *hctl, uint32 hash_val)
Definition: dynahash.c:888
#define IS_PARTITIONED(hctl)
Definition: dynahash.c:211
#define ELEMENTKEY(helem)
Definition: dynahash.c:245
int errcode(int sqlerrcode)
Definition: elog.c:610
HashAllocFunc alloc
Definition: dynahash.c:227
slock_t mutex
Definition: dynahash.c:155
static HASHBUCKET get_hash_entry(HTAB *hashp, int freelist_idx)
Definition: dynahash.c:1271
long ffactor
Definition: dynahash.c:194
#define SpinLockAcquire(lock)
Definition: spin.h:62
long ssize
Definition: dynahash.c:238
#define ERROR
Definition: elog.h:43
int sshift
Definition: dynahash.c:239
#define MOD(x, y)
Definition: dynahash.c:256
HASHHDR * hctl
Definition: dynahash.c:222
static void hash_corrupted(HTAB *hashp)
Definition: dynahash.c:1725
static bool has_seq_scans(HTAB *hashp)
Definition: dynahash.c:1843
unsigned int uint32
Definition: c.h:374
long nentries
Definition: dynahash.c:156
HashCompareFunc match
Definition: dynahash.c:225
bool isshared
Definition: dynahash.c:230
#define SpinLockRelease(lock)
Definition: spin.h:64
bool frozen
Definition: dynahash.c:234
FreeListData freeList[NUM_FREELISTS]
Definition: dynahash.c:180
#define ereport(elevel,...)
Definition: elog.h:144
HashCopyFunc keycopy
Definition: dynahash.c:226
#define Assert(condition)
Definition: c.h:745
size_t Size
Definition: c.h:473
static bool expand_table(HTAB *hashp)
Definition: dynahash.c:1523
char * tabname
Definition: dynahash.c:229
static void * DynaHashAlloc(Size size)
Definition: dynahash.c:290
int errmsg(const char *fmt,...)
Definition: elog.c:824
struct HASHELEMENT * link
Definition: hsearch.h:53
#define elog(elevel,...)
Definition: elog.h:214
HASHELEMENT * freeList
Definition: dynahash.c:157
HASHSEGMENT * dir
Definition: dynahash.c:223
#define FREELIST_IDX(hctl, hashcode)
Definition: dynahash.c:213
uint32 hashvalue
Definition: hsearch.h:54
unsigned char bool
Definition: c.h:324

◆ hash_select_dirsize()

long hash_select_dirsize ( long  num_entries)

Definition at line 800 of file dynahash.c.

References DEF_DIRSIZE, DEF_FFACTOR, DEF_SEGSIZE, and next_pow2_long().

Referenced by ShmemInitHash().

801 {
802  long nBuckets,
803  nSegments,
804  nDirEntries;
805 
806  /* estimate number of buckets wanted */
807  nBuckets = next_pow2_long((num_entries - 1) / DEF_FFACTOR + 1);
808  /* # of segments needed for nBuckets */
809  nSegments = next_pow2_long((nBuckets - 1) / DEF_SEGSIZE + 1);
810  /* directory entries */
811  nDirEntries = DEF_DIRSIZE;
812  while (nDirEntries < nSegments)
813  nDirEntries <<= 1; /* dir_alloc doubles dsize at each call */
814 
815  return nDirEntries;
816 }
static long next_pow2_long(long num)
Definition: dynahash.c:1757
#define DEF_FFACTOR
Definition: dynahash.c:125
#define DEF_SEGSIZE
Definition: dynahash.c:122
#define DEF_DIRSIZE
Definition: dynahash.c:124

◆ hash_seq_init()

void hash_seq_init ( HASH_SEQ_STATUS status,
HTAB hashp 
)

Definition at line 1400 of file dynahash.c.

References HASH_SEQ_STATUS::curBucket, HASH_SEQ_STATUS::curEntry, HTAB::frozen, HASH_SEQ_STATUS::hashp, and register_seq_scan().

Referenced by AtAbort_Portals(), AtCleanup_Portals(), AtEOSubXact_RelationCache(), AtEOXact_RelationCache(), AtPrepare_Locks(), AtSubAbort_Portals(), AtSubCleanup_Portals(), AtSubCommit_Portals(), CheckForBufferLeaks(), CheckTableForSerializableConflictIn(), compute_array_stats(), compute_tsvector_stats(), dblink_get_connections(), DestroyPartitionDirectory(), DropAllPredicateLocksFromTable(), DropAllPreparedStatements(), end_heap_rewrite(), entry_dealloc(), entry_reset(), forget_invalid_pages(), forget_invalid_pages_db(), gc_qtexts(), GetLockmodeName(), GetLockStatusData(), GetPredicateLockStatusData(), GetRunningTransactionLocks(), HoldPinnedPortals(), InvalidateAttoptCacheCallback(), InvalidateOprCacheCallBack(), InvalidateOprProofCacheCallBack(), InvalidateShippableCacheCallback(), InvalidateTableSpaceCacheCallback(), InvalidateTSCacheCallBack(), LockReassignCurrentOwner(), LockReleaseAll(), LockReleaseCurrentOwner(), LockReleaseSession(), logical_end_heap_rewrite(), logical_heap_rewrite_flush_mappings(), logicalrep_partmap_invalidate_cb(), logicalrep_relmap_invalidate_cb(), packArcInfoCmp(), packGraph(), pg_cursor(), pg_get_shmem_allocations(), pg_prepared_statement(), pg_stat_statements_internal(), pgfdw_inval_callback(), pgfdw_subxact_callback(), pgfdw_xact_callback(), pgss_shmem_shutdown(), pgstat_send_funcstats(), pgstat_vacuum_stat(), pgstat_write_db_statsfile(), pgstat_write_statsfiles(), plperl_fini(), PortalErrorCleanup(), PortalHashTableDeleteAll(), PostPrepare_Locks(), PreCommit_Portals(), ProcessSyncRequests(), prune_element_hashtable(), prune_lexemes_hashtable(), rebuild_database_list(), rel_sync_cache_publication_cb(), RelationCacheInitializePhase3(), RelationCacheInvalidate(), RelfilenodeMapInvalidateCallback(), RememberSyncRequest(), RememberToFreeTupleDescAtEOX(), ReorderBufferLargestTXN(), ReorderBufferToastReset(), selectColorTrigrams(), SerializeEnumBlacklist(), SerializePendingSyncs(), smgrcloseall(), smgrDoPendingSyncs(), StandbyReleaseAllLocks(), StandbyReleaseOldLocks(), ThereAreNoReadyPortals(), TypeCacheOpcCallback(), TypeCacheRelCallback(), TypeCacheTypCallback(), write_relcache_init_file(), and XLogCheckInvalidPages().

1401 {
1402  status->hashp = hashp;
1403  status->curBucket = 0;
1404  status->curEntry = NULL;
1405  if (!hashp->frozen)
1406  register_seq_scan(hashp);
1407 }
uint32 curBucket
Definition: hsearch.h:115
HASHELEMENT * curEntry
Definition: hsearch.h:116
HTAB * hashp
Definition: hsearch.h:114
bool frozen
Definition: dynahash.c:234
static void register_seq_scan(HTAB *hashp)
Definition: dynahash.c:1810

◆ hash_seq_search()

void* hash_seq_search ( HASH_SEQ_STATUS status)

Definition at line 1410 of file dynahash.c.

References HASH_SEQ_STATUS::curBucket, HASH_SEQ_STATUS::curEntry, HTAB::dir, ELEMENTKEY, hash_seq_term(), HASH_SEQ_STATUS::hashp, HTAB::hctl, HASHELEMENT::link, HASHHDR::max_bucket, MOD, HTAB::sshift, HASHHDR::ssize, and HTAB::ssize.

Referenced by AtAbort_Portals(), AtCleanup_Portals(), AtEOSubXact_RelationCache(), AtEOXact_RelationCache(), AtPrepare_Locks(), AtSubAbort_Portals(), AtSubCleanup_Portals(), AtSubCommit_Portals(), CheckForBufferLeaks(), CheckTableForSerializableConflictIn(), compute_array_stats(), compute_tsvector_stats(), dblink_get_connections(), DestroyPartitionDirectory(), DropAllPredicateLocksFromTable(), DropAllPreparedStatements(), end_heap_rewrite(), entry_dealloc(), entry_reset(), forget_invalid_pages(), forget_invalid_pages_db(), gc_qtexts(), GetLockmodeName(), GetLockStatusData(), GetPredicateLockStatusData(), GetRunningTransactionLocks(), HoldPinnedPortals(), InvalidateAttoptCacheCallback(), InvalidateOprCacheCallBack(), InvalidateOprProofCacheCallBack(), InvalidateShippableCacheCallback(), InvalidateTableSpaceCacheCallback(), InvalidateTSCacheCallBack(), LockReassignCurrentOwner(), LockReleaseAll(), LockReleaseCurrentOwner(), LockReleaseSession(), logical_end_heap_rewrite(), logical_heap_rewrite_flush_mappings(), logicalrep_partmap_invalidate_cb(), logicalrep_relmap_invalidate_cb(), packArcInfoCmp(), packGraph(), pg_cursor(), pg_get_shmem_allocations(), pg_prepared_statement(), pg_stat_statements_internal(), pgfdw_inval_callback(), pgfdw_subxact_callback(), pgfdw_xact_callback(), pgss_shmem_shutdown(), pgstat_send_funcstats(), pgstat_vacuum_stat(), pgstat_write_db_statsfile(), pgstat_write_statsfiles(), plperl_fini(), PortalErrorCleanup(), PortalHashTableDeleteAll(), PostPrepare_Locks(), PreCommit_Portals(), ProcessSyncRequests(), prune_element_hashtable(), prune_lexemes_hashtable(), rebuild_database_list(), rel_sync_cache_publication_cb(), RelationCacheInitializePhase3(), RelationCacheInvalidate(), RelfilenodeMapInvalidateCallback(), RememberSyncRequest(), RememberToFreeTupleDescAtEOX(), ReorderBufferLargestTXN(), ReorderBufferToastReset(), selectColorTrigrams(), SerializeEnumBlacklist(), SerializePendingSyncs(), smgrcloseall(), smgrDoPendingSyncs(), StandbyReleaseAllLocks(), StandbyReleaseOldLocks(), ThereAreNoReadyPortals(), TypeCacheOpcCallback(), TypeCacheRelCallback(), TypeCacheTypCallback(), write_relcache_init_file(), and XLogCheckInvalidPages().

1411 {
1412  HTAB *hashp;
1413  HASHHDR *hctl;
1414  uint32 max_bucket;
1415  long ssize;
1416  long segment_num;
1417  long segment_ndx;
1418  HASHSEGMENT segp;
1419  uint32 curBucket;
1420  HASHELEMENT *curElem;
1421 
1422  if ((curElem = status->curEntry) != NULL)
1423  {
1424  /* Continuing scan of curBucket... */
1425  status->curEntry = curElem->link;
1426  if (status->curEntry == NULL) /* end of this bucket */
1427  ++status->curBucket;
1428  return (void *) ELEMENTKEY(curElem);
1429  }
1430 
1431  /*
1432  * Search for next nonempty bucket starting at curBucket.
1433  */
1434  curBucket = status->curBucket;
1435  hashp = status->hashp;
1436  hctl = hashp->hctl;
1437  ssize = hashp->ssize;
1438  max_bucket = hctl->max_bucket;
1439 
1440  if (curBucket > max_bucket)
1441  {
1442  hash_seq_term(status);
1443  return NULL; /* search is done */
1444  }
1445 
1446  /*
1447  * first find the right segment in the table directory.
1448  */
1449  segment_num = curBucket >> hashp->sshift;
1450  segment_ndx = MOD(curBucket, ssize);
1451 
1452  segp = hashp->dir[segment_num];
1453 
1454  /*
1455  * Pick up the first item in this bucket's chain. If chain is not empty
1456  * we can begin searching it. Otherwise we have to advance to find the
1457  * next nonempty bucket. We try to optimize that case since searching a
1458  * near-empty hashtable has to iterate this loop a lot.
1459  */
1460  while ((curElem = segp[segment_ndx]) == NULL)
1461  {
1462  /* empty bucket, advance to next */
1463  if (++curBucket > max_bucket)
1464  {
1465  status->curBucket = curBucket;
1466  hash_seq_term(status);
1467  return NULL; /* search is done */
1468  }
1469  if (++segment_ndx >= ssize)
1470  {
1471  segment_num++;
1472  segment_ndx = 0;
1473  segp = hashp->dir[segment_num];
1474  }
1475  }
1476 
1477  /* Begin scan of curBucket... */
1478  status->curEntry = curElem->link;
1479  if (status->curEntry == NULL) /* end of this bucket */
1480  ++curBucket;
1481  status->curBucket = curBucket;
1482  return (void *) ELEMENTKEY(curElem);
1483 }
uint32 curBucket
Definition: hsearch.h:115
uint32 max_bucket
Definition: dynahash.c:186
#define ELEMENTKEY(helem)
Definition: dynahash.c:245
HASHELEMENT * curEntry
Definition: hsearch.h:116
Definition: dynahash.c:220
long ssize
Definition: dynahash.c:238
int sshift
Definition: dynahash.c:239
#define MOD(x, y)
Definition: dynahash.c:256
HASHHDR * hctl
Definition: dynahash.c:222
unsigned int uint32
Definition: c.h:374
HTAB * hashp
Definition: hsearch.h:114
struct HASHELEMENT * link
Definition: hsearch.h:53
HASHSEGMENT * dir
Definition: dynahash.c:223
void hash_seq_term(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1486

◆ hash_seq_term()

void hash_seq_term ( HASH_SEQ_STATUS status)

◆ hash_stats()

void hash_stats ( const char *  where,
HTAB hashp 
)

Definition at line 854 of file dynahash.c.

References fprintf, hash_get_num_entries(), HTAB::hctl, HASHHDR::keysize, HASHHDR::max_bucket, and HASHHDR::nsegs.

Referenced by hash_destroy().

855 {
856 #ifdef HASH_STATISTICS
857  fprintf(stderr, "%s: this HTAB -- accesses %ld collisions %ld\n",
858  where, hashp->hctl->accesses, hashp->hctl->collisions);
859 
860  fprintf(stderr, "hash_stats: entries %ld keysize %ld maxp %u segmentcount %ld\n",
861  hash_get_num_entries(hashp), (long) hashp->hctl->keysize,
862  hashp->hctl->max_bucket, hashp->hctl->nsegs);
863  fprintf(stderr, "%s: total accesses %ld total collisions %ld\n",
864  where, hash_accesses, hash_collisions);
865  fprintf(stderr, "hash_stats: total expansions %ld\n",
866  hash_expansions);
867 #endif
868 }
Size keysize
Definition: dynahash.c:191
uint32 max_bucket
Definition: dynahash.c:186
long hash_get_num_entries(HTAB *hashp)
Definition: dynahash.c:1356
#define fprintf
Definition: port.h:197
HASHHDR * hctl
Definition: dynahash.c:222
long nsegs
Definition: dynahash.c:185

◆ hash_update_hash_key()

bool hash_update_hash_key ( HTAB hashp,
void *  existingEntry,
const void *  newKeyPtr 
)

Definition at line 1136 of file dynahash.c.

References calc_bucket(), HTAB::dir, ELEMENT_FROM_KEY, ELEMENTKEY, elog, ERROR, HTAB::frozen, HTAB::hash, hash_corrupted(), HASHELEMENT::hashvalue, HTAB::hctl, HTAB::keycopy, HASHHDR::keysize, HTAB::keysize, HASHELEMENT::link, HTAB::match, MOD, HTAB::sshift, HTAB::ssize, and HTAB::tabname.

Referenced by PostPrepare_Locks().

1139 {
1140  HASHELEMENT *existingElement = ELEMENT_FROM_KEY(existingEntry);
1141  HASHHDR *hctl = hashp->hctl;
1142  uint32 newhashvalue;
1143  Size keysize;
1144  uint32 bucket;
1145  uint32 newbucket;
1146  long segment_num;
1147  long segment_ndx;
1148  HASHSEGMENT segp;
1149  HASHBUCKET currBucket;
1150  HASHBUCKET *prevBucketPtr;
1151  HASHBUCKET *oldPrevPtr;
1152  HashCompareFunc match;
1153 
1154 #ifdef HASH_STATISTICS
1155  hash_accesses++;
1156  hctl->accesses++;
1157 #endif
1158 
1159  /* disallow updates if frozen */
1160  if (hashp->frozen)
1161  elog(ERROR, "cannot update in frozen hashtable \"%s\"",
1162  hashp->tabname);
1163 
1164  /*
1165  * Lookup the existing element using its saved hash value. We need to do
1166  * this to be able to unlink it from its hash chain, but as a side benefit
1167  * we can verify the validity of the passed existingEntry pointer.
1168  */
1169  bucket = calc_bucket(hctl, existingElement->hashvalue);
1170 
1171  segment_num = bucket >> hashp->sshift;
1172  segment_ndx = MOD(bucket, hashp->ssize);
1173 
1174  segp = hashp->dir[segment_num];
1175 
1176  if (segp == NULL)
1177  hash_corrupted(hashp);
1178 
1179  prevBucketPtr = &segp[segment_ndx];
1180  currBucket = *prevBucketPtr;
1181 
1182  while (currBucket != NULL)
1183  {
1184  if (currBucket == existingElement)
1185  break;
1186  prevBucketPtr = &(currBucket->link);
1187  currBucket = *prevBucketPtr;
1188  }
1189 
1190  if (currBucket == NULL)
1191  elog(ERROR, "hash_update_hash_key argument is not in hashtable \"%s\"",
1192  hashp->tabname);
1193 
1194  oldPrevPtr = prevBucketPtr;
1195 
1196  /*
1197  * Now perform the equivalent of a HASH_ENTER operation to locate the hash
1198  * chain we want to put the entry into.
1199  */
1200  newhashvalue = hashp->hash(newKeyPtr, hashp->keysize);
1201 
1202  newbucket = calc_bucket(hctl, newhashvalue);
1203 
1204  segment_num = newbucket >> hashp->sshift;
1205  segment_ndx = MOD(newbucket, hashp->ssize);
1206 
1207  segp = hashp->dir[segment_num];
1208 
1209  if (segp == NULL)
1210  hash_corrupted(hashp);
1211 
1212  prevBucketPtr = &segp[segment_ndx];
1213  currBucket = *prevBucketPtr;
1214 
1215  /*
1216  * Follow collision chain looking for matching key
1217  */
1218  match = hashp->match; /* save one fetch in inner loop */
1219  keysize = hashp->keysize; /* ditto */
1220 
1221  while (currBucket != NULL)
1222  {
1223  if (currBucket->hashvalue == newhashvalue &&
1224  match(ELEMENTKEY(currBucket), newKeyPtr, keysize) == 0)
1225  break;
1226  prevBucketPtr = &(currBucket->link);
1227  currBucket = *prevBucketPtr;
1228 #ifdef HASH_STATISTICS
1229  hash_collisions++;
1230  hctl->collisions++;
1231 #endif
1232  }
1233 
1234  if (currBucket != NULL)
1235  return false; /* collision with an existing entry */
1236 
1237  currBucket = existingElement;
1238 
1239  /*
1240  * If old and new hash values belong to the same bucket, we need not
1241  * change any chain links, and indeed should not since this simplistic
1242  * update will corrupt the list if currBucket is the last element. (We
1243  * cannot fall out earlier, however, since we need to scan the bucket to
1244  * check for duplicate keys.)
1245  */
1246  if (bucket != newbucket)
1247  {
1248  /* OK to remove record from old hash bucket's chain. */
1249  *oldPrevPtr = currBucket->link;
1250 
1251  /* link into new hashbucket chain */
1252  *prevBucketPtr = currBucket;
1253  currBucket->link = NULL;
1254  }
1255 
1256  /* copy new key into record */
1257  currBucket->hashvalue = newhashvalue;
1258  hashp->keycopy(ELEMENTKEY(currBucket), newKeyPtr, keysize);
1259 
1260  /* rest of record is untouched */
1261 
1262  return true;
1263 }
int(* HashCompareFunc)(const void *key1, const void *key2, Size keysize)
Definition: hsearch.h:29
Size keysize
Definition: dynahash.c:237
static uint32 calc_bucket(HASHHDR *hctl, uint32 hash_val)
Definition: dynahash.c:888
#define ELEMENTKEY(helem)
Definition: dynahash.c:245
#define ELEMENT_FROM_KEY(key)
Definition: dynahash.c:250
HashValueFunc hash
Definition: dynahash.c:224
long ssize
Definition: dynahash.c:238
#define ERROR
Definition: elog.h:43
int sshift
Definition: dynahash.c:239
#define MOD(x, y)
Definition: dynahash.c:256
HASHHDR * hctl
Definition: dynahash.c:222
static void hash_corrupted(HTAB *hashp)
Definition: dynahash.c:1725
unsigned int uint32
Definition: c.h:374
HashCompareFunc match
Definition: dynahash.c:225
bool frozen
Definition: dynahash.c:234
HashCopyFunc keycopy
Definition: dynahash.c:226
size_t Size
Definition: c.h:473
char * tabname
Definition: dynahash.c:229
struct HASHELEMENT * link
Definition: hsearch.h:53
#define elog(elevel,...)
Definition: elog.h:214
HASHSEGMENT * dir
Definition: dynahash.c:223
uint32 hashvalue
Definition: hsearch.h:54