Improved concurrent inserts with low number of elements

This commit is contained in:
Andrew Kane
2023-08-10 15:07:28 -07:00
parent 483173460b
commit a18bea24b8
2 changed files with 15 additions and 3 deletions

View File

@@ -290,6 +290,7 @@ UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswEleme
HnswNeighborTuple ntup;
Size ntupSize;
int idx = -1;
int startIdx;
OffsetNumber offno = hc->element->neighborOffno;
/* Get latest neighbors */
@@ -312,10 +313,21 @@ UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswEleme
ntupSize = ItemIdGetLength(itemid);
/* 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 */
if (idx < ntup->count)
if (idx >= 0 && idx < ntup->count)
{
ItemPointer indextid = &ntup->indextids[idx];

View File

@@ -818,7 +818,7 @@ HnswUpdateConnection(HnswElement element, HnswCandidate * hc, int m, int lc, int
/* Track update */
if (updateIdx != NULL)
*updateIdx = currentNeighbors->length - 1;
*updateIdx = -2;
}
else
{