mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 12:07:34 +08:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9250ddce87 | ||
|
|
bb431d531a | ||
|
|
2821648051 | ||
|
|
e583329be6 | ||
|
|
9d4fbeb7df | ||
|
|
eab825ae21 | ||
|
|
0d2ef735e5 | ||
|
|
1697c9f6d0 | ||
|
|
77814eb0ee | ||
|
|
1a381ffdcd | ||
|
|
250d453f8c | ||
|
|
498c23aa0c | ||
|
|
f09ef49dbf | ||
|
|
544686feb1 | ||
|
|
1a8ebb1129 | ||
|
|
aca89aec73 | ||
|
|
c9875f5150 | ||
|
|
df2c3d301f |
236
.github/workflows/build.yml
vendored
236
.github/workflows/build.yml
vendored
@@ -1,109 +1,143 @@
|
||||
name: build
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
ubuntu:
|
||||
runs-on: ${{ matrix.os }}
|
||||
# ubuntu:
|
||||
# runs-on: ${{ matrix.os }}
|
||||
# if: ${{ !startsWith(github.ref_name, 'mac') && !startsWith(github.ref_name, 'windows') }}
|
||||
# strategy:
|
||||
# fail-fast: false
|
||||
# matrix:
|
||||
# include:
|
||||
# - postgres: 19
|
||||
# os: ubuntu-24.04
|
||||
# - postgres: 18
|
||||
# os: ubuntu-24.04
|
||||
# - postgres: 17
|
||||
# os: ubuntu-24.04
|
||||
# - postgres: 16
|
||||
# os: ubuntu-24.04-arm
|
||||
# - postgres: 15
|
||||
# os: ubuntu-22.04
|
||||
# - postgres: 14
|
||||
# os: ubuntu-22.04-arm
|
||||
# - postgres: 13
|
||||
# os: ubuntu-22.04
|
||||
# steps:
|
||||
# - uses: actions/checkout@v5
|
||||
# - uses: ankane/setup-postgres@v1
|
||||
# with:
|
||||
# postgres-version: ${{ matrix.postgres }}
|
||||
# dev-files: true
|
||||
# - run: make
|
||||
# env:
|
||||
# PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-compare ${{ matrix.postgres >= 18 && '-Wno-missing-field-initializers' || '' }}
|
||||
# - run: |
|
||||
# export PG_CONFIG=`which pg_config`
|
||||
# sudo --preserve-env=PG_CONFIG make install
|
||||
# - run: make installcheck
|
||||
# - if: ${{ failure() }}
|
||||
# run: cat regression.diffs
|
||||
# - run: |
|
||||
# sudo apt-get update
|
||||
# sudo apt-get install libipc-run-perl
|
||||
# - run: make prove_installcheck
|
||||
# mac:
|
||||
# runs-on: ${{ matrix.os }}
|
||||
# if: ${{ !startsWith(github.ref_name, 'windows') }}
|
||||
# strategy:
|
||||
# fail-fast: false
|
||||
# matrix:
|
||||
# include:
|
||||
# - postgres: 18
|
||||
# os: macos-26
|
||||
# - postgres: 14
|
||||
# os: macos-15-intel
|
||||
# steps:
|
||||
# - uses: actions/checkout@v5
|
||||
# - uses: ankane/setup-postgres@v1
|
||||
# with:
|
||||
# postgres-version: ${{ matrix.postgres }}
|
||||
# - run: make
|
||||
# env:
|
||||
# PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unknown-warning-option ${{ matrix.postgres >= 18 && '-Wno-missing-field-initializers' || '' }}
|
||||
# - run: make install
|
||||
# - run: make installcheck
|
||||
# - if: ${{ failure() }}
|
||||
# run: cat regression.diffs
|
||||
# # Homebrew Postgres does not enable TAP tests, so need to download
|
||||
# - run: |
|
||||
# brew install cpanm
|
||||
# cpanm --notest IPC::Run
|
||||
# wget -q https://github.com/postgres/postgres/archive/refs/tags/$TAG.tar.gz
|
||||
# tar xf $TAG.tar.gz
|
||||
# mv postgres-$TAG postgres
|
||||
# env:
|
||||
# TAG: ${{ matrix.postgres == 18 && 'REL_18_0' || 'REL_14_19' }}
|
||||
# - run: make prove_installcheck PROVE_FLAGS="-I ./postgres/src/test/perl -I ./test/perl"
|
||||
# env:
|
||||
# PERL5LIB: /Users/runner/perl5/lib/perl5
|
||||
# - run: make clean && $(brew --prefix llvm@$LLVM_VERSION)/bin/scan-build --status-bugs make
|
||||
# env:
|
||||
# LLVM_VERSION: ${{ matrix.os == 'macos-26' && 20 || 18 }}
|
||||
# PG_CFLAGS: -DUSE_ASSERT_CHECKING
|
||||
# windows:
|
||||
# runs-on: ${{ matrix.os }}
|
||||
# if: ${{ !startsWith(github.ref_name, 'mac') }}
|
||||
# strategy:
|
||||
# fail-fast: false
|
||||
# matrix:
|
||||
# include:
|
||||
# - postgres: 17
|
||||
# os: windows-2025
|
||||
# - postgres: 14
|
||||
# os: windows-2022
|
||||
# steps:
|
||||
# - uses: actions/checkout@v5
|
||||
# - uses: ankane/setup-postgres@v1
|
||||
# with:
|
||||
# postgres-version: ${{ matrix.postgres }}
|
||||
# - run: |
|
||||
# call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && ^
|
||||
# nmake /NOLOGO /F Makefile.win && ^
|
||||
# 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 clean && ^
|
||||
# nmake /NOLOGO /F Makefile.win uninstall
|
||||
# shell: cmd
|
||||
# - if: ${{ failure() }}
|
||||
# run: cat regression.diffs
|
||||
i386:
|
||||
if: ${{ !startsWith(github.ref_name, 'mac') && !startsWith(github.ref_name, 'windows') }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- postgres: 19
|
||||
os: ubuntu-24.04
|
||||
- postgres: 18
|
||||
os: ubuntu-24.04
|
||||
- postgres: 17
|
||||
os: ubuntu-24.04
|
||||
- postgres: 16
|
||||
os: ubuntu-24.04-arm
|
||||
- postgres: 15
|
||||
os: ubuntu-22.04
|
||||
- postgres: 14
|
||||
os: ubuntu-22.04-arm
|
||||
- postgres: 13
|
||||
os: ubuntu-22.04
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: alpine:3.23
|
||||
options: --platform linux/386
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: ankane/setup-postgres@v1
|
||||
with:
|
||||
postgres-version: ${{ matrix.postgres }}
|
||||
dev-files: true
|
||||
- run: make
|
||||
env:
|
||||
PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-compare ${{ matrix.postgres >= 18 && '-Wno-missing-field-initializers' || '' }}
|
||||
- run: apk add --update build-base git openrc perl perl-ipc-run perl-test-harness-utils postgresql18 postgresql18-dev
|
||||
- run: mkdir /run/openrc && touch /run/openrc/softlevel && rc-update add postgresql && rc-service postgresql start
|
||||
- run: |
|
||||
export PG_CONFIG=`which pg_config`
|
||||
sudo --preserve-env=PG_CONFIG make install
|
||||
- run: make installcheck
|
||||
- if: ${{ failure() }}
|
||||
run: cat regression.diffs
|
||||
# - run: |
|
||||
# sudo apt-get update
|
||||
# sudo apt-get install libipc-run-perl
|
||||
# - run: make prove_installcheck
|
||||
mac:
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: ${{ !startsWith(github.ref_name, 'windows') }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- postgres: 18
|
||||
os: macos-26
|
||||
- postgres: 14
|
||||
os: macos-15-intel
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: ankane/setup-postgres@v1
|
||||
with:
|
||||
postgres-version: ${{ matrix.postgres }}
|
||||
- run: make
|
||||
git clone https://github.com/${{ github.repository }}.git pgvector
|
||||
cd pgvector
|
||||
git fetch origin ${{ github.ref }}
|
||||
git reset --hard FETCH_HEAD
|
||||
make
|
||||
make install
|
||||
chown -R postgres .
|
||||
su postgres -c "make installcheck"
|
||||
su postgres -c "make prove_installcheck"
|
||||
env:
|
||||
PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unknown-warning-option ${{ matrix.postgres >= 18 && '-Wno-missing-field-initializers' || '' }}
|
||||
- run: make install
|
||||
- run: make installcheck
|
||||
PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-compare -Wno-missing-field-initializers
|
||||
- if: ${{ failure() }}
|
||||
run: cat regression.diffs
|
||||
# Homebrew Postgres does not enable TAP tests, so need to download
|
||||
# - run: |
|
||||
# brew install cpanm
|
||||
# cpanm --notest IPC::Run
|
||||
# wget -q https://github.com/postgres/postgres/archive/refs/tags/$TAG.tar.gz
|
||||
# tar xf $TAG.tar.gz
|
||||
# mv postgres-$TAG postgres
|
||||
# env:
|
||||
# TAG: ${{ matrix.postgres == 18 && 'REL_18_0' || 'REL_14_19' }}
|
||||
# - run: make prove_installcheck PROVE_FLAGS="-I ./postgres/src/test/perl -I ./test/perl"
|
||||
# env:
|
||||
# PERL5LIB: /Users/runner/perl5/lib/perl5
|
||||
# - run: make clean && $(brew --prefix llvm@$LLVM_VERSION)/bin/scan-build --status-bugs make
|
||||
# env:
|
||||
# LLVM_VERSION: ${{ matrix.os == 'macos-26' && 20 || 18 }}
|
||||
# PG_CFLAGS: -DUSE_ASSERT_CHECKING
|
||||
windows:
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: ${{ !startsWith(github.ref_name, 'mac') }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- postgres: 17
|
||||
os: windows-2025
|
||||
- postgres: 14
|
||||
os: windows-2022
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: ankane/setup-postgres@v1
|
||||
with:
|
||||
postgres-version: ${{ matrix.postgres }}
|
||||
- run: |
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && ^
|
||||
nmake /NOLOGO /F Makefile.win && ^
|
||||
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 clean && ^
|
||||
nmake /NOLOGO /F Makefile.win uninstall
|
||||
shell: cmd
|
||||
- if: ${{ failure() }}
|
||||
run: cat regression.diffs
|
||||
|
||||
run: cat pgvector/regression.diffs
|
||||
# valgrind:
|
||||
# if: ${{ !startsWith(github.ref_name, 'mac') && !startsWith(github.ref_name, 'windows') }}
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v5
|
||||
# - uses: ankane/setup-postgres-valgrind@v1
|
||||
# with:
|
||||
# postgres-version: 18
|
||||
# check-ub: yes
|
||||
# - run: make OPTFLAGS=""
|
||||
# - run: sudo --preserve-env=PG_CONFIG make install
|
||||
# - run: make installcheck
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||
Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
|
||||
|
||||
Portions Copyright (c) 1994, The Regents of the University of California
|
||||
|
||||
|
||||
5
Makefile
5
Makefile
@@ -27,6 +27,11 @@ ifneq ($(filter ppc64%, $(shell uname -m)), )
|
||||
OPTFLAGS =
|
||||
endif
|
||||
|
||||
# RISC-V64 doesn't support -march=native
|
||||
ifeq ($(shell uname -m), riscv64)
|
||||
OPTFLAGS =
|
||||
endif
|
||||
|
||||
# For auto-vectorization:
|
||||
# - GCC (needs -ftree-vectorize OR -O3) - https://gcc.gnu.org/projects/tree-ssa/vectorization.html
|
||||
# - Clang (could use pragma instead) - https://llvm.org/docs/Vectorizers.html
|
||||
|
||||
@@ -776,6 +776,7 @@ Algol | [pgvector-algol](https://github.com/pgvector/pgvector-algol)
|
||||
C | [pgvector-c](https://github.com/pgvector/pgvector-c)
|
||||
C++ | [pgvector-cpp](https://github.com/pgvector/pgvector-cpp)
|
||||
C#, F#, Visual Basic | [pgvector-dotnet](https://github.com/pgvector/pgvector-dotnet)
|
||||
COBOL | [pgvector-cobol](https://github.com/pgvector/pgvector-cobol)
|
||||
Crystal | [pgvector-crystal](https://github.com/pgvector/pgvector-crystal)
|
||||
D | [pgvector-d](https://github.com/pgvector/pgvector-d)
|
||||
Dart | [pgvector-dart](https://github.com/pgvector/pgvector-dart)
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#include "varatt.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#include "parser/scansup.h"
|
||||
#endif
|
||||
|
||||
#define STATE_DIMS(x) (ARR_DIMS(x)[0] - 1)
|
||||
#define CreateStateDatums(dim) palloc(sizeof(Datum) * (dim + 1))
|
||||
|
||||
@@ -133,9 +137,9 @@ InitHalfVector(int dim)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for whitespace, since array_isspace() is static
|
||||
*/
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#define halfvec_isspace(ch) scanner_isspace(ch)
|
||||
#else
|
||||
static inline bool
|
||||
halfvec_isspace(char ch)
|
||||
{
|
||||
@@ -148,6 +152,7 @@ halfvec_isspace(char ch)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check state array
|
||||
|
||||
@@ -12,11 +12,7 @@
|
||||
#include "fmgr.h"
|
||||
#include "hnsw.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/nodes.h"
|
||||
#include "nodes/pathnodes.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "storage/shmem.h"
|
||||
#include "utils/float.h"
|
||||
#include "utils/guc.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
@@ -47,36 +47,16 @@
|
||||
#include "catalog/index.h"
|
||||
#include "catalog/pg_type_d.h"
|
||||
#include "commands/progress.h"
|
||||
#include "common/relpath.h"
|
||||
#include "hnsw.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/execnodes.h"
|
||||
#include "optimizer/optimizer.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/condition_variable.h"
|
||||
#include "storage/dsm.h"
|
||||
#include "storage/itemid.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "storage/lwlock.h"
|
||||
#include "storage/off.h"
|
||||
#include "storage/shm_toc.h"
|
||||
#include "storage/shmem.h"
|
||||
#include "storage/spin.h"
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/snapmgr.h"
|
||||
#include "utils/snapshot.h"
|
||||
|
||||
#if PG_VERSION_NUM < 190000
|
||||
#include "storage/item.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 160000
|
||||
#include "varatt.h"
|
||||
@@ -90,11 +70,6 @@
|
||||
|
||||
#if PG_VERSION_NUM >= 140000
|
||||
#include "utils/backend_status.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#include "utils/wait_event_types.h"
|
||||
#elif PG_VERSION_NUM >= 140000
|
||||
#include "utils/wait_event.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,26 +2,13 @@
|
||||
|
||||
#include "access/genam.h"
|
||||
#include "access/generic_xlog.h"
|
||||
#include "common/relpath.h"
|
||||
#include "hnsw.h"
|
||||
#include "nodes/execnodes.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/itemid.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/lmgr.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "storage/off.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
#if PG_VERSION_NUM < 190000
|
||||
#include "storage/item.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 160000
|
||||
#include "varatt.h"
|
||||
|
||||
@@ -2,16 +2,12 @@
|
||||
|
||||
#include "access/genam.h"
|
||||
#include "access/relscan.h"
|
||||
#include "access/sdir.h"
|
||||
#include "access/skey.h"
|
||||
#include "hnsw.h"
|
||||
#include "lib/pairingheap.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/lmgr.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "utils/float.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
@@ -5,24 +5,16 @@
|
||||
#include "access/genam.h"
|
||||
#include "access/generic_xlog.h"
|
||||
#include "common/hashfn.h"
|
||||
#include "common/relpath.h"
|
||||
#include "fmgr.h"
|
||||
#include "hnsw.h"
|
||||
#include "lib/pairingheap.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "port/atomics.h"
|
||||
#include "sparsevec.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/lwlock.h"
|
||||
#include "storage/off.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/memdebug.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "vector.h"
|
||||
|
||||
#if PG_VERSION_NUM >= 160000
|
||||
|
||||
@@ -3,24 +3,12 @@
|
||||
#include "access/genam.h"
|
||||
#include "access/generic_xlog.h"
|
||||
#include "commands/vacuum.h"
|
||||
#include "common/relpath.h"
|
||||
#include "hnsw.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/lmgr.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "storage/off.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
#if PG_VERSION_NUM < 190000
|
||||
#include "storage/item.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 160000
|
||||
#include "varatt.h"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#include "access/attnum.h"
|
||||
#include "access/genam.h"
|
||||
#include "access/generic_xlog.h"
|
||||
#include "access/itup.h"
|
||||
@@ -17,38 +16,19 @@
|
||||
#include "catalog/pg_operator_d.h"
|
||||
#include "catalog/pg_type_d.h"
|
||||
#include "commands/progress.h"
|
||||
#include "common/relpath.h"
|
||||
#include "executor/tuptable.h"
|
||||
#include "fmgr.h"
|
||||
#include "ivfflat.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/execnodes.h"
|
||||
#include "optimizer/optimizer.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/condition_variable.h"
|
||||
#include "storage/dsm.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "storage/off.h"
|
||||
#include "storage/shm_toc.h"
|
||||
#include "storage/shmem.h"
|
||||
#include "storage/spin.h"
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/sampling.h"
|
||||
#include "utils/snapmgr.h"
|
||||
#include "utils/snapshot.h"
|
||||
#include "utils/tuplesort.h"
|
||||
|
||||
#if PG_VERSION_NUM < 190000
|
||||
#include "storage/item.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 160000
|
||||
#include "varatt.h"
|
||||
#endif
|
||||
@@ -61,11 +41,6 @@
|
||||
|
||||
#if PG_VERSION_NUM >= 140000
|
||||
#include "utils/backend_status.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#include "utils/wait_event_types.h"
|
||||
#elif PG_VERSION_NUM >= 140000
|
||||
#include "utils/wait_event.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
#include "commands/vacuum.h"
|
||||
#include "fmgr.h"
|
||||
#include "ivfflat.h"
|
||||
#include "nodes/nodes.h"
|
||||
#include "nodes/pathnodes.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "utils/float.h"
|
||||
#include "utils/guc.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
@@ -5,26 +5,13 @@
|
||||
#include "access/genam.h"
|
||||
#include "access/generic_xlog.h"
|
||||
#include "access/itup.h"
|
||||
#include "common/relpath.h"
|
||||
#include "fmgr.h"
|
||||
#include "ivfflat.h"
|
||||
#include "nodes/execnodes.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/itemid.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/lmgr.h"
|
||||
#include "storage/lockdefs.h"
|
||||
#include "storage/off.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
#if PG_VERSION_NUM < 190000
|
||||
#include "storage/item.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Find the list that minimizes the distance function
|
||||
|
||||
@@ -2,32 +2,20 @@
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#include "access/attnum.h"
|
||||
#include "access/genam.h"
|
||||
#include "access/itup.h"
|
||||
#include "access/relscan.h"
|
||||
#include "access/sdir.h"
|
||||
#include "access/skey.h"
|
||||
#include "access/tupdesc.h"
|
||||
#include "catalog/pg_operator_d.h"
|
||||
#include "catalog/pg_type_d.h"
|
||||
#include "common/relpath.h"
|
||||
#include "executor/tuptable.h"
|
||||
#include "fmgr.h"
|
||||
#include "lib/pairingheap.h"
|
||||
#include "ivfflat.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/itemid.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/off.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/snapmgr.h"
|
||||
#include "utils/tuplesort.h"
|
||||
|
||||
|
||||
@@ -2,15 +2,11 @@
|
||||
|
||||
#include "access/genam.h"
|
||||
#include "access/generic_xlog.h"
|
||||
#include "common/relpath.h"
|
||||
#include "fmgr.h"
|
||||
#include "halfutils.h"
|
||||
#include "halfvec.h"
|
||||
#include "ivfflat.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/varbit.h"
|
||||
#include "vector.h"
|
||||
|
||||
@@ -4,14 +4,8 @@
|
||||
#include "access/generic_xlog.h"
|
||||
#include "access/itup.h"
|
||||
#include "commands/vacuum.h"
|
||||
#include "common/relpath.h"
|
||||
#include "ivfflat.h"
|
||||
#include "storage/block.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/itemptr.h"
|
||||
#include "storage/off.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
#if PG_VERSION_NUM >= 180000
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#include "varatt.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#include "parser/scansup.h"
|
||||
#endif
|
||||
|
||||
typedef struct SparseInputElement
|
||||
{
|
||||
int32 index;
|
||||
@@ -155,9 +159,9 @@ InitSparseVector(int dim, int nnz)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for whitespace, since array_isspace() is static
|
||||
*/
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#define sparsevec_isspace(ch) scanner_isspace(ch)
|
||||
#else
|
||||
static inline bool
|
||||
sparsevec_isspace(char ch)
|
||||
{
|
||||
@@ -170,6 +174,7 @@ sparsevec_isspace(char ch)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compare indices
|
||||
|
||||
11
src/vector.c
11
src/vector.c
@@ -26,6 +26,10 @@
|
||||
#include "varatt.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#include "parser/scansup.h"
|
||||
#endif
|
||||
|
||||
#define STATE_DIMS(x) (ARR_DIMS(x)[0] - 1)
|
||||
#define CreateStateDatums(dim) palloc(sizeof(Datum) * (dim + 1))
|
||||
|
||||
@@ -129,9 +133,9 @@ InitVector(int dim)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for whitespace, since array_isspace() is static
|
||||
*/
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#define vector_isspace(ch) scanner_isspace(ch)
|
||||
#else
|
||||
static inline bool
|
||||
vector_isspace(char ch)
|
||||
{
|
||||
@@ -144,6 +148,7 @@ vector_isspace(char ch)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check state array
|
||||
|
||||
@@ -16,29 +16,19 @@ $node->safe_psql("postgres",
|
||||
"INSERT INTO tst SELECT i, ARRAY[random(), random(), random()] FROM generate_series(1, 100000) i;"
|
||||
);
|
||||
|
||||
# Check each index type
|
||||
my @operators = ("<->", "<#>", "<=>");
|
||||
my @opclasses = ("vector_l2_ops", "vector_ip_ops", "vector_cosine_ops");
|
||||
# Add index
|
||||
$node->safe_psql("postgres", "CREATE INDEX ON tst USING ivfflat (v vector_l2_ops);");
|
||||
|
||||
for my $i (0 .. $#operators)
|
||||
# Test 100% recall
|
||||
for (1 .. 20)
|
||||
{
|
||||
my $operator = $operators[$i];
|
||||
my $opclass = $opclasses[$i];
|
||||
|
||||
# Add index
|
||||
$node->safe_psql("postgres", "CREATE INDEX ON tst USING ivfflat (v $opclass);");
|
||||
|
||||
# Test 100% recall
|
||||
for (1 .. 20)
|
||||
{
|
||||
my $id = int(rand() * 100000);
|
||||
my $query = $node->safe_psql("postgres", "SELECT v FROM tst WHERE i = $id;");
|
||||
my $res = $node->safe_psql("postgres", qq(
|
||||
SET enable_seqscan = off;
|
||||
SELECT v FROM tst ORDER BY v <-> '$query' LIMIT 1;
|
||||
));
|
||||
is($res, $query);
|
||||
}
|
||||
my $id = int(rand() * 100000);
|
||||
my $query = $node->safe_psql("postgres", "SELECT v FROM tst WHERE i = $id;");
|
||||
my $res = $node->safe_psql("postgres", qq(
|
||||
SET enable_seqscan = off;
|
||||
SELECT v FROM tst ORDER BY v <-> '$query' LIMIT 1;
|
||||
));
|
||||
is($res, $query);
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
||||
Reference in New Issue
Block a user