Skip to content

Commit

Permalink
fix: pg16 updates RelFileNode to RelFileLocator (#174)
Browse files Browse the repository at this point in the history
Signed-off-by: silver-ymz <[email protected]>
  • Loading branch information
silver-ymz authored Nov 28, 2023
1 parent 189fe96 commit 282727e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/postgres/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ pub unsafe fn init() {
pgrx::pg_sys::RegisterXactCallback(Some(xact_callback), std::ptr::null_mut());
}

#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
unsafe fn xact_delete() {
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
let mut ptr: *mut pgrx::pg_sys::RelFileNode = std::ptr::null_mut();
#[cfg(feature = "pg16")]
let mut ptr: *mut pgrx::pg_sys::RelFileLocator = std::ptr::null_mut();
let n = pgrx::pg_sys::smgrGetPendingDeletes(true, &mut ptr as *mut _);
if n > 0 {
let nodes = std::slice::from_raw_parts(ptr, n as usize);
Expand All @@ -54,3 +52,20 @@ unsafe fn xact_delete() {
});
}
}

#[cfg(feature = "pg16")]
unsafe fn xact_delete() {
let mut ptr: *mut pgrx::pg_sys::RelFileLocator = std::ptr::null_mut();
let n = pgrx::pg_sys::smgrGetPendingDeletes(true, &mut ptr as *mut _);
if n > 0 {
let nodes = std::slice::from_raw_parts(ptr, n as usize);
let ids = nodes
.iter()
.map(|node| Id::from_sys(node.relNumber))
.collect::<Vec<_>>();
client(|mut rpc| {
rpc.destory(ids).friendly();
rpc
});
}
}
6 changes: 6 additions & 0 deletions src/postgres/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ pub unsafe extern "C" fn aminsert(
_index_info: *mut pgrx::pg_sys::IndexInfo,
) -> bool {
use pgrx::FromDatum;
#[cfg(any(feature = "pg14", feature = "pg15"))]
let oid = (*index_relation).rd_node.relNode;
#[cfg(feature = "pg16")]
let oid = (*index_relation).rd_locator.relNumber;
let id = Id::from_sys(oid);
let vector = VectorInput::from_datum(*values.add(0), *is_null.add(0)).unwrap();
let vector = vector.data().to_vec();
Expand Down Expand Up @@ -274,7 +277,10 @@ pub unsafe extern "C" fn ambulkdelete(
callback: pgrx::pg_sys::IndexBulkDeleteCallback,
callback_state: *mut std::os::raw::c_void,
) -> *mut pgrx::pg_sys::IndexBulkDeleteResult {
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
let oid = (*(*info).index).rd_node.relNode;
#[cfg(feature = "pg16")]
let oid = (*(*info).index).rd_locator.relNumber;
let id = Id::from_sys(oid);
if let Some(callback) = callback {
index_update::update_delete(id, |pointer| {
Expand Down
6 changes: 6 additions & 0 deletions src/postgres/index_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ pub unsafe fn build(
index: pgrx::pg_sys::Relation,
data: Option<(*mut RelationData, *mut IndexInfo, *mut IndexBuildResult)>,
) {
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
let oid = (*index).rd_node.relNode;
#[cfg(feature = "pg16")]
let oid = (*index).rd_locator.relNumber;
let id = Id::from_sys(oid);
flush_if_commit(id);
let options = options(index);
Expand Down Expand Up @@ -81,7 +84,10 @@ unsafe extern "C" fn callback(
use super::datatype::VectorInput;
use pgrx::FromDatum;

#[cfg(any(feature = "pg13", feature = "pg14", feature = "pg15"))]
let oid = (*index_relation).rd_node.relNode;
#[cfg(feature = "pg16")]
let oid = (*index_relation).rd_locator.relNumber;
let id = Id::from_sys(oid);
let state = &mut *(state as *mut Builder);
let pgvector = VectorInput::from_datum(*values.add(0), *is_null.add(0)).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/index_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ pub unsafe fn next_scan(scan: pgrx::pg_sys::IndexScanDesc) -> bool {
else {
unreachable!()
};
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
let oid = (*(*scan).indexRelation).rd_node.relNode;
#[cfg(feature = "pg16")]
let oid = (*(*scan).indexRelation).rd_locator.relNumber;
let id = Id::from_sys(oid);
let vector = vector.expect("`rescan` is never called.");
if index_scan_state.is_some() && ENABLE_PREFILTER.get() {
Expand Down

0 comments on commit 282727e

Please sign in to comment.