From ed9e450571d728b7e0ea53b5d04e29169ab86f73 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 3 Sep 2023 17:06:22 -0700 Subject: [PATCH] Copy index tuple --- src/ivfflat.h | 1 + src/ivfscan.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ivfflat.h b/src/ivfflat.h index ef44a6c..10a51c8 100644 --- a/src/ivfflat.h +++ b/src/ivfflat.h @@ -248,6 +248,7 @@ typedef struct IvfflatScanOpaqueData bool first; Buffer buf; ItemPointerData heaptid; + IndexTuple itup; /* Sorting */ Tuplesortstate *sortstate; diff --git a/src/ivfscan.c b/src/ivfscan.c index 29a822b..bead69b 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -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);