*** a/src/backend/storage/ipc/shmem.c --- b/src/backend/storage/ipc/shmem.c *************** *** 268,273 **** ShmemInitHash(const char *name, /* table string name for shmem index */ --- 268,274 ---- * * The shared memory allocator must be specified too. */ + infoP->max_size = max_size; infoP->dsize = infoP->max_dsize = hash_select_dirsize(max_size); infoP->alloc = ShmemAlloc; hash_flags |= HASH_SHARED_MEM | HASH_ALLOC | HASH_DIRSIZE; *** a/src/backend/utils/hash/dynahash.c --- b/src/backend/utils/hash/dynahash.c *************** *** 129,134 **** struct HASHHDR --- 129,135 ---- long ffactor; /* target fill factor */ long max_dsize; /* 'dsize' limit if directory is fixed size */ long ssize; /* segment size --- must be power of 2 */ + long max_size; /* maximum number of entries expected */ int sshift; /* segment shift = log2(ssize) */ int nelem_alloc; /* number of entries to allocate at once */ *************** *** 368,373 **** hash_create(const char *tabname, long nelem, HASHCTL *info, int flags) --- 369,375 ---- hdefault(hashp); hctl = hashp->hctl; + hctl->max_size = info->max_size; if (flags & HASH_PARTITION) { *************** *** 1333,1338 **** element_alloc(HTAB *hashp, int nelem) --- 1335,1341 ---- HASHELEMENT *tmpElement; HASHELEMENT *prevElement; int i; + bool warningNeeded; /* Each element has a HASHELEMENT header plus user data. */ elementSize = MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(hctlv->entrysize); *************** *** 1360,1369 **** element_alloc(HTAB *hashp, int nelem) --- 1363,1378 ---- /* freelist could be nonempty if two backends did this concurrently */ firstElement->link = hctlv->freeList; hctlv->freeList = prevElement; + warningNeeded = (hctlv->max_size > 0 && hctlv->nentries == hctlv->max_size); if (IS_PARTITIONED(hctlv)) SpinLockRelease(&hctlv->mutex); + if (warningNeeded) + ereport(WARNING, + (errmsg("hash table \"%s\" has more entries than expected", hashp->tabname), + errdetail("The maximum was set to %li on creation.", hctlv->max_size))); + return true; } *** a/src/include/utils/hsearch.h --- b/src/include/utils/hsearch.h *************** *** 69,74 **** typedef struct HASHCTL --- 69,75 ---- long dsize; /* (initial) directory size */ long max_dsize; /* limit to dsize if dir size is limited */ long ffactor; /* fill factor */ + long max_size; /* maximum number of entries expected */ Size keysize; /* hash key length in bytes */ Size entrysize; /* total user element size in bytes */ HashValueFunc hash; /* hash function */