Skip to content

Commit 052b9bc

Browse files
authored
Bump pgrx version to 0.12.5 (#137)
* Bump pgrx version to 0.12.5 * Fix on pg13 * fix unused warning * Replace ItemPointerData usage with a string of the ctid
1 parent 659c100 commit 052b9bc

File tree

11 files changed

+47
-46
lines changed

11 files changed

+47
-46
lines changed

.github/workflows/deb-packager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
uses: ./.github/actions/install-pgrx
7070
with:
7171
pg-install-dir: ~/${{ env.PG_INSTALL_DIR }}
72-
pgrx-version: 0.11.1
72+
pgrx-version: 0.12.5
7373

7474
- name: Build Deb
7575
id: debbuild

.github/workflows/pgrx_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uses: ./.github/actions/install-pgrx
6363
with:
6464
pg-install-dir: ~/${{ env.PG_INSTALL_DIR }}
65-
pgrx-version: 0.11.1
65+
pgrx-version: 0.12.5
6666

6767
- name: Run tests
6868
id: runtests

pgvectorscale/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ edition = "2021"
66
[lib]
77
crate-type = ["cdylib", "rlib"]
88

9+
[[bin]]
10+
name = "pgrx_embed_vectorscale"
11+
path = "./src/bin/pgrx_embed.rs"
12+
913
[features]
1014
default = ["pg16"]
1115
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
@@ -16,16 +20,17 @@ pg_test = []
1620

1721
[dependencies]
1822
memoffset = "0.9.0"
19-
pgrx = "=0.11.4"
23+
pgrx = "=0.12.5"
2024
rkyv = { version="0.7.42", features=["validation"]}
2125
simdeez = {version = "1.0.8"}
2226
rand = { version = "0.8", features = [ "small_rng" ] }
2327
pgvectorscale_derive = { path = "pgvectorscale_derive" }
2428
semver = "1.0.22"
29+
once_cell = "1.20.1"
2530

2631
[dev-dependencies]
27-
pgrx-tests = "=0.11.4"
28-
pgrx-pg-config = "=0.11.4"
32+
pgrx-tests = "=0.12.5"
33+
pgrx-pg-config = "=0.12.5"
2934
criterion = "0.5.1"
3035
tempfile = "3.3.0"
3136

pgvectorscale/src/access_method/build.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub unsafe extern "C" fn aminsert(
9898
isnull: *mut bool,
9999
heap_tid: pg_sys::ItemPointer,
100100
heaprel: pg_sys::Relation,
101-
_check_unique: pg_sys::IndexUniqueCheck,
101+
_check_unique: pg_sys::IndexUniqueCheck::Type,
102102
_index_unchanged: bool,
103103
_index_info: *mut pg_sys::IndexInfo,
104104
) -> bool {
@@ -113,7 +113,7 @@ pub unsafe extern "C" fn aminsert(
113113
isnull: *mut bool,
114114
heap_tid: pg_sys::ItemPointer,
115115
heaprel: pg_sys::Relation,
116-
_check_unique: pg_sys::IndexUniqueCheck,
116+
_check_unique: pg_sys::IndexUniqueCheck::Type,
117117
_index_info: *mut pg_sys::IndexInfo,
118118
) -> bool {
119119
aminsert_internal(indexrel, values, isnull, heap_tid, heaprel)
@@ -488,8 +488,6 @@ pub mod tests {
488488

489489
use pgrx::*;
490490

491-
use crate::util::ItemPointer;
492-
493491
//TODO: add test where inserting and querying with vectors that are all the same.
494492

495493
#[cfg(any(test, feature = "pg_test"))]
@@ -596,15 +594,15 @@ pub mod tests {
596594
",
597595
))?;
598596

599-
let with_index: Option<Vec<pgrx::pg_sys::ItemPointerData>> = Spi::get_one_with_args(
597+
let with_index: Option<Vec<String>> = Spi::get_one_with_args(
600598
&format!(
601599
"
602600
SET enable_seqscan = 0;
603601
SET enable_indexscan = 1;
604602
SET diskann.query_search_list_size = 25;
605603
WITH cte AS (
606604
SELECT
607-
ctid
605+
ctid::TEXT
608606
FROM
609607
{table_name}
610608
ORDER BY
@@ -644,14 +642,14 @@ pub mod tests {
644642
assert!(explain.is_some());
645643
//warning!("explain: {}", explain.unwrap().0);
646644

647-
let without_index: Option<Vec<pgrx::pg_sys::ItemPointerData>> = Spi::get_one_with_args(
645+
let without_index: Vec<String> = Spi::get_one_with_args(
648646
&format!(
649647
"
650648
SET enable_seqscan = 1;
651649
SET enable_indexscan = 0;
652650
WITH cte AS (
653651
SELECT
654-
ctid
652+
ctid::TEXT
655653
FROM
656654
{table_name}
657655
ORDER BY
@@ -664,17 +662,14 @@ pub mod tests {
664662
pgrx::PgOid::Custom(pgrx::pg_sys::FLOAT4ARRAYOID),
665663
test_vec.clone().into_datum(),
666664
)],
667-
)?;
665+
)?
666+
.unwrap();
668667

669-
let set: HashSet<_> = without_index
670-
.unwrap()
671-
.iter()
672-
.map(|&ctid| ItemPointer::with_item_pointer_data(ctid))
673-
.collect();
668+
let set: HashSet<_> = without_index.iter().collect();
674669

675670
let mut matches = 0;
676671
for ctid in with_index.unwrap() {
677-
if set.contains(&ItemPointer::with_item_pointer_data(ctid)) {
672+
if set.contains(&ctid) {
678673
matches += 1;
679674
}
680675
}

pgvectorscale/src/access_method/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ END;
107107
$$;
108108
109109
"#,
110-
name = "diskann_ops_operator"
110+
name = "diskann_ops_operator",
111+
requires = [amhandler]
111112
);
112113

113114
#[pg_guard]

pgvectorscale/src/access_method/options.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use memoffset::*;
2-
use pgrx::{pg_sys::AsPgCStr, prelude::*, set_varsize, void_ptr, PgRelation};
2+
use pgrx::{pg_sys::AsPgCStr, prelude::*, set_varsize_4b, void_ptr, PgRelation};
33
use std::{ffi::CStr, fmt::Debug};
44

55
use super::storage::StorageType;
@@ -41,7 +41,7 @@ impl TSVIndexOptions {
4141
ops.num_dimensions = NUM_DIMENSIONS_DEFAULT_SENTINEL;
4242
ops.bq_num_bits_per_dimension = SBQ_NUM_BITS_PER_DIMENSION_DEFAULT_SENTINEL;
4343
unsafe {
44-
set_varsize(
44+
set_varsize_4b(
4545
ops.as_ptr().cast(),
4646
std::mem::size_of::<TSVIndexOptions>() as i32,
4747
);
@@ -87,7 +87,7 @@ impl TSVIndexOptions {
8787
}
8888

8989
const NUM_REL_OPTS: usize = 6;
90-
static mut RELOPT_KIND_TSV: pg_sys::relopt_kind = 0;
90+
static mut RELOPT_KIND_TSV: pg_sys::relopt_kind::Type = 0;
9191

9292
// amoptions is a function that gets a datum of text[] data from pg_class.reloptions (which contains text in the format "key=value") and returns a bytea for the struct for the parsed options.
9393
// this is used to fill the rd_options field in the index relation.
@@ -108,32 +108,32 @@ pub unsafe extern "C" fn amoptions(
108108
let tab: [pg_sys::relopt_parse_elt; NUM_REL_OPTS] = [
109109
pg_sys::relopt_parse_elt {
110110
optname: "storage_layout".as_pg_cstr(),
111-
opttype: pg_sys::relopt_type_RELOPT_TYPE_STRING,
111+
opttype: pg_sys::relopt_type::RELOPT_TYPE_STRING,
112112
offset: offset_of!(TSVIndexOptions, storage_layout_offset) as i32,
113113
},
114114
pg_sys::relopt_parse_elt {
115115
optname: "num_neighbors".as_pg_cstr(),
116-
opttype: pg_sys::relopt_type_RELOPT_TYPE_INT,
116+
opttype: pg_sys::relopt_type::RELOPT_TYPE_INT,
117117
offset: offset_of!(TSVIndexOptions, num_neighbors) as i32,
118118
},
119119
pg_sys::relopt_parse_elt {
120120
optname: "search_list_size".as_pg_cstr(),
121-
opttype: pg_sys::relopt_type_RELOPT_TYPE_INT,
121+
opttype: pg_sys::relopt_type::RELOPT_TYPE_INT,
122122
offset: offset_of!(TSVIndexOptions, search_list_size) as i32,
123123
},
124124
pg_sys::relopt_parse_elt {
125125
optname: "num_dimensions".as_pg_cstr(),
126-
opttype: pg_sys::relopt_type_RELOPT_TYPE_INT,
126+
opttype: pg_sys::relopt_type::RELOPT_TYPE_INT,
127127
offset: offset_of!(TSVIndexOptions, num_dimensions) as i32,
128128
},
129129
pg_sys::relopt_parse_elt {
130130
optname: "num_bits_per_dimension".as_pg_cstr(),
131-
opttype: pg_sys::relopt_type_RELOPT_TYPE_INT,
131+
opttype: pg_sys::relopt_type::RELOPT_TYPE_INT,
132132
offset: offset_of!(TSVIndexOptions, bq_num_bits_per_dimension) as i32,
133133
},
134134
pg_sys::relopt_parse_elt {
135135
optname: "max_alpha".as_pg_cstr(),
136-
opttype: pg_sys::relopt_type_RELOPT_TYPE_REAL,
136+
opttype: pg_sys::relopt_type::RELOPT_TYPE_REAL,
137137
offset: offset_of!(TSVIndexOptions, max_alpha) as i32,
138138
},
139139
];

pgvectorscale/src/access_method/scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ pub extern "C" fn amrescan(
365365
#[pg_guard]
366366
pub extern "C" fn amgettuple(
367367
scan: pg_sys::IndexScanDesc,
368-
_direction: pg_sys::ScanDirection,
368+
_direction: pg_sys::ScanDirection::Type,
369369
) -> bool {
370370
let scan: PgBox<pg_sys::IndexScanDescData> = unsafe { PgBox::from_pg(scan) };
371371
let state = unsafe { (scan.opaque as *mut TSVScanState).as_mut() }.expect("no scandesc state");

pgvectorscale/src/access_method/vacuum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub extern "C" fn ambulkdelete(
3333
let nblocks = unsafe {
3434
pg_sys::RelationGetNumberOfBlocksInFork(
3535
index_relation.as_ptr(),
36-
pg_sys::ForkNumber_MAIN_FORKNUM,
36+
pg_sys::ForkNumber::MAIN_FORKNUM,
3737
)
3838
};
3939

@@ -127,7 +127,7 @@ pub extern "C" fn amvacuumcleanup(
127127

128128
(*stats).num_pages = pg_sys::RelationGetNumberOfBlocksInFork(
129129
index_relation.as_ptr(),
130-
pg_sys::ForkNumber_MAIN_FORKNUM,
130+
pg_sys::ForkNumber::MAIN_FORKNUM,
131131
);
132132

133133
stats

pgvectorscale/src/bin/pgrx_embed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::pgrx::pgrx_embed!();

pgvectorscale/src/util/buffer.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use std::ops::Deref;
88
use pgrx::*;
99

1010
use pgrx::pg_sys::{
11-
BlockNumber, Buffer, BufferGetBlockNumber, ForkNumber_MAIN_FORKNUM, InvalidBlockNumber,
12-
ReadBufferMode_RBM_NORMAL,
11+
BlockNumber, Buffer, BufferGetBlockNumber, ForkNumber, InvalidBlockNumber, ReadBufferMode,
1312
};
1413

1514
pub struct LockRelationForExtension<'a> {
@@ -74,13 +73,13 @@ impl<'a> LockedBufferExclusive<'a> {
7473

7574
/// Safety: unsafe because tje block number is not verifiwed
7675
unsafe fn read_unchecked(index: &'a PgRelation, block: BlockNumber) -> Self {
77-
let fork_number = ForkNumber_MAIN_FORKNUM;
76+
let fork_number = ForkNumber::MAIN_FORKNUM;
7877

7978
let buf = pg_sys::ReadBufferExtended(
8079
index.as_ptr(),
8180
fork_number,
8281
block,
83-
ReadBufferMode_RBM_NORMAL,
82+
ReadBufferMode::RBM_NORMAL,
8483
std::ptr::null_mut(),
8584
);
8685

@@ -95,13 +94,13 @@ impl<'a> LockedBufferExclusive<'a> {
9594
/// Obtaining this lock is more restrictive. It will only be obtained once the pin
9695
/// count is 1. Refer to the PG code for `LockBufferForCleanup` for more info
9796
pub unsafe fn read_for_cleanup(index: &'a PgRelation, block: BlockNumber) -> Self {
98-
let fork_number = ForkNumber_MAIN_FORKNUM;
97+
let fork_number = ForkNumber::MAIN_FORKNUM;
9998

10099
let buf = pg_sys::ReadBufferExtended(
101100
index.as_ptr(),
102101
fork_number,
103102
block,
104-
ReadBufferMode_RBM_NORMAL,
103+
ReadBufferMode::RBM_NORMAL,
105104
std::ptr::null_mut(),
106105
);
107106

@@ -153,14 +152,14 @@ impl<'a> LockedBufferShare<'a> {
153152
///
154153
/// Safety: Safe because it checks the block number doesn't overflow. ReadBufferExtended will throw an error if the block number is out of range for the relation
155154
pub fn read(index: &'a PgRelation, block: BlockNumber) -> Self {
156-
let fork_number = ForkNumber_MAIN_FORKNUM;
155+
let fork_number = ForkNumber::MAIN_FORKNUM;
157156

158157
unsafe {
159158
let buf = pg_sys::ReadBufferExtended(
160159
index.as_ptr(),
161160
fork_number,
162161
block,
163-
ReadBufferMode_RBM_NORMAL,
162+
ReadBufferMode::RBM_NORMAL,
164163
std::ptr::null_mut(),
165164
);
166165

@@ -210,14 +209,14 @@ impl PinnedBufferShare {
210209
///
211210
/// Safety: Safe because it checks the block number doesn't overflow. ReadBufferExtended will throw an error if the block number is out of range for the relation
212211
pub fn read(index: &PgRelation, block: BlockNumber) -> Self {
213-
let fork_number = ForkNumber_MAIN_FORKNUM;
212+
let fork_number = ForkNumber::MAIN_FORKNUM;
214213

215214
unsafe {
216215
let buf = pg_sys::ReadBufferExtended(
217216
index.as_ptr(),
218217
fork_number,
219218
block,
220-
ReadBufferMode_RBM_NORMAL,
219+
ReadBufferMode::RBM_NORMAL,
221220
std::ptr::null_mut(),
222221
);
223222
PinnedBufferShare { buffer: buf }

pgvectorscale/src/util/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ impl ItemPointer {
9696
}
9797

9898
pub unsafe fn with_item_pointer_data(ctid: pgrx::pg_sys::ItemPointerData) -> Self {
99-
let ip = pgrx::item_pointer_get_block_number(&ctid);
100-
let off = pgrx::item_pointer_get_offset_number(&ctid);
99+
let ip = pgrx::itemptr::item_pointer_get_block_number(&ctid);
100+
let off = pgrx::itemptr::item_pointer_get_offset_number(&ctid);
101101
Self::new(ip, off)
102102
}
103103

104104
pub fn to_item_pointer_data(&self, ctid: &mut pgrx::pg_sys::ItemPointerData) {
105-
pgrx::item_pointer_set_all(ctid, self.block_number, self.offset)
105+
pgrx::itemptr::item_pointer_set_all(ctid, self.block_number, self.offset)
106106
}
107107

108108
pub unsafe fn read_bytes(self, index: &PgRelation) -> ReadableBuffer {

0 commit comments

Comments
 (0)