Commit 055467d5 authored by Tom Lane's avatar Tom Lane

Marginal hack to use a specialized hash function for dynahash hashtables

whose keys are OIDs.  The only one that looks particularly performance
critical is the relcache hashtable, but as long as we've got the function
we may as well use it wherever it's applicable.
parent 162bd08b
......@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.91 2005/04/14 20:03:25 tgl Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.92 2005/04/14 20:32:42 tgl Exp $
* ----------
*/
#include "postgres.h"
......@@ -2065,7 +2065,7 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
hash_ctl.hash = tag_hash;
hash_ctl.hash = oid_hash;
dbentry->tables = hash_create("Per-database table",
PGSTAT_TAB_HASH_SIZE,
&hash_ctl,
......@@ -2364,7 +2364,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(PgStat_StatDBEntry);
hash_ctl.hash = tag_hash;
hash_ctl.hash = oid_hash;
hash_ctl.hcxt = use_mcxt;
*dbhash = hash_create("Databases hash", PGSTAT_DB_HASH_SIZE, &hash_ctl,
HASH_ELEM | HASH_FUNCTION | mcxt_flags);
......@@ -2453,7 +2453,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
hash_ctl.hash = tag_hash;
hash_ctl.hash = oid_hash;
hash_ctl.hcxt = use_mcxt;
dbentry->tables = hash_create("Per-database table",
PGSTAT_TAB_HASH_SIZE,
......@@ -2888,7 +2888,7 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
hash_ctl.hash = tag_hash;
hash_ctl.hash = oid_hash;
dbentry->tables = hash_create("Per-database table",
PGSTAT_TAB_HASH_SIZE,
&hash_ctl,
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.220 2005/04/14 20:03:26 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.221 2005/04/14 20:32:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1032,7 +1032,7 @@ LookupOpclassInfo(Oid operatorClassOid,
MemSet(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(Oid);
ctl.entrysize = sizeof(OpClassCacheEnt);
ctl.hash = tag_hash;
ctl.hash = oid_hash;
OpClassCache = hash_create("Operator class cache", 64,
&ctl, HASH_ELEM | HASH_FUNCTION);
}
......@@ -2151,7 +2151,7 @@ RelationCacheInitialize(void)
MemSet(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(Oid);
ctl.entrysize = sizeof(RelIdCacheEnt);
ctl.hash = tag_hash;
ctl.hash = oid_hash;
RelationIdCache = hash_create("Relcache by OID", INITRELCACHESIZE,
&ctl, HASH_ELEM | HASH_FUNCTION);
......
......@@ -36,7 +36,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.12 2005/04/14 20:03:26 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.13 2005/04/14 20:32:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -123,7 +123,7 @@ lookup_type_cache(Oid type_id, int flags)
MemSet(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(Oid);
ctl.entrysize = sizeof(TypeCacheEntry);
ctl.hash = tag_hash;
ctl.hash = oid_hash;
TypeCacheHash = hash_create("Type information cache", 64,
&ctl, HASH_ELEM | HASH_FUNCTION);
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.93 2005/03/31 22:46:16 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.94 2005/04/14 20:32:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -509,7 +509,7 @@ record_C_func(HeapTuple procedureTuple,
MemSet(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
hash_ctl.hash = tag_hash;
hash_ctl.hash = oid_hash;
CFuncHash = hash_create("CFuncHash",
100,
&hash_ctl,
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/hash/hashfn.c,v 1.22 2004/12/31 22:01:37 pgsql Exp $
* $PostgreSQL: pgsql/src/backend/utils/hash/hashfn.c,v 1.23 2005/04/14 20:32:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -40,3 +40,16 @@ tag_hash(const void *key, Size keysize)
return DatumGetUInt32(hash_any((const unsigned char *) key,
(int) keysize));
}
/*
* oid_hash: hash function for keys that are OIDs
*
* (tag_hash works for this case too, but is slower)
*/
uint32
oid_hash(const void *key, Size keysize)
{
Assert(keysize == sizeof(Oid));
/* We don't actually bother to do anything to the OID value ... */
return (uint32) *((const Oid *) key);
}
......@@ -7,7 +7,7 @@
* 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.34 2004/12/31 22:03:46 pgsql Exp $
* $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.35 2005/04/14 20:32:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -184,5 +184,6 @@ extern long hash_select_dirsize(long num_entries);
*/
extern uint32 string_hash(const void *key, Size keysize);
extern uint32 tag_hash(const void *key, Size keysize);
extern uint32 oid_hash(const void *key, Size keysize);
#endif /* HSEARCH_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment