From 659c1001a0d705bd4acc14d5c4d9d9cb9576ee83 Mon Sep 17 00:00:00 2001 From: yihong Date: Fri, 4 Oct 2024 03:57:35 +0800 Subject: [PATCH] feat: support pg13, pg14 as pgvector does (#94) * feat: support pg12, pg13, pg14 as pgvector does This PR try to support pg12-pg14 as pgvector supports. some of the codes from zombodb close: #93 Signed-off-by: yihong0618 Co-authored-by: zombodb * fix: drop pg12 support because of EOL Signed-off-by: yihong0618 * fix: adress review comments Signed-off-by: yihong0618 * Fix formatting/warnings * Add Pg13 and Pg14 tests Signed-off-by: Matvey Arye --------- Signed-off-by: yihong0618 Signed-off-by: Matvey Arye Co-authored-by: zombodb Co-authored-by: syvb Co-authored-by: Matvey Arye --- .github/workflows/pgrx_test.yaml | 6 ++++- pgvectorscale/Cargo.toml | 2 ++ pgvectorscale/src/access_method/build.rs | 29 ++++++++++++++++++++-- pgvectorscale/src/access_method/mod.rs | 2 +- pgvectorscale/src/access_method/options.rs | 1 - 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pgrx_test.yaml b/.github/workflows/pgrx_test.yaml index c244ab42..ced4a99b 100644 --- a/.github/workflows/pgrx_test.yaml +++ b/.github/workflows/pgrx_test.yaml @@ -13,6 +13,10 @@ jobs: pgvector: - version: 0.7.4 pg: + - major: 13 + minor: 16 + - major: 14 + minor: 13 - major: 15 minor: 7 - major: 16 @@ -65,4 +69,4 @@ jobs: run: | cd pgvectorscale ${{ matrix.platform.rustflags != '' && format('export RUSTFLAGS="{0}"', matrix.platform.rustflags) || '' }} - cargo pgrx test -- pg${{ matrix.pg.major }} \ No newline at end of file + cargo pgrx test -- pg${{ matrix.pg.major }} diff --git a/pgvectorscale/Cargo.toml b/pgvectorscale/Cargo.toml index 273b653b..37b8960d 100644 --- a/pgvectorscale/Cargo.toml +++ b/pgvectorscale/Cargo.toml @@ -8,6 +8,8 @@ crate-type = ["cdylib", "rlib"] [features] default = ["pg16"] +pg13 = ["pgrx/pg13", "pgrx-tests/pg13"] +pg14 = ["pgrx/pg14", "pgrx-tests/pg14"] pg15 = ["pgrx/pg15", "pgrx-tests/pg15"] pg16 = ["pgrx/pg16", "pgrx-tests/pg16"] pg_test = [] diff --git a/pgvectorscale/src/access_method/build.rs b/pgvectorscale/src/access_method/build.rs index 307c09b9..6fa34c82 100644 --- a/pgvectorscale/src/access_method/build.rs +++ b/pgvectorscale/src/access_method/build.rs @@ -90,6 +90,7 @@ pub extern "C" fn ambuild( result.into_pg() } +#[cfg(any(feature = "pg14", feature = "pg15", feature = "pg16"))] #[pg_guard] pub unsafe extern "C" fn aminsert( indexrel: pg_sys::Relation, @@ -101,8 +102,32 @@ pub unsafe extern "C" fn aminsert( _index_unchanged: bool, _index_info: *mut pg_sys::IndexInfo, ) -> bool { - let index_relation = unsafe { PgRelation::from_pg(indexrel) }; - let heap_relation = unsafe { PgRelation::from_pg(heaprel) }; + aminsert_internal(indexrel, values, isnull, heap_tid, heaprel) +} + +#[cfg(any(feature = "pg13"))] +#[pg_guard] +pub unsafe extern "C" fn aminsert( + indexrel: pg_sys::Relation, + values: *mut pg_sys::Datum, + isnull: *mut bool, + heap_tid: pg_sys::ItemPointer, + heaprel: pg_sys::Relation, + _check_unique: pg_sys::IndexUniqueCheck, + _index_info: *mut pg_sys::IndexInfo, +) -> bool { + aminsert_internal(indexrel, values, isnull, heap_tid, heaprel) +} + +unsafe fn aminsert_internal( + indexrel: pg_sys::Relation, + values: *mut pg_sys::Datum, + isnull: *mut bool, + heap_tid: pg_sys::ItemPointer, + heaprel: pg_sys::Relation, +) -> bool { + let index_relation = PgRelation::from_pg(indexrel); + let heap_relation = PgRelation::from_pg(heaprel); let mut meta_page = MetaPage::fetch(&index_relation); let vec = PgVector::from_pg_parts(values, isnull, 0, &meta_page, true, false); if let None = vec { diff --git a/pgvectorscale/src/access_method/mod.rs b/pgvectorscale/src/access_method/mod.rs index c0202ed8..90a3b46b 100644 --- a/pgvectorscale/src/access_method/mod.rs +++ b/pgvectorscale/src/access_method/mod.rs @@ -47,7 +47,6 @@ fn amhandler(_fcinfo: pg_sys::FunctionCallInfo) -> PgBox amroutine.amstrategies = 0; amroutine.amsupport = 0; //TODO - amroutine.amoptsprocnum = 0; amroutine.amcanorder = false; amroutine.amcanorderbyop = true; @@ -62,6 +61,7 @@ fn amhandler(_fcinfo: pg_sys::FunctionCallInfo) -> PgBox amroutine.ampredlocks = false; amroutine.amcanparallel = false; //TODO amroutine.amcaninclude = false; //TODO + amroutine.amoptsprocnum = 0; amroutine.amusemaintenanceworkmem = false; /* not used during VACUUM */ //amroutine.amparallelvacuumoptions = pg_sys VACUUM_OPTION_PARALLEL_BULKDEL; //TODO amroutine.amkeytype = pg_sys::InvalidOid; diff --git a/pgvectorscale/src/access_method/options.rs b/pgvectorscale/src/access_method/options.rs index f978fe1d..53e9a560 100644 --- a/pgvectorscale/src/access_method/options.rs +++ b/pgvectorscale/src/access_method/options.rs @@ -141,7 +141,6 @@ pub unsafe extern "C" fn amoptions( build_relopts(reloptions, validate, tab) } -#[cfg(any(feature = "pg13", feature = "pg14", feature = "pg15", feature = "pg16"))] unsafe fn build_relopts( reloptions: pg_sys::Datum, validate: bool,