Skip to content

Commit 68d3073

Browse files
Merge pull request #5 from pgvector/hnsw-streaming
Fixed crash with empty index [skip ci]
2 parents 7fce7c8 + b2fa625 commit 68d3073

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/hnswscan.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ hnswbeginscan(Relation index, int nkeys, int norderbys)
117117
so = (HnswScanOpaque) palloc(sizeof(HnswScanOpaqueData));
118118
so->typeInfo = HnswGetTypeInfo(index);
119119
so->first = true;
120+
so->v.tids = NULL;
121+
so->discarded = NULL;
120122
so->tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
121123
"Hnsw scan temporary context",
122124
ALLOCSET_DEFAULT_SIZES);
@@ -139,11 +141,12 @@ hnswrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int no
139141
{
140142
HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
141143

142-
if (!so->first)
143-
{
144-
pairingheap_reset(so->discarded);
144+
if (so->v.tids != NULL)
145145
tidhash_reset(so->v.tids);
146-
}
146+
147+
if (so->discarded != NULL)
148+
pairingheap_reset(so->discarded);
149+
147150
so->first = true;
148151
so->tuples = 0;
149152
MemoryContextReset(so->tmpCtx);
@@ -219,6 +222,10 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
219222
if (!hnsw_streaming)
220223
break;
221224

225+
/* Empty index */
226+
if (so->discarded == NULL)
227+
break;
228+
222229
/* Reached max number of additional tuples */
223230
if (hnsw_ef_stream != -1 && so->tuples >= hnsw_ef_search + hnsw_ef_stream)
224231
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy