diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-03-19 23:27:11 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-03-19 23:27:11 +0000 |
commit | 91728fa26cabac4b34055ab8e23d0751f0b16753 (patch) | |
tree | 59a1caabd632d250173dbe6fcec4031ce05283b4 /src/backend/storage/buffer/localbuf.c | |
parent | d65522aeb6eac89f8491b0852c3543d6c0aeb94a (diff) | |
download | postgresql-91728fa26cabac4b34055ab8e23d0751f0b16753.tar.gz postgresql-91728fa26cabac4b34055ab8e23d0751f0b16753.zip |
Add temp_buffers GUC variable to allow users to determine the size
of the local buffer arena for temporary table access.
Diffstat (limited to 'src/backend/storage/buffer/localbuf.c')
-rw-r--r-- | src/backend/storage/buffer/localbuf.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c index c2a1ed587e1..0e9e7b68cc3 100644 --- a/src/backend/storage/buffer/localbuf.c +++ b/src/backend/storage/buffer/localbuf.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.65 2005/03/19 17:39:43 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.66 2005/03/19 23:27:05 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,6 +18,7 @@ #include "storage/buf_internals.h" #include "storage/bufmgr.h" #include "storage/smgr.h" +#include "utils/guc.h" #include "utils/memutils.h" #include "utils/resowner.h" @@ -46,6 +47,9 @@ static int nextFreeLocalBuf = 0; static HTAB *LocalBufHash = NULL; +static void InitLocalBuffers(void); + + /* * LocalBufferAlloc - * Find or create a local buffer for the given page of the given relation. @@ -66,6 +70,10 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) INIT_BUFFERTAG(newTag, reln, blockNum); + /* Initialize local buffers if first request in this session */ + if (LocalBufHash == NULL) + InitLocalBuffers(); + /* See if the desired buffer already exists */ hresult = (LocalBufferLookupEnt *) hash_search(LocalBufHash, (void *) &newTag, HASH_FIND, NULL); @@ -238,32 +246,18 @@ WriteLocalBuffer(Buffer buffer, bool release) } /* - * InitLocalBuffer - + * InitLocalBuffers - * init the local buffer cache. Since most queries (esp. multi-user ones) * don't involve local buffers, we delay allocating actual memory for the * buffers until we need them; just make the buffer headers here. */ -void -InitLocalBuffer(void) +static void +InitLocalBuffers(void) { - int nbufs = 64; /* should be from a GUC var */ + int nbufs = num_temp_buffers; HASHCTL info; int i; - /* Create the lookup hash table */ - MemSet(&info, 0, sizeof(info)); - info.keysize = sizeof(BufferTag); - info.entrysize = sizeof(LocalBufferLookupEnt); - info.hash = tag_hash; - - LocalBufHash = hash_create("Local Buffer Lookup Table", - nbufs, - &info, - HASH_ELEM | HASH_FUNCTION); - - if (!LocalBufHash) - elog(ERROR, "could not initialize local buffer hash table"); - /* Allocate and zero buffer headers and auxiliary arrays */ LocalBufferDescriptors = (BufferDesc *) MemoryContextAllocZero(TopMemoryContext, @@ -291,6 +285,20 @@ InitLocalBuffer(void) buf->buf_id = -i - 2; } + /* Create the lookup hash table */ + MemSet(&info, 0, sizeof(info)); + info.keysize = sizeof(BufferTag); + info.entrysize = sizeof(LocalBufferLookupEnt); + info.hash = tag_hash; + + LocalBufHash = hash_create("Local Buffer Lookup Table", + nbufs, + &info, + HASH_ELEM | HASH_FUNCTION); + + if (!LocalBufHash) + elog(ERROR, "could not initialize local buffer hash table"); + /* Initialization done, mark buffers allocated */ NLocBuffer = nbufs; } |