mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 20:15:46 +08:00
Compare commits
1 Commits
v0.8.3
...
amgettuple
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47c7fa715c |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -97,7 +97,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
postgres-version: ${{ matrix.postgres }}
|
postgres-version: ${{ matrix.postgres }}
|
||||||
- run: |
|
- run: |
|
||||||
call "C:\Program Files\Microsoft Visual Studio\${{ matrix.os == 'windows-2025' && 18 || 2022 }}\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && ^
|
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && ^
|
||||||
nmake /NOLOGO /F Makefile.win && ^
|
nmake /NOLOGO /F Makefile.win && ^
|
||||||
nmake /NOLOGO /F Makefile.win install && ^
|
nmake /NOLOGO /F Makefile.win install && ^
|
||||||
nmake /NOLOGO /F Makefile.win installcheck ${{ matrix.postgres != 17 && 'PG_REGRESS=$(PGROOT)\bin\pg_regress' || '' }} && ^
|
nmake /NOLOGO /F Makefile.win installcheck ${{ matrix.postgres != 17 && 'PG_REGRESS=$(PGROOT)\bin\pg_regress' || '' }} && ^
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
## 0.8.3 (2026-06-17)
|
|
||||||
|
|
||||||
- Fixed possible index corruption with HNSW vacuuming
|
|
||||||
- Fixed performance regression with Hamming distance and Jaccard distance with Postgres 18
|
|
||||||
|
|
||||||
## 0.8.2 (2026-02-25)
|
## 0.8.2 (2026-02-25)
|
||||||
|
|
||||||
- Fixed buffer overflow with parallel HNSW index build - [more info](https://github.com/pgvector/pgvector/issues/959)
|
- Fixed buffer overflow with parallel HNSW index build - [more info](https://github.com/pgvector/pgvector/issues/959)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ ARG DEBIAN_CODENAME=bookworm
|
|||||||
FROM postgres:$PG_MAJOR-$DEBIAN_CODENAME
|
FROM postgres:$PG_MAJOR-$DEBIAN_CODENAME
|
||||||
ARG PG_MAJOR
|
ARG PG_MAJOR
|
||||||
|
|
||||||
ADD https://github.com/pgvector/pgvector.git#v0.8.3 /tmp/pgvector
|
ADD https://github.com/pgvector/pgvector.git#v0.8.2 /tmp/pgvector
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-mark hold locales && \
|
apt-mark hold locales && \
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "vector",
|
"name": "vector",
|
||||||
"abstract": "Open-source vector similarity search for Postgres",
|
"abstract": "Open-source vector similarity search for Postgres",
|
||||||
"description": "Supports L2 distance, inner product, and cosine distance",
|
"description": "Supports L2 distance, inner product, and cosine distance",
|
||||||
"version": "0.8.3",
|
"version": "0.8.2",
|
||||||
"maintainer": [
|
"maintainer": [
|
||||||
"Andrew Kane <andrew@ankane.org>"
|
"Andrew Kane <andrew@ankane.org>"
|
||||||
],
|
],
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
"vector": {
|
"vector": {
|
||||||
"file": "sql/vector.sql",
|
"file": "sql/vector.sql",
|
||||||
"docfile": "README.md",
|
"docfile": "README.md",
|
||||||
"version": "0.8.3",
|
"version": "0.8.2",
|
||||||
"abstract": "Open-source vector similarity search for Postgres"
|
"abstract": "Open-source vector similarity search for Postgres"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
|||||||
EXTENSION = vector
|
EXTENSION = vector
|
||||||
EXTVERSION = 0.8.3
|
EXTVERSION = 0.8.2
|
||||||
|
|
||||||
MODULE_big = vector
|
MODULE_big = vector
|
||||||
DATA = $(wildcard sql/*--*--*.sql)
|
DATA = $(wildcard sql/*--*--*.sql)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
EXTENSION = vector
|
EXTENSION = vector
|
||||||
EXTVERSION = 0.8.3
|
EXTVERSION = 0.8.2
|
||||||
|
|
||||||
DATA_built = sql\$(EXTENSION)--$(EXTVERSION).sql
|
DATA_built = sql\$(EXTENSION)--$(EXTVERSION).sql
|
||||||
OBJS = src\bitutils.obj src\bitvec.obj src\halfutils.obj src\halfvec.obj src\hnsw.obj src\hnswbuild.obj src\hnswinsert.obj src\hnswscan.obj src\hnswutils.obj src\hnswvacuum.obj src\ivfbuild.obj src\ivfflat.obj src\ivfinsert.obj src\ivfkmeans.obj src\ivfscan.obj src\ivfutils.obj src\ivfvacuum.obj src\sparsevec.obj src\vector.obj
|
OBJS = src\bitutils.obj src\bitvec.obj src\halfutils.obj src\halfvec.obj src\hnsw.obj src\hnswbuild.obj src\hnswinsert.obj src\hnswscan.obj src\hnswutils.obj src\hnswvacuum.obj src\ivfbuild.obj src\ivfflat.obj src\ivfinsert.obj src\ivfkmeans.obj src\ivfscan.obj src\ivfutils.obj src\ivfvacuum.obj src\sparsevec.obj src\vector.obj
|
||||||
|
|||||||
32
README.md
32
README.md
@@ -23,7 +23,7 @@ Compile and install the extension (supports Postgres 13+)
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd /tmp
|
cd /tmp
|
||||||
git clone --branch v0.8.3 https://github.com/pgvector/pgvector.git
|
git clone --branch v0.8.2 https://github.com/pgvector/pgvector.git
|
||||||
cd pgvector
|
cd pgvector
|
||||||
make
|
make
|
||||||
make install # may need sudo
|
make install # may need sudo
|
||||||
@@ -40,7 +40,7 @@ Ensure [C++ support in Visual Studio](https://learn.microsoft.com/en-us/cpp/buil
|
|||||||
```cmd
|
```cmd
|
||||||
set "PGROOT=C:\Program Files\PostgreSQL\18"
|
set "PGROOT=C:\Program Files\PostgreSQL\18"
|
||||||
cd %TEMP%
|
cd %TEMP%
|
||||||
git clone --branch v0.8.3 https://github.com/pgvector/pgvector.git
|
git clone --branch v0.8.2 https://github.com/pgvector/pgvector.git
|
||||||
cd pgvector
|
cd pgvector
|
||||||
nmake /F Makefile.win
|
nmake /F Makefile.win
|
||||||
nmake /F Makefile.win install
|
nmake /F Makefile.win install
|
||||||
@@ -1151,23 +1151,23 @@ This adds pgvector to the [Postgres image](https://hub.docker.com/_/postgres) (r
|
|||||||
|
|
||||||
Supported tags are:
|
Supported tags are:
|
||||||
|
|
||||||
- `pg18-trixie`, `0.8.3-pg18-trixie`
|
- `pg18-trixie`, `0.8.2-pg18-trixie`
|
||||||
- `pg18-bookworm`, `0.8.3-pg18-bookworm`, `pg18`, `0.8.3-pg18`
|
- `pg18-bookworm`, `0.8.2-pg18-bookworm`, `pg18`, `0.8.2-pg18`
|
||||||
- `pg17-trixie`, `0.8.3-pg17-trixie`
|
- `pg17-trixie`, `0.8.2-pg17-trixie`
|
||||||
- `pg17-bookworm`, `0.8.3-pg17-bookworm`, `pg17`, `0.8.3-pg17`
|
- `pg17-bookworm`, `0.8.2-pg17-bookworm`, `pg17`, `0.8.2-pg17`
|
||||||
- `pg16-trixie`, `0.8.3-pg16-trixie`
|
- `pg16-trixie`, `0.8.2-pg16-trixie`
|
||||||
- `pg16-bookworm`, `0.8.3-pg16-bookworm`, `pg16`, `0.8.3-pg16`
|
- `pg16-bookworm`, `0.8.2-pg16-bookworm`, `pg16`, `0.8.2-pg16`
|
||||||
- `pg15-trixie`, `0.8.3-pg15-trixie`
|
- `pg15-trixie`, `0.8.2-pg15-trixie`
|
||||||
- `pg15-bookworm`, `0.8.3-pg15-bookworm`, `pg15`, `0.8.3-pg15`
|
- `pg15-bookworm`, `0.8.2-pg15-bookworm`, `pg15`, `0.8.2-pg15`
|
||||||
- `pg14-trixie`, `0.8.3-pg14-trixie`
|
- `pg14-trixie`, `0.8.2-pg14-trixie`
|
||||||
- `pg14-bookworm`, `0.8.3-pg14-bookworm`, `pg14`, `0.8.3-pg14`
|
- `pg14-bookworm`, `0.8.2-pg14-bookworm`, `pg14`, `0.8.2-pg14`
|
||||||
- `pg13-trixie`, `0.8.3-pg13-trixie`
|
- `pg13-trixie`, `0.8.2-pg13-trixie`
|
||||||
- `pg13-bookworm`, `0.8.3-pg13-bookworm`, `pg13`, `0.8.3-pg13`
|
- `pg13-bookworm`, `0.8.2-pg13-bookworm`, `pg13`, `0.8.2-pg13`
|
||||||
|
|
||||||
You can also build the image manually:
|
You can also build the image manually:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone --branch v0.8.3 https://github.com/pgvector/pgvector.git
|
git clone --branch v0.8.2 https://github.com/pgvector/pgvector.git
|
||||||
cd pgvector
|
cd pgvector
|
||||||
docker build --pull --build-arg PG_MAJOR=18 -t myuser/pgvector .
|
docker build --pull --build-arg PG_MAJOR=18 -t myuser/pgvector .
|
||||||
```
|
```
|
||||||
@@ -1329,7 +1329,7 @@ make clean && PG_CFLAGS="-DUSE_ASSERT_CHECKING" make && make install
|
|||||||
To enable benchmarking:
|
To enable benchmarking:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make clean && PG_CFLAGS="-DHNSW_BENCH -DIVFFLAT_BENCH" make && make install
|
make clean && PG_CFLAGS="-DIVFFLAT_BENCH" make && make install
|
||||||
```
|
```
|
||||||
|
|
||||||
To show memory usage:
|
To show memory usage:
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
||||||
\echo Use "ALTER EXTENSION vector UPDATE TO '0.8.3'" to load this file. \quit
|
|
||||||
@@ -31,12 +31,10 @@
|
|||||||
#define BIT_TARGET_CLONES
|
#define BIT_TARGET_CLONES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Use built-ins when possible for Postgres < 19 for inlining */
|
/* Use built-ins when possible for inlining */
|
||||||
#if PG_VERSION_NUM >= 190000
|
#if defined(HAVE__BUILTIN_POPCOUNT) && defined(HAVE_LONG_INT_64)
|
||||||
#define popcount64(x) pg_popcount64(x)
|
|
||||||
#elif defined(HAVE__BUILTIN_POPCOUNT) && (defined(HAVE_LONG_INT_64) || SIZEOF_LONG == 8)
|
|
||||||
#define popcount64(x) __builtin_popcountl(x)
|
#define popcount64(x) __builtin_popcountl(x)
|
||||||
#elif defined(HAVE__BUILTIN_POPCOUNT) && (defined(HAVE_LONG_LONG_INT_64) || SIZEOF_LONG_LONG == 8)
|
#elif defined(HAVE__BUILTIN_POPCOUNT) && defined(HAVE_LONG_LONG_INT_64)
|
||||||
#define popcount64(x) __builtin_popcountll(x)
|
#define popcount64(x) __builtin_popcountll(x)
|
||||||
#elif !defined(_MSC_VER)
|
#elif !defined(_MSC_VER)
|
||||||
/* Fails to resolve with MSVC */
|
/* Fails to resolve with MSVC */
|
||||||
|
|||||||
@@ -279,6 +279,7 @@ hnswhandler(PG_FUNCTION_ARGS)
|
|||||||
.amconsistentequality = false,
|
.amconsistentequality = false,
|
||||||
.amconsistentordering = false,
|
.amconsistentordering = false,
|
||||||
.amcanbackward = false,
|
.amcanbackward = false,
|
||||||
|
.amcanmarkpos = false,
|
||||||
.amcanunique = false,
|
.amcanunique = false,
|
||||||
.amcanmulticol = false,
|
.amcanmulticol = false,
|
||||||
.amoptionalkey = true,
|
.amoptionalkey = true,
|
||||||
@@ -312,10 +313,13 @@ hnswhandler(PG_FUNCTION_ARGS)
|
|||||||
.ambeginscan = hnswbeginscan,
|
.ambeginscan = hnswbeginscan,
|
||||||
.amrescan = hnswrescan,
|
.amrescan = hnswrescan,
|
||||||
.amgettuple = hnswgettuple,
|
.amgettuple = hnswgettuple,
|
||||||
|
.amgetbatch = NULL,
|
||||||
|
.amunguardbatch = NULL,
|
||||||
|
.amkillitemsbatch = NULL,
|
||||||
|
.amgettransform = NULL,
|
||||||
.amgetbitmap = NULL,
|
.amgetbitmap = NULL,
|
||||||
.amendscan = hnswendscan,
|
.amendscan = hnswendscan,
|
||||||
.ammarkpos = NULL,
|
.amposreset = NULL,
|
||||||
.amrestrpos = NULL,
|
|
||||||
.amestimateparallelscan = NULL,
|
.amestimateparallelscan = NULL,
|
||||||
.aminitparallelscan = NULL,
|
.aminitparallelscan = NULL,
|
||||||
.amparallelrescan = NULL,
|
.amparallelrescan = NULL,
|
||||||
|
|||||||
20
src/hnsw.h
20
src/hnsw.h
@@ -18,10 +18,6 @@
|
|||||||
#include "utils/sampling.h"
|
#include "utils/sampling.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
#ifdef HNSW_BENCH
|
|
||||||
#include "portability/instr_time.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 190000
|
#if PG_VERSION_NUM >= 190000
|
||||||
typedef Pointer Item;
|
typedef Pointer Item;
|
||||||
#endif
|
#endif
|
||||||
@@ -82,21 +78,6 @@ typedef Pointer Item;
|
|||||||
#define HnswPageGetOpaque(page) ((HnswPageOpaque) PageGetSpecialPointer(page))
|
#define HnswPageGetOpaque(page) ((HnswPageOpaque) PageGetSpecialPointer(page))
|
||||||
#define HnswPageGetMeta(page) ((HnswMetaPageData *) PageGetContents(page))
|
#define HnswPageGetMeta(page) ((HnswMetaPageData *) PageGetContents(page))
|
||||||
|
|
||||||
#ifdef HNSW_BENCH
|
|
||||||
#define HnswBench(name, code) \
|
|
||||||
do { \
|
|
||||||
instr_time start; \
|
|
||||||
instr_time duration; \
|
|
||||||
INSTR_TIME_SET_CURRENT(start); \
|
|
||||||
(code); \
|
|
||||||
INSTR_TIME_SET_CURRENT(duration); \
|
|
||||||
INSTR_TIME_SUBTRACT(duration, start); \
|
|
||||||
elog(INFO, "%s: %.3f ms", name, INSTR_TIME_GET_MILLISEC(duration)); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define HnswBench(name, code) (code)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 150000
|
#if PG_VERSION_NUM >= 150000
|
||||||
#define RandomDouble() pg_prng_double(&pg_global_prng_state)
|
#define RandomDouble() pg_prng_double(&pg_global_prng_state)
|
||||||
#define SeedRandom(seed) pg_prng_seed(&pg_global_prng_state, seed)
|
#define SeedRandom(seed) pg_prng_seed(&pg_global_prng_state, seed)
|
||||||
@@ -431,7 +412,6 @@ typedef struct HnswVacuumState
|
|||||||
BufferAccessStrategy bas;
|
BufferAccessStrategy bas;
|
||||||
HnswNeighborTuple ntup;
|
HnswNeighborTuple ntup;
|
||||||
HnswElementData highestPoint;
|
HnswElementData highestPoint;
|
||||||
HnswElementData fallbackPoint;
|
|
||||||
|
|
||||||
/* Memory */
|
/* Memory */
|
||||||
MemoryContext tmpCtx;
|
MemoryContext tmpCtx;
|
||||||
|
|||||||
@@ -546,9 +546,6 @@ HnswLoadElementImpl(BlockNumber blkno, OffsetNumber offno, double *distance, Hns
|
|||||||
|
|
||||||
Assert(HnswIsElementTuple(etup));
|
Assert(HnswIsElementTuple(etup));
|
||||||
|
|
||||||
if (unlikely(etup->deleted))
|
|
||||||
elog(ERROR, "cannot load deleted element");
|
|
||||||
|
|
||||||
/* Calculate distance */
|
/* Calculate distance */
|
||||||
if (distance != NULL)
|
if (distance != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
163
src/hnswvacuum.c
163
src/hnswvacuum.c
@@ -37,20 +37,17 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
|||||||
{
|
{
|
||||||
BlockNumber blkno = HNSW_HEAD_BLKNO;
|
BlockNumber blkno = HNSW_HEAD_BLKNO;
|
||||||
HnswElement highestPoint = &vacuumstate->highestPoint;
|
HnswElement highestPoint = &vacuumstate->highestPoint;
|
||||||
HnswElement fallbackPoint = &vacuumstate->fallbackPoint;
|
|
||||||
Relation index = vacuumstate->index;
|
Relation index = vacuumstate->index;
|
||||||
BufferAccessStrategy bas = vacuumstate->bas;
|
BufferAccessStrategy bas = vacuumstate->bas;
|
||||||
|
HnswElement entryPoint = HnswGetEntryPoint(vacuumstate->index);
|
||||||
IndexBulkDeleteResult *stats = vacuumstate->stats;
|
IndexBulkDeleteResult *stats = vacuumstate->stats;
|
||||||
|
|
||||||
/* Store separately since HnswElement level is uint8 */
|
/* Store separately since highestPoint.level is uint8 */
|
||||||
int highestLevel = -1;
|
int highestLevel = -1;
|
||||||
int fallbackLevel = -1;
|
|
||||||
|
|
||||||
/* Initialize highest point and fallback point */
|
/* Initialize highest point */
|
||||||
highestPoint->blkno = InvalidBlockNumber;
|
highestPoint->blkno = InvalidBlockNumber;
|
||||||
highestPoint->offno = InvalidOffsetNumber;
|
highestPoint->offno = InvalidOffsetNumber;
|
||||||
fallbackPoint->blkno = InvalidBlockNumber;
|
|
||||||
fallbackPoint->offno = InvalidOffsetNumber;
|
|
||||||
|
|
||||||
while (BlockNumberIsValid(blkno))
|
while (BlockNumberIsValid(blkno))
|
||||||
{
|
{
|
||||||
@@ -122,31 +119,14 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
|||||||
tidhash_insert(vacuumstate->deleted, ip, &found);
|
tidhash_insert(vacuumstate->deleted, ip, &found);
|
||||||
Assert(!found);
|
Assert(!found);
|
||||||
}
|
}
|
||||||
else if (etup->level > highestLevel)
|
else if (etup->level > highestLevel && !(entryPoint != NULL && blkno == entryPoint->blkno && offno == entryPoint->offno))
|
||||||
{
|
{
|
||||||
if (BlockNumberIsValid(highestPoint->blkno))
|
/* Keep track of highest non-entry point */
|
||||||
{
|
|
||||||
/* Current highest point becomes fallback */
|
|
||||||
fallbackPoint->blkno = highestPoint->blkno;
|
|
||||||
fallbackPoint->offno = highestPoint->offno;
|
|
||||||
fallbackPoint->level = highestPoint->level;
|
|
||||||
fallbackLevel = highestLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Keep track of highest point */
|
|
||||||
highestPoint->blkno = blkno;
|
highestPoint->blkno = blkno;
|
||||||
highestPoint->offno = offno;
|
highestPoint->offno = offno;
|
||||||
highestPoint->level = etup->level;
|
highestPoint->level = etup->level;
|
||||||
highestLevel = etup->level;
|
highestLevel = etup->level;
|
||||||
}
|
}
|
||||||
else if (etup->level > fallbackLevel)
|
|
||||||
{
|
|
||||||
/* Keep track of second highest point */
|
|
||||||
fallbackPoint->blkno = blkno;
|
|
||||||
fallbackPoint->offno = offno;
|
|
||||||
fallbackPoint->level = etup->level;
|
|
||||||
fallbackLevel = etup->level;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blkno = HnswPageGetOpaque(page)->nextblkno;
|
blkno = HnswPageGetOpaque(page)->nextblkno;
|
||||||
@@ -158,10 +138,6 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
|||||||
|
|
||||||
UnlockReleaseBuffer(buf);
|
UnlockReleaseBuffer(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HNSW_MEMORY
|
|
||||||
elog(INFO, "memory: %zu KB", MemoryContextMemAllocated(CurrentMemoryContext, true) / 1024);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -293,27 +269,12 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
/* Get a shared lock */
|
/* Get a shared lock */
|
||||||
LockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
LockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
||||||
|
|
||||||
/* Get latest entry point */
|
/* Load element */
|
||||||
entryPoint = HnswGetEntryPoint(index);
|
HnswLoadElement(highestPoint, NULL, NULL, index, support, true, NULL);
|
||||||
|
|
||||||
/* Use fallback point if highest point is entry point */
|
/* Repair if needed */
|
||||||
if (entryPoint != NULL && entryPoint->blkno == highestPoint->blkno && entryPoint->offno == highestPoint->offno)
|
if (NeedsUpdated(vacuumstate, highestPoint))
|
||||||
{
|
RepairGraphElement(vacuumstate, highestPoint, HnswGetEntryPoint(index));
|
||||||
highestPoint = &vacuumstate->fallbackPoint;
|
|
||||||
|
|
||||||
if (!BlockNumberIsValid(highestPoint->blkno))
|
|
||||||
highestPoint = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (highestPoint != NULL)
|
|
||||||
{
|
|
||||||
/* Load element */
|
|
||||||
HnswLoadElement(highestPoint, NULL, NULL, index, support, true, NULL);
|
|
||||||
|
|
||||||
/* Repair if needed */
|
|
||||||
if (NeedsUpdated(vacuumstate, highestPoint))
|
|
||||||
RepairGraphElement(vacuumstate, highestPoint, entryPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release lock */
|
/* Release lock */
|
||||||
UnlockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
UnlockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
||||||
@@ -480,99 +441,6 @@ RepairGraph(HnswVacuumState * vacuumstate)
|
|||||||
/* Reset memory context */
|
/* Reset memory context */
|
||||||
MemoryContextSwitchTo(oldCtx);
|
MemoryContextSwitchTo(oldCtx);
|
||||||
MemoryContextReset(vacuumstate->tmpCtx);
|
MemoryContextReset(vacuumstate->tmpCtx);
|
||||||
|
|
||||||
#ifdef HNSW_VACUUM_PROGRESS
|
|
||||||
if (!BlockNumberIsValid(blkno) || (blkno - HNSW_HEAD_BLKNO) % 1000 == 0)
|
|
||||||
{
|
|
||||||
BlockNumber totalBlocks = RelationGetNumberOfBlocks(index);
|
|
||||||
BlockNumber currentBlocks = BlockNumberIsValid(blkno) ? blkno : totalBlocks;
|
|
||||||
|
|
||||||
elog(INFO, "hnsw vacuum progress: %.1f%%", 100.0 * currentBlocks / totalBlocks);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Confirm graph was repaired
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
ConfirmRepaired(HnswVacuumState * vacuumstate)
|
|
||||||
{
|
|
||||||
BlockNumber blkno = HNSW_HEAD_BLKNO;
|
|
||||||
Relation index = vacuumstate->index;
|
|
||||||
BufferAccessStrategy bas = vacuumstate->bas;
|
|
||||||
|
|
||||||
while (BlockNumberIsValid(blkno))
|
|
||||||
{
|
|
||||||
Buffer buf;
|
|
||||||
Page page;
|
|
||||||
OffsetNumber offno;
|
|
||||||
OffsetNumber maxoffno;
|
|
||||||
|
|
||||||
vacuum_delay_point();
|
|
||||||
|
|
||||||
buf = ReadBufferExtended(index, MAIN_FORKNUM, blkno, RBM_NORMAL, bas);
|
|
||||||
LockBuffer(buf, BUFFER_LOCK_SHARE);
|
|
||||||
page = BufferGetPage(buf);
|
|
||||||
maxoffno = PageGetMaxOffsetNumber(page);
|
|
||||||
|
|
||||||
/* Iterate over nodes */
|
|
||||||
for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno))
|
|
||||||
{
|
|
||||||
HnswElementTuple etup = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno));
|
|
||||||
HnswNeighborTuple ntup;
|
|
||||||
Buffer nbuf;
|
|
||||||
Page npage;
|
|
||||||
BlockNumber neighborPage;
|
|
||||||
OffsetNumber neighborOffno;
|
|
||||||
|
|
||||||
/* Skip neighbor tuples */
|
|
||||||
if (!HnswIsElementTuple(etup))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Skip if being deleted */
|
|
||||||
if (!ItemPointerIsValid(&etup->heaptids[0]))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Get neighbor page */
|
|
||||||
neighborPage = ItemPointerGetBlockNumber(&etup->neighbortid);
|
|
||||||
neighborOffno = ItemPointerGetOffsetNumber(&etup->neighbortid);
|
|
||||||
|
|
||||||
if (neighborPage == blkno)
|
|
||||||
{
|
|
||||||
nbuf = buf;
|
|
||||||
npage = page;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nbuf = ReadBufferExtended(index, MAIN_FORKNUM, neighborPage, RBM_NORMAL, bas);
|
|
||||||
LockBuffer(nbuf, BUFFER_LOCK_SHARE);
|
|
||||||
npage = BufferGetPage(nbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
ntup = (HnswNeighborTuple) PageGetItem(npage, PageGetItemId(npage, neighborOffno));
|
|
||||||
|
|
||||||
/* Check neighbors */
|
|
||||||
for (int i = 0; i < ntup->count; i++)
|
|
||||||
{
|
|
||||||
ItemPointer indextid = &ntup->indextids[i];
|
|
||||||
|
|
||||||
if (!ItemPointerIsValid(indextid))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Check if in deleted list */
|
|
||||||
if (DeletedContains(vacuumstate->deleted, indextid))
|
|
||||||
elog(ERROR, "hnsw graph not repaired");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nbuf != buf)
|
|
||||||
UnlockReleaseBuffer(nbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
blkno = HnswPageGetOpaque(page)->nextblkno;
|
|
||||||
|
|
||||||
UnlockReleaseBuffer(buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -766,16 +634,13 @@ hnswbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
|
|||||||
InitVacuumState(&vacuumstate, info, stats, callback, callback_state);
|
InitVacuumState(&vacuumstate, info, stats, callback, callback_state);
|
||||||
|
|
||||||
/* Pass 1: Remove heap TIDs */
|
/* Pass 1: Remove heap TIDs */
|
||||||
HnswBench("RemoveHeapTids", RemoveHeapTids(&vacuumstate));
|
RemoveHeapTids(&vacuumstate);
|
||||||
|
|
||||||
/* Pass 2: Repair graph */
|
/* Pass 2: Repair graph */
|
||||||
HnswBench("RepairGraph", RepairGraph(&vacuumstate));
|
RepairGraph(&vacuumstate);
|
||||||
|
|
||||||
/* Pass 3: Confirm repaired */
|
/* Pass 3: Mark as deleted */
|
||||||
HnswBench("ConfirmRepaired", ConfirmRepaired(&vacuumstate));
|
MarkDeleted(&vacuumstate);
|
||||||
|
|
||||||
/* Pass 4: Mark as deleted */
|
|
||||||
HnswBench("MarkDeleted", MarkDeleted(&vacuumstate));
|
|
||||||
|
|
||||||
FreeVacuumState(&vacuumstate);
|
FreeVacuumState(&vacuumstate);
|
||||||
|
|
||||||
|
|||||||
@@ -399,7 +399,6 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In
|
|||||||
|
|
||||||
buildstate->slot = MakeSingleTupleTableSlot(buildstate->sortdesc, &TTSOpsVirtual);
|
buildstate->slot = MakeSingleTupleTableSlot(buildstate->sortdesc, &TTSOpsVirtual);
|
||||||
|
|
||||||
/* TODO Ensure within maintenance_work_mem */
|
|
||||||
buildstate->centers = VectorArrayInit(buildstate->lists, buildstate->dimensions, buildstate->typeInfo->itemSize(buildstate->dimensions));
|
buildstate->centers = VectorArrayInit(buildstate->lists, buildstate->dimensions, buildstate->typeInfo->itemSize(buildstate->dimensions));
|
||||||
buildstate->listInfo = palloc(sizeof(ListInfo) * buildstate->lists);
|
buildstate->listInfo = palloc(sizeof(ListInfo) * buildstate->lists);
|
||||||
|
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ ivfflathandler(PG_FUNCTION_ARGS)
|
|||||||
.amconsistentequality = false,
|
.amconsistentequality = false,
|
||||||
.amconsistentordering = false,
|
.amconsistentordering = false,
|
||||||
.amcanbackward = false,
|
.amcanbackward = false,
|
||||||
|
.amcanmarkpos = false,
|
||||||
.amcanunique = false,
|
.amcanunique = false,
|
||||||
.amcanmulticol = false,
|
.amcanmulticol = false,
|
||||||
.amoptionalkey = true,
|
.amoptionalkey = true,
|
||||||
@@ -229,10 +230,13 @@ ivfflathandler(PG_FUNCTION_ARGS)
|
|||||||
.ambeginscan = ivfflatbeginscan,
|
.ambeginscan = ivfflatbeginscan,
|
||||||
.amrescan = ivfflatrescan,
|
.amrescan = ivfflatrescan,
|
||||||
.amgettuple = ivfflatgettuple,
|
.amgettuple = ivfflatgettuple,
|
||||||
|
.amgetbatch = NULL,
|
||||||
|
.amunguardbatch = NULL,
|
||||||
|
.amkillitemsbatch = NULL,
|
||||||
|
.amgettransform = NULL,
|
||||||
.amgetbitmap = NULL,
|
.amgetbitmap = NULL,
|
||||||
.amendscan = ivfflatendscan,
|
.amendscan = ivfflatendscan,
|
||||||
.ammarkpos = NULL,
|
.amposreset = NULL,
|
||||||
.amrestrpos = NULL,
|
|
||||||
.amestimateparallelscan = NULL,
|
.amestimateparallelscan = NULL,
|
||||||
.aminitparallelscan = NULL,
|
.aminitparallelscan = NULL,
|
||||||
.amparallelrescan = NULL,
|
.amparallelrescan = NULL,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 180000
|
#if PG_VERSION_NUM >= 180000
|
||||||
PG_MODULE_MAGIC_EXT(.name = "vector", .version = "0.8.3");
|
PG_MODULE_MAGIC_EXT(.name = "vector", .version = "0.8.2");
|
||||||
#else
|
#else
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
comment = 'vector data type and ivfflat and hnsw access methods'
|
comment = 'vector data type and ivfflat and hnsw access methods'
|
||||||
default_version = '0.8.3'
|
default_version = '0.8.2'
|
||||||
module_pathname = '$libdir/vector'
|
module_pathname = '$libdir/vector'
|
||||||
relocatable = true
|
relocatable = true
|
||||||
|
|||||||
Reference in New Issue
Block a user