mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 15:16:54 +08:00
Use memory context for adding samples
This commit is contained in:
@@ -39,20 +39,16 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Callback for sampling
|
* Add sample
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
SampleCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
|
AddSample(Datum *values, IvfflatBuildState * buildstate)
|
||||||
bool *isnull, bool tupleIsAlive, void *state)
|
|
||||||
{
|
{
|
||||||
IvfflatBuildState *buildstate = (IvfflatBuildState *) state;
|
|
||||||
VectorArray samples = buildstate->samples;
|
VectorArray samples = buildstate->samples;
|
||||||
int targsamples = samples->maxlen;
|
int targsamples = samples->maxlen;
|
||||||
Datum value = values[0];
|
|
||||||
|
|
||||||
/* Skip nulls */
|
/* Detoast once for all calls */
|
||||||
if (isnull[0])
|
Datum value = PointerGetDatum(PG_DETOAST_DATUM(values[0]));
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Normalize with KMEANS_NORM_PROC since spherical distance function
|
* Normalize with KMEANS_NORM_PROC since spherical distance function
|
||||||
@@ -90,6 +86,31 @@ SampleCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Callback for sampling
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
SampleCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
|
||||||
|
bool *isnull, bool tupleIsAlive, void *state)
|
||||||
|
{
|
||||||
|
IvfflatBuildState *buildstate = (IvfflatBuildState *) state;
|
||||||
|
MemoryContext oldCtx;
|
||||||
|
|
||||||
|
/* Skip nulls */
|
||||||
|
if (isnull[0])
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Use memory context since detoast can allocate */
|
||||||
|
oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);
|
||||||
|
|
||||||
|
/* Add sample */
|
||||||
|
AddSample(values, state);
|
||||||
|
|
||||||
|
/* Reset memory context */
|
||||||
|
MemoryContextSwitchTo(oldCtx);
|
||||||
|
MemoryContextReset(buildstate->tmpCtx);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sample rows with same logic as ANALYZE
|
* Sample rows with same logic as ANALYZE
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user