mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-12 23:56:55 +08:00
Improved concurrent inserts with low number of elements
This commit is contained in:
@@ -290,6 +290,7 @@ UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswEleme
|
|||||||
HnswNeighborTuple ntup;
|
HnswNeighborTuple ntup;
|
||||||
Size ntupSize;
|
Size ntupSize;
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
int startIdx;
|
||||||
OffsetNumber offno = hc->element->neighborOffno;
|
OffsetNumber offno = hc->element->neighborOffno;
|
||||||
|
|
||||||
/* Get latest neighbors */
|
/* Get latest neighbors */
|
||||||
@@ -312,10 +313,21 @@ UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswEleme
|
|||||||
ntupSize = ItemIdGetLength(itemid);
|
ntupSize = ItemIdGetLength(itemid);
|
||||||
|
|
||||||
/* Calculate index for update */
|
/* Calculate index for update */
|
||||||
idx += (hc->element->level - lc) * m;
|
startIdx = (hc->element->level - lc) * m;
|
||||||
|
|
||||||
|
if (idx == -2)
|
||||||
|
{
|
||||||
|
/* Find free offset if still exists */
|
||||||
|
/* TODO Retry updating connections if not */
|
||||||
|
for (int i = 0; i < lm; i++)
|
||||||
|
if (!ItemPointerIsValid(&ntup->indextids[startIdx + i]))
|
||||||
|
idx = startIdx + i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
idx += startIdx;
|
||||||
|
|
||||||
/* Make robust to issues */
|
/* Make robust to issues */
|
||||||
if (idx < ntup->count)
|
if (idx >= 0 && idx < ntup->count)
|
||||||
{
|
{
|
||||||
ItemPointer indextid = &ntup->indextids[idx];
|
ItemPointer indextid = &ntup->indextids[idx];
|
||||||
|
|
||||||
|
|||||||
@@ -818,7 +818,7 @@ HnswUpdateConnection(HnswElement element, HnswCandidate * hc, int m, int lc, int
|
|||||||
|
|
||||||
/* Track update */
|
/* Track update */
|
||||||
if (updateIdx != NULL)
|
if (updateIdx != NULL)
|
||||||
*updateIdx = currentNeighbors->length - 1;
|
*updateIdx = -2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user