123#define DEF_SEGSIZE 256
124#define DEF_SEGSIZE_SHIFT 8
125#define DEF_DIRSIZE 256
128#define NUM_FREELISTS 32
200#ifdef HASH_STATISTICS
212#define IS_PARTITIONED(hctl) ((hctl)->num_partitions != 0)
214#define FREELIST_IDX(hctl, hashcode) \
215 (IS_PARTITIONED(hctl) ? (hashcode) % NUM_FREELISTS : 0)
255#define ELEMENTKEY(helem) (((char *)(helem)) + MAXALIGN(sizeof(HASHELEMENT)))
260#define ELEMENT_FROM_KEY(key) \
261 ((HASHELEMENT *) (((char *) (key)) - MAXALIGN(sizeof(HASHELEMENT))))
266#define MOD(x,y) ((x) & ((y)-1))
403 hashp->
tabname = (
char *) (hashp + 1);
523 errmsg(
"out of memory")));
603 if (nelem_alloc <= 0)
623 errmsg(
"out of memory")));
657#ifdef HASH_STATISTICS
658 hctl->accesses = hctl->collisions = hctl->expansions = 0;
690 }
while (nelem_alloc < 32);
736 nsegs = (nbuckets - 1) / hctl->
ssize + 1;
743 if (nsegs > hctl->
dsize)
886#ifdef HASH_STATISTICS
978#ifdef HASH_STATISTICS
1011 match = hashp->
match;
1021#ifdef HASH_STATISTICS
1077 elog(
ERROR,
"cannot insert into frozen hashtable \"%s\"",
1090 errmsg(
"out of shared memory")));
1094 errmsg(
"out of memory")));
1115 elog(
ERROR,
"unrecognized hash action code: %d", (
int) action);
1154#ifdef HASH_STATISTICS
1162 elog(
ERROR,
"cannot update in frozen hashtable \"%s\"",
1183 elog(
ERROR,
"hash_update_hash_key argument is not in hashtable \"%s\"",
1199 match = hashp->
match;
1209#ifdef HASH_STATISTICS
1382 status->
hashp = hashp;
1458 hashp = status->
hashp;
1460 ssize = hashp->
ssize;
1463 if (curBucket > max_bucket)
1486 if (++curBucket > max_bucket)
1534 elog(
ERROR,
"cannot freeze hashtable \"%s\" because it has active scans",
1564#ifdef HASH_STATISTICS
1875#define MAX_SEQ_SCANS 100
1887 elog(
ERROR,
"too many active hash_seq_search scans, cannot start one on \"%s\"",
1911 elog(
ERROR,
"no hash_seq_search scan for hash table \"%s\"",
1948 elog(
WARNING,
"leaked hash_seq_search scan for hash table %p",
1971 elog(
WARNING,
"leaked hash_seq_search scan for hash table %p",
#define Assert(condition)
#define MemSet(start, val, len)
void(* pg_funcptr_t)(void)
static HTAB * seq_scan_tables[MAX_SEQ_SCANS]
static int seq_scan_level[MAX_SEQ_SCANS]
void hash_seq_init_with_hash_value(HASH_SEQ_STATUS *status, HTAB *hashp, uint32 hashvalue)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
#define ELEMENT_FROM_KEY(key)
static void * DynaHashAlloc(Size size)
static bool element_alloc(HTAB *hashp, int nelem, int freelist_idx)
void AtEOXact_HashTables(bool isCommit)
Size hash_estimate_size(int64 num_entries, Size entrysize)
static HASHSEGMENT seg_alloc(HTAB *hashp)
static MemoryContext CurrentDynaHashCxt
static int next_pow2_int(int64 num)
static int choose_nelem_alloc(Size entrysize)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Size hash_get_shared_size(HASHCTL *info, int flags)
static void register_seq_scan(HTAB *hashp)
#define IS_PARTITIONED(hctl)
#define DEF_SEGSIZE_SHIFT
void AtEOSubXact_HashTables(bool isCommit, int nestDepth)
static HASHBUCKET get_hash_entry(HTAB *hashp, int freelist_idx)
void hash_destroy(HTAB *hashp)
static int string_compare(const char *key1, const char *key2, Size keysize)
int64 hash_select_dirsize(int64 num_entries)
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
void * hash_seq_search(HASH_SEQ_STATUS *status)
static bool expand_table(HTAB *hashp)
static void hdefault(HTAB *hashp)
static void deregister_seq_scan(HTAB *hashp)
static int my_log2(int64 num)
#define ELEMENTKEY(helem)
void hash_seq_term(HASH_SEQ_STATUS *status)
int64 hash_get_num_entries(HTAB *hashp)
static int64 next_pow2_int64(int64 num)
#define FREELIST_IDX(hctl, hashcode)
void hash_stats(const char *caller, HTAB *hashp)
static bool init_htab(HTAB *hashp, int64 nelem)
static pg_noreturn void hash_corrupted(HTAB *hashp)
void hash_freeze(HTAB *hashp)
static bool dir_realloc(HTAB *hashp)
bool hash_update_hash_key(HTAB *hashp, void *existingEntry, const void *newKeyPtr)
static uint32 hash_initial_lookup(HTAB *hashp, uint32 hashvalue, HASHBUCKET **bucketptr)
uint32 get_hash_value(HTAB *hashp, const void *keyPtr)
static uint32 calc_bucket(HASHHDR *hctl, uint32 hash_val)
static bool has_seq_scans(HTAB *hashp)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define MCXT_ALLOC_NO_OOM
uint32 tag_hash(const void *key, Size keysize)
uint32 uint32_hash(const void *key, Size keysize)
uint32 string_hash(const void *key, Size keysize)
void *(* HashAllocFunc)(Size request)
int(* HashCompareFunc)(const void *key1, const void *key2, Size keysize)
uint32(* HashValueFunc)(const void *key, Size keysize)
void *(* HashCopyFunc)(void *dest, const void *src, Size keysize)
static void slist_push_head(slist_head *head, slist_node *node)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
void MemoryContextDelete(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
#define MemoryContextIsValid(context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static uint64 pg_ceil_log2_64(uint64 num)
size_t strlcpy(char *dst, const char *src, size_t siz)
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
struct HASHELEMENT * link
FreeListData freeList[NUM_FREELISTS]
int GetCurrentTransactionNestLevel(void)