spotted by Qingqing Zhou. The HASH_ENTER action now automatically
fails with elog(ERROR) on out-of-memory --- which incidentally lets
us eliminate duplicate error checks in quite a bunch of places. If
you really need the old return-NULL-on-out-of-memory behavior, you
can ask for HASH_ENTER_NULL. But there is now an Assert in that path
checking that you aren't hoping to get that behavior in a palloc-based
hash table.
Along the way, remove the old HASH_FIND_SAVE/HASH_REMOVE_SAVED actions,
which were not being used anywhere anymore, and were surely too ugly
and unsafe to want to see revived again.
index f23151ac146ea973cbfbe8dc2f69c5af12736a5b..b216dbeea98debb4eed348bbfe3f6f53d5ee5c6c 100644 (file)
@@ -2061,11 +2061,6 @@ createNewConnection(const char *name, remoteConn * con)
hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key,
HASH_ENTER, &found);
- if (!hentry)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
-
if (found)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
index c364fc659541aea7909ede67bd367c66365a20fb..0aa52b5281404115df11fa23e3269b8ef2ffcbdb 100644 (file)
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
hentry = (crosstab_HashEnt*) hash_search(crosstab_HashTable, \
key, HASH_ENTER, &found); \
- if (hentry == NULL) \
- ereport(ERROR, \
- (errcode(ERRCODE_OUT_OF_MEMORY), \
- errmsg("out of memory"))); \
if (found) \
ereport(ERROR, \
(errcode(ERRCODE_DUPLICATE_OBJECT), \
index 251098d4083e204c5a2860068b4cd7857b1ddf2c..72833a755f78206ed5f3e59b4f946df620eec4ee 100644 (file)
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.36 2005年01月10日 20:02:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.37 2005年05月29日 04:23:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -223,9 +223,6 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
hentry = (XLogRelCacheEntry *)
hash_search(_xlrelcache, (void *) &rnode, HASH_ENTER, &found);
- if (hentry == NULL)
- elog(PANIC, "XLogOpenRelation: out of memory for cache");
-
if (found)
elog(PANIC, "XLogOpenRelation: file found on insert into cache");
index ada9d534de305fbf16585d235a0282a3fde0c893..16aae6869388b75caf6d1c272b5c789834e70ca2 100644 (file)
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.37 2005年05月24日 04:18:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.38 2005年05月29日 04:23:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -346,9 +346,9 @@ StorePreparedStatement(const char *stmt_name,
HASH_ENTER,
&found);
- /* Shouldn't get a failure, nor a duplicate entry */
- if (!entry || found)
- elog(ERROR, "could not store prepared statement \"%s\"",
+ /* Shouldn't get a duplicate entry */
+ if (found)
+ elog(ERROR, "duplicate prepared statement \"%s\"",
stmt_name);
/* Fill in the hash table entry with copied data */
index 37db2bcd2f66759a9e55df570a745aded415c155..1bf46d815cc7ec3daf88badc12e2f1687bcb489f 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/execGrouping.c,v 1.14 2005年03月16日 21:38:06 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/execGrouping.c,v 1.15 2005年05月29日 04:23:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -379,13 +379,9 @@ LookupTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot,
}
else
{
- /* created new entry ... we hope */
- if (entry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
-
/*
+ * created new entry
+ *
* Zero any caller-requested space in the entry. (This zaps
* the "key data" dynahash.c copied into the new entry, but we
* don't care since we're about to overwrite it anyway.)
index d0ca978cb624baaddf2a2a79c0958ac1b3824f9c..1da1aa785ef931d4b76e1166f21c1eae4484bf8c 100644 (file)
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.3 2005年05月17日 00:43:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.4 2005年05月29日 04:23:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
page = (PagetableEntry *) hash_search(tbm->pagetable,
(void *) &tbm->entry1.blockno,
HASH_ENTER, &found);
- if (page == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
Assert(!found);
memcpy(page, &tbm->entry1, sizeof(PagetableEntry));
}
@@ -726,10 +722,6 @@ tbm_get_pageentry(TIDBitmap *tbm, BlockNumber pageno)
page = (PagetableEntry *) hash_search(tbm->pagetable,
(void *) &pageno,
HASH_ENTER, &found);
- if (page == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
}
/* Initialize it if not present before */
@@ -820,10 +812,6 @@ tbm_mark_page_lossy(TIDBitmap *tbm, BlockNumber pageno)
page = (PagetableEntry *) hash_search(tbm->pagetable,
(void *) &chunk_pageno,
HASH_ENTER, &found);
- if (page == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
/* Initialize it if not present before */
if (!found)
index 3d2244b0d81cf0f4d15c329e1d138569ed340f38..b7f15ea38eb6308218c7b5463d73095e4ba48b80 100644 (file)
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.94 2005年05月11日 01:41:40 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.95 2005年05月29日 04:23:03 tgl Exp $
* ----------
*/
#include "postgres.h"
result = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
&databaseid,
HASH_ENTER, &found);
- if (result == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory in statistics collector --- abort")));
/* If not found, initialize the new one. */
if (!found)
(void *) &procpid,
HASH_ENTER,
&found);
- if (deadbe == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory in statistics collector --- abort")));
if (!found)
{
(void *) &dbbuf.databaseid,
HASH_ENTER,
&found);
- if (dbentry == NULL)
- {
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
- }
if (found)
{
ereport(pgStatRunningInCollector ? LOG : WARNING,
tabentry = (PgStat_StatTabEntry *) hash_search(tabhash,
(void *) &tabbuf.tableid,
HASH_ENTER, &found);
- if (tabentry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
if (found)
{
@@ -2730,10 +2712,6 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
(void *) &(tabmsg[i].t_id),
HASH_ENTER, &found);
- if (tabentry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory in statistics collector --- abort")));
if (!found)
{
index 7fe9e83477c0ad142bbf0b4f63300226467fbea7..5ef277edc95f6fb7df61a021a2f41ceca3e0756f 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.40 2005年03月04日 20:21:06 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.41 2005年05月29日 04:23:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -110,11 +110,6 @@ BufTableInsert(BufferTag *tagPtr, int buf_id)
result = (BufferLookupEnt *)
hash_search(SharedBufHash, (void *) tagPtr, HASH_ENTER, &found);
- if (!result)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of shared memory")));
-
if (found) /* found something already in the table */
return result->id;
index 0e9e7b68cc3366fa55741f7cfcbac098a09a0804..a2604dcf550e0641c13573392c3873709a67b3a4 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.66 2005年03月19日 23:27:05 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.67 2005年05月29日 04:23:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -192,10 +192,6 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
hresult = (LocalBufferLookupEnt *)
hash_search(LocalBufHash, (void *) &newTag, HASH_ENTER, &found);
- if (!hresult)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
if (found) /* shouldn't happen */
elog(ERROR, "local buffer hash table corrupted");
hresult->id = b;
index b5cb8ef71317a2910ebb8c811331792d564b643e..27e9952b3ff083f644a7235ee56824c3e1c204b4 100644 (file)
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.44 2005年04月24日 03:51:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.45 2005年05月29日 04:23:04 tgl Exp $
*
*
* NOTES:
(void *) rel,
HASH_ENTER,
&found);
- if (!fsmrel)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of shared memory")));
if (!found)
{
index ca4ca193402726e3e93551c22bc1d8adf70f4b0c..9af059139e7d48eeb6e815ff9bfb05445afa0ce4 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.83 2005年04月04日 04:34:41 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.84 2005年05月29日 04:23:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
result = (ShmemIndexEnt *)
hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
- if (!result)
- ereport(FATAL,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of shared memory")));
Assert(!found);
@@ -367,7 +363,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
/* look it up in the shmem index */
result = (ShmemIndexEnt *)
- hash_search(ShmemIndex, (void *) &item, HASH_ENTER, foundPtr);
+ hash_search(ShmemIndex, (void *) &item, HASH_ENTER_NULL, foundPtr);
if (!result)
{
@@ -375,7 +371,6 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
- return NULL;
}
if (*foundPtr)
index 49843b2de60e156ceef0a6013ad4e46eab8cf20a..d7180d7c1fd93022eb86f9307db8026617a7f6d8 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.152 2005年05月19日 23:30:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.153 2005年05月29日 04:23:04 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -470,10 +470,6 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
locallock = (LOCALLOCK *) hash_search(LockMethodLocalHash[lockmethodid],
(void *) &localtag,
HASH_ENTER, &found);
- if (!locallock)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
/*
* if it's a new locallock object, initialize it
@@ -531,7 +527,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
*/
lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid],
(void *) locktag,
- HASH_ENTER, &found);
+ HASH_ENTER_NULL, &found);
if (!lock)
{
LWLockRelease(masterLock);
@@ -578,7 +574,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
*/
proclock = (PROCLOCK *) hash_search(LockMethodProcLockHash[lockmethodid],
(void *) &proclocktag,
- HASH_ENTER, &found);
+ HASH_ENTER_NULL, &found);
if (!proclock)
{
/* Ooops, not enough shmem for the proclock */
index 73194ec4ef3dfa852602b784797f652e6d6fbf03..1c0cb7e240b9b61a65cfef399a9251da056bfd9f 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.114 2004年12月31日 22:01:13 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.115 2005年05月29日 04:23:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -805,9 +805,8 @@ register_dirty_segment(SMgrRelation reln, MdfdVec *seg)
entry.rnode = reln->smgr_rnode;
entry.segno = seg->mdfd_segno;
- if (hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL) != NULL)
- return true;
- /* out of memory: fall through to do it locally */
+ (void) hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL);
+ return true;
}
else
{
@@ -838,10 +837,7 @@ RememberFsyncRequest(RelFileNode rnode, BlockNumber segno)
entry.rnode = rnode;
entry.segno = segno;
- if (hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL) == NULL)
- ereport(FATAL,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
+ (void) hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL);
}
/*
index 5abfc6d47741b97c6fe5f09e3ace0a422caa5847..0b5a7154d3f3f572ccc7384997692745729e1a8b 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.86 2005年03月20日 22:00:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.87 2005年05月29日 04:23:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
reln = (SMgrRelation) hash_search(SMgrRelationHash,
(void *) &rnode,
HASH_ENTER, &found);
- if (reln == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
/* Initialize it if not present before */
if (!found)
index 78a85b7edccd794dc4678579eec61878b55d7ad8..0dc1241012434ca02edfe3960ed965a673163124 100644 (file)
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.77 2005年04月28日 21:47:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.78 2005年05月29日 04:23:05 tgl Exp $
*
* ----------
*/
entry = (RI_QueryHashEntry *) hash_search(ri_query_cache,
(void *) key,
HASH_ENTER, &found);
- if (entry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
entry->plan = plan;
}
index 3123eca518edfc16ae1c9744dc45f3a44febdc3d..7b140228c8c0033ebfdfc1709b17899d104891bd 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.224 2005年05月27日 23:31:20 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.225 2005年05月29日 04:23:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
(void *) &(RELATION->rd_id), \
HASH_ENTER, \
&found); \
- if (idhentry == NULL) \
- ereport(ERROR, \
- (errcode(ERRCODE_OUT_OF_MEMORY), \
- errmsg("out of memory"))); \
/* used to give notice if found -- now just keep quiet */ \
idhentry->reldesc = RELATION; \
} while(0)
opcentry = (OpClassCacheEnt *) hash_search(OpClassCache,
(void *) &operatorClassOid,
HASH_ENTER, &found);
- if (opcentry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
if (found && opcentry->valid)
{
index a46267643b5e5bffb54c5c25d9dbd87f0cbf3d89..b0b890516df6ee418467aae635118e7813884bcf 100644 (file)
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.13 2005年04月14日 20:32:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.14 2005年05月29日 04:23:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
typentry = (TypeCacheEntry *) hash_search(TypeCacheHash,
(void *) &type_id,
HASH_ENTER, &found);
- if (typentry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
Assert(!found); /* it wasn't there a moment ago */
MemSet(typentry, 0, sizeof(TypeCacheEntry));
@@ -480,10 +476,6 @@ assign_record_type_typmod(TupleDesc tupDesc)
recentry = (RecordCacheEntry *) hash_search(RecordCacheHash,
(void *) hashkey,
HASH_ENTER, &found);
- if (recentry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
if (!found)
{
/* New entry ... hash_search initialized only the hash key */
index 181da00fd7e916a5701776798a2e4735ffef08c5..0733f190c2bff8e32a2540986db1a0e811b70be1 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.94 2005年04月14日 20:32:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.95 2005年05月29日 04:23:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
&fn_oid,
HASH_ENTER,
&found);
- if (entry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
/* OID is already filled in */
entry->fn_xmin = HeapTupleHeaderGetXmin(procedureTuple->t_data);
entry->fn_cmin = HeapTupleHeaderGetCmin(procedureTuple->t_data);
index 85bd82244c3e07c7edd237350335d34b5286150f..8f1af2b8fa3ef628a0f74ea12d810d640a0524ac 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.60 2005年05月16日 00:19:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.61 2005年05月29日 04:23:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* action is one of:
* HASH_FIND: look up key in table
* HASH_ENTER: look up key in table, creating entry if not present
+ * HASH_ENTER_NULL: same, but return NULL if out of memory
* HASH_REMOVE: look up key in table, remove entry if present
- * HASH_FIND_SAVE: look up key in table, also save in static var
- * HASH_REMOVE_SAVED: remove entry saved by HASH_FIND_SAVE
*
* Return value is a pointer to the element found/entered/removed if any,
- * or NULL if no match was found. (NB: in the case of the REMOVE actions,
+ * or NULL if no match was found. (NB: in the case of the REMOVE action,
* the result is a dangling pointer that shouldn't be dereferenced!)
- * A NULL result for HASH_ENTER implies we ran out of memory.
+ *
+ * HASH_ENTER will normally ereport a generic "out of memory" error if
+ * it is unable to create a new entry. The HASH_ENTER_NULL operation is
+ * the same except it will return NULL if out of memory. Note that
+ * HASH_ENTER_NULL cannot be used with the default palloc-based allocator,
+ * since palloc internally ereports on out-of-memory.
*
* If foundPtr isn't NULL, then *foundPtr is set TRUE if we found an
* existing entry in the table, FALSE otherwise. This is needed in the
* HASH_ENTER case, but is redundant with the return value otherwise.
- *
- * The HASH_FIND_SAVE/HASH_REMOVE_SAVED interface is a hack to save one
- * table lookup in a find/process/remove scenario. Note that no other
- * addition or removal in the table can safely happen in between.
*----------
*/
void *
bool *foundPtr)
{
HASHHDR *hctl = hashp->hctl;
- uint32 hashvalue = 0;
+ Size keysize = hctl->keysize;
+ uint32 hashvalue;
uint32 bucket;
long segment_num;
long segment_ndx;
HASHSEGMENT segp;
HASHBUCKET currBucket;
HASHBUCKET *prevBucketPtr;
-
- static struct State
- {
- HASHBUCKET currBucket;
- HASHBUCKET *prevBucketPtr;
- } saveState;
+ HashCompareFunc match;
#if HASH_STATISTICS
hash_accesses++;
#endif
/*
- * Do the initial lookup (or recall result of prior lookup)
+ * Do the initial lookup
*/
- if (action == HASH_REMOVE_SAVED)
- {
- currBucket = saveState.currBucket;
- prevBucketPtr = saveState.prevBucketPtr;
+ hashvalue = hashp->hash(keyPtr, keysize);
+ bucket = calc_bucket(hctl, hashvalue);
- /*
- * Try to catch subsequent errors
- */
- Assert(currBucket);
- saveState.currBucket = NULL;
- }
- else
- {
- HashCompareFunc match;
- Size keysize = hctl->keysize;
+ segment_num = bucket >> hctl->sshift;
+ segment_ndx = MOD(bucket, hctl->ssize);
- hashvalue = hashp->hash(keyPtr, keysize);
- bucket = calc_bucket(hctl, hashvalue);
+ segp = hashp->dir[segment_num];
- segment_num = bucket >> hctl->sshift;
- segment_ndx = MOD(bucket, hctl->ssize);
+ if (segp == NULL)
+ hash_corrupted(hashp);
- segp = hashp->dir[segment_num];
+ prevBucketPtr = &segp[segment_ndx];
+ currBucket = *prevBucketPtr;
- if (segp == NULL)
- hash_corrupted(hashp);
+ /*
+ * Follow collision chain looking for matching key
+ */
+ match = hashp->match; /* save one fetch in inner loop */
- prevBucketPtr = &segp[segment_ndx];
+ while (currBucket != NULL)
+ {
+ if (currBucket->hashvalue == hashvalue &&
+ match(ELEMENTKEY(currBucket), keyPtr, keysize) == 0)
+ break;
+ prevBucketPtr = &(currBucket->link);
currBucket = *prevBucketPtr;
-
- /*
- * Follow collision chain looking for matching key
- */
- match = hashp->match; /* save one fetch in inner loop */
- while (currBucket != NULL)
- {
- if (currBucket->hashvalue == hashvalue &&
- match(ELEMENTKEY(currBucket), keyPtr, keysize) == 0)
- break;
- prevBucketPtr = &(currBucket->link);
- currBucket = *prevBucketPtr;
#if HASH_STATISTICS
- hash_collisions++;
- hctl->collisions++;
+ hash_collisions++;
+ hctl->collisions++;
#endif
- }
}
if (foundPtr)
return (void *) ELEMENTKEY(currBucket);
return NULL;
- case HASH_FIND_SAVE:
- if (currBucket != NULL)
- {
- saveState.currBucket = currBucket;
- saveState.prevBucketPtr = prevBucketPtr;
- return (void *) ELEMENTKEY(currBucket);
- }
- return NULL;
-
case HASH_REMOVE:
- case HASH_REMOVE_SAVED:
if (currBucket != NULL)
{
Assert(hctl->nentries > 0);
}
return NULL;
+ case HASH_ENTER_NULL:
+ /* ENTER_NULL does not work with palloc-based allocator */
+ Assert(hashp->alloc != DynaHashAlloc);
+ /* FALL THRU */
+
case HASH_ENTER:
/* Return existing element if found, else create one */
if (currBucket != NULL)
{
/* no free elements. allocate another chunk of buckets */
if (!element_alloc(hashp, HASHELEMENT_ALLOC_INCR))
- return NULL; /* out of memory */
+ {
+ /* out of memory */
+ if (action == HASH_ENTER_NULL)
+ return NULL;
+ /* report a generic message */
+ if (hashp->isshared)
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of shared memory")));
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
+ }
currBucket = hctl->freeList;
Assert(currBucket != NULL);
}
index 362d3df967fd0faa514b24f916b1548f3f00d014..26c5dd02a313c7d079bfcc6560def8afc0e3cbbb 100644 (file)
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.79 2005年05月11日 18:05:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.80 2005年05月29日 04:23:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
StrNCpy(key, NAME, MAX_PORTALNAME_LEN); \
hentry = (PortalHashEnt*)hash_search(PortalHashTable, \
key, HASH_ENTER, &found); \
- if (hentry == NULL) \
- ereport(ERROR, \
- (errcode(ERRCODE_OUT_OF_MEMORY), \
- errmsg("out of memory"))); \
if (found) \
elog(ERROR, "duplicate portal name"); \
hentry->portal = PORTAL; \
index e6293bc000ccc5fb79985d5878e5a3f2fd6313ac..bb93dea0775d6d5488f36a181c6dec412507d2cf 100644 (file)
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.35 2005年04月14日 20:32:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.36 2005年05月29日 04:23:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
HASH_FIND,
HASH_ENTER,
HASH_REMOVE,
- HASH_FIND_SAVE,
- HASH_REMOVE_SAVED
+ HASH_ENTER_NULL
} HASHACTION;
/* hash_seq status (should be considered an opaque type by callers) */
index b4cd6d1fdd467972c6debd0bd4753860be57768e..b746a8374bda03603ff92feebc6de69fb7fef602 100644 (file)
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.89 2005年05月06日 17:24:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.90 2005年05月29日 04:23:06 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
(void *) func_key,
HASH_ENTER,
&found);
- if (hentry == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
if (found)
elog(WARNING, "trying to insert a function that already exists");
index bdf3d40407916ceded48ff67ad56a14af0cbc691..38c719640654f44299606a85d9629a0d132d53e7 100644 (file)
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.31 2005年05月23日 21:54:02 momjian Exp $
+ * $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.32 2005年05月29日 04:23:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* load and parse the TZ definition file every time it is selected.
*/
static HTAB *timezone_cache = NULL;
+
static bool
init_timezone_hashtable(void)
{
HASH_FIND,
NULL);
if (tzp)
+ {
/* Timezone found in cache, nothing more to do */
return tzp;
+ }
if (tzload(name, &tz.state) != 0)
{
if (name[0] == ':' || tzparse(name, &tz.state, FALSE) != 0)
+ {
/* Unknown timezone. Fail our call instead of loading GMT! */
return NULL;
+ }
}
strcpy(tz.TZname, name);
HASH_ENTER,
NULL);
- if (!tzp)
- return NULL;
-
strcpy(tzp->TZname, tz.TZname);
memcpy(&tzp->state, &tz.state, sizeof(tz.state));