From bf5b2c8d7eae8a68f2659c8337fbc4956bac4408 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 14 Feb 2022 21:31:08 -0800 Subject: [PATCH] Use tuple id directly --- src/ivfbuild.c | 25 +++++++++---------------- src/ivfscan.c | 23 +++++++++-------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/ivfbuild.c b/src/ivfbuild.c index a106246..904f759 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -173,12 +173,10 @@ BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values, ExecClearTuple(slot); slot->tts_values[0] = Int32GetDatum(closestCenter); slot->tts_isnull[0] = false; - slot->tts_values[1] = Int32GetDatum(ItemPointerGetBlockNumberNoCheck(tid)); + slot->tts_values[1] = PointerGetDatum(tid); slot->tts_isnull[1] = false; - slot->tts_values[2] = Int32GetDatum(ItemPointerGetOffsetNumberNoCheck(tid)); + slot->tts_values[2] = value; slot->tts_isnull[2] = false; - slot->tts_values[3] = value; - slot->tts_isnull[3] = false; ExecStoreVirtualTuple(slot); /* @@ -200,8 +198,6 @@ GetNextTuple(Tuplesortstate *sortstate, TupleDesc tupdesc, TupleTableSlot *slot, { Datum value; bool isnull; - int tupblk; - int tupoff; #if PG_VERSION_NUM >= 100000 if (tuplesort_gettupleslot(sortstate, true, false, slot, NULL)) @@ -210,13 +206,11 @@ GetNextTuple(Tuplesortstate *sortstate, TupleDesc tupdesc, TupleTableSlot *slot, #endif { *list = DatumGetInt32(slot_getattr(slot, 1, &isnull)); - tupblk = DatumGetInt32(slot_getattr(slot, 2, &isnull)); - tupoff = DatumGetInt32(slot_getattr(slot, 3, &isnull)); - value = slot_getattr(slot, 4, &isnull); + value = slot_getattr(slot, 3, &isnull); /* Form the index tuple */ *itup = index_form_tuple(tupdesc, &value, &isnull); - ItemPointerSet(&(*itup)->t_tid, tupblk, tupoff); + (*itup)->t_tid = *((ItemPointer) DatumGetPointer(slot_getattr(slot, 2, &isnull))); } else *list = -1; @@ -325,17 +319,16 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In /* Create tuple description for sorting */ #if PG_VERSION_NUM >= 120000 - buildstate->tupdesc = CreateTemplateTupleDesc(4); + buildstate->tupdesc = CreateTemplateTupleDesc(3); #else - buildstate->tupdesc = CreateTemplateTupleDesc(4, false); + buildstate->tupdesc = CreateTemplateTupleDesc(3, false); #endif TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 1, "list", INT4OID, -1, 0); - TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 2, "blkno", INT4OID, -1, 0); - TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 3, "offset", INT4OID, -1, 0); + TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 2, "tid", TIDOID, -1, 0); #if PG_VERSION_NUM >= 110000 - TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 4, "vector", RelationGetDescr(index)->attrs[0].atttypid, -1, 0); + TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 3, "vector", RelationGetDescr(index)->attrs[0].atttypid, -1, 0); #else - TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 4, "vector", RelationGetDescr(index)->attrs[0]->atttypid, -1, 0); + TupleDescInitEntry(buildstate->tupdesc, (AttrNumber) 3, "vector", RelationGetDescr(index)->attrs[0]->atttypid, -1, 0); #endif #if PG_VERSION_NUM >= 120000 diff --git a/src/ivfscan.c b/src/ivfscan.c index cc3bdfd..958faae 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -158,12 +158,10 @@ GetScanItems(IndexScanDesc scan, Datum value) ExecClearTuple(slot); slot->tts_values[0] = FunctionCall2Coll(so->procinfo, so->collation, datum, value); slot->tts_isnull[0] = false; - slot->tts_values[1] = Int32GetDatum((int) ItemPointerGetBlockNumberNoCheck(&itup->t_tid)); + slot->tts_values[1] = PointerGetDatum(&itup->t_tid); slot->tts_isnull[1] = false; - slot->tts_values[2] = Int32GetDatum((int) ItemPointerGetOffsetNumberNoCheck(&itup->t_tid)); + slot->tts_values[2] = Int32GetDatum((int) searchPage); slot->tts_isnull[2] = false; - slot->tts_values[3] = Int32GetDatum((int) searchPage); - slot->tts_isnull[3] = false; ExecStoreVirtualTuple(slot); tuplesort_puttupleslot(so->sortstate, slot); @@ -211,14 +209,13 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys) /* Create tuple description for sorting */ #if PG_VERSION_NUM >= 120000 - so->tupdesc = CreateTemplateTupleDesc(4); + so->tupdesc = CreateTemplateTupleDesc(3); #else - so->tupdesc = CreateTemplateTupleDesc(4, false); + so->tupdesc = CreateTemplateTupleDesc(3, false); #endif TupleDescInitEntry(so->tupdesc, (AttrNumber) 1, "distance", FLOAT8OID, -1, 0); - TupleDescInitEntry(so->tupdesc, (AttrNumber) 2, "blkno", INT4OID, -1, 0); - TupleDescInitEntry(so->tupdesc, (AttrNumber) 3, "offset", INT4OID, -1, 0); - TupleDescInitEntry(so->tupdesc, (AttrNumber) 4, "indexblkno", INT4OID, -1, 0); + TupleDescInitEntry(so->tupdesc, (AttrNumber) 2, "tid", TIDOID, -1, 0); + TupleDescInitEntry(so->tupdesc, (AttrNumber) 3, "indexblkno", INT4OID, -1, 0); /* Prep sort */ #if PG_VERSION_NUM >= 110000 @@ -313,14 +310,12 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir) if (tuplesort_gettupleslot(so->sortstate, true, so->slot, NULL)) #endif { - BlockNumber blkno = DatumGetInt32(slot_getattr(so->slot, 2, &so->isnull)); - OffsetNumber offset = DatumGetInt32(slot_getattr(so->slot, 3, &so->isnull)); - BlockNumber indexblkno = DatumGetInt32(slot_getattr(so->slot, 4, &so->isnull)); + BlockNumber indexblkno = DatumGetInt32(slot_getattr(so->slot, 3, &so->isnull)); #if PG_VERSION_NUM >= 120000 - ItemPointerSet(&scan->xs_heaptid, blkno, offset); + scan->xs_heaptid = *((ItemPointer) DatumGetPointer(slot_getattr(so->slot, 2, &so->isnull))); #else - ItemPointerSet(&scan->xs_ctup.t_self, blkno, offset); + scan->xs_ctup.t_self = *((ItemPointer) DatumGetPointer(slot_getattr(so->slot, 2, &so->isnull))); #endif if (BufferIsValid(so->buf))