aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/Makefile4
-rw-r--r--src/backend/utils/adt/regproc.c5
-rw-r--r--src/backend/utils/cache/catcache.c4
-rw-r--r--src/backend/utils/cache/relcache.c8
-rw-r--r--src/backend/utils/hash/dynahash.c83
5 files changed, 84 insertions, 20 deletions
diff --git a/src/backend/utils/adt/Makefile b/src/backend/utils/adt/Makefile
index 75ba6448beb..0f8bdfe0b24 100644
--- a/src/backend/utils/adt/Makefile
+++ b/src/backend/utils/adt/Makefile
@@ -1,7 +1,7 @@
#
# Makefile for utils/adt
#
-# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.48 2000/10/20 21:03:52 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.49 2001/06/22 19:16:23 wieck Exp $
#
subdir = src/backend/utils/adt
@@ -24,7 +24,7 @@ OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o \
tid.o timestamp.o varbit.o varchar.o varlena.o version.o \
network.o mac.o inet_net_ntop.o inet_net_pton.o \
ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \
- ascii.o quote.o
+ ascii.o quote.o pgstatfuncs.o
all: SUBSYS.o
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 1f3abde5f11..eb6ab3f4646 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.61 2001/03/22 03:59:53 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.62 2001/06/22 19:16:23 wieck Exp $
*
*-------------------------------------------------------------------------
*/
@@ -90,7 +90,8 @@ regprocin(PG_FUNCTION_ARGS)
tuple.t_self = indexRes->heap_iptr;
heap_fetch(hdesc, SnapshotNow,
&tuple,
- &buffer);
+ &buffer,
+ sd);
pfree(indexRes);
if (tuple.t_data != NULL)
{
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index d6901ea8391..f5f16e77188 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.80 2001/06/19 19:42:16 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.81 2001/06/22 19:16:23 wieck Exp $
*
*-------------------------------------------------------------------------
*/
@@ -980,7 +980,7 @@ SearchCatCache(CatCache *cache,
while ((indexRes = index_getnext(isd, ForwardScanDirection)))
{
tuple.t_self = indexRes->heap_iptr;
- heap_fetch(relation, SnapshotNow, &tuple, &buffer);
+ heap_fetch(relation, SnapshotNow, &tuple, &buffer, isd);
pfree(indexRes);
if (tuple.t_data != NULL)
{
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index d44c3dc2340..7b90122b9f2 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.138 2001/06/18 03:35:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.139 2001/06/22 19:16:23 wieck Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2257,7 +2257,7 @@ AttrDefaultFetch(Relation relation)
break;
tuple.t_self = indexRes->heap_iptr;
- heap_fetch(adrel, SnapshotNow, &tuple, &buffer);
+ heap_fetch(adrel, SnapshotNow, &tuple, &buffer, sd);
pfree(indexRes);
if (tuple.t_data == NULL)
continue;
@@ -2364,7 +2364,7 @@ RelCheckFetch(Relation relation)
break;
tuple.t_self = indexRes->heap_iptr;
- heap_fetch(rcrel, SnapshotNow, &tuple, &buffer);
+ heap_fetch(rcrel, SnapshotNow, &tuple, &buffer, sd);
pfree(indexRes);
if (tuple.t_data == NULL)
continue;
@@ -2502,7 +2502,7 @@ RelationGetIndexList(Relation relation)
tuple.t_self = indexRes->heap_iptr;
tuple.t_datamcxt = NULL;
tuple.t_data = NULL;
- heap_fetch(indrel, SnapshotNow, &tuple, &buffer);
+ heap_fetch(indrel, SnapshotNow, &tuple, &buffer, sd);
pfree(indexRes);
if (tuple.t_data == NULL)
continue;
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index b3a991fdc52..fd9b11ba98e 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.35 2001/03/22 03:59:59 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.36 2001/06/22 19:16:23 wieck Exp $
*
*-------------------------------------------------------------------------
*/
@@ -82,18 +82,13 @@ static int init_htab(HTAB *hashp, int nelem);
* ----------------
*/
static MemoryContext DynaHashCxt = NULL;
+static MemoryContext CurrentDynaHashCxt = NULL;
static void *
DynaHashAlloc(Size size)
{
- if (!DynaHashCxt)
- DynaHashCxt = AllocSetContextCreate(TopMemoryContext,
- "DynaHash",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
-
- return MemoryContextAlloc(DynaHashCxt, size);
+ Assert(MemoryContextIsValid(CurrentDynaHashCxt));
+ return MemoryContextAlloc(CurrentDynaHashCxt, size);
}
#define MEM_ALLOC DynaHashAlloc
@@ -133,6 +128,17 @@ hash_create(int nelem, HASHCTL *info, int flags)
HHDR *hctl;
HTAB *hashp;
+ if (!DynaHashCxt)
+ DynaHashCxt = AllocSetContextCreate(TopMemoryContext,
+ "DynaHash",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
+
+ if (flags & HASH_CONTEXT)
+ CurrentDynaHashCxt = info->hcxt;
+ else
+ CurrentDynaHashCxt = DynaHashCxt;
hashp = (HTAB *) MEM_ALLOC(sizeof(HTAB));
MemSet(hashp, 0, sizeof(HTAB));
@@ -157,6 +163,7 @@ hash_create(int nelem, HASHCTL *info, int flags)
hashp->segbase = (char *) info->segbase;
hashp->alloc = info->alloc;
hashp->dir = (SEG_OFFSET *) info->dir;
+ hashp->hcxt = NULL;
/* hash table already exists, we're just attaching to it */
if (flags & HASH_ATTACH)
@@ -171,12 +178,13 @@ hash_create(int nelem, HASHCTL *info, int flags)
hashp->alloc = MEM_ALLOC;
hashp->dir = NULL;
hashp->segbase = NULL;
+ hashp->hcxt = DynaHashCxt;
}
if (!hashp->hctl)
{
- hashp->hctl = (HHDR *) hashp->alloc(sizeof(HHDR));
+ hashp->hctl = (HHDR *) hashp->alloc(sizeof(HHDR));
if (!hashp->hctl)
return 0;
}
@@ -218,6 +226,28 @@ hash_create(int nelem, HASHCTL *info, int flags)
}
if (flags & HASH_ALLOC)
hashp->alloc = info->alloc;
+ else
+ {
+ if (flags & HASH_CONTEXT)
+ {
+ CurrentDynaHashCxt = AllocSetContextCreate(info->hcxt,
+ "DynaHashTable",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
+
+ hashp->hcxt = CurrentDynaHashCxt;
+ }
+ else
+ {
+ CurrentDynaHashCxt = AllocSetContextCreate(DynaHashCxt,
+ "DynaHashTable",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
+ hashp->hcxt = CurrentDynaHashCxt;
+ }
+ }
if (init_htab(hashp, nelem))
{
@@ -305,6 +335,7 @@ init_htab(HTAB *hashp, int nelem)
/* Allocate a directory */
if (!(hashp->dir))
{
+ CurrentDynaHashCxt = hashp->hcxt;
hashp->dir = (SEG_OFFSET *)
hashp->alloc(hctl->dsize * sizeof(SEG_OFFSET));
if (!hashp->dir)
@@ -414,6 +445,14 @@ hash_select_dirsize(long num_entries)
* allocated individually, see bucket_alloc!! Why doesn't it crash?
* ANSWER: it probably does crash, but is never invoked in normal
* operations...
+ *
+ * Thomas is right, it does crash. Therefore I changed the code
+ * to use a separate memory context which is a child of the DynaHashCxt
+ * by default. And the HASHCTL structure got extended with a hcxt
+ * field, where someone can specify an explicit context (giving new
+ * flag HASH_CONTEXT) and forget about hash_destroy() completely.
+ * The shmem operations aren't changed, but in shmem mode a destroy
+ * doesn't work anyway. Jan Wieck 03/2001.
*/
void
@@ -421,6 +460,7 @@ hash_destroy(HTAB *hashp)
{
if (hashp != NULL)
{
+#if 0
SEG_OFFSET segNum;
SEGMENT segp;
int nsegs = hashp->hctl->nsegs;
@@ -429,14 +469,27 @@ hash_destroy(HTAB *hashp)
p,
q;
ELEMENT *curr;
+#endif
/* cannot destroy a shared memory hash table */
Assert(!hashp->segbase);
/* allocation method must be one we know how to free, too */
Assert(hashp->alloc == MEM_ALLOC);
+ /* so this hashtable must have it's own context */
+ Assert(hashp->hcxt != NULL);
hash_stats("destroy", hashp);
+ /*
+ * Free buckets, dir etc. by destroying the hash tables
+ * memory context.
+ */
+ MemoryContextDelete(hashp->hcxt);
+
+#if 0
+ /*
+ * Dead code - replaced by MemoryContextDelete() above
+ */
for (segNum = 0; nsegs > 0; nsegs--, segNum++)
{
@@ -453,6 +506,13 @@ hash_destroy(HTAB *hashp)
MEM_FREE((char *) segp);
}
MEM_FREE((char *) hashp->dir);
+#endif
+
+ /*
+ * Free the HTAB and control structure, which are allocated
+ * in the parent context (DynaHashCxt or the context given
+ * by the caller of hash_create().
+ */
MEM_FREE((char *) hashp->hctl);
MEM_FREE((char *) hashp);
}
@@ -876,6 +936,7 @@ dir_realloc(HTAB *hashp)
old_dirsize = hashp->hctl->dsize * sizeof(SEG_OFFSET);
new_dirsize = new_dsize * sizeof(SEG_OFFSET);
+ CurrentDynaHashCxt = hashp->hcxt;
old_p = (char *) hashp->dir;
p = (char *) hashp->alloc((Size) new_dirsize);
@@ -898,6 +959,7 @@ seg_alloc(HTAB *hashp)
SEGMENT segp;
SEG_OFFSET segOffset;
+ CurrentDynaHashCxt = hashp->hcxt;
segp = (SEGMENT) hashp->alloc(sizeof(BUCKET_INDEX) * hashp->hctl->ssize);
if (!segp)
@@ -928,6 +990,7 @@ bucket_alloc(HTAB *hashp)
/* make sure its aligned correctly */
bucketSize = MAXALIGN(bucketSize);
+ CurrentDynaHashCxt = hashp->hcxt;
tmpBucket = (ELEMENT *) hashp->alloc(BUCKET_ALLOC_INCR * bucketSize);
if (!tmpBucket)