From 282727e1c9f25224e4015299afbff8f0bb41cc70 Mon Sep 17 00:00:00 2001 From: Mingzhuo Yin Date: Tue, 28 Nov 2023 22:20:11 +0800 Subject: [PATCH] fix: pg16 updates RelFileNode to RelFileLocator (#174) Signed-off-by: silver-ymz --- src/postgres/hooks.rs | 21 ++++++++++++++++++--- src/postgres/index.rs | 6 ++++++ src/postgres/index_build.rs | 6 ++++++ src/postgres/index_scan.rs | 3 +++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/postgres/hooks.rs b/src/postgres/hooks.rs index 07d193a16..f652bf0ea 100644 --- a/src/postgres/hooks.rs +++ b/src/postgres/hooks.rs @@ -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); @@ -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::>(); + client(|mut rpc| { + rpc.destory(ids).friendly(); + rpc + }); + } +} diff --git a/src/postgres/index.rs b/src/postgres/index.rs index 2c86954a1..e8ec4152a 100644 --- a/src/postgres/index.rs +++ b/src/postgres/index.rs @@ -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(); @@ -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| { diff --git a/src/postgres/index_build.rs b/src/postgres/index_build.rs index 64173e2b4..f6b41b114 100644 --- a/src/postgres/index_build.rs +++ b/src/postgres/index_build.rs @@ -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); @@ -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(); diff --git a/src/postgres/index_scan.rs b/src/postgres/index_scan.rs index a8bb77ef5..b5251d900 100644 --- a/src/postgres/index_scan.rs +++ b/src/postgres/index_scan.rs @@ -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() {