From: | Maarten Boekhold <maartenb(at)dutepp0(dot)et(dot)tudelft(dot)nl> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Need some help on code |
Date: | 1998-06-07 19:27:13 |
Message-ID: | Pine.SUN.3.91.980607212322.3487A-100000@dutepp0.et.tudelft.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
I was trying to change to cluster command to do the its writes clustered
by a 100 tuples, thus hoping to improve performance. However, the code
I've written crashes. This has certainly to do with some internal states
of pgsql that aren't preserved in a HeapTuple.
Could somebody with knowledge have a brief glimpse on my code and perhaps
tell me how to do it properly?
Maarten
_____________________________________________________________________________
| TU Delft, The Netherlands, Faculty of Information Technology and Systems |
| Department of Electrical Engineering |
| Computer Architecture and Digital Technique section |
| M(dot)Boekhold(at)et(dot)tudelft(dot)nl |
-----------------------------------------------------------------------------
static void
rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
{
Relation LocalNewHeap,
LocalOldHeap,
LocalOldIndex;
IndexScanDesc ScanDesc;
RetrieveIndexResult ScanResult;
ItemPointer HeapTid;
HeapTuple LocalHeapTuple;
Buffer LocalBuffer[100];
Oid OIDNewHeapInsert;
Dllist *ScanResList;
Dlelem *ListEl;
int count, loop;
/*
* Open the relations I need. Scan through the OldHeap on the OldIndex
* and insert each tuple into the NewHeap.
*/
LocalNewHeap = (Relation) heap_open(OIDNewHeap);
LocalOldHeap = (Relation) heap_open(OIDOldHeap);
LocalOldIndex = (Relation) index_open(OIDOldIndex);
ScanResList = DLNewList();
ScanDesc = index_beginscan(LocalOldIndex, false, 0, (ScanKey) NULL);
loop = 1;
while (loop) {
count = 0;
while ((count < 100) &&
((ScanResult =
index_getnext(ScanDesc,
ForwardScanDirection)) != NULL))
{
HeapTid = &ScanResult->heap_iptr;
pfree(ScanResult);
LocalHeapTuple = heap_fetch(LocalOldHeap, false,
HeapTid, &LocalBuffer[count]);
ListEl = DLNewElem(LocalHeapTuple);
DLAddTail(ScanResList, ListEl);
count++;
}
if (count < 100) loop = 0;
count = 0;
while ((ListEl = DLRemHead(ScanResList)) != NULL) {
LocalHeapTuple = (HeapTuple)ListEl->dle_val;
DLFreeElem(ListEl);
OIDNewHeapInsert =
heap_insert(LocalNewHeap, LocalHeapTuple);
ReleaseBuffer(LocalBuffer[count]);
count++;
}
}
index_endscan(ScanDesc);
index_close(LocalOldIndex);
heap_close(LocalOldHeap);
heap_close(LocalNewHeap);
DLFreeList(ScanResList);
}
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 1998-06-07 20:26:55 | Re: [HACKERS] Need some help on code |
Previous Message | Bruce Momjian | 1998-06-07 17:10:59 | Re: [HACKERS] v6.4 - What is planned...? |