From 055467d5049b928ebc8e38c2bc479413db64eab6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 14 Apr 2005 20:32:43 +0000 Subject: [PATCH] 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. --- src/backend/postmaster/pgstat.c | 10 +++++----- src/backend/utils/cache/relcache.c | 6 +++--- src/backend/utils/cache/typcache.c | 4 ++-- src/backend/utils/fmgr/fmgr.c | 4 ++-- src/backend/utils/hash/hashfn.c | 15 ++++++++++++++- src/include/utils/hsearch.h | 3 ++- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index ce4dc45f3d..e21adab7ca 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -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, diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index ab773de9c8..7c24e648af 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -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); diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c index 01990db8ad..a46267643b 100644 --- a/src/backend/utils/cache/typcache.c +++ b/src/backend/utils/cache/typcache.c @@ -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); } diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index 0e9716de01..181da00fd7 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -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, diff --git a/src/backend/utils/hash/hashfn.c b/src/backend/utils/hash/hashfn.c index c27417d7d3..24255f31e6 100644 --- a/src/backend/utils/hash/hashfn.c +++ b/src/backend/utils/hash/hashfn.c @@ -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); +} diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h index 9773dc733f..e6293bc000 100644 --- a/src/include/utils/hsearch.h +++ b/src/include/utils/hsearch.h @@ -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 */ -- 2.40.0