Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/deb-packager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
minor: 3
- major: 17
minor: 0
- major: 18
minor: 0
platform:
- type: amd64
runs_on: ubuntu-latest
Expand Down Expand Up @@ -81,7 +83,7 @@ jobs:
uses: ./.github/actions/install-pgrx
with:
pg-install-dir: ~/${{ env.PG_INSTALL_DIR }}
pgrx-version: 0.12.9
pgrx-version: 0.16.1

- name: Build Deb
id: debbuild
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pgrx_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
pgvector:
- version: 0.8.0
- version: 0.8.1
pg:
- major: 13
minor: 16
Expand All @@ -23,6 +23,8 @@ jobs:
minor: 3
- major: 17
minor: 0
- major: 18
minor: 0
platform:
- type: amd64
runs_on: ubuntu-22.04
Expand Down Expand Up @@ -62,7 +64,7 @@ jobs:
uses: ./.github/actions/install-pgrx
with:
pg-install-dir: ~/${{ env.PG_INSTALL_DIR }}
pgrx-version: 0.12.9
pgrx-version: 0.16.1

- name: Run Clippy
id: clippy
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
pgvector:
- version: 0.8.0
- version: 0.8.1
pg:
- major: 13
minor: 16
Expand All @@ -23,7 +23,8 @@ jobs:
minor: 3
- major: 17
minor: 0

- major: 18
minor: 0
env:
PG_SRC_DIR: pgbuild
PG_INSTALL_DIR: postgresql
Expand Down Expand Up @@ -69,7 +70,7 @@ jobs:
uses: ./.github/actions/install-pgrx
with:
pg-install-dir: ~/${{ env.PG_INSTALL_DIR }}
pgrx-version: 0.12.9
pgrx-version: 0.16.1

- name: Build and install pgvectorscale
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ You can install pgvectorscale from source and install it in an existing PostgreS
cd pgvectorscale/pgvectorscale
# install cargo-pgrx with the same version as pgrx
cargo install --locked cargo-pgrx --version $(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "pgrx") | .version')
cargo pgrx init --pg17 pg_config
cargo pgrx init --pg18 pg_config
# build and install pgvectorscale
cargo pgrx install --release
```
Expand Down
9 changes: 5 additions & 4 deletions pgvectorscale/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ name = "pgrx_embed_vectorscale"
path = "./src/bin/pgrx_embed.rs"

[features]
default = ["pg17"]
default = ["pg18"]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
pg_test = []

[lints.rust]
Expand All @@ -27,7 +28,7 @@ unexpected_cfgs = { level = "allow", check-cfg = [

[dependencies]
memoffset = "0.9.0"
pgrx = "=0.12.9"
pgrx = "=0.16.1"
rkyv = { version = "0.7.43", features = ["validation"] }
simdeez = { version = "1.0.8" }
rand = { version = "0.8", features = ["small_rng"] }
Expand All @@ -38,8 +39,8 @@ once_cell = "1.20.1"
lru = "0.14.0"

[dev-dependencies]
pgrx-tests = "=0.12.9"
pgrx-pg-config = "=0.12.9"
pgrx-tests = "=0.16.1"
pgrx-pg-config = "=0.16.1"
criterion = "0.5.1"
tempfile = "3.15.0"

Expand Down
82 changes: 38 additions & 44 deletions pgvectorscale/src/access_method/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub const MAX_DIMENSION: u32 = 16000;
pub const MAX_DIMENSION_NO_SBQ: u32 = 2000;

#[pg_guard]
pub extern "C" fn ambuild(
pub extern "C-unwind" fn ambuild(
heaprel: pg_sys::Relation,
indexrel: pg_sys::Relation,
index_info: *mut pg_sys::IndexInfo,
Expand Down Expand Up @@ -146,10 +146,16 @@ pub extern "C" fn ambuild(
result.into_pg()
}

#[cfg(any(feature = "pg14", feature = "pg15", feature = "pg16", feature = "pg17"))]
#[cfg(any(
feature = "pg14",
feature = "pg15",
feature = "pg16",
feature = "pg17",
feature = "pg18"
))]
#[pg_guard]
#[allow(clippy::too_many_arguments)]
pub unsafe extern "C" fn aminsert(
pub unsafe extern "C-unwind" fn aminsert(
indexrel: pg_sys::Relation,
values: *mut pg_sys::Datum,
isnull: *mut bool,
Expand All @@ -164,7 +170,7 @@ pub unsafe extern "C" fn aminsert(

#[cfg(feature = "pg13")]
#[pg_guard]
pub unsafe extern "C" fn aminsert(
pub unsafe extern "C-unwind" fn aminsert(
indexrel: pg_sys::Relation,
values: *mut pg_sys::Datum,
isnull: *mut bool,
Expand Down Expand Up @@ -260,7 +266,7 @@ unsafe fn insert_storage<S: Storage>(
}

#[pg_guard]
pub extern "C" fn ambuildempty(_index_relation: pg_sys::Relation) {
pub extern "C-unwind" fn ambuildempty(_index_relation: pg_sys::Relation) {
panic!("ambuildempty: not yet implemented")
}

Expand Down Expand Up @@ -450,7 +456,7 @@ fn finalize_index_build<S: Storage>(
}

#[pg_guard]
unsafe extern "C" fn build_callback_bq_train(
unsafe extern "C-unwind" fn build_callback_bq_train(
_index: pg_sys::Relation,
_ctid: pg_sys::ItemPointer,
values: *mut pg_sys::Datum,
Expand All @@ -466,7 +472,7 @@ unsafe extern "C" fn build_callback_bq_train(
}

#[pg_guard]
unsafe extern "C" fn build_callback(
unsafe extern "C-unwind" fn build_callback(
index: pg_sys::Relation,
ctid: pg_sys::ItemPointer,
values: *mut pg_sys::Datum,
Expand Down Expand Up @@ -552,7 +558,7 @@ const BUILD_PHASE_BUILDING_GRAPH: i64 = 1;
const BUILD_PHASE_FINALIZING_GRAPH: i64 = 2;

#[pg_guard]
pub unsafe extern "C" fn ambuildphasename(phasenum: i64) -> *mut ffi::c_char {
pub unsafe extern "C-unwind" fn ambuildphasename(phasenum: i64) -> *mut ffi::c_char {
match phasenum {
BUILD_PHASE_TRAINING => "training quantizer".as_pg_cstr(),
BUILD_PHASE_BUILDING_GRAPH => "building graph".as_pg_cstr(),
Expand Down Expand Up @@ -656,10 +662,7 @@ pub mod tests {
WITH cte as (select * from {table_name} order by embedding {operator} $1::vector) SELECT count(*) from cte;
",
),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe { pgrx::datum::DatumWithOid::new(test_vec.clone().into_datum(), pgrx::pg_sys::FLOAT4ARRAYOID) }],
)?;

//FIXME: should work in all cases
Expand Down Expand Up @@ -724,10 +727,12 @@ pub mod tests {
)
SELECT array_agg(ctid) from cte;"
),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe {
pgrx::datum::DatumWithOid::new(
test_vec.clone().into_datum(),
pgrx::pg_sys::FLOAT4ARRAYOID,
)
}],
)?;

/* Test that the explain plan is generated ok */
Expand All @@ -747,10 +752,12 @@ pub mod tests {
)
SELECT array_agg(ctid) from cte;"
),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe {
pgrx::datum::DatumWithOid::new(
test_vec.clone().into_datum(),
pgrx::pg_sys::FLOAT4ARRAYOID,
)
}],
)?;
assert!(explain.is_some());
//warning!("explain: {}", explain.unwrap().0);
Expand All @@ -771,10 +778,12 @@ pub mod tests {
)
SELECT array_agg(ctid) from cte;"
),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe {
pgrx::datum::DatumWithOid::new(
test_vec.clone().into_datum(),
pgrx::pg_sys::FLOAT4ARRAYOID,
)
}],
)?
.unwrap();

Expand All @@ -800,10 +809,7 @@ pub mod tests {
WITH cte as (select * from {table_name} order by embedding {operator} $1::vector) SELECT count(*) from cte;
",
),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.into_datum(),
)],
&[unsafe { pgrx::datum::DatumWithOid::new(test_vec.into_datum(), pgrx::pg_sys::FLOAT4ARRAYOID) }],
)?;

assert_eq!(cnt.unwrap(), 312);
Expand Down Expand Up @@ -1066,10 +1072,7 @@ pub mod tests {
WITH cte as (select * from {table_name} order by embedding {operator} $1::vector) SELECT count(*) from cte;
",
),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe { pgrx::datum::DatumWithOid::new(test_vec.clone().into_datum(), pgrx::pg_sys::FLOAT4ARRAYOID) }],
)?;

assert!(cnt.unwrap() == expected_cnt, "initial count");
Expand Down Expand Up @@ -1105,10 +1108,7 @@ pub mod tests {
WITH cte as (select * from {table_name} order by embedding {operator} $1::vector) SELECT count(*) from cte;
",
),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe { pgrx::datum::DatumWithOid::new(test_vec.clone().into_datum(), pgrx::pg_sys::FLOAT4ARRAYOID) }],
)?;

assert!(cnt.unwrap() == expected_cnt, "after update count");
Expand All @@ -1133,10 +1133,7 @@ pub mod tests {
SET diskann.query_search_list_size = 2;
WITH cte as (select * from {table_name} order by embedding <=> $1::vector) SELECT count(*) from cte;
"),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe { pgrx::datum::DatumWithOid::new(test_vec.clone().into_datum(), pgrx::pg_sys::FLOAT4ARRAYOID) }],
)?;

if cnt.unwrap() != expected_cnt {
Expand All @@ -1148,10 +1145,7 @@ pub mod tests {
SET diskann.query_search_list_size = 2;
WITH cte as (select id from {table_name} EXCEPT (select id from {table_name} order by embedding <=> $1::vector)) SELECT ctid::text || ' ' || id from {table_name} where id in (select id from cte limit 1);
"),
vec![(
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
test_vec.clone().into_datum(),
)],
&[unsafe { pgrx::datum::DatumWithOid::new(test_vec.clone().into_datum(), pgrx::pg_sys::FLOAT4ARRAYOID) }],
)?;

assert_eq!(cnt.unwrap(), expected_cnt, "id is {}", id.unwrap());
Expand Down
23 changes: 8 additions & 15 deletions pgvectorscale/src/access_method/cost_estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pgrx::*;
/// cost estimate function loosely based on how ivfflat does things
#[pg_guard(immutable, parallel_safe)]
#[allow(clippy::too_many_arguments)]
pub unsafe extern "C" fn amcostestimate(
pub unsafe extern "C-unwind" fn amcostestimate(
root: *mut pg_sys::PlannerInfo,
path: *mut pg_sys::IndexPath,
loop_count: f64,
Expand All @@ -14,28 +14,21 @@ pub unsafe extern "C" fn amcostestimate(
index_pages: *mut f64,
) {
if (*path).indexorderbys.is_null() {
//can't use index without order bys
// Can't use index without order-bys
*index_startup_cost = f64::MAX;
*index_total_cost = f64::MAX;
*index_selectivity = 0.;
*index_correlation = 0.;
*index_pages = 0.;
#[cfg(any(feature = "pg18"))]
{
// Following in the footsteps of pgvector's PG18+ cost estimate change
// https://github.com/pgvector/pgvector/commit/1291b12090bbb03bd92b92e42a1567ae5b1c96ad
(*path).path.disabled_nodes = 2;
}
return;
}
let path_ref = path.as_ref().expect("path argument is NULL");
/*let indexinfo = path_ref
.indexinfo
.as_ref()
.expect("indexinfo in path is NULL");
let index_relation = unsafe {
PgRelation::with_lock(
indexinfo.indexoid,
pg_sys::AccessShareLock as pg_sys::LOCKMODE,
)
};
let heap_relation = index_relation
.heap_relation()
.expect("failed to get heap relation for index");*/

let total_index_tuples = (*path_ref.indexinfo).tuples;

Expand Down
Loading
Loading