Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf379ee

Browse files
committed
Use a memory context for IVFFlat index scans
1 parente1bc929 commitbf379ee

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

‎src/ivfflat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ typedef struct IvfflatScanOpaqueData
260260
intdimensions;
261261
boolfirst;
262262
Datumvalue;
263+
MemoryContexttmpCtx;
263264

264265
/* Sorting */
265266
Tuplesortstate*sortstate;

‎src/ivfscan.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
#include"miscadmin.h"
1111
#include"pgstat.h"
1212
#include"storage/bufmgr.h"
13-
14-
#ifdefIVFFLAT_MEMORY
1513
#include"utils/memutils.h"
16-
#endif
1714

1815
#defineGetScanList(ptr) pairingheap_container(IvfflatScanList, ph_node, ptr)
1916
#defineGetScanListConst(ptr) pairingheap_const_container(IvfflatScanList, ph_node, ptr)
@@ -221,7 +218,13 @@ GetScanValue(IndexScanDesc scan)
221218

222219
/* Normalize if needed */
223220
if (so->normprocinfo!=NULL)
221+
{
222+
MemoryContextoldCtx=MemoryContextSwitchTo(so->tmpCtx);
223+
224224
value=IvfflatNormValue(so->typeInfo,so->collation,value);
225+
226+
MemoryContextSwitchTo(oldCtx);
227+
}
225228
}
226229

227230
returnvalue;
@@ -253,6 +256,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
253256
intdimensions;
254257
intprobes=ivfflat_probes;
255258
intmaxProbes;
259+
MemoryContextoldCtx;
256260

257261
scan=RelationGetIndexScan(index,nkeys,norderbys);
258262

@@ -292,6 +296,12 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
292296
so->normprocinfo=IvfflatOptionalProcInfo(index,IVFFLAT_NORM_PROC);
293297
so->collation=index->rd_indcollation[0];
294298

299+
so->tmpCtx=AllocSetContextCreate(CurrentMemoryContext,
300+
"Ivfflat scan temporary context",
301+
ALLOCSET_DEFAULT_SIZES);
302+
303+
oldCtx=MemoryContextSwitchTo(so->tmpCtx);
304+
295305
/* Create tuple description for sorting */
296306
so->tupdesc=CreateTemplateTupleDesc(2);
297307
TupleDescInitEntry(so->tupdesc, (AttrNumber)1,"distance",FLOAT8OID,-1,0);
@@ -316,6 +326,8 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
316326
so->listIndex=0;
317327
so->lists=palloc(maxProbes*sizeof(IvfflatScanList));
318328

329+
MemoryContextSwitchTo(oldCtx);
330+
319331
scan->opaque=so;
320332

321333
returnscan;
@@ -377,8 +389,6 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
377389
IvfflatBench("GetScanItems",GetScanItems(scan,value));
378390
so->first= false;
379391
so->value=value;
380-
381-
/* TODO clean up if we allocated a new value */
382392
}
383393

384394
while (!tuplesort_gettupleslot(so->sortstate, true, false,so->mslot,NULL))
@@ -405,14 +415,10 @@ ivfflatendscan(IndexScanDesc scan)
405415
{
406416
IvfflatScanOpaqueso= (IvfflatScanOpaque)scan->opaque;
407417

408-
pairingheap_free(so->listQueue);
409-
pfree(so->listPages);
418+
/* Free any temporary files */
410419
tuplesort_end(so->sortstate);
411-
FreeAccessStrategy(so->bas);
412-
FreeTupleDesc(so->tupdesc);
413-
pfree(so->lists);
414420

415-
/* TODO Free vslot and mslot without freeing TupleDesc */
421+
MemoryContextDelete(so->tmpCtx);
416422

417423
pfree(so);
418424
scan->opaque=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp