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;
Buffer buf;
ItemPointerData heaptid;
IndexTuple itup;
/* Sorting */
Tuplesortstate *sortstate;

View File

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