Copy index tuple

This commit is contained in:
Andrew Kane
2023-09-03 17:06:22 -07:00
parent 97000a7903
commit ed9e450571
2 changed files with 17 additions and 2 deletions

View File

@@ -248,6 +248,7 @@ typedef struct IvfflatScanOpaqueData
bool first; bool first;
Buffer buf; Buffer buf;
ItemPointerData heaptid; ItemPointerData heaptid;
IndexTuple itup;
/* Sorting */ /* Sorting */
Tuplesortstate *sortstate; Tuplesortstate *sortstate;

View File

@@ -266,6 +266,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
so->buf = InvalidBuffer; so->buf = InvalidBuffer;
so->first = true; so->first = true;
ItemPointerSetInvalid(&so->heaptid); ItemPointerSetInvalid(&so->heaptid);
so->itup = NULL;
so->probes = probes; so->probes = probes;
so->dimensions = dimensions; so->dimensions = dimensions;
@@ -410,12 +411,22 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
if (scan->xs_want_itup) if (scan->xs_want_itup)
{ {
Page page; Page page;
OffsetNumber offno;
IndexTuple itup;
Size itupSize;
LockBuffer(so->buf, BUFFER_LOCK_SHARE); LockBuffer(so->buf, BUFFER_LOCK_SHARE);
page = BufferGetPage(so->buf); page = BufferGetPage(so->buf);
offno = ItemPointerGetOffsetNumber(indextid);
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offno));
itupSize = IndexTupleSize(itup);
/* TODO Copy tuple to IvfflatScanOpaque */ if (so->itup == NULL)
scan->xs_itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, ItemPointerGetOffsetNumber(indextid))); so->itup = palloc(BLCKSZ);
memcpy(so->itup, itup, itupSize);
scan->xs_itup = so->itup;
LockBuffer(so->buf, BUFFER_LOCK_UNLOCK); LockBuffer(so->buf, BUFFER_LOCK_UNLOCK);
} }
@@ -439,6 +450,9 @@ ivfflatendscan(IndexScanDesc scan)
if (BufferIsValid(so->buf)) if (BufferIsValid(so->buf))
ReleaseBuffer(so->buf); ReleaseBuffer(so->buf);
if (so->itup != NULL)
pfree(so->itup);
pairingheap_free(so->listQueue); pairingheap_free(so->listQueue);
tuplesort_end(so->sortstate); tuplesort_end(so->sortstate);