summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-03-07 02:01:09 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-03-07 02:01:09 +0000
commit2ecbf94430265822e08758df375ffea9d041a86a (patch)
treefbbdbe291eeec725547069f0b15536697eff69c3 /src/include
parent0fda84bfcd7e3ab1a8bcca7282e2b319930f7070 (diff)
downloadpostgresql-REL6_4.tar.gz
Retrofit hashtable and shared-mem-size-estimation bug fixesREL6_4
into REL6_4.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/storage/lock.h8
-rw-r--r--src/include/utils/hsearch.h33
2 files changed, 25 insertions, 16 deletions
diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h
index 329aa758a7..07cf6a903d 100644
--- a/src/include/storage/lock.h
+++ b/src/include/storage/lock.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: lock.h,v 1.19 1998/10/08 18:30:45 momjian Exp $
+ * $Id: lock.h,v 1.19.2.1 1999/03/07 02:00:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -175,6 +175,9 @@ typedef struct XIDLookupEnt
SHM_QUEUE queue;
} XIDLookupEnt;
+#define SHMEM_XIDTAB_KEYSIZE sizeof(XIDTAG)
+#define SHMEM_XIDTAB_DATASIZE (sizeof(XIDLookupEnt) - SHMEM_XIDTAB_KEYSIZE)
+
#define XID_TAGSIZE (sizeof(XIDTAG))
#define XIDENT_LOCKMETHOD(xident) (XIDTAG_LOCKMETHOD((xident).tag))
@@ -211,6 +214,9 @@ typedef struct LOCK
int nActive;
} LOCK;
+#define SHMEM_LOCKTAB_KEYSIZE sizeof(LOCKTAG)
+#define SHMEM_LOCKTAB_DATASIZE (sizeof(LOCK) - SHMEM_LOCKTAB_KEYSIZE)
+
#define LOCK_LOCKMETHOD(lock) (LOCKTAG_LOCKMETHOD((lock).tag))
#define LockGetLock_nHolders(l) l->nHolders
diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h
index f0a8009776..96efd88748 100644
--- a/src/include/utils/hsearch.h
+++ b/src/include/utils/hsearch.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: hsearch.h,v 1.9 1998/09/01 04:39:12 momjian Exp $
+ * $Id: hsearch.h,v 1.9.2.1 1999/03/07 02:01:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -16,16 +16,23 @@
/*
* Constants
+ *
+ * A hash table has a top-level "directory", each of whose entries points
+ * to a "segment" of ssize bucket headers. The maximum number of hash
+ * buckets is thus dsize * ssize (but dsize may be expansible). Of course,
+ * the number of records in the table can be larger, but we don't want a
+ * whole lot of records per bucket or performance goes down.
+ *
+ * In a hash table allocated in shared memory, the directory cannot be
+ * expanded because it must stay at a fixed address.
*/
-#define DEF_BUCKET_SIZE 256
-#define DEF_BUCKET_SHIFT 8/* log2(BUCKET) */
#define DEF_SEGSIZE 256
-#define DEF_SEGSIZE_SHIFT 8 /* log2(SEGSIZE) */
+#define DEF_SEGSIZE_SHIFT 8 /* log2(SEGSIZE) */
#define DEF_DIRSIZE 256
-#define PRIME1 37
+#define DEF_FFACTOR 1 /* default fill factor */
+
+#define PRIME1 37 /* for the hash function */
#define PRIME2 1048583
-#define DEF_FFACTOR 1
-#define SPLTMAX 8
/*
@@ -46,10 +53,8 @@ typedef unsigned long SEG_OFFSET;
typedef struct hashhdr
{
- long bsize; /* Bucket/Page Size */
- long bshift; /* Bucket shift */
long dsize; /* Directory Size */
- long ssize; /* Segment Size */
+ long ssize; /* Segment Size --- must be power of 2 */
long sshift; /* Segment shift */
long max_bucket; /* ID of Maximum bucket in use */
long high_mask; /* Mask to modulo into entire table */
@@ -59,8 +64,7 @@ typedef struct hashhdr
long nsegs; /* Number of allocated segments */
long keysize; /* hash key length in bytes */
long datasize; /* elem data length in bytes */
- long max_dsize; /* 'dsize' limit if directory is fixed
- * size */
+ long max_dsize; /* 'dsize' limit if directory is fixed size */
BUCKET_INDEX freeBucketIndex;
/* index of first free bucket */
#ifdef HASH_STATISTICS
@@ -83,14 +87,13 @@ typedef struct htab
typedef struct hashctl
{
- long bsize; /* Bucket Size */
long ssize; /* Segment Size */
long dsize; /* Dirsize Size */
long ffactor; /* Fill factor */
long (*hash) (); /* Hash Function */
long keysize; /* hash key length in bytes */
long datasize; /* elem data length in bytes */
- long max_size; /* limit to dsize if directory size is
+ long max_dsize; /* limit to dsize if directory size is
* limited */
long *segbase; /* base for calculating bucket + seg ptrs */
long *(*alloc) (); /* memory allocation function */
@@ -100,7 +103,6 @@ typedef struct hashctl
} HASHCTL;
/* Flags to indicate action for hctl */
-#define HASH_BUCKET 0x001 /* Setting bucket size */
#define HASH_SEGMENT 0x002 /* Setting segment size */
#define HASH_DIRSIZE 0x004 /* Setting directory size */
#define HASH_FFACTOR 0x008 /* Setting fill factor */
@@ -136,6 +138,7 @@ extern void hash_stats(char *where, HTAB *hashp);
extern long *hash_search(HTAB *hashp, char *keyPtr, HASHACTION action,
bool *foundPtr);
extern long *hash_seq(HTAB *hashp);
+extern long hash_estimate_size(long num_entries, long keysize, long datasize);
/*
* prototypes from functions in hashfn.c