Commit 5999e78f authored by Tom Lane's avatar Tom Lane

Another round of cleanups for dynahash.c (maybe it's finally clean of

portability issues).  Caller-visible data structures are now allocated
on MAXALIGN boundaries, allowing safe use of datatypes wider than 'long'.
Rejigger hash_create API so that caller specifies size of key and
total size of entry, not size of key and size of rest of entry.
This simplifies life considerably since each number is just a sizeof(),
and padding issues etc. are taken care of automatically.
parent f5817966
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.18 2001/08/25 18:52:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.19 2001/10/01 05:36:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -228,9 +228,9 @@ _xl_init_rel_cache(void) ...@@ -228,9 +228,9 @@ _xl_init_rel_cache(void)
_xlrelarr[0].moreRecently = &(_xlrelarr[0]); _xlrelarr[0].moreRecently = &(_xlrelarr[0]);
_xlrelarr[0].lessRecently = &(_xlrelarr[0]); _xlrelarr[0].lessRecently = &(_xlrelarr[0]);
memset(&ctl, 0, (int) sizeof(ctl)); memset(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(RelFileNode); ctl.keysize = sizeof(RelFileNode);
ctl.datasize = sizeof(XLogRelDesc *); ctl.entrysize = sizeof(XLogRelCacheEntry);
ctl.hash = tag_hash; ctl.hash = tag_hash;
_xlrelcache = hash_create(_XLOG_RELCACHESIZE, &ctl, _xlrelcache = hash_create(_XLOG_RELCACHESIZE, &ctl,
...@@ -249,7 +249,7 @@ _xl_remove_hash_entry(XLogRelDesc **edata, Datum dummy) ...@@ -249,7 +249,7 @@ _xl_remove_hash_entry(XLogRelDesc **edata, Datum dummy)
rdesc->moreRecently->lessRecently = rdesc->lessRecently; rdesc->moreRecently->lessRecently = rdesc->lessRecently;
hentry = (XLogRelCacheEntry *) hash_search(_xlrelcache, hentry = (XLogRelCacheEntry *) hash_search(_xlrelcache,
(char *) &(rdesc->reldata.rd_node), HASH_REMOVE, &found); (void *) &(rdesc->reldata.rd_node), HASH_REMOVE, &found);
if (hentry == NULL) if (hentry == NULL)
elog(STOP, "_xl_remove_hash_entry: can't delete from cache"); elog(STOP, "_xl_remove_hash_entry: can't delete from cache");
...@@ -321,7 +321,7 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode) ...@@ -321,7 +321,7 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
bool found; bool found;
hentry = (XLogRelCacheEntry *) hentry = (XLogRelCacheEntry *)
hash_search(_xlrelcache, (char *) &rnode, HASH_FIND, &found); hash_search(_xlrelcache, (void *) &rnode, HASH_FIND, &found);
if (hentry == NULL) if (hentry == NULL)
elog(STOP, "XLogOpenRelation: error in cache"); elog(STOP, "XLogOpenRelation: error in cache");
...@@ -345,7 +345,7 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode) ...@@ -345,7 +345,7 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
res->reldata.rd_node = rnode; res->reldata.rd_node = rnode;
hentry = (XLogRelCacheEntry *) hentry = (XLogRelCacheEntry *)
hash_search(_xlrelcache, (char *) &rnode, HASH_ENTER, &found); hash_search(_xlrelcache, (void *) &rnode, HASH_ENTER, &found);
if (hentry == NULL) if (hentry == NULL)
elog(STOP, "XLogOpenRelation: can't insert into cache"); elog(STOP, "XLogOpenRelation: can't insert into cache");
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* Copyright (c) 2001, PostgreSQL Global Development Group * Copyright (c) 2001, PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.7 2001/08/23 23:06:37 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.8 2001/10/01 05:36:13 tgl Exp $
* ---------- * ----------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -511,7 +511,8 @@ pgstat_vacuum_tabstat(void) ...@@ -511,7 +511,8 @@ pgstat_vacuum_tabstat(void)
* Lookup our own database entry * Lookup our own database entry
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash,
(char *)&MyDatabaseId, HASH_FIND, &found); (void *) &MyDatabaseId,
HASH_FIND, &found);
if (!found || dbentry == NULL) if (!found || dbentry == NULL)
return -1; return -1;
...@@ -926,8 +927,9 @@ pgstat_fetch_stat_dbentry(Oid dbid) ...@@ -926,8 +927,9 @@ pgstat_fetch_stat_dbentry(Oid dbid)
/* /*
* Lookup the requested database * Lookup the requested database
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
(char *)&dbid, HASH_FIND, &found); (void *) &dbid,
HASH_FIND, &found);
if (!found || dbentry == NULL) if (!found || dbentry == NULL)
return NULL; return NULL;
...@@ -966,8 +968,9 @@ pgstat_fetch_stat_tabentry(Oid relid) ...@@ -966,8 +968,9 @@ pgstat_fetch_stat_tabentry(Oid relid)
/* /*
* Lookup our database. * Lookup our database.
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
(char *)&MyDatabaseId, HASH_FIND, &found); (void *) &MyDatabaseId,
HASH_FIND, &found);
if (!found || dbentry == NULL) if (!found || dbentry == NULL)
return NULL; return NULL;
...@@ -976,8 +979,9 @@ pgstat_fetch_stat_tabentry(Oid relid) ...@@ -976,8 +979,9 @@ pgstat_fetch_stat_tabentry(Oid relid)
*/ */
if (dbentry->tables == NULL) if (dbentry->tables == NULL)
return NULL; return NULL;
tabentry = (PgStat_StatTabEntry *)hash_search(dbentry->tables, tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
(char *)&relid, HASH_FIND, &found); (void *) &relid,
HASH_FIND, &found);
if (!found || tabentry == NULL) if (!found || tabentry == NULL)
return NULL; return NULL;
...@@ -1198,7 +1202,7 @@ pgstat_main(int real_argc, char *real_argv[]) ...@@ -1198,7 +1202,7 @@ pgstat_main(int real_argc, char *real_argv[])
*/ */
memset(&hash_ctl, 0, sizeof(hash_ctl)); memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(int); hash_ctl.keysize = sizeof(int);
hash_ctl.datasize = sizeof(PgStat_StatBeDead); hash_ctl.entrysize = sizeof(PgStat_StatBeDead);
hash_ctl.hash = tag_hash; hash_ctl.hash = tag_hash;
pgStatBeDead = hash_create(PGSTAT_BE_HASH_SIZE, &hash_ctl, pgStatBeDead = hash_create(PGSTAT_BE_HASH_SIZE, &hash_ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
...@@ -1720,8 +1724,9 @@ pgstat_add_backend(PgStat_MsgHdr *msg) ...@@ -1720,8 +1724,9 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
* *
* If the backend is known to be dead, we ignore this add. * If the backend is known to be dead, we ignore this add.
*/ */
deadbe = (PgStat_StatBeDead *)hash_search(pgStatBeDead, deadbe = (PgStat_StatBeDead *) hash_search(pgStatBeDead,
(char *)&(msg->m_procpid), HASH_FIND, &found); (void *) &(msg->m_procpid),
HASH_FIND, &found);
if (deadbe == NULL) if (deadbe == NULL)
{ {
fprintf(stderr, "PGSTAT: Dead backend table corrupted - abort\n"); fprintf(stderr, "PGSTAT: Dead backend table corrupted - abort\n");
...@@ -1747,9 +1752,9 @@ pgstat_add_backend(PgStat_MsgHdr *msg) ...@@ -1747,9 +1752,9 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
/* /*
* Lookup or create the database entry for this backends DB. * Lookup or create the database entry for this backends DB.
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
(char *)&(msg->m_databaseid), HASH_ENTER, (void *) &(msg->m_databaseid),
&found); HASH_ENTER, &found);
if (dbentry == NULL) if (dbentry == NULL)
{ {
fprintf(stderr, "PGSTAT: DB hash table corrupted - abort\n"); fprintf(stderr, "PGSTAT: DB hash table corrupted - abort\n");
...@@ -1773,7 +1778,7 @@ pgstat_add_backend(PgStat_MsgHdr *msg) ...@@ -1773,7 +1778,7 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
memset(&hash_ctl, 0, sizeof(hash_ctl)); memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid); hash_ctl.keysize = sizeof(Oid);
hash_ctl.datasize = sizeof(PgStat_StatTabEntry); hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
hash_ctl.hash = tag_hash; hash_ctl.hash = tag_hash;
dbentry->tables = hash_create(PGSTAT_TAB_HASH_SIZE, &hash_ctl, dbentry->tables = hash_create(PGSTAT_TAB_HASH_SIZE, &hash_ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
...@@ -1827,8 +1832,9 @@ pgstat_sub_backend(int procpid) ...@@ -1827,8 +1832,9 @@ pgstat_sub_backend(int procpid)
* the counting of backends, not the table access stats they * the counting of backends, not the table access stats they
* sent). * sent).
*/ */
deadbe = (PgStat_StatBeDead *)hash_search(pgStatBeDead, deadbe = (PgStat_StatBeDead *) hash_search(pgStatBeDead,
(char *)&procpid, HASH_ENTER, &found); (void *) &procpid,
HASH_ENTER, &found);
if (deadbe == NULL) if (deadbe == NULL)
{ {
fprintf(stderr, "PGSTAT: dead backend hash table corrupted " fprintf(stderr, "PGSTAT: dead backend hash table corrupted "
...@@ -1914,7 +1920,7 @@ pgstat_write_statsfile(void) ...@@ -1914,7 +1920,7 @@ pgstat_write_statsfile(void)
hash_destroy(dbentry->tables); hash_destroy(dbentry->tables);
hentry = hash_search(pgStatDBHash, hentry = hash_search(pgStatDBHash,
(char *)&(dbentry->databaseid), (void *) &(dbentry->databaseid),
HASH_REMOVE, &found); HASH_REMOVE, &found);
if (hentry == NULL) if (hentry == NULL)
{ {
...@@ -1959,7 +1965,7 @@ pgstat_write_statsfile(void) ...@@ -1959,7 +1965,7 @@ pgstat_write_statsfile(void)
if (--(tabentry->destroy) == 0) if (--(tabentry->destroy) == 0)
{ {
hentry = hash_search(dbentry->tables, hentry = hash_search(dbentry->tables,
(char *)&(tabentry->tableid), (void *) &(tabentry->tableid),
HASH_REMOVE, &found); HASH_REMOVE, &found);
if (hentry == NULL) if (hentry == NULL)
{ {
...@@ -2047,7 +2053,8 @@ pgstat_write_statsfile(void) ...@@ -2047,7 +2053,8 @@ pgstat_write_statsfile(void)
*/ */
if (--(deadbe->destroy) <= 0) if (--(deadbe->destroy) <= 0)
{ {
hentry = hash_search(pgStatBeDead, (char *)&(deadbe->procpid), hentry = hash_search(pgStatBeDead,
(void *) &(deadbe->procpid),
HASH_REMOVE, &found); HASH_REMOVE, &found);
if (hentry == NULL) if (hentry == NULL)
{ {
...@@ -2108,7 +2115,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb, ...@@ -2108,7 +2115,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
*/ */
memset(&hash_ctl, 0, sizeof(hash_ctl)); memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid); hash_ctl.keysize = sizeof(Oid);
hash_ctl.datasize = sizeof(PgStat_StatDBEntry); hash_ctl.entrysize = sizeof(PgStat_StatDBEntry);
hash_ctl.hash = tag_hash; hash_ctl.hash = tag_hash;
hash_ctl.hcxt = use_mcxt; hash_ctl.hcxt = use_mcxt;
*dbhash = hash_create(PGSTAT_DB_HASH_SIZE, &hash_ctl, *dbhash = hash_create(PGSTAT_DB_HASH_SIZE, &hash_ctl,
...@@ -2175,8 +2182,8 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb, ...@@ -2175,8 +2182,8 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
/* /*
* Add to the DB hash * Add to the DB hash
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(*dbhash, dbentry = (PgStat_StatDBEntry *) hash_search(*dbhash,
(char *)&dbbuf.databaseid, (void *) &dbbuf.databaseid,
HASH_ENTER, &found); HASH_ENTER, &found);
if (dbentry == NULL) if (dbentry == NULL)
{ {
...@@ -2223,7 +2230,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb, ...@@ -2223,7 +2230,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
memset(&hash_ctl, 0, sizeof(hash_ctl)); memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid); hash_ctl.keysize = sizeof(Oid);
hash_ctl.datasize = sizeof(PgStat_StatTabEntry); hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
hash_ctl.hash = tag_hash; hash_ctl.hash = tag_hash;
hash_ctl.hcxt = use_mcxt; hash_ctl.hcxt = use_mcxt;
dbentry->tables = hash_create(PGSTAT_TAB_HASH_SIZE, &hash_ctl, dbentry->tables = hash_create(PGSTAT_TAB_HASH_SIZE, &hash_ctl,
...@@ -2286,8 +2293,8 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb, ...@@ -2286,8 +2293,8 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
if (tabhash == NULL) if (tabhash == NULL)
break; break;
tabentry = (PgStat_StatTabEntry *)hash_search(tabhash, tabentry = (PgStat_StatTabEntry *) hash_search(tabhash,
(char *)&tabbuf.tableid, (void *) &tabbuf.tableid,
HASH_ENTER, &found); HASH_ENTER, &found);
if (tabentry == NULL) if (tabentry == NULL)
{ {
...@@ -2411,7 +2418,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb, ...@@ -2411,7 +2418,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
* Count backends per database here. * Count backends per database here.
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(*dbhash, dbentry = (PgStat_StatDBEntry *)hash_search(*dbhash,
(char *)&((*betab)[havebackends].databaseid), (void *) &((*betab)[havebackends].databaseid),
HASH_FIND, &found); HASH_FIND, &found);
if (found) if (found)
dbentry->n_backends++; dbentry->n_backends++;
...@@ -2525,8 +2532,8 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len) ...@@ -2525,8 +2532,8 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
/* /*
* Lookup the database in the hashtable. * Lookup the database in the hashtable.
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
(char *)&(msg->m_hdr.m_databaseid), (void *) &(msg->m_hdr.m_databaseid),
HASH_FIND, &found); HASH_FIND, &found);
if (dbentry == NULL) if (dbentry == NULL)
{ {
...@@ -2551,8 +2558,8 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len) ...@@ -2551,8 +2558,8 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
*/ */
for (i = 0; i < msg->m_nentries; i++) for (i = 0; i < msg->m_nentries; i++)
{ {
tabentry = (PgStat_StatTabEntry *)hash_search(dbentry->tables, tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
(char *)&(tabmsg[i].t_id), (void *) &(tabmsg[i].t_id),
HASH_ENTER, &found); HASH_ENTER, &found);
if (tabentry == NULL) if (tabentry == NULL)
{ {
...@@ -2625,8 +2632,8 @@ pgstat_recv_tabpurge(PgStat_MsgTabpurge *msg, int len) ...@@ -2625,8 +2632,8 @@ pgstat_recv_tabpurge(PgStat_MsgTabpurge *msg, int len)
/* /*
* Lookup the database in the hashtable. * Lookup the database in the hashtable.
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
(char *)&(msg->m_hdr.m_databaseid), (void *) &(msg->m_hdr.m_databaseid),
HASH_FIND, &found); HASH_FIND, &found);
if (dbentry == NULL) if (dbentry == NULL)
{ {
...@@ -2648,8 +2655,8 @@ pgstat_recv_tabpurge(PgStat_MsgTabpurge *msg, int len) ...@@ -2648,8 +2655,8 @@ pgstat_recv_tabpurge(PgStat_MsgTabpurge *msg, int len)
*/ */
for (i = 0; i < msg->m_nentries; i++) for (i = 0; i < msg->m_nentries; i++)
{ {
tabentry = (PgStat_StatTabEntry *)hash_search(dbentry->tables, tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
(char *)&(msg->m_tableid[i]), (void *) &(msg->m_tableid[i]),
HASH_FIND, &found); HASH_FIND, &found);
if (tabentry == NULL) if (tabentry == NULL)
{ {
...@@ -2685,8 +2692,8 @@ pgstat_recv_dropdb(PgStat_MsgDropdb *msg, int len) ...@@ -2685,8 +2692,8 @@ pgstat_recv_dropdb(PgStat_MsgDropdb *msg, int len)
/* /*
* Lookup the database in the hashtable. * Lookup the database in the hashtable.
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
(char *)&(msg->m_databaseid), (void *) &(msg->m_databaseid),
HASH_FIND, &found); HASH_FIND, &found);
if (dbentry == NULL) if (dbentry == NULL)
{ {
...@@ -2725,8 +2732,8 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len) ...@@ -2725,8 +2732,8 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
/* /*
* Lookup the database in the hashtable. * Lookup the database in the hashtable.
*/ */
dbentry = (PgStat_StatDBEntry *)hash_search(pgStatDBHash, dbentry = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
(char *)&(msg->m_hdr.m_databaseid), (void *) &(msg->m_hdr.m_databaseid),
HASH_FIND, &found); HASH_FIND, &found);
if (dbentry == NULL) if (dbentry == NULL)
{ {
...@@ -2753,7 +2760,7 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len) ...@@ -2753,7 +2760,7 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
memset(&hash_ctl, 0, sizeof(hash_ctl)); memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid); hash_ctl.keysize = sizeof(Oid);
hash_ctl.datasize = sizeof(PgStat_StatTabEntry); hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
hash_ctl.hash = tag_hash; hash_ctl.hash = tag_hash;
dbentry->tables = hash_create(PGSTAT_TAB_HASH_SIZE, &hash_ctl, dbentry->tables = hash_create(PGSTAT_TAB_HASH_SIZE, &hash_ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.44 2001/09/29 04:02:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.45 2001/10/01 05:36:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -280,9 +280,7 @@ BufferShmemSize(void) ...@@ -280,9 +280,7 @@ BufferShmemSize(void)
int size = 0; int size = 0;
/* size of shmem index hash table */ /* size of shmem index hash table */
size += hash_estimate_size(SHMEM_INDEX_SIZE, size += hash_estimate_size(SHMEM_INDEX_SIZE, sizeof(ShmemIndexEnt));
SHMEM_INDEX_KEYSIZE,
SHMEM_INDEX_DATASIZE);
/* size of buffer descriptors */ /* size of buffer descriptors */
size += MAXALIGN((NBuffers + 1) * sizeof(BufferDesc)); size += MAXALIGN((NBuffers + 1) * sizeof(BufferDesc));
...@@ -291,9 +289,7 @@ BufferShmemSize(void) ...@@ -291,9 +289,7 @@ BufferShmemSize(void)
size += NBuffers * MAXALIGN(BLCKSZ); size += NBuffers * MAXALIGN(BLCKSZ);
/* size of buffer hash table */ /* size of buffer hash table */
size += hash_estimate_size(NBuffers, size += hash_estimate_size(NBuffers, sizeof(BufferLookupEnt));
sizeof(BufferTag),
sizeof(Buffer));
#ifdef BMTRACE #ifdef BMTRACE
size += (BMT_LIMIT * sizeof(bmtrace)) + sizeof(long); size += (BMT_LIMIT * sizeof(bmtrace)) + sizeof(long);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.22 2001/09/29 04:02:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.23 2001/10/01 05:36:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -33,54 +33,42 @@ ...@@ -33,54 +33,42 @@
static HTAB *SharedBufHash; static HTAB *SharedBufHash;
typedef struct lookup
{
BufferTag key;
Buffer id;
} LookupEnt;
/* /*
* Initialize shmem hash table for mapping buffers * Initialize shmem hash table for mapping buffers
*/ */
void void
InitBufTable() InitBufTable(void)
{ {
HASHCTL info; HASHCTL info;
int hash_flags;
/* assume lock is held */ /* assume lock is held */
/* BufferTag maps to Buffer */ /* BufferTag maps to Buffer */
info.keysize = sizeof(BufferTag); info.keysize = sizeof(BufferTag);
info.datasize = sizeof(Buffer); info.entrysize = sizeof(BufferLookupEnt);
info.hash = tag_hash; info.hash = tag_hash;
hash_flags = (HASH_ELEM | HASH_FUNCTION); SharedBufHash = ShmemInitHash("Shared Buffer Lookup Table",
SharedBufHash = (HTAB *) ShmemInitHash("Shared Buffer Lookup Table",
NBuffers, NBuffers, NBuffers, NBuffers,
&info, hash_flags); &info,
HASH_ELEM | HASH_FUNCTION);
if (!SharedBufHash) if (!SharedBufHash)
{
elog(FATAL, "couldn't initialize shared buffer pool Hash Tbl"); elog(FATAL, "couldn't initialize shared buffer pool Hash Tbl");
exit(1);
}
} }
BufferDesc * BufferDesc *
BufTableLookup(BufferTag *tagPtr) BufTableLookup(BufferTag *tagPtr)
{ {
LookupEnt *result; BufferLookupEnt *result;
bool found; bool found;
if (tagPtr->blockNum == P_NEW) if (tagPtr->blockNum == P_NEW)
return NULL; return NULL;
result = (LookupEnt *) result = (BufferLookupEnt *)
hash_search(SharedBufHash, (char *) tagPtr, HASH_FIND, &found); hash_search(SharedBufHash, (void *) tagPtr, HASH_FIND, &found);
if (!result) if (!result)
{ {
...@@ -98,7 +86,7 @@ BufTableLookup(BufferTag *tagPtr) ...@@ -98,7 +86,7 @@ BufTableLookup(BufferTag *tagPtr)
bool bool
BufTableDelete(BufferDesc *buf) BufTableDelete(BufferDesc *buf)
{ {
LookupEnt *result; BufferLookupEnt *result;
bool found; bool found;
/* /*
...@@ -110,8 +98,8 @@ BufTableDelete(BufferDesc *buf) ...@@ -110,8 +98,8 @@ BufTableDelete(BufferDesc *buf)
buf->flags |= BM_DELETED; buf->flags |= BM_DELETED;
result = (LookupEnt *) result = (BufferLookupEnt *)
hash_search(SharedBufHash, (char *) &(buf->tag), HASH_REMOVE, &found); hash_search(SharedBufHash, (void *) &(buf->tag), HASH_REMOVE, &found);
if (!(result && found)) if (!(result && found))
{ {
...@@ -134,15 +122,15 @@ BufTableDelete(BufferDesc *buf) ...@@ -134,15 +122,15 @@ BufTableDelete(BufferDesc *buf)
bool bool
BufTableInsert(BufferDesc *buf) BufTableInsert(BufferDesc *buf)
{ {
LookupEnt *result; BufferLookupEnt *result;
bool found; bool found;
/* cannot insert it twice */ /* cannot insert it twice */
Assert(buf->flags & BM_DELETED); Assert(buf->flags & BM_DELETED);
buf->flags &= ~(BM_DELETED); buf->flags &= ~(BM_DELETED);
result = (LookupEnt *) result = (BufferLookupEnt *)
hash_search(SharedBufHash, (char *) &(buf->tag), HASH_ENTER, &found); hash_search(SharedBufHash, (void *) &(buf->tag), HASH_ENTER, &found);
if (!result) if (!result)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/freespace/freespace.c,v 1.5 2001/09/29 04:02:23 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/freespace/freespace.c,v 1.6 2001/10/01 05:36:14 tgl Exp $
* *
* *
* NOTES: * NOTES:
...@@ -100,9 +100,6 @@ struct FSMRelation ...@@ -100,9 +100,6 @@ struct FSMRelation
FSMChunk *relChunks; /* linked list of page info chunks */ FSMChunk *relChunks; /* linked list of page info chunks */
}; };
#define SHMEM_FSMHASH_KEYSIZE sizeof(RelFileNode)
#define SHMEM_FSMHASH_DATASIZE (sizeof(FSMRelation) - SHMEM_FSMHASH_KEYSIZE)
/* /*
* Info about individual pages in a relation is stored in chunks to reduce * Info about individual pages in a relation is stored in chunks to reduce
* allocation overhead. Note that we allow any chunk of a relation's list * allocation overhead. Note that we allow any chunk of a relation's list
...@@ -180,8 +177,8 @@ InitFreeSpaceMap(void) ...@@ -180,8 +177,8 @@ InitFreeSpaceMap(void)
MemSet(FreeSpaceMap, 0, sizeof(FSMHeader)); MemSet(FreeSpaceMap, 0, sizeof(FSMHeader));
/* Create hashtable for FSMRelations */ /* Create hashtable for FSMRelations */
info.keysize = SHMEM_FSMHASH_KEYSIZE; info.keysize = sizeof(RelFileNode);
info.datasize = SHMEM_FSMHASH_DATASIZE; info.entrysize = sizeof(FSMRelation);
info.hash = tag_hash; info.hash = tag_hash;
FreeSpaceMap->relHash = ShmemInitHash("Free Space Map Hash", FreeSpaceMap->relHash = ShmemInitHash("Free Space Map Hash",
...@@ -224,9 +221,7 @@ FreeSpaceShmemSize(void) ...@@ -224,9 +221,7 @@ FreeSpaceShmemSize(void)
size = MAXALIGN(sizeof(FSMHeader)); size = MAXALIGN(sizeof(FSMHeader));
/* hash table, including the FSMRelation objects */ /* hash table, including the FSMRelation objects */
size += hash_estimate_size(MaxFSMRelations, size += hash_estimate_size(MaxFSMRelations, sizeof(FSMRelation));
SHMEM_FSMHASH_KEYSIZE,
SHMEM_FSMHASH_DATASIZE);
/* FSMChunk objects */ /* FSMChunk objects */
nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1; nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1;
...@@ -498,7 +493,7 @@ lookup_fsm_rel(RelFileNode *rel) ...@@ -498,7 +493,7 @@ lookup_fsm_rel(RelFileNode *rel)
bool found; bool found;
fsmrel = (FSMRelation *) hash_search(FreeSpaceMap->relHash, fsmrel = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
(Pointer) rel, (void *) rel,
HASH_FIND, HASH_FIND,
&found); &found);
if (!fsmrel) if (!fsmrel)
...@@ -524,7 +519,7 @@ create_fsm_rel(RelFileNode *rel) ...@@ -524,7 +519,7 @@ create_fsm_rel(RelFileNode *rel)
bool found; bool found;
fsmrel = (FSMRelation *) hash_search(FreeSpaceMap->relHash, fsmrel = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
(Pointer) rel, (void *) rel,
HASH_ENTER, HASH_ENTER,
&found); &found);
if (!fsmrel) if (!fsmrel)
...@@ -595,7 +590,7 @@ delete_fsm_rel(FSMRelation *fsmrel) ...@@ -595,7 +590,7 @@ delete_fsm_rel(FSMRelation *fsmrel)
unlink_fsm_rel(fsmrel); unlink_fsm_rel(fsmrel);
FreeSpaceMap->numRels--; FreeSpaceMap->numRels--;
result = (FSMRelation *) hash_search(FreeSpaceMap->relHash, result = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
(Pointer) &(fsmrel->key), (void *) &(fsmrel->key),
HASH_REMOVE, HASH_REMOVE,
&found); &found);
if (!result || !found) if (!result || !found)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.59 2001/09/29 04:02:23 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.60 2001/10/01 05:36:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -191,7 +191,7 @@ InitShmemIndex(void) ...@@ -191,7 +191,7 @@ InitShmemIndex(void)
/* create the shared memory shmem index */ /* create the shared memory shmem index */
info.keysize = SHMEM_INDEX_KEYSIZE; info.keysize = SHMEM_INDEX_KEYSIZE;
info.datasize = SHMEM_INDEX_DATASIZE; info.entrysize = sizeof(ShmemIndexEnt);
hash_flags = HASH_ELEM; hash_flags = HASH_ELEM;
/* This will acquire the shmem index lock, but not release it. */ /* This will acquire the shmem index lock, but not release it. */
...@@ -208,7 +208,7 @@ InitShmemIndex(void) ...@@ -208,7 +208,7 @@ InitShmemIndex(void)
strncpy(item.key, "ShmemIndex", SHMEM_INDEX_KEYSIZE); strncpy(item.key, "ShmemIndex", SHMEM_INDEX_KEYSIZE);
result = (ShmemIndexEnt *) result = (ShmemIndexEnt *)
hash_search(ShmemIndex, (char *) &item, HASH_ENTER, &found); hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
if (!result) if (!result)
elog(FATAL, "InitShmemIndex: corrupted shmem index"); elog(FATAL, "InitShmemIndex: corrupted shmem index");
...@@ -248,17 +248,15 @@ ShmemInitHash(char *name, /* table string name for shmem index */ ...@@ -248,17 +248,15 @@ ShmemInitHash(char *name, /* table string name for shmem index */
* can't grow or other backends wouldn't be able to find it. So, make * can't grow or other backends wouldn't be able to find it. So, make
* sure we make it big enough to start with. * sure we make it big enough to start with.
* *
* The segbase is for calculating pointer values. The shared memory * The shared memory allocator must be specified too.
* allocator must be specified too.
*/ */
infoP->dsize = infoP->max_dsize = hash_select_dirsize(max_size); infoP->dsize = infoP->max_dsize = hash_select_dirsize(max_size);
infoP->segbase = (long *) ShmemBase;
infoP->alloc = ShmemAlloc; infoP->alloc = ShmemAlloc;
hash_flags |= HASH_SHARED_MEM | HASH_DIRSIZE; hash_flags |= HASH_SHARED_MEM | HASH_DIRSIZE;
/* look it up in the shmem index */ /* look it up in the shmem index */
location = ShmemInitStruct(name, location = ShmemInitStruct(name,
sizeof(HHDR) + infoP->dsize * sizeof(SEG_OFFSET), sizeof(HASHHDR) + infoP->dsize * sizeof(HASHSEGMENT),
&found); &found);
/* /*
...@@ -266,18 +264,18 @@ ShmemInitHash(char *name, /* table string name for shmem index */ ...@@ -266,18 +264,18 @@ ShmemInitHash(char *name, /* table string name for shmem index */
* message since they have more information * message since they have more information
*/ */
if (location == NULL) if (location == NULL)
return 0; return NULL;
/* /*
* it already exists, attach to it rather than allocate and initialize * if it already exists, attach to it rather than allocate and initialize
* new space * new space
*/ */
if (found) if (found)
hash_flags |= HASH_ATTACH; hash_flags |= HASH_ATTACH;
/* Now provide the header and directory pointers */ /* Now provide the header and directory pointers */
infoP->hctl = (long *) location; infoP->hctl = (HASHHDR *) location;
infoP->dir = (long *) (((char *) location) + sizeof(HHDR)); infoP->dir = (HASHSEGMENT *) (((char *) location) + sizeof(HASHHDR));
return hash_create(init_size, infoP, hash_flags); return hash_create(init_size, infoP, hash_flags);
} }
...@@ -325,7 +323,7 @@ ShmemInitStruct(char *name, Size size, bool *foundPtr) ...@@ -325,7 +323,7 @@ ShmemInitStruct(char *name, Size size, bool *foundPtr)
/* look it up in the shmem index */ /* look it up in the shmem index */
result = (ShmemIndexEnt *) result = (ShmemIndexEnt *)
hash_search(ShmemIndex, (char *) &item, HASH_ENTER, foundPtr); hash_search(ShmemIndex, (void *) &item, HASH_ENTER, foundPtr);
if (!result) if (!result)
{ {
...@@ -359,7 +357,7 @@ ShmemInitStruct(char *name, Size size, bool *foundPtr) ...@@ -359,7 +357,7 @@ ShmemInitStruct(char *name, Size size, bool *foundPtr)
{ {
/* out of memory */ /* out of memory */
Assert(ShmemIndex); Assert(ShmemIndex);
hash_search(ShmemIndex, (char *) &item, HASH_REMOVE, foundPtr); hash_search(ShmemIndex, (void *) &item, HASH_REMOVE, foundPtr);
LWLockRelease(ShmemIndexLock); LWLockRelease(ShmemIndexLock);
*foundPtr = FALSE; *foundPtr = FALSE;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.98 2001/09/30 00:45:47 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.99 2001/10/01 05:36:14 tgl Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
...@@ -308,8 +308,8 @@ LockMethodTableInit(char *tabName, ...@@ -308,8 +308,8 @@ LockMethodTableInit(char *tabName,
* allocate a hash table for LOCK structs. This is used to store * allocate a hash table for LOCK structs. This is used to store
* per-locked-object information. * per-locked-object information.
*/ */
info.keysize = SHMEM_LOCKTAB_KEYSIZE; info.keysize = sizeof(LOCKTAG);
info.datasize = SHMEM_LOCKTAB_DATASIZE; info.entrysize = sizeof(LOCK);
info.hash = tag_hash; info.hash = tag_hash;
hash_flags = (HASH_ELEM | HASH_FUNCTION); hash_flags = (HASH_ELEM | HASH_FUNCTION);
...@@ -328,8 +328,8 @@ LockMethodTableInit(char *tabName, ...@@ -328,8 +328,8 @@ LockMethodTableInit(char *tabName,
* allocate a hash table for HOLDER structs. This is used to store * allocate a hash table for HOLDER structs. This is used to store
* per-lock-holder information. * per-lock-holder information.
*/ */
info.keysize = SHMEM_HOLDERTAB_KEYSIZE; info.keysize = sizeof(HOLDERTAG);
info.datasize = SHMEM_HOLDERTAB_DATASIZE; info.entrysize = sizeof(HOLDER);
info.hash = tag_hash; info.hash = tag_hash;
hash_flags = (HASH_ELEM | HASH_FUNCTION); hash_flags = (HASH_ELEM | HASH_FUNCTION);
...@@ -485,7 +485,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -485,7 +485,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* Find or create a lock with this tag * Find or create a lock with this tag
*/ */
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(lockMethodTable->lockHash->hash == tag_hash);
lock = (LOCK *) hash_search(lockMethodTable->lockHash, (Pointer) locktag, lock = (LOCK *) hash_search(lockMethodTable->lockHash,
(void *) locktag,
HASH_ENTER, &found); HASH_ENTER, &found);
if (!lock) if (!lock)
{ {
...@@ -530,7 +531,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -530,7 +531,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* Find or create a holder entry with this tag * Find or create a holder entry with this tag
*/ */
holderTable = lockMethodTable->holderHash; holderTable = lockMethodTable->holderHash;
holder = (HOLDER *) hash_search(holderTable, (Pointer) &holdertag, holder = (HOLDER *) hash_search(holderTable,
(void *) &holdertag,
HASH_ENTER, &found); HASH_ENTER, &found);
if (!holder) if (!holder)
{ {
...@@ -655,7 +657,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -655,7 +657,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
SHMQueueDelete(&holder->lockLink); SHMQueueDelete(&holder->lockLink);
SHMQueueDelete(&holder->procLink); SHMQueueDelete(&holder->procLink);
holder = (HOLDER *) hash_search(holderTable, holder = (HOLDER *) hash_search(holderTable,
(Pointer) holder, (void *) holder,
HASH_REMOVE, &found); HASH_REMOVE, &found);
if (!holder || !found) if (!holder || !found)
elog(NOTICE, "LockAcquire: remove holder, table corrupted"); elog(NOTICE, "LockAcquire: remove holder, table corrupted");
...@@ -1019,7 +1021,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1019,7 +1021,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* Find a lock with this tag * Find a lock with this tag
*/ */
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(lockMethodTable->lockHash->hash == tag_hash);
lock = (LOCK *) hash_search(lockMethodTable->lockHash, (Pointer) locktag, lock = (LOCK *) hash_search(lockMethodTable->lockHash,
(void *) locktag,
HASH_FIND, &found); HASH_FIND, &found);
/* /*
...@@ -1051,7 +1054,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1051,7 +1054,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
TransactionIdStore(xid, &holdertag.xid); TransactionIdStore(xid, &holdertag.xid);
holderTable = lockMethodTable->holderHash; holderTable = lockMethodTable->holderHash;
holder = (HOLDER *) hash_search(holderTable, (Pointer) &holdertag, holder = (HOLDER *) hash_search(holderTable,
(void *) &holdertag,
HASH_FIND_SAVE, &found); HASH_FIND_SAVE, &found);
if (!holder || !found) if (!holder || !found)
{ {
...@@ -1124,7 +1128,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1124,7 +1128,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
*/ */
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(lockMethodTable->lockHash->hash == tag_hash);
lock = (LOCK *) hash_search(lockMethodTable->lockHash, lock = (LOCK *) hash_search(lockMethodTable->lockHash,
(Pointer) &(lock->tag), (void *) &(lock->tag),
HASH_REMOVE, HASH_REMOVE,
&found); &found);
if (!lock || !found) if (!lock || !found)
...@@ -1153,7 +1157,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -1153,7 +1157,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
HOLDER_PRINT("LockRelease: deleting", holder); HOLDER_PRINT("LockRelease: deleting", holder);
SHMQueueDelete(&holder->lockLink); SHMQueueDelete(&holder->lockLink);
SHMQueueDelete(&holder->procLink); SHMQueueDelete(&holder->procLink);
holder = (HOLDER *) hash_search(holderTable, (Pointer) &holder, holder = (HOLDER *) hash_search(holderTable,
(void *) &holder,
HASH_REMOVE_SAVED, &found); HASH_REMOVE_SAVED, &found);
if (!holder || !found) if (!holder || !found)
{ {
...@@ -1306,7 +1311,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc, ...@@ -1306,7 +1311,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
* remove the holder entry from the hashtable * remove the holder entry from the hashtable
*/ */
holder = (HOLDER *) hash_search(lockMethodTable->holderHash, holder = (HOLDER *) hash_search(lockMethodTable->holderHash,
(Pointer) holder, (void *) holder,
HASH_REMOVE, HASH_REMOVE,
&found); &found);
if (!holder || !found) if (!holder || !found)
...@@ -1326,7 +1331,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc, ...@@ -1326,7 +1331,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
LOCK_PRINT("LockReleaseAll: deleting", lock, 0); LOCK_PRINT("LockReleaseAll: deleting", lock, 0);
Assert(lockMethodTable->lockHash->hash == tag_hash); Assert(lockMethodTable->lockHash->hash == tag_hash);
lock = (LOCK *) hash_search(lockMethodTable->lockHash, lock = (LOCK *) hash_search(lockMethodTable->lockHash,
(Pointer) &(lock->tag), (void *) &(lock->tag),
HASH_REMOVE, &found); HASH_REMOVE, &found);
if (!lock || !found) if (!lock || !found)
{ {
...@@ -1364,14 +1369,10 @@ LockShmemSize(int maxBackends) ...@@ -1364,14 +1369,10 @@ LockShmemSize(int maxBackends)
* lockMethodTable->ctl */ * lockMethodTable->ctl */
/* lockHash table */ /* lockHash table */
size += hash_estimate_size(max_table_size, size += hash_estimate_size(max_table_size, sizeof(LOCK));
SHMEM_LOCKTAB_KEYSIZE,
SHMEM_LOCKTAB_DATASIZE);
/* holderHash table */ /* holderHash table */
size += hash_estimate_size(max_table_size, size += hash_estimate_size(max_table_size, sizeof(HOLDER));
SHMEM_HOLDERTAB_KEYSIZE,
SHMEM_HOLDERTAB_DATASIZE);
/* /*
* Since the lockHash entry count above is only an estimate, add 10% * Since the lockHash entry count above is only an estimate, add 10%
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.25 2001/09/29 04:02:25 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.26 2001/10/01 05:36:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -103,10 +103,10 @@ mminit() ...@@ -103,10 +103,10 @@ mminit()
} }
info.keysize = sizeof(MMCacheTag); info.keysize = sizeof(MMCacheTag);
info.datasize = sizeof(MMHashEntry) - sizeof(MMCacheTag); info.entrysize = sizeof(MMHashEntry);
info.hash = tag_hash; info.hash = tag_hash;
MMCacheHT = (HTAB *) ShmemInitHash("Main memory store HT", MMCacheHT = ShmemInitHash("Main memory store HT",
MMNBUFFERS, MMNBUFFERS, MMNBUFFERS, MMNBUFFERS,
&info, (HASH_ELEM | HASH_FUNCTION)); &info, (HASH_ELEM | HASH_FUNCTION));
...@@ -117,10 +117,10 @@ mminit() ...@@ -117,10 +117,10 @@ mminit()
} }
info.keysize = sizeof(MMRelTag); info.keysize = sizeof(MMRelTag);
info.datasize = sizeof(MMRelHashEntry) - sizeof(MMRelTag); info.entrysize = sizeof(MMRelHashEntry);
info.hash = tag_hash; info.hash = tag_hash;
MMRelCacheHT = (HTAB *) ShmemInitHash("Main memory rel HT", MMRelCacheHT = ShmemInitHash("Main memory rel HT",
MMNRELATIONS, MMNRELATIONS, MMNRELATIONS, MMNRELATIONS,
&info, (HASH_ELEM | HASH_FUNCTION)); &info, (HASH_ELEM | HASH_FUNCTION));
...@@ -180,7 +180,8 @@ mmcreate(Relation reln) ...@@ -180,7 +180,8 @@ mmcreate(Relation reln)
tag.mmrt_dbid = MyDatabaseId; tag.mmrt_dbid = MyDatabaseId;
entry = (MMRelHashEntry *) hash_search(MMRelCacheHT, entry = (MMRelHashEntry *) hash_search(MMRelCacheHT,
(char *) &tag, HASH_ENTER, &found); (void *) &tag,
HASH_ENTER, &found);
if (entry == (MMRelHashEntry *) NULL) if (entry == (MMRelHashEntry *) NULL)
{ {
...@@ -224,7 +225,7 @@ mmunlink(RelFileNode rnode) ...@@ -224,7 +225,7 @@ mmunlink(RelFileNode rnode)
&& MMBlockTags[i].mmct_relid == rnode.relNode) && MMBlockTags[i].mmct_relid == rnode.relNode)
{ {
entry = (MMHashEntry *) hash_search(MMCacheHT, entry = (MMHashEntry *) hash_search(MMCacheHT,
(char *) &MMBlockTags[i], (void *) &MMBlockTags[i],
HASH_REMOVE, &found); HASH_REMOVE, &found);
if (entry == (MMHashEntry *) NULL || !found) if (entry == (MMHashEntry *) NULL || !found)
{ {
...@@ -239,7 +240,8 @@ mmunlink(RelFileNode rnode) ...@@ -239,7 +240,8 @@ mmunlink(RelFileNode rnode)
rtag.mmrt_dbid = rnode.tblNode; rtag.mmrt_dbid = rnode.tblNode;
rtag.mmrt_relid = rnode.relNode; rtag.mmrt_relid = rnode.relNode;
rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT, (char *) &rtag, rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT,
(void *) &rtag,
HASH_REMOVE, &found); HASH_REMOVE, &found);
if (rentry == (MMRelHashEntry *) NULL || !found) if (rentry == (MMRelHashEntry *) NULL || !found)
...@@ -302,7 +304,8 @@ mmextend(Relation reln, BlockNumber blocknum, char *buffer) ...@@ -302,7 +304,8 @@ mmextend(Relation reln, BlockNumber blocknum, char *buffer)
(*MMCurTop)++; (*MMCurTop)++;
} }
rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT, (char *) &rtag, rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT,
(void *) &rtag,
HASH_FIND, &found); HASH_FIND, &found);
if (rentry == (MMRelHashEntry *) NULL || !found) if (rentry == (MMRelHashEntry *) NULL || !found)
{ {
...@@ -312,7 +315,8 @@ mmextend(Relation reln, BlockNumber blocknum, char *buffer) ...@@ -312,7 +315,8 @@ mmextend(Relation reln, BlockNumber blocknum, char *buffer)
tag.mmct_blkno = rentry->mmrhe_nblocks; tag.mmct_blkno = rentry->mmrhe_nblocks;
entry = (MMHashEntry *) hash_search(MMCacheHT, (char *) &tag, entry = (MMHashEntry *) hash_search(MMCacheHT,
(void *) &tag,
HASH_ENTER, &found); HASH_ENTER, &found);
if (entry == (MMHashEntry *) NULL || found) if (entry == (MMHashEntry *) NULL || found)
{ {
...@@ -381,7 +385,8 @@ mmread(Relation reln, BlockNumber blocknum, char *buffer) ...@@ -381,7 +385,8 @@ mmread(Relation reln, BlockNumber blocknum, char *buffer)
tag.mmct_blkno = blocknum; tag.mmct_blkno = blocknum;
LWLockAcquire(MMCacheLock, LW_EXCLUSIVE); LWLockAcquire(MMCacheLock, LW_EXCLUSIVE);
entry = (MMHashEntry *) hash_search(MMCacheHT, (char *) &tag, entry = (MMHashEntry *) hash_search(MMCacheHT,
(void *) &tag,
HASH_FIND, &found); HASH_FIND, &found);
if (entry == (MMHashEntry *) NULL) if (entry == (MMHashEntry *) NULL)
...@@ -428,7 +433,8 @@ mmwrite(Relation reln, BlockNumber blocknum, char *buffer) ...@@ -428,7 +433,8 @@ mmwrite(Relation reln, BlockNumber blocknum, char *buffer)
tag.mmct_blkno = blocknum; tag.mmct_blkno = blocknum;
LWLockAcquire(MMCacheLock, LW_EXCLUSIVE); LWLockAcquire(MMCacheLock, LW_EXCLUSIVE);
entry = (MMHashEntry *) hash_search(MMCacheHT, (char *) &tag, entry = (MMHashEntry *) hash_search(MMCacheHT,
(void *) &tag,
HASH_FIND, &found); HASH_FIND, &found);
if (entry == (MMHashEntry *) NULL) if (entry == (MMHashEntry *) NULL)
...@@ -502,7 +508,8 @@ mmnblocks(Relation reln) ...@@ -502,7 +508,8 @@ mmnblocks(Relation reln)
LWLockAcquire(MMCacheLock, LW_EXCLUSIVE); LWLockAcquire(MMCacheLock, LW_EXCLUSIVE);
rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT, (char *) &rtag, rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT,
(void *) &rtag,
HASH_FIND, &found); HASH_FIND, &found);
if (rentry == (MMRelHashEntry *) NULL) if (rentry == (MMRelHashEntry *) NULL)
...@@ -558,16 +565,12 @@ MMShmemSize() ...@@ -558,16 +565,12 @@ MMShmemSize()
/* /*
* first compute space occupied by the (dbid,relid,blkno) hash table * first compute space occupied by the (dbid,relid,blkno) hash table
*/ */
size += hash_estimate_size(MMNBUFFERS, size += hash_estimate_size(MMNBUFFERS, sizeof(MMHashEntry));
0, /* MMHashEntry includes key */
sizeof(MMHashEntry));
/* /*
* now do the same for the rel hash table * now do the same for the rel hash table
*/ */
size += hash_estimate_size(MMNRELATIONS, size += hash_estimate_size(MMNRELATIONS, sizeof(MMRelHashEntry));
0, /* MMRelHashEntry includes key */
sizeof(MMRelHashEntry));
/* /*
* finally, add in the memory block we use directly * finally, add in the memory block we use directly
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group * Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group
* Copyright 1999 Jan Wieck * Copyright 1999 Jan Wieck
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.25 2001/05/31 17:32:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.26 2001/10/01 05:36:16 tgl Exp $
* *
* ---------- * ----------
*/ */
...@@ -2988,12 +2988,13 @@ ri_InitHashTables(void) ...@@ -2988,12 +2988,13 @@ ri_InitHashTables(void)
memset(&ctl, 0, sizeof(ctl)); memset(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(RI_QueryKey); ctl.keysize = sizeof(RI_QueryKey);
ctl.datasize = sizeof(void *); ctl.entrysize = sizeof(RI_QueryHashEntry);
ri_query_cache = hash_create(RI_INIT_QUERYHASHSIZE, &ctl, HASH_ELEM); ctl.hash = tag_hash;
ri_query_cache = hash_create(RI_INIT_QUERYHASHSIZE, &ctl,
HASH_ELEM | HASH_FUNCTION);
memset(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(Oid); ctl.keysize = sizeof(Oid);
ctl.datasize = sizeof(Oid) + sizeof(FmgrInfo); ctl.entrysize = sizeof(RI_OpreqHashEntry);
ctl.hash = tag_hash; ctl.hash = tag_hash;
ri_opreq_cache = hash_create(RI_INIT_OPREQHASHSIZE, &ctl, ri_opreq_cache = hash_create(RI_INIT_OPREQHASHSIZE, &ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
...@@ -3023,7 +3024,8 @@ ri_FetchPreparedPlan(RI_QueryKey *key) ...@@ -3023,7 +3024,8 @@ ri_FetchPreparedPlan(RI_QueryKey *key)
* Lookup for the key * Lookup for the key
*/ */
entry = (RI_QueryHashEntry *) hash_search(ri_query_cache, entry = (RI_QueryHashEntry *) hash_search(ri_query_cache,
(char *) key, HASH_FIND, &found); (void *) key,
HASH_FIND, &found);
if (entry == NULL) if (entry == NULL)
elog(FATAL, "error in RI plan cache"); elog(FATAL, "error in RI plan cache");
if (!found) if (!found)
...@@ -3054,7 +3056,8 @@ ri_HashPreparedPlan(RI_QueryKey *key, void *plan) ...@@ -3054,7 +3056,8 @@ ri_HashPreparedPlan(RI_QueryKey *key, void *plan)
* Add the new plan. * Add the new plan.
*/ */
entry = (RI_QueryHashEntry *) hash_search(ri_query_cache, entry = (RI_QueryHashEntry *) hash_search(ri_query_cache,
(char *) key, HASH_ENTER, &found); (void *) key,
HASH_ENTER, &found);
if (entry == NULL) if (entry == NULL)
elog(FATAL, "can't insert into RI plan cache"); elog(FATAL, "can't insert into RI plan cache");
entry->plan = plan; entry->plan = plan;
...@@ -3224,14 +3227,15 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue) ...@@ -3224,14 +3227,15 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue)
/* /*
* On the first call initialize the hashtable * On the first call initialize the hashtable
*/ */
if (!ri_query_cache) if (!ri_opreq_cache)
ri_InitHashTables(); ri_InitHashTables();
/* /*
* Try to find the '=' operator for this type in our cache * Try to find the '=' operator for this type in our cache
*/ */
entry = (RI_OpreqHashEntry *) hash_search(ri_opreq_cache, entry = (RI_OpreqHashEntry *) hash_search(ri_opreq_cache,
(char *) &typeid, HASH_FIND, &found); (void *) &typeid,
HASH_FIND, &found);
if (entry == NULL) if (entry == NULL)
elog(FATAL, "error in RI operator cache"); elog(FATAL, "error in RI operator cache");
...@@ -3271,9 +3275,8 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue) ...@@ -3271,9 +3275,8 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue)
MemoryContextSwitchTo(oldcontext); MemoryContextSwitchTo(oldcontext);
entry = (RI_OpreqHashEntry *) hash_search(ri_opreq_cache, entry = (RI_OpreqHashEntry *) hash_search(ri_opreq_cache,
(char *) &typeid, (void *) &typeid,
HASH_ENTER, HASH_ENTER, &found);
&found);
if (entry == NULL) if (entry == NULL)
elog(FATAL, "can't insert into RI operator cache"); elog(FATAL, "can't insert into RI operator cache");
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.143 2001/08/25 18:52:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.144 2001/10/01 05:36:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -132,7 +132,7 @@ typedef struct relnodecacheent ...@@ -132,7 +132,7 @@ typedef struct relnodecacheent
} RelNodeCacheEnt; } RelNodeCacheEnt;
/* /*
* macros to manipulate name cache and id cache * macros to manipulate the lookup hashtables
*/ */
#define RelationCacheInsert(RELATION) \ #define RelationCacheInsert(RELATION) \
do { \ do { \
...@@ -149,7 +149,7 @@ do { \ ...@@ -149,7 +149,7 @@ do { \
/* used to give notice -- now just keep quiet */ ; \ /* used to give notice -- now just keep quiet */ ; \
namehentry->reldesc = RELATION; \ namehentry->reldesc = RELATION; \
idhentry = (RelIdCacheEnt*)hash_search(RelationIdCache, \ idhentry = (RelIdCacheEnt*)hash_search(RelationIdCache, \
(char *)&(RELATION->rd_id), \ (void *) &(RELATION->rd_id), \
HASH_ENTER, \ HASH_ENTER, \
&found); \ &found); \
if (idhentry == NULL) \ if (idhentry == NULL) \
...@@ -158,7 +158,7 @@ do { \ ...@@ -158,7 +158,7 @@ do { \
/* used to give notice -- now just keep quiet */ ; \ /* used to give notice -- now just keep quiet */ ; \
idhentry->reldesc = RELATION; \ idhentry->reldesc = RELATION; \
nodentry = (RelNodeCacheEnt*)hash_search(RelationNodeCache, \ nodentry = (RelNodeCacheEnt*)hash_search(RelationNodeCache, \
(char *)&(RELATION->rd_node), \ (void *) &(RELATION->rd_node), \
HASH_ENTER, \ HASH_ENTER, \
&found); \ &found); \
if (nodentry == NULL) \ if (nodentry == NULL) \
...@@ -172,7 +172,7 @@ do { \ ...@@ -172,7 +172,7 @@ do { \
do { \ do { \
RelNameCacheEnt *hentry; bool found; \ RelNameCacheEnt *hentry; bool found; \
hentry = (RelNameCacheEnt*)hash_search(RelationNameCache, \ hentry = (RelNameCacheEnt*)hash_search(RelationNameCache, \
(char *)NAME,HASH_FIND,&found); \ (void *) (NAME),HASH_FIND,&found); \
if (hentry == NULL) \ if (hentry == NULL) \
elog(FATAL, "error in CACHE"); \ elog(FATAL, "error in CACHE"); \
if (found) \ if (found) \
...@@ -186,7 +186,7 @@ do { \ ...@@ -186,7 +186,7 @@ do { \
RelIdCacheEnt *hentry; \ RelIdCacheEnt *hentry; \
bool found; \ bool found; \
hentry = (RelIdCacheEnt*)hash_search(RelationIdCache, \ hentry = (RelIdCacheEnt*)hash_search(RelationIdCache, \
(char *)&(ID),HASH_FIND, &found); \ (void *)&(ID),HASH_FIND, &found); \
if (hentry == NULL) \ if (hentry == NULL) \
elog(FATAL, "error in CACHE"); \ elog(FATAL, "error in CACHE"); \
if (found) \ if (found) \
...@@ -200,7 +200,7 @@ do { \ ...@@ -200,7 +200,7 @@ do { \
RelNodeCacheEnt *hentry; \ RelNodeCacheEnt *hentry; \
bool found; \ bool found; \
hentry = (RelNodeCacheEnt*)hash_search(RelationNodeCache, \ hentry = (RelNodeCacheEnt*)hash_search(RelationNodeCache, \
(char *)&(NODE),HASH_FIND, &found); \ (void *)&(NODE),HASH_FIND, &found); \
if (hentry == NULL) \ if (hentry == NULL) \
elog(FATAL, "error in CACHE"); \ elog(FATAL, "error in CACHE"); \
if (found) \ if (found) \
...@@ -223,14 +223,14 @@ do { \ ...@@ -223,14 +223,14 @@ do { \
if (!found) \ if (!found) \
elog(NOTICE, "trying to delete a reldesc that does not exist."); \ elog(NOTICE, "trying to delete a reldesc that does not exist."); \
idhentry = (RelIdCacheEnt*)hash_search(RelationIdCache, \ idhentry = (RelIdCacheEnt*)hash_search(RelationIdCache, \
(char *)&(RELATION->rd_id), \ (void *)&(RELATION->rd_id), \
HASH_REMOVE, &found); \ HASH_REMOVE, &found); \
if (idhentry == NULL) \ if (idhentry == NULL) \
elog(FATAL, "can't delete from relation descriptor cache"); \ elog(FATAL, "can't delete from relation descriptor cache"); \
if (!found) \ if (!found) \
elog(NOTICE, "trying to delete a reldesc that does not exist."); \ elog(NOTICE, "trying to delete a reldesc that does not exist."); \
nodentry = (RelNodeCacheEnt*)hash_search(RelationNodeCache, \ nodentry = (RelNodeCacheEnt*)hash_search(RelationNodeCache, \
(char *)&(RELATION->rd_node), \ (void *)&(RELATION->rd_node), \
HASH_REMOVE, &found); \ HASH_REMOVE, &found); \
if (nodentry == NULL) \ if (nodentry == NULL) \
elog(FATAL, "can't delete from relation descriptor cache"); \ elog(FATAL, "can't delete from relation descriptor cache"); \
...@@ -2092,17 +2092,19 @@ RelationCacheInitialize(void) ...@@ -2092,17 +2092,19 @@ RelationCacheInitialize(void)
/* /*
* create global caches * create global caches
*/ */
MemSet(&ctl, 0, (int) sizeof(ctl)); MemSet(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(NameData); ctl.keysize = sizeof(NameData);
ctl.datasize = sizeof(Relation); ctl.entrysize = sizeof(RelNameCacheEnt);
RelationNameCache = hash_create(INITRELCACHESIZE, &ctl, HASH_ELEM); RelationNameCache = hash_create(INITRELCACHESIZE, &ctl, HASH_ELEM);
ctl.keysize = sizeof(Oid); ctl.keysize = sizeof(Oid);
ctl.entrysize = sizeof(RelIdCacheEnt);
ctl.hash = tag_hash; ctl.hash = tag_hash;
RelationIdCache = hash_create(INITRELCACHESIZE, &ctl, RelationIdCache = hash_create(INITRELCACHESIZE, &ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
ctl.keysize = sizeof(RelFileNode); ctl.keysize = sizeof(RelFileNode);
ctl.entrysize = sizeof(RelNodeCacheEnt);
ctl.hash = tag_hash; ctl.hash = tag_hash;
RelationNodeCache = hash_create(INITRELCACHESIZE, &ctl, RelationNodeCache = hash_create(INITRELCACHESIZE, &ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
...@@ -2182,17 +2184,19 @@ CreateDummyCaches(void) ...@@ -2182,17 +2184,19 @@ CreateDummyCaches(void)
oldcxt = MemoryContextSwitchTo(CacheMemoryContext); oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
MemSet(&ctl, 0, (int) sizeof(ctl)); MemSet(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(NameData); ctl.keysize = sizeof(NameData);
ctl.datasize = sizeof(Relation); ctl.entrysize = sizeof(RelNameCacheEnt);
RelationNameCache = hash_create(INITRELCACHESIZE, &ctl, HASH_ELEM); RelationNameCache = hash_create(INITRELCACHESIZE, &ctl, HASH_ELEM);
ctl.keysize = sizeof(Oid); ctl.keysize = sizeof(Oid);
ctl.entrysize = sizeof(RelIdCacheEnt);
ctl.hash = tag_hash; ctl.hash = tag_hash;
RelationIdCache = hash_create(INITRELCACHESIZE, &ctl, RelationIdCache = hash_create(INITRELCACHESIZE, &ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
ctl.keysize = sizeof(RelFileNode); ctl.keysize = sizeof(RelFileNode);
ctl.entrysize = sizeof(RelNodeCacheEnt);
ctl.hash = tag_hash; ctl.hash = tag_hash;
RelationNodeCache = hash_create(INITRELCACHESIZE, &ctl, RelationNodeCache = hash_create(INITRELCACHESIZE, &ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION);
......
This diff is collapsed.
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* hashfn.c * hashfn.c
* Hash functions for use in dynahash.c hashtables
* *
* *
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
...@@ -8,7 +9,7 @@ ...@@ -8,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/hash/hashfn.c,v 1.13 2001/01/24 19:43:15 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/hash/hashfn.c,v 1.14 2001/10/01 05:36:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,155 +18,100 @@ ...@@ -17,155 +18,100 @@
#include "utils/hsearch.h" #include "utils/hsearch.h"
/* /*
* Assume that we've already split the bucket to which this * string_hash: hash function for keys that are null-terminated strings.
* key hashes, calculate that bucket, and check that in fact *
* we did already split it. * NOTE: since dynahash.c backs this up with a fixed-length memcmp(),
* the key must actually be zero-padded to the specified maximum length
* to work correctly. However, if it is known that nothing after the
* first zero byte is interesting, this is the right hash function to use.
*
* NOTE: this is the default hash function if none is specified.
*/ */
long long
string_hash(char *key, int keysize) string_hash(void *key, int keysize)
{ {
int h;
unsigned char *k = (unsigned char *) key; unsigned char *k = (unsigned char *) key;
long h = 0;
h = 0;
/*
* Convert string to integer
*/
while (*k) while (*k)
h = h * PRIME1 ^ (*k++ - ' '); h = (h * PRIME1) ^ (*k++);
h %= PRIME2; h %= PRIME2;
return h; return h;
} }
/*
* tag_hash: hash function for fixed-size tag values
*
* NB: we assume that the supplied key is aligned at least on an 'int'
* boundary, if its size is >= sizeof(int).
*/
long long
tag_hash(int *key, int keysize) tag_hash(void *key, int keysize)
{ {
int *k = (int *) key;
long h = 0; long h = 0;
/* /*
* Convert tag to integer; Use four byte chunks in a "jump table" to * Use four byte chunks in a "jump table" to go a little faster.
* go a little faster. Currently the maximum keysize is 16 (mar 17 *
* 1992) I have put in cases for up to 24. Bigger than this will * Currently the maximum keysize is 16 (mar 17 1992). I have put in
* resort to the old behavior of the for loop. (see the default case). * cases for up to 32. Bigger than this will resort to a for loop
* (see the default case).
*/ */
switch (keysize) switch (keysize)
{ {
case 8 * sizeof(int):
h = (h * PRIME1) ^ (*k++);
/* fall through */
case 7 * sizeof(int):
h = (h * PRIME1) ^ (*k++);
/* fall through */
case 6 * sizeof(int): case 6 * sizeof(int):
h = h * PRIME1 ^ (*key); h = (h * PRIME1) ^ (*k++);
key++;
/* fall through */ /* fall through */
case 5 * sizeof(int): case 5 * sizeof(int):
h = h * PRIME1 ^ (*key); h = (h * PRIME1) ^ (*k++);
key++;
/* fall through */ /* fall through */
case 4 * sizeof(int): case 4 * sizeof(int):
h = h * PRIME1 ^ (*key); h = (h * PRIME1) ^ (*k++);
key++;
/* fall through */ /* fall through */
case 3 * sizeof(int): case 3 * sizeof(int):
h = h * PRIME1 ^ (*key); h = (h * PRIME1) ^ (*k++);
key++;
/* fall through */ /* fall through */
case 2 * sizeof(int): case 2 * sizeof(int):
h = h * PRIME1 ^ (*key); h = (h * PRIME1) ^ (*k++);
key++;
/* fall through */ /* fall through */
case sizeof(int): case sizeof(int):
h = h * PRIME1 ^ (*key); h = (h * PRIME1) ^ (*k++);
key++;
break; break;
default: default:
for (; keysize >= (int) sizeof(int); keysize -= sizeof(int), key++) /* Do an int at a time */
h = h * PRIME1 ^ (*key); for (; keysize >= (int) sizeof(int); keysize -= sizeof(int))
h = (h * PRIME1) ^ (*k++);
/* /* Cope with any partial-int leftover bytes */
* now let's grab the last few bytes of the tag if the tag has if (keysize > 0)
* (size % 4) != 0 (which it sometimes will on a sun3).
*/
if (keysize)
{ {
char *keytmp = (char *) key; unsigned char *keybyte = (unsigned char *) k;
switch (keysize) do
{ h = (h * PRIME1) ^ (*keybyte++);
case 3: while (--keysize > 0);
h = h * PRIME1 ^ (*keytmp);
keytmp++;
/* fall through */
case 2:
h = h * PRIME1 ^ (*keytmp);
keytmp++;
/* fall through */
case 1:
h = h * PRIME1 ^ (*keytmp);
break;
}
} }
break; break;
} }
h %= PRIME2; h %= PRIME2;
return h;
}
/*
* This is INCREDIBLY ugly, but fast.
* We break the string up into 8 byte units. On the first time
* through the loop we get the "leftover bytes" (strlen % 8).
* On every other iteration, we perform 8 HASHC's so we handle
* all 8 bytes. Essentially, this saves us 7 cmp & branch
* instructions. If this routine is heavily used enough, it's
* worth the ugly coding
*/
#ifdef NOT_USED
long
disk_hash(char *key)
{
int n = 0;
char *str = key;
int len = strlen(key);
int loop;
#define HASHC n = *str++ + 65599 * n return h;
if (len > 0)
{
loop = (len + 8 - 1) >> 3;
switch (len & (8 - 1))
{
case 0:
do
{ /* All fall throughs */
HASHC;
case 7:
HASHC;
case 6:
HASHC;
case 5:
HASHC;
case 4:
HASHC;
case 3:
HASHC;
case 2:
HASHC;
case 1:
HASHC;
} while (--loop);
}
}
return n;
} }
#endif
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.41 2001/03/22 04:00:08 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.42 2001/10/01 05:36:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -123,7 +123,7 @@ EnablePortalManager(void) ...@@ -123,7 +123,7 @@ EnablePortalManager(void)
ALLOCSET_DEFAULT_MAXSIZE); ALLOCSET_DEFAULT_MAXSIZE);
ctl.keysize = MAX_PORTALNAME_LEN; ctl.keysize = MAX_PORTALNAME_LEN;
ctl.datasize = sizeof(Portal); ctl.entrysize = sizeof(PortalHashEnt);
/* /*
* use PORTALS_PER_USER, defined in utils/portal.h as a guess of how * use PORTALS_PER_USER, defined in utils/portal.h as a guess of how
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: buf_internals.h,v 1.50 2001/09/29 04:02:26 tgl Exp $ * $Id: buf_internals.h,v 1.51 2001/10/01 05:36:17 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -115,6 +115,13 @@ typedef struct sbufdesc ...@@ -115,6 +115,13 @@ typedef struct sbufdesc
#define BL_IO_IN_PROGRESS (1 << 0) /* unimplemented */ #define BL_IO_IN_PROGRESS (1 << 0) /* unimplemented */
#define BL_PIN_COUNT_LOCK (1 << 1) #define BL_PIN_COUNT_LOCK (1 << 1)
/* entry for buffer hashtable */
typedef struct
{
BufferTag key;
Buffer id;
} BufferLookupEnt;
/* /*
* mao tracing buffer allocation * mao tracing buffer allocation
*/ */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: lock.h,v 1.55 2001/09/30 00:45:48 momjian Exp $ * $Id: lock.h,v 1.56 2001/10/01 05:36:17 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -169,9 +169,6 @@ typedef struct LOCK ...@@ -169,9 +169,6 @@ typedef struct LOCK
int nGranted; /* total of granted[] array */ int nGranted; /* total of granted[] array */
} LOCK; } LOCK;
#define SHMEM_LOCKTAB_KEYSIZE sizeof(LOCKTAG)
#define SHMEM_LOCKTAB_DATASIZE (sizeof(LOCK) - SHMEM_LOCKTAB_KEYSIZE)
#define LOCK_LOCKMETHOD(lock) ((lock).tag.lockmethod) #define LOCK_LOCKMETHOD(lock) ((lock).tag.lockmethod)
...@@ -222,9 +219,6 @@ typedef struct HOLDER ...@@ -222,9 +219,6 @@ typedef struct HOLDER
SHM_QUEUE procLink; /* list link for process's list of holders */ SHM_QUEUE procLink; /* list link for process's list of holders */
} HOLDER; } HOLDER;
#define SHMEM_HOLDERTAB_KEYSIZE sizeof(HOLDERTAG)
#define SHMEM_HOLDERTAB_DATASIZE (sizeof(HOLDER) - SHMEM_HOLDERTAB_KEYSIZE)
#define HOLDER_LOCKMETHOD(holder) \ #define HOLDER_LOCKMETHOD(holder) \
(((LOCK *) MAKE_PTR((holder).tag.lock))->tag.lockmethod) (((LOCK *) MAKE_PTR((holder).tag.lock))->tag.lockmethod)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: shmem.h,v 1.31 2001/09/29 04:02:27 tgl Exp $ * $Id: shmem.h,v 1.32 2001/10/01 05:36:17 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -73,9 +73,7 @@ extern void *ShmemInitStruct(char *name, Size size, bool *foundPtr); ...@@ -73,9 +73,7 @@ extern void *ShmemInitStruct(char *name, Size size, bool *foundPtr);
/* size constants for the shmem index table */ /* size constants for the shmem index table */
/* max size of data structure string name */ /* max size of data structure string name */
#define SHMEM_INDEX_KEYSIZE (50) #define SHMEM_INDEX_KEYSIZE (48)
/* data in shmem index table hash bucket */
#define SHMEM_INDEX_DATASIZE (sizeof(ShmemIndexEnt) - SHMEM_INDEX_KEYSIZE)
/* maximum size of the shmem index table */ /* maximum size of the shmem index table */
#define SHMEM_INDEX_SIZE (100) #define SHMEM_INDEX_SIZE (100)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: hsearch.h,v 1.20 2001/06/22 19:16:24 wieck Exp $ * $Id: hsearch.h,v 1.21 2001/10/01 05:36:17 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,31 +31,32 @@ ...@@ -31,31 +31,32 @@
* tables, the initial directory size can be left at the default. * tables, the initial directory size can be left at the default.
*/ */
#define DEF_SEGSIZE 256 #define DEF_SEGSIZE 256
#define DEF_SEGSIZE_SHIFT 8/* must be log2(DEF_SEGSIZE) */ #define DEF_SEGSIZE_SHIFT 8 /* must be log2(DEF_SEGSIZE) */
#define DEF_DIRSIZE 256 #define DEF_DIRSIZE 256
#define DEF_FFACTOR 1/* default fill factor */ #define DEF_FFACTOR 1 /* default fill factor */
#define PRIME1 37 /* for the hash function */ #define PRIME1 37 /* for the hash function */
#define PRIME2 1048583 #define PRIME2 1048583
/* /*
* Hash bucket is actually bigger than this. Key field can have * HASHELEMENT is the private part of a hashtable entry. The caller's data
* variable length and a variable length data field follows it. * follows the HASHELEMENT structure (on a MAXALIGN'd boundary). The hash key
* is expected to be at the start of the caller's hash entry structure.
*/ */
typedef struct element typedef struct HASHELEMENT
{ {
unsigned long next; /* secret from user */ struct HASHELEMENT *link; /* link to next entry in same bucket */
long key; } HASHELEMENT;
} ELEMENT;
typedef unsigned long BUCKET_INDEX; /* A hash bucket is a linked list of HASHELEMENTs */
typedef HASHELEMENT *HASHBUCKET;
/* segment is an array of bucket pointers */ /* A hash segment is an array of bucket headers */
typedef BUCKET_INDEX *SEGMENT; typedef HASHBUCKET *HASHSEGMENT;
typedef unsigned long SEG_OFFSET;
typedef struct hashhdr /* Header structure for a hash table --- contains all changeable info */
typedef struct HASHHDR
{ {
long dsize; /* Directory Size */ long dsize; /* Directory Size */
long ssize; /* Segment Size --- must be power of 2 */ long ssize; /* Segment Size --- must be power of 2 */
...@@ -64,65 +65,66 @@ typedef struct hashhdr ...@@ -64,65 +65,66 @@ typedef struct hashhdr
long high_mask; /* Mask to modulo into entire table */ long high_mask; /* Mask to modulo into entire table */
long low_mask; /* Mask to modulo into lower half of table */ long low_mask; /* Mask to modulo into lower half of table */
long ffactor; /* Fill factor */ long ffactor; /* Fill factor */
long nkeys; /* Number of keys in hash table */ long nentries; /* Number of entries in hash table */
long nsegs; /* Number of allocated segments */ long nsegs; /* Number of allocated segments */
long keysize; /* hash key length in bytes */ long keysize; /* hash key length in bytes */
long datasize; /* elem data length in bytes */ long entrysize; /* total user element size in bytes */
long max_dsize; /* 'dsize' limit if directory is fixed long max_dsize; /* 'dsize' limit if directory is fixed
* size */ * size */
BUCKET_INDEX freeBucketIndex; /* index of first free bucket */ HASHELEMENT *freeList; /* linked list of free elements */
#ifdef HASH_STATISTICS #ifdef HASH_STATISTICS
long accesses; long accesses;
long collisions; long collisions;
#endif #endif
} HHDR; } HASHHDR;
typedef struct htab /*
* Top control structure for a hashtable --- need not be shared, since
* no fields change at runtime
*/
typedef struct HTAB
{ {
HHDR *hctl; /* shared control information */ HASHHDR *hctl; /* shared control information */
long (*hash) (); /* Hash Function */ long (*hash) (void *key, int keysize); /* Hash Function */
char *segbase; /* segment base address for calculating HASHSEGMENT *dir; /* directory of segment starts */
* pointer values */
SEG_OFFSET *dir; /* 'directory' of segm starts */
void *(*alloc) (Size);/* memory allocator */ void *(*alloc) (Size);/* memory allocator */
MemoryContext hcxt; /* memory context if default allocator used */ MemoryContext hcxt; /* memory context if default allocator used */
} HTAB; } HTAB;
typedef struct hashctl /* Parameter data structure for hash_create */
/* Only those fields indicated by hash_flags need be set */
typedef struct HASHCTL
{ {
long ssize; /* Segment Size */ long ssize; /* Segment Size */
long dsize; /* Dirsize Size */ long dsize; /* (initial) Directory Size */
long ffactor; /* Fill factor */ long ffactor; /* Fill factor */
long (*hash) (); /* Hash Function */ long (*hash) (void *key, int keysize); /* Hash Function */
long keysize; /* hash key length in bytes */ long keysize; /* hash key length in bytes */
long datasize; /* elem data length in bytes */ long entrysize; /* total user element size in bytes */
long max_dsize; /* limit to dsize if directory size is long max_dsize; /* limit to dsize if directory size is
* limited */ * limited */
long *segbase; /* base for calculating bucket + seg ptrs */
void *(*alloc) (Size);/* memory allocation function */ void *(*alloc) (Size);/* memory allocation function */
long *dir; /* directory if allocated already */ HASHSEGMENT *dir; /* directory of segment starts */
long *hctl; /* location of header information in shd HASHHDR *hctl; /* location of header in shared mem */
* mem */ MemoryContext hcxt; /* memory context to use for allocations */
MemoryContext hcxt; /* memory context to use for all allocations */
} HASHCTL; } HASHCTL;
/* Flags to indicate action for hctl */ /* Flags to indicate which parameters are supplied */
#define HASH_SEGMENT 0x002 /* Setting segment size */ #define HASH_SEGMENT 0x002 /* Setting segment size */
#define HASH_DIRSIZE 0x004 /* Setting directory size */ #define HASH_DIRSIZE 0x004 /* Setting directory size */
#define HASH_FFACTOR 0x008 /* Setting fill factor */ #define HASH_FFACTOR 0x008 /* Setting fill factor */
#define HASH_FUNCTION 0x010 /* Set user defined hash function */ #define HASH_FUNCTION 0x010 /* Set user defined hash function */
#define HASH_ELEM 0x020 /* Setting key/data size */ #define HASH_ELEM 0x020 /* Setting key/entry size */
#define HASH_SHARED_MEM 0x040 /* Setting shared mem const */ #define HASH_SHARED_MEM 0x040 /* Setting shared mem const */
#define HASH_ATTACH 0x080 /* Do not initialize hctl */ #define HASH_ATTACH 0x080 /* Do not initialize hctl */
#define HASH_ALLOC 0x100 /* Setting memory allocator */ #define HASH_ALLOC 0x100 /* Setting memory allocator */
#define HASH_CONTEXT 0x200 /* Setting explicit memory context */ #define HASH_CONTEXT 0x200 /* Setting explicit memory context */
/* seg_alloc assumes that INVALID_INDEX is 0 */ /* max_dsize value to indicate expansible directory */
#define INVALID_INDEX (0)
#define NO_MAX_DSIZE (-1) #define NO_MAX_DSIZE (-1)
/* number of hash buckets allocated at once */ /* number of hash elements allocated at once */
#define BUCKET_ALLOC_INCR (30) #define HASHELEMENT_ALLOC_INCR (32)
/* hash_search operations */ /* hash_search operations */
typedef enum typedef enum
...@@ -138,27 +140,27 @@ typedef enum ...@@ -138,27 +140,27 @@ typedef enum
typedef struct typedef struct
{ {
HTAB *hashp; HTAB *hashp;
long curBucket; long curBucket; /* index of current bucket */
BUCKET_INDEX curIndex; HASHELEMENT *curEntry; /* current entry in bucket */
} HASH_SEQ_STATUS; } HASH_SEQ_STATUS;
/* /*
* prototypes from functions in dynahash.c * prototypes for functions in dynahash.c
*/ */
extern HTAB *hash_create(int nelem, HASHCTL *info, int flags); extern HTAB *hash_create(long nelem, HASHCTL *info, int flags);
extern void hash_destroy(HTAB *hashp); extern void hash_destroy(HTAB *hashp);
extern void hash_stats(char *where, HTAB *hashp); extern void hash_stats(char *where, HTAB *hashp);
extern long *hash_search(HTAB *hashp, char *keyPtr, HASHACTION action, extern void *hash_search(HTAB *hashp, void *keyPtr, HASHACTION action,
bool *foundPtr); bool *foundPtr);
extern void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp); extern void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp);
extern long *hash_seq_search(HASH_SEQ_STATUS *status); extern void *hash_seq_search(HASH_SEQ_STATUS *status);
extern long hash_estimate_size(long num_entries, long keysize, long datasize); extern long hash_estimate_size(long num_entries, long entrysize);
extern long hash_select_dirsize(long num_entries); extern long hash_select_dirsize(long num_entries);
/* /*
* prototypes from functions in hashfn.c * prototypes for functions in hashfn.c
*/ */
extern long string_hash(char *key, int keysize); extern long string_hash(void *key, int keysize);
extern long tag_hash(int *key, int keysize); extern long tag_hash(void *key, int keysize);
#endif /* HSEARCH_H */ #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