diff --git a/pgvectorscale/src/access_method/sbq.rs b/pgvectorscale/src/access_method/sbq.rs index a62219d..ca998fd 100644 --- a/pgvectorscale/src/access_method/sbq.rs +++ b/pgvectorscale/src/access_method/sbq.rs @@ -117,7 +117,7 @@ impl SbqMeans { quantizer } _ => { - pgrx::error!("Invalid page type for SbqMeans"); + pgrx::error!("Invalid page type {} for SbqMeans", page_type as u8); } } } diff --git a/pgvectorscale/src/util/chain.rs b/pgvectorscale/src/util/chain.rs index 4b584a6..aadf980 100644 --- a/pgvectorscale/src/util/chain.rs +++ b/pgvectorscale/src/util/chain.rs @@ -147,3 +147,43 @@ impl<'a, S: StatsNodeRead> Iterator for ChainedItemIterator<'a, S> { } } } + +#[cfg(any(test, feature = "pg_test"))] +#[pgrx::pg_schema] +mod tests { + use pgrx::{pg_sys, pg_test, Spi}; + + use crate::access_method::stats::InsertStats; + + use super::*; + + fn make_test_relation() -> PgRelation { + Spi::run( + "CREATE TABLE test(encoding vector(3)); + CREATE INDEX idxtest + ON test + USING diskann(encoding) + WITH (num_neighbors=30);", + ) + .unwrap(); + + let index_oid = Spi::get_one::("SELECT 'idxtest'::regclass::oid") + .unwrap() + .expect("oid was null"); + unsafe { PgRelation::from_pg(pg_sys::RelationIdGetRelation(index_oid)) } + } + + #[pg_test] + fn test_chain_tape() { + let mut stats = InsertStats::default(); + let index = make_test_relation(); + let mut tape = ChainTapeWriter::new(&index, PageType::SbqMeans, &mut stats); + let data = b"hello world"; + let ip = tape.write(data).unwrap(); + let mut reader = ChainTapeReader::new(&index, PageType::SbqMeans, &mut stats); + let mut iter = reader.read(ip); + let item = iter.next().unwrap(); + assert_eq!(item.get_data_slice(), data); + assert!(iter.next().is_none()); + } +} diff --git a/pgvectorscale/src/util/page.rs b/pgvectorscale/src/util/page.rs index 97383d2..741fe0b 100644 --- a/pgvectorscale/src/util/page.rs +++ b/pgvectorscale/src/util/page.rs @@ -32,9 +32,8 @@ pub enum PageType { PqQuantizerVector = 3, SbqMeansV1 = 4, SbqNode = 5, - MetaV2 = 6, - Meta = 7, - SbqMeans = 8, + Meta = 6, + SbqMeans = 7, } impl PageType { @@ -44,15 +43,15 @@ impl PageType { 1 => PageType::Node, 2 => PageType::PqQuantizerDef, 3 => PageType::PqQuantizerVector, - 4 => PageType::SbqMeans, + 4 => PageType::SbqMeansV1, 5 => PageType::SbqNode, - 6 => PageType::MetaV2, - 7 => PageType::Meta, + 6 => PageType::Meta, + 7 => PageType::SbqMeans, _ => panic!("Unknown PageType number {}", value), } } - /// `Tape` supports chaining of pages that might contain large data. + /// `ChainTape` supports chaining of pages that might contain large data. pub fn is_chained(self) -> bool { matches!(self, PageType::SbqMeans) } @@ -144,12 +143,6 @@ impl<'a> WritablePage<'a> { unsafe { self.add_item_unchecked(data) } } - pub unsafe fn replace_item(&mut self, offset: OffsetNumber, data: &[u8]) { - let result = - pg_sys::PageIndexTupleOverwrite(self.page, offset, data.as_ptr() as _, data.len()); - assert!(result); - } - pub unsafe fn add_item_unchecked(&mut self, data: &[u8]) -> OffsetNumber { let size = data.len(); assert!(size < BLCKSZ as usize); diff --git a/pgvectorscale/src/util/tape.rs b/pgvectorscale/src/util/tape.rs index 7e18aa0..b1ce88b 100644 --- a/pgvectorscale/src/util/tape.rs +++ b/pgvectorscale/src/util/tape.rs @@ -121,19 +121,6 @@ mod tests { node_page }; - { - let mut tape = Tape::resume(&indexrel, PageType::SbqMeans); - let ip = tape.write(&[99]); - assert_eq!( - ip.block_number, tape.current, - "Tape block number should match IP" - ); - assert_ne!( - tape.current, node_page, - "Data can only be written to page of its type" - ); - } - { let mut tape = Tape::resume(&indexrel, PageType::PqQuantizerVector); let ip = tape.write(&[99]);