Skip to content

Commit aae5023

Browse files
committed
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
1 parent 71a8a4f commit aae5023

File tree

10 files changed

+29
-32
lines changed

10 files changed

+29
-32
lines changed

contrib/amcheck/verify_nbtree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static BTScanInsert bt_right_page_check_scankey(BtreeCheckState *state);
140140
static void bt_downlink_check(BtreeCheckState *state, BTScanInsert targetkey,
141141
BlockNumber childblock);
142142
static void bt_downlink_missing_check(BtreeCheckState *state);
143-
static void bt_tuple_present_callback(Relation index, HeapTuple htup,
143+
static void bt_tuple_present_callback(Relation index, ItemPointer tid,
144144
Datum *values, bool *isnull,
145145
bool tupleIsAlive, void *checkstate);
146146
static IndexTuple bt_normalize_tuple(BtreeCheckState *state,
@@ -1890,7 +1890,7 @@ bt_downlink_missing_check(BtreeCheckState *state)
18901890
* also allows us to detect the corruption in many cases.
18911891
*/
18921892
static void
1893-
bt_tuple_present_callback(Relation index, HeapTuple htup, Datum *values,
1893+
bt_tuple_present_callback(Relation index, ItemPointer tid, Datum *values,
18941894
bool *isnull, bool tupleIsAlive, void *checkstate)
18951895
{
18961896
BtreeCheckState *state = (BtreeCheckState *) checkstate;
@@ -1901,7 +1901,7 @@ bt_tuple_present_callback(Relation index, HeapTuple htup, Datum *values,
19011901

19021902
/* Generate a normalized index tuple for fingerprinting */
19031903
itup = index_form_tuple(RelationGetDescr(index), values, isnull);
1904-
itup->t_tid = htup->t_self;
1904+
itup->t_tid = *tid;
19051905
norm = bt_normalize_tuple(state, itup);
19061906

19071907
/* Probe Bloom filter -- tuple should be present */

contrib/bloom/blinsert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ initCachedPage(BloomBuildState *buildstate)
7272
* Per-tuple callback for table_index_build_scan.
7373
*/
7474
static void
75-
bloomBuildCallback(Relation index, HeapTuple htup, Datum *values,
75+
bloomBuildCallback(Relation index, ItemPointer tid, Datum *values,
7676
bool *isnull, bool tupleIsAlive, void *state)
7777
{
7878
BloomBuildState *buildstate = (BloomBuildState *) state;
@@ -81,7 +81,7 @@ bloomBuildCallback(Relation index, HeapTuple htup, Datum *values,
8181

8282
oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);
8383

84-
itup = BloomFormTuple(&buildstate->blstate, &htup->t_self, values, isnull);
84+
itup = BloomFormTuple(&buildstate->blstate, tid, values, isnull);
8585

8686
/* Try to add next item to cached page */
8787
if (BloomPageAddItem(&buildstate->blstate, buildstate->data.data, itup))

src/backend/access/brin/brin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ brinendscan(IndexScanDesc scan)
597597
*/
598598
static void
599599
brinbuildCallback(Relation index,
600-
HeapTuple htup,
600+
ItemPointer tid,
601601
Datum *values,
602602
bool *isnull,
603603
bool tupleIsAlive,
@@ -607,7 +607,7 @@ brinbuildCallback(Relation index,
607607
BlockNumber thisblock;
608608
int i;
609609

610-
thisblock = ItemPointerGetBlockNumber(&htup->t_self);
610+
thisblock = ItemPointerGetBlockNumber(tid);
611611

612612
/*
613613
* If we're in a block that belongs to a future range, summarize what

src/backend/access/gin/gininsert.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ ginHeapTupleBulkInsert(GinBuildState *buildstate, OffsetNumber attnum,
276276
}
277277

278278
static void
279-
ginBuildCallback(Relation index, HeapTuple htup, Datum *values,
279+
ginBuildCallback(Relation index, ItemPointer tid, Datum *values,
280280
bool *isnull, bool tupleIsAlive, void *state)
281281
{
282282
GinBuildState *buildstate = (GinBuildState *) state;
@@ -287,8 +287,7 @@ ginBuildCallback(Relation index, HeapTuple htup, Datum *values,
287287

288288
for (i = 0; i < buildstate->ginstate.origTupdesc->natts; i++)
289289
ginHeapTupleBulkInsert(buildstate, (OffsetNumber) (i + 1),
290-
values[i], isnull[i],
291-
&htup->t_self);
290+
values[i], isnull[i], tid);
292291

293292
/* If we've maxed out our available memory, dump everything to the index */
294293
if (buildstate->accum.allocatedMemory >= (Size) maintenance_work_mem * 1024L)

src/backend/access/gist/gistbuild.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef struct
8080
static void gistInitBuffering(GISTBuildState *buildstate);
8181
static int calculatePagesPerBuffer(GISTBuildState *buildstate, int levelStep);
8282
static void gistBuildCallback(Relation index,
83-
HeapTuple htup,
83+
ItemPointer tid,
8484
Datum *values,
8585
bool *isnull,
8686
bool tupleIsAlive,
@@ -440,7 +440,7 @@ calculatePagesPerBuffer(GISTBuildState *buildstate, int levelStep)
440440
*/
441441
static void
442442
gistBuildCallback(Relation index,
443-
HeapTuple htup,
443+
ItemPointer tid,
444444
Datum *values,
445445
bool *isnull,
446446
bool tupleIsAlive,
@@ -454,7 +454,7 @@ gistBuildCallback(Relation index,
454454

455455
/* form an index tuple and point it at the heap tuple */
456456
itup = gistFormTuple(buildstate->giststate, index, values, isnull, true);
457-
itup->t_tid = htup->t_self;
457+
itup->t_tid = *tid;
458458

459459
if (buildstate->bufferingMode == GIST_BUFFERING_ACTIVE)
460460
{

src/backend/access/hash/hash.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct
4343
} HashBuildState;
4444

4545
static void hashbuildCallback(Relation index,
46-
HeapTuple htup,
46+
ItemPointer tid,
4747
Datum *values,
4848
bool *isnull,
4949
bool tupleIsAlive,
@@ -201,7 +201,7 @@ hashbuildempty(Relation index)
201201
*/
202202
static void
203203
hashbuildCallback(Relation index,
204-
HeapTuple htup,
204+
ItemPointer tid,
205205
Datum *values,
206206
bool *isnull,
207207
bool tupleIsAlive,
@@ -220,14 +220,13 @@ hashbuildCallback(Relation index,
220220

221221
/* Either spool the tuple for sorting, or just put it into the index */
222222
if (buildstate->spool)
223-
_h_spool(buildstate->spool, &htup->t_self,
224-
index_values, index_isnull);
223+
_h_spool(buildstate->spool, tid, index_values, index_isnull);
225224
else
226225
{
227226
/* form an index tuple and point it at the heap tuple */
228227
itup = index_form_tuple(RelationGetDescr(index),
229228
index_values, index_isnull);
230-
itup->t_tid = htup->t_self;
229+
itup->t_tid = *tid;
231230
_hash_doinsert(index, itup, buildstate->heapRel);
232231
pfree(itup);
233232
}

src/backend/access/heap/heapam_handler.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,10 +1636,9 @@ heapam_index_build_range_scan(Relation heapRelation,
16361636
* For a heap-only tuple, pretend its TID is that of the root. See
16371637
* src/backend/access/heap/README.HOT for discussion.
16381638
*/
1639-
HeapTupleData rootTuple;
1639+
ItemPointerData tid;
16401640
OffsetNumber offnum;
16411641

1642-
rootTuple = *heapTuple;
16431642
offnum = ItemPointerGetOffsetNumber(&heapTuple->t_self);
16441643

16451644
if (!OffsetNumberIsValid(root_offsets[offnum - 1]))
@@ -1650,18 +1649,18 @@ heapam_index_build_range_scan(Relation heapRelation,
16501649
offnum,
16511650
RelationGetRelationName(heapRelation))));
16521651

1653-
ItemPointerSetOffsetNumber(&rootTuple.t_self,
1654-
root_offsets[offnum - 1]);
1652+
ItemPointerSet(&tid, ItemPointerGetBlockNumber(&heapTuple->t_self),
1653+
root_offsets[offnum - 1]);
16551654

16561655
/* Call the AM's callback routine to process the tuple */
1657-
callback(indexRelation, &rootTuple, values, isnull, tupleIsAlive,
1656+
callback(indexRelation, &tid, values, isnull, tupleIsAlive,
16581657
callback_state);
16591658
}
16601659
else
16611660
{
16621661
/* Call the AM's callback routine to process the tuple */
1663-
callback(indexRelation, heapTuple, values, isnull, tupleIsAlive,
1664-
callback_state);
1662+
callback(indexRelation, &heapTuple->t_self, values, isnull,
1663+
tupleIsAlive, callback_state);
16651664
}
16661665
}
16671666

src/backend/access/nbtree/nbtsort.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static void _bt_spooldestroy(BTSpool *btspool);
269269
static void _bt_spool(BTSpool *btspool, ItemPointer self,
270270
Datum *values, bool *isnull);
271271
static void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2);
272-
static void _bt_build_callback(Relation index, HeapTuple htup, Datum *values,
272+
static void _bt_build_callback(Relation index, ItemPointer tid, Datum *values,
273273
bool *isnull, bool tupleIsAlive, void *state);
274274
static Page _bt_blnewpage(uint32 level);
275275
static BTPageState *_bt_pagestate(BTWriteState *wstate, uint32 level);
@@ -585,7 +585,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
585585
*/
586586
static void
587587
_bt_build_callback(Relation index,
588-
HeapTuple htup,
588+
ItemPointer tid,
589589
Datum *values,
590590
bool *isnull,
591591
bool tupleIsAlive,
@@ -598,12 +598,12 @@ _bt_build_callback(Relation index,
598598
* processing
599599
*/
600600
if (tupleIsAlive || buildstate->spool2 == NULL)
601-
_bt_spool(buildstate->spool, &htup->t_self, values, isnull);
601+
_bt_spool(buildstate->spool, tid, values, isnull);
602602
else
603603
{
604604
/* dead tuples are put into spool2 */
605605
buildstate->havedead = true;
606-
_bt_spool(buildstate->spool2, &htup->t_self, values, isnull);
606+
_bt_spool(buildstate->spool2, tid, values, isnull);
607607
}
608608

609609
buildstate->indtuples += 1;

src/backend/access/spgist/spginsert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ typedef struct
4040

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

src/include/access/tableam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef struct TM_FailureData
141141

142142
/* Typedef for callback function for table_index_build_scan */
143143
typedef void (*IndexBuildCallback) (Relation index,
144-
HeapTuple htup,
144+
ItemPointer tid,
145145
Datum *values,
146146
bool *isnull,
147147
bool tupleIsAlive,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy