Skip to content

Commit

Permalink
Move helper function to proper spot; fix new clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgreen42 committed Jan 7, 2025
1 parent 8bd2acf commit 9fe0531
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 52 deletions.
9 changes: 6 additions & 3 deletions pgvectorscale/src/access_method/plain_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,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 @@ -159,9 +159,12 @@ impl PlainStorageLsnPrivateData {
}
}

impl<'a> Storage for PlainStorage<'a> {
impl Storage for PlainStorage<'_> {
type QueryDistanceMeasure = PlainDistanceMeasure;
type NodeDistanceMeasure<'b> = IndexFullDistanceMeasure<'b> where Self: 'b;
type NodeDistanceMeasure<'b>
= IndexFullDistanceMeasure<'b>
where
Self: 'b;
type ArchivedType = ArchivedNode;
type LSNPrivateData = PlainStorageLsnPrivateData;

Expand Down
9 changes: 6 additions & 3 deletions pgvectorscale/src/access_method/sbq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,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 @@ -611,9 +611,12 @@ 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> where Self: 'b;
type NodeDistanceMeasure<'b>
= SbqNodeDistanceMeasure<'b>
where
Self: 'b;
type ArchivedType = ArchivedSbqNode;
type LSNPrivateData = SbqSpeedupStorageLsnPrivateData; //no data stored

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, meta_page::MetaPage, pg_vector::PgVector,
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 9fe0531

Please sign in to comment.