Skip to content

Commit

Permalink
feat: support pg13, pg14 as pgvector does (#94)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: zombodb <[email protected]>

* fix: drop pg12 support because of EOL

Signed-off-by: yihong0618 <[email protected]>

* fix: adress review comments

Signed-off-by: yihong0618 <[email protected]>

* Fix formatting/warnings

* Add Pg13 and Pg14 tests

Signed-off-by: Matvey Arye <[email protected]>

---------

Signed-off-by: yihong0618 <[email protected]>
Signed-off-by: Matvey Arye <[email protected]>
Co-authored-by: zombodb <[email protected]>
Co-authored-by: syvb <[email protected]>
Co-authored-by: Matvey Arye <[email protected]>
  • Loading branch information
4 people authored Oct 3, 2024
1 parent 04e1d13 commit 659c100
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/pgrx_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
cargo pgrx test -- pg${{ matrix.pg.major }}
2 changes: 2 additions & 0 deletions pgvectorscale/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
29 changes: 27 additions & 2 deletions pgvectorscale/src/access_method/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pgvectorscale/src/access_method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ fn amhandler(_fcinfo: pg_sys::FunctionCallInfo) -> PgBox<pg_sys::IndexAmRoutine>

amroutine.amstrategies = 0;
amroutine.amsupport = 0; //TODO
amroutine.amoptsprocnum = 0;

amroutine.amcanorder = false;
amroutine.amcanorderbyop = true;
Expand All @@ -62,6 +61,7 @@ fn amhandler(_fcinfo: pg_sys::FunctionCallInfo) -> PgBox<pg_sys::IndexAmRoutine>
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;
Expand Down
1 change: 0 additions & 1 deletion pgvectorscale/src/access_method/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 659c100

Please sign in to comment.