Skip to content

Commit 55dc735

Browse files
committed
Moved allocations out of GetScanItems [skip ci]
1 parent be4e9a9 commit 55dc735

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/ivfflat.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ typedef struct IvfflatScanOpaqueData
253253
/* Sorting */
254254
Tuplesortstate *sortstate;
255255
TupleDesc tupdesc;
256-
TupleTableSlot *slot;
257-
bool isnull;
256+
TupleTableSlot *vslot;
257+
TupleTableSlot *mslot;
258+
BufferAccessStrategy bas;
258259

259260
/* Support functions */
260261
FmgrInfo *procinfo;

src/ivfscan.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,7 @@ GetScanItems(IndexScanDesc scan, Datum value)
113113
IvfflatScanOpaque so = (IvfflatScanOpaque) scan->opaque;
114114
TupleDesc tupdesc = RelationGetDescr(scan->indexRelation);
115115
double tuples = 0;
116-
TupleTableSlot *slot = MakeSingleTupleTableSlot(so->tupdesc, &TTSOpsVirtual);
117-
118-
/*
119-
* Reuse same set of shared buffers for scan
120-
*
121-
* See postgres/src/backend/storage/buffer/README for description
122-
*/
123-
BufferAccessStrategy bas = GetAccessStrategy(BAS_BULKREAD);
116+
TupleTableSlot *slot = so->vslot;
124117

125118
/* Search closest probes lists */
126119
while (!pairingheap_is_empty(so->listQueue))
@@ -134,7 +127,7 @@ GetScanItems(IndexScanDesc scan, Datum value)
134127
Page page;
135128
OffsetNumber maxoffno;
136129

137-
buf = ReadBufferExtended(scan->indexRelation, MAIN_FORKNUM, searchPage, RBM_NORMAL, bas);
130+
buf = ReadBufferExtended(scan->indexRelation, MAIN_FORKNUM, searchPage, RBM_NORMAL, so->bas);
138131
LockBuffer(buf, BUFFER_LOCK_SHARE);
139132
page = BufferGetPage(buf);
140133
maxoffno = PageGetMaxOffsetNumber(page);
@@ -173,8 +166,6 @@ GetScanItems(IndexScanDesc scan, Datum value)
173166
}
174167
}
175168

176-
FreeAccessStrategy(bas);
177-
178169
if (tuples < 100)
179170
ereport(DEBUG1,
180171
(errmsg("index scan found few tuples"),
@@ -277,7 +268,16 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
277268
/* Prep sort */
278269
so->sortstate = InitScanSortState(so->tupdesc);
279270

280-
so->slot = MakeSingleTupleTableSlot(so->tupdesc, &TTSOpsMinimalTuple);
271+
/* Need separate slots for puttuple and gettuple */
272+
so->vslot = MakeSingleTupleTableSlot(so->tupdesc, &TTSOpsVirtual);
273+
so->mslot = MakeSingleTupleTableSlot(so->tupdesc, &TTSOpsMinimalTuple);
274+
275+
/*
276+
* Reuse same set of shared buffers for scan
277+
*
278+
* See postgres/src/backend/storage/buffer/README for description
279+
*/
280+
so->bas = GetAccessStrategy(BAS_BULKREAD);
281281

282282
so->listQueue = pairingheap_allocate(CompareLists, scan);
283283

@@ -351,9 +351,10 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
351351
pfree(DatumGetPointer(value));
352352
}
353353

354-
if (tuplesort_gettupleslot(so->sortstate, true, false, so->slot, NULL))
354+
if (tuplesort_gettupleslot(so->sortstate, true, false, so->mslot, NULL))
355355
{
356-
ItemPointer heaptid = (ItemPointer) DatumGetPointer(slot_getattr(so->slot, 2, &so->isnull));
356+
bool isnull;
357+
ItemPointer heaptid = (ItemPointer) DatumGetPointer(slot_getattr(so->mslot, 2, &isnull));
357358

358359
scan->xs_heaptid = *heaptid;
359360
scan->xs_recheck = false;
@@ -374,6 +375,7 @@ ivfflatendscan(IndexScanDesc scan)
374375

375376
pairingheap_free(so->listQueue);
376377
tuplesort_end(so->sortstate);
378+
FreeAccessStrategy(so->bas);
377379

378380
pfree(so);
379381
scan->opaque = NULL;

0 commit comments

Comments
 (0)