Skip to content

Commit

Permalink
Merge branch 'main' into tj/filtered_diskann
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgreen42 committed Jan 16, 2025
2 parents b8168e0 + 33d8117 commit f2b0020
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To create a pgvectorscale developer environment, you need the following on your
* [Cargo-pgrx][cargo-pgrx]:
```shell
cargo install --locked cargo-pgrx
cargo install --locked cargo-pgrx --version $(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "pgrx") | .version')
```
You must reinstall cargo-pgrx whenever you update Rust, cargo-pgrx must
be built with the same compiler as pgvectorscale.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ You can install pgvectorscale from source and install it in an existing PostgreS
# install prerequisites
## rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
## pgrx
cargo install --locked cargo-pgrx
## 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
#download, build and install pgvectorscale
Expand Down
4 changes: 2 additions & 2 deletions pgvectorscale/src/access_method/plain_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'a> IndexFullDistanceMeasure<'a> {
}
}

impl<'a> NodeDistanceMeasure for IndexFullDistanceMeasure<'a> {
impl NodeDistanceMeasure for IndexFullDistanceMeasure<'_> {
unsafe fn get_distance<T: StatsNodeRead + StatsDistanceComparison>(
&self,
index_pointer: IndexPointer,
Expand Down Expand Up @@ -164,7 +164,7 @@ impl PlainStorageLsnPrivateData {
}
}

impl<'a> Storage for PlainStorage<'a> {
impl Storage for PlainStorage<'_> {
type QueryDistanceMeasure = PlainDistanceMeasure;
type NodeDistanceMeasure<'b>
= IndexFullDistanceMeasure<'b>
Expand Down
4 changes: 2 additions & 2 deletions pgvectorscale/src/access_method/sbq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl<'a> SbqNodeDistanceMeasure<'a> {
}
}

impl<'a> NodeDistanceMeasure for SbqNodeDistanceMeasure<'a> {
impl NodeDistanceMeasure for SbqNodeDistanceMeasure<'_> {
unsafe fn get_distance<T: StatsNodeRead + StatsDistanceComparison>(
&self,
index_pointer: IndexPointer,
Expand Down Expand Up @@ -617,7 +617,7 @@ impl<'a> SbqSpeedupStorage<'a> {

pub type SbqSpeedupStorageLsnPrivateData = PhantomData<bool>; //no data stored

impl<'a> Storage for SbqSpeedupStorage<'a> {
impl Storage for SbqSpeedupStorage<'_> {
type QueryDistanceMeasure = SbqSearchDistanceMeasure;
type NodeDistanceMeasure<'b>
= SbqNodeDistanceMeasure<'b>
Expand Down
36 changes: 1 addition & 35 deletions pgvectorscale/src/access_method/scan.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::collections::BinaryHeap;

#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
use pg_sys::pgstat_assoc_relation;

use pgrx::{pg_sys::InvalidOffsetNumber, *};

use crate::{
access_method::{
graph_neighbor_store::GraphNeighborStore, labels::LabeledVector, meta_page::MetaPage,
sbq::SbqSpeedupStorage,
},
util::{buffer::PinnedBufferShare, HeapPointer, IndexPointer},
util::{buffer::PinnedBufferShare, ports::pgstat_count_index_scan, HeapPointer, IndexPointer},
};

use super::{
Expand Down Expand Up @@ -296,37 +293,6 @@ impl<QDM, PD> TSVResponseIterator<QDM, PD> {
}
}

/// Hand implementation of `pgstat_count_index_scan` which is missing from pgrx.
#[allow(unused_variables)]
pub unsafe fn pgstat_count_index_scan(index_relation: pg_sys::Relation, indexrel: PgRelation) {
if !indexrel.pgstat_info.is_null() {
let tmp = indexrel.pgstat_info;
#[cfg(any(feature = "pg13", feature = "pg14", feature = "pg15"))]
{
(*tmp).t_counts.t_numscans += 1;
}
#[cfg(any(feature = "pg16", feature = "pg17"))]
{
(*tmp).counts.numscans += 1;
}
}

#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
if indexrel.pgstat_info.is_null() && indexrel.pgstat_enabled {
pgstat_assoc_relation(index_relation);
assert!(!indexrel.pgstat_info.is_null());
let tmp = indexrel.pgstat_info;
#[cfg(feature = "pg15")]
{
(*tmp).t_counts.t_numscans += 1;
}
#[cfg(any(feature = "pg16", feature = "pg17"))]
{
(*tmp).counts.numscans += 1;
}
}
}

#[pg_guard]
pub extern "C" fn ambeginscan(
index_relation: pg_sys::Relation,
Expand Down
10 changes: 5 additions & 5 deletions pgvectorscale/src/util/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> LockRelationForExtension<'a> {
}
}

impl<'a> Drop for LockRelationForExtension<'a> {
impl Drop for LockRelationForExtension<'_> {
/// drop both unlock and unpins the buffer.
fn drop(&mut self) {
unsafe {
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<'a> LockedBufferExclusive<'a> {
}
}

impl<'a> Drop for LockedBufferExclusive<'a> {
impl Drop for LockedBufferExclusive<'_> {
/// drop both unlock and unpins the buffer.
fn drop(&mut self) {
unsafe {
Expand All @@ -129,7 +129,7 @@ impl<'a> Drop for LockedBufferExclusive<'a> {
}
}

impl<'a> Deref for LockedBufferExclusive<'a> {
impl Deref for LockedBufferExclusive<'_> {
type Target = Buffer;
fn deref(&self) -> &Self::Target {
&self.buffer
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'a> LockedBufferShare<'a> {
}
}

impl<'a> Drop for LockedBufferShare<'a> {
impl Drop for LockedBufferShare<'_> {
/// drop both unlock and unpins the buffer.
fn drop(&mut self) {
unsafe {
Expand All @@ -185,7 +185,7 @@ impl<'a> Drop for LockedBufferShare<'a> {
}
}

impl<'a> Deref for LockedBufferShare<'a> {
impl Deref for LockedBufferShare<'_> {
type Target = Buffer;
fn deref(&self) -> &Self::Target {
&self.buffer
Expand Down
2 changes: 1 addition & 1 deletion pgvectorscale/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct WritableBuffer<'a> {
ptr: *mut u8,
}

impl<'a> WritableBuffer<'a> {
impl WritableBuffer<'_> {
pub fn get_data_slice(&mut self) -> &mut [u8] {
unsafe { std::slice::from_raw_parts_mut(self.ptr, self.len) }
}
Expand Down
7 changes: 3 additions & 4 deletions pgvectorscale/src/util/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl PageType {

/// This is the Tsv-specific data that goes on every "diskann-owned" page
/// It is placed at the end of a page in the "special" area
#[repr(C)]
struct TsvPageOpaqueData {
page_type: u8, // stores the PageType enum as an integer (u8 because we doubt we'll have more than 256 types).
Expand Down Expand Up @@ -225,7 +224,7 @@ impl<'a> WritablePage<'a> {
}
}

impl<'a> Drop for WritablePage<'a> {
impl Drop for WritablePage<'_> {
// drop aborts the xlog if it has not been committed.
fn drop(&mut self) {
if !self.committed {
Expand All @@ -236,7 +235,7 @@ impl<'a> Drop for WritablePage<'a> {
}
}

impl<'a> Deref for WritablePage<'a> {
impl Deref for WritablePage<'_> {
type Target = Page;
fn deref(&self) -> &Self::Target {
&self.page
Expand Down Expand Up @@ -281,7 +280,7 @@ impl<'a> ReadablePage<'a> {
}
}

impl<'a> Deref for ReadablePage<'a> {
impl Deref for ReadablePage<'_> {
type Target = Page;
fn deref(&self) -> &Self::Target {
&self.page
Expand Down
36 changes: 35 additions & 1 deletion pgvectorscale/src/util/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
use std::os::raw::c_int;

use memoffset::*;

#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
use pg_sys::pgstat_assoc_relation;

use pgrx::pg_sys::{Datum, ItemId, OffsetNumber, Pointer, TupleTableSlot};
use pgrx::{pg_sys, PgBox};
use pgrx::{pg_sys, PgBox, PgRelation};

/// Given a valid Page pointer, return address of the "Special Pointer" (custom info at end of page)
///
Expand Down Expand Up @@ -119,3 +123,33 @@ pub unsafe fn slot_getattr(
}
Some(*slot.tts_values.add(index))
}

#[allow(unused_variables)]
pub unsafe fn pgstat_count_index_scan(index_relation: pg_sys::Relation, indexrel: PgRelation) {
if !indexrel.pgstat_info.is_null() {
let tmp = indexrel.pgstat_info;
#[cfg(any(feature = "pg13", feature = "pg14", feature = "pg15"))]
{
(*tmp).t_counts.t_numscans += 1;
}
#[cfg(any(feature = "pg16", feature = "pg17"))]
{
(*tmp).counts.numscans += 1;
}
}

#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
if indexrel.pgstat_info.is_null() && indexrel.pgstat_enabled {
pgstat_assoc_relation(index_relation);
assert!(!indexrel.pgstat_info.is_null());
let tmp = indexrel.pgstat_info;
#[cfg(feature = "pg15")]
{
(*tmp).t_counts.t_numscans += 1;
}
#[cfg(any(feature = "pg16", feature = "pg17"))]
{
(*tmp).counts.numscans += 1;
}
}
}

0 comments on commit f2b0020

Please sign in to comment.