Pass ItemPointer not HeapTuple to IndexBuildCallback.

Not all AMs use HeapTuples internally, making it inconvenient to pass
a HeapTuple. As the index callbacks really only need the TID, not the
full tuple, modify callback to only take ItemPointer.

Author: Ashwin Agrawal
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CALfoeis6=8ehuR=VNtHvj3z16cYfCwPdTcpaxU+sfSUJ5QgR3g@mail.gmail.com
This commit is contained in:
Andres Freund 2019-11-08 00:44:52 -08:00
parent 71a8a4f6e3
commit aae50236e4
10 changed files with 29 additions and 32 deletions

View File

@ -140,7 +140,7 @@ static BTScanInsert bt_right_page_check_scankey(BtreeCheckState *state);
static void bt_downlink_check(BtreeCheckState *state, BTScanInsert targetkey, static void bt_downlink_check(BtreeCheckState *state, BTScanInsert targetkey,
BlockNumber childblock); BlockNumber childblock);
static void bt_downlink_missing_check(BtreeCheckState *state); static void bt_downlink_missing_check(BtreeCheckState *state);
static void bt_tuple_present_callback(Relation index, HeapTuple htup, static void bt_tuple_present_callback(Relation index, ItemPointer tid,
Datum *values, bool *isnull, Datum *values, bool *isnull,
bool tupleIsAlive, void *checkstate); bool tupleIsAlive, void *checkstate);
static IndexTuple bt_normalize_tuple(BtreeCheckState *state, static IndexTuple bt_normalize_tuple(BtreeCheckState *state,
@ -1890,7 +1890,7 @@ bt_downlink_missing_check(BtreeCheckState *state)
* also allows us to detect the corruption in many cases. * also allows us to detect the corruption in many cases.
*/ */
static void static void
bt_tuple_present_callback(Relation index, HeapTuple htup, Datum *values, bt_tuple_present_callback(Relation index, ItemPointer tid, Datum *values,
bool *isnull, bool tupleIsAlive, void *checkstate) bool *isnull, bool tupleIsAlive, void *checkstate)
{ {
BtreeCheckState *state = (BtreeCheckState *) checkstate; BtreeCheckState *state = (BtreeCheckState *) checkstate;
@ -1901,7 +1901,7 @@ bt_tuple_present_callback(Relation index, HeapTuple htup, Datum *values,
/* Generate a normalized index tuple for fingerprinting */ /* Generate a normalized index tuple for fingerprinting */
itup = index_form_tuple(RelationGetDescr(index), values, isnull); itup = index_form_tuple(RelationGetDescr(index), values, isnull);
itup->t_tid = htup->t_self; itup->t_tid = *tid;
norm = bt_normalize_tuple(state, itup); norm = bt_normalize_tuple(state, itup);
/* Probe Bloom filter -- tuple should be present */ /* Probe Bloom filter -- tuple should be present */

View File

@ -72,7 +72,7 @@ initCachedPage(BloomBuildState *buildstate)
* Per-tuple callback for table_index_build_scan. * Per-tuple callback for table_index_build_scan.
*/ */
static void static void
bloomBuildCallback(Relation index, HeapTuple htup, Datum *values, bloomBuildCallback(Relation index, ItemPointer tid, Datum *values,
bool *isnull, bool tupleIsAlive, void *state) bool *isnull, bool tupleIsAlive, void *state)
{ {
BloomBuildState *buildstate = (BloomBuildState *) state; BloomBuildState *buildstate = (BloomBuildState *) state;
@ -81,7 +81,7 @@ bloomBuildCallback(Relation index, HeapTuple htup, Datum *values,
oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx); oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);
itup = BloomFormTuple(&buildstate->blstate, &htup->t_self, values, isnull); itup = BloomFormTuple(&buildstate->blstate, tid, values, isnull);
/* Try to add next item to cached page */ /* Try to add next item to cached page */
if (BloomPageAddItem(&buildstate->blstate, buildstate->data.data, itup)) if (BloomPageAddItem(&buildstate->blstate, buildstate->data.data, itup))

View File

@ -597,7 +597,7 @@ brinendscan(IndexScanDesc scan)
*/ */
static void static void
brinbuildCallback(Relation index, brinbuildCallback(Relation index,
HeapTuple htup, ItemPointer tid,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
bool tupleIsAlive, bool tupleIsAlive,
@ -607,7 +607,7 @@ brinbuildCallback(Relation index,
BlockNumber thisblock; BlockNumber thisblock;
int i; int i;
thisblock = ItemPointerGetBlockNumber(&htup->t_self); thisblock = ItemPointerGetBlockNumber(tid);
/* /*
* If we're in a block that belongs to a future range, summarize what * If we're in a block that belongs to a future range, summarize what

View File

@ -276,7 +276,7 @@ ginHeapTupleBulkInsert(GinBuildState *buildstate, OffsetNumber attnum,
} }
static void static void
ginBuildCallback(Relation index, HeapTuple htup, Datum *values, ginBuildCallback(Relation index, ItemPointer tid, Datum *values,
bool *isnull, bool tupleIsAlive, void *state) bool *isnull, bool tupleIsAlive, void *state)
{ {
GinBuildState *buildstate = (GinBuildState *) state; GinBuildState *buildstate = (GinBuildState *) state;
@ -287,8 +287,7 @@ ginBuildCallback(Relation index, HeapTuple htup, Datum *values,
for (i = 0; i < buildstate->ginstate.origTupdesc->natts; i++) for (i = 0; i < buildstate->ginstate.origTupdesc->natts; i++)
ginHeapTupleBulkInsert(buildstate, (OffsetNumber) (i + 1), ginHeapTupleBulkInsert(buildstate, (OffsetNumber) (i + 1),
values[i], isnull[i], values[i], isnull[i], tid);
&htup->t_self);
/* If we've maxed out our available memory, dump everything to the index */ /* If we've maxed out our available memory, dump everything to the index */
if (buildstate->accum.allocatedMemory >= (Size) maintenance_work_mem * 1024L) if (buildstate->accum.allocatedMemory >= (Size) maintenance_work_mem * 1024L)

View File

@ -80,7 +80,7 @@ typedef struct
static void gistInitBuffering(GISTBuildState *buildstate); static void gistInitBuffering(GISTBuildState *buildstate);
static int calculatePagesPerBuffer(GISTBuildState *buildstate, int levelStep); static int calculatePagesPerBuffer(GISTBuildState *buildstate, int levelStep);
static void gistBuildCallback(Relation index, static void gistBuildCallback(Relation index,
HeapTuple htup, ItemPointer tid,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
bool tupleIsAlive, bool tupleIsAlive,
@ -440,7 +440,7 @@ calculatePagesPerBuffer(GISTBuildState *buildstate, int levelStep)
*/ */
static void static void
gistBuildCallback(Relation index, gistBuildCallback(Relation index,
HeapTuple htup, ItemPointer tid,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
bool tupleIsAlive, bool tupleIsAlive,
@ -454,7 +454,7 @@ gistBuildCallback(Relation index,
/* form an index tuple and point it at the heap tuple */ /* form an index tuple and point it at the heap tuple */
itup = gistFormTuple(buildstate->giststate, index, values, isnull, true); itup = gistFormTuple(buildstate->giststate, index, values, isnull, true);
itup->t_tid = htup->t_self; itup->t_tid = *tid;
if (buildstate->bufferingMode == GIST_BUFFERING_ACTIVE) if (buildstate->bufferingMode == GIST_BUFFERING_ACTIVE)
{ {

View File

@ -43,7 +43,7 @@ typedef struct
} HashBuildState; } HashBuildState;
static void hashbuildCallback(Relation index, static void hashbuildCallback(Relation index,
HeapTuple htup, ItemPointer tid,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
bool tupleIsAlive, bool tupleIsAlive,
@ -201,7 +201,7 @@ hashbuildempty(Relation index)
*/ */
static void static void
hashbuildCallback(Relation index, hashbuildCallback(Relation index,
HeapTuple htup, ItemPointer tid,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
bool tupleIsAlive, bool tupleIsAlive,
@ -220,14 +220,13 @@ hashbuildCallback(Relation index,
/* Either spool the tuple for sorting, or just put it into the index */ /* Either spool the tuple for sorting, or just put it into the index */
if (buildstate->spool) if (buildstate->spool)
_h_spool(buildstate->spool, &htup->t_self, _h_spool(buildstate->spool, tid, index_values, index_isnull);
index_values, index_isnull);
else else
{ {
/* form an index tuple and point it at the heap tuple */ /* form an index tuple and point it at the heap tuple */
itup = index_form_tuple(RelationGetDescr(index), itup = index_form_tuple(RelationGetDescr(index),
index_values, index_isnull); index_values, index_isnull);
itup->t_tid = htup->t_self; itup->t_tid = *tid;
_hash_doinsert(index, itup, buildstate->heapRel); _hash_doinsert(index, itup, buildstate->heapRel);
pfree(itup); pfree(itup);
} }

View File

@ -1636,10 +1636,9 @@ heapam_index_build_range_scan(Relation heapRelation,
* For a heap-only tuple, pretend its TID is that of the root. See * For a heap-only tuple, pretend its TID is that of the root. See
* src/backend/access/heap/README.HOT for discussion. * src/backend/access/heap/README.HOT for discussion.
*/ */
HeapTupleData rootTuple; ItemPointerData tid;
OffsetNumber offnum; OffsetNumber offnum;
rootTuple = *heapTuple;
offnum = ItemPointerGetOffsetNumber(&heapTuple->t_self); offnum = ItemPointerGetOffsetNumber(&heapTuple->t_self);
if (!OffsetNumberIsValid(root_offsets[offnum - 1])) if (!OffsetNumberIsValid(root_offsets[offnum - 1]))
@ -1650,18 +1649,18 @@ heapam_index_build_range_scan(Relation heapRelation,
offnum, offnum,
RelationGetRelationName(heapRelation)))); RelationGetRelationName(heapRelation))));
ItemPointerSetOffsetNumber(&rootTuple.t_self, ItemPointerSet(&tid, ItemPointerGetBlockNumber(&heapTuple->t_self),
root_offsets[offnum - 1]); root_offsets[offnum - 1]);
/* Call the AM's callback routine to process the tuple */ /* Call the AM's callback routine to process the tuple */
callback(indexRelation, &rootTuple, values, isnull, tupleIsAlive, callback(indexRelation, &tid, values, isnull, tupleIsAlive,
callback_state); callback_state);
} }
else else
{ {
/* Call the AM's callback routine to process the tuple */ /* Call the AM's callback routine to process the tuple */
callback(indexRelation, heapTuple, values, isnull, tupleIsAlive, callback(indexRelation, &heapTuple->t_self, values, isnull,
callback_state); tupleIsAlive, callback_state);
} }
} }

View File

@ -269,7 +269,7 @@ static void _bt_spooldestroy(BTSpool *btspool);
static void _bt_spool(BTSpool *btspool, ItemPointer self, static void _bt_spool(BTSpool *btspool, ItemPointer self,
Datum *values, bool *isnull); Datum *values, bool *isnull);
static void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2); static void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2);
static void _bt_build_callback(Relation index, HeapTuple htup, Datum *values, static void _bt_build_callback(Relation index, ItemPointer tid, Datum *values,
bool *isnull, bool tupleIsAlive, void *state); bool *isnull, bool tupleIsAlive, void *state);
static Page _bt_blnewpage(uint32 level); static Page _bt_blnewpage(uint32 level);
static BTPageState *_bt_pagestate(BTWriteState *wstate, uint32 level); static BTPageState *_bt_pagestate(BTWriteState *wstate, uint32 level);
@ -585,7 +585,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
*/ */
static void static void
_bt_build_callback(Relation index, _bt_build_callback(Relation index,
HeapTuple htup, ItemPointer tid,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
bool tupleIsAlive, bool tupleIsAlive,
@ -598,12 +598,12 @@ _bt_build_callback(Relation index,
* processing * processing
*/ */
if (tupleIsAlive || buildstate->spool2 == NULL) if (tupleIsAlive || buildstate->spool2 == NULL)
_bt_spool(buildstate->spool, &htup->t_self, values, isnull); _bt_spool(buildstate->spool, tid, values, isnull);
else else
{ {
/* dead tuples are put into spool2 */ /* dead tuples are put into spool2 */
buildstate->havedead = true; buildstate->havedead = true;
_bt_spool(buildstate->spool2, &htup->t_self, values, isnull); _bt_spool(buildstate->spool2, tid, values, isnull);
} }
buildstate->indtuples += 1; buildstate->indtuples += 1;

View File

@ -40,7 +40,7 @@ typedef struct
/* Callback to process one heap tuple during table_index_build_scan */ /* Callback to process one heap tuple during table_index_build_scan */
static void static void
spgistBuildCallback(Relation index, HeapTuple htup, Datum *values, spgistBuildCallback(Relation index, ItemPointer tid, Datum *values,
bool *isnull, bool tupleIsAlive, void *state) bool *isnull, bool tupleIsAlive, void *state)
{ {
SpGistBuildState *buildstate = (SpGistBuildState *) state; SpGistBuildState *buildstate = (SpGistBuildState *) state;
@ -55,7 +55,7 @@ spgistBuildCallback(Relation index, HeapTuple htup, Datum *values,
* lock on some buffer. So we need to be willing to retry. We can flush * lock on some buffer. So we need to be willing to retry. We can flush
* any temp data when retrying. * any temp data when retrying.
*/ */
while (!spgdoinsert(index, &buildstate->spgstate, &htup->t_self, while (!spgdoinsert(index, &buildstate->spgstate, tid,
*values, *isnull)) *values, *isnull))
{ {
MemoryContextReset(buildstate->tmpCtx); MemoryContextReset(buildstate->tmpCtx);

View File

@ -141,7 +141,7 @@ typedef struct TM_FailureData
/* Typedef for callback function for table_index_build_scan */ /* Typedef for callback function for table_index_build_scan */
typedef void (*IndexBuildCallback) (Relation index, typedef void (*IndexBuildCallback) (Relation index,
HeapTuple htup, ItemPointer tid,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
bool tupleIsAlive, bool tupleIsAlive,