Skip to content

Commit

Permalink
feat: max_scan_tuples
Browse files Browse the repository at this point in the history
Signed-off-by: usamoi <[email protected]>
  • Loading branch information
usamoi committed Nov 15, 2024
1 parent e95b11f commit 7c45933
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/gucs/executing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ffi::CStr;

static PROBES: GucSetting<Option<&'static CStr>> = GucSetting::<Option<&CStr>>::new(Some(c"10"));
static EPSILON: GucSetting<f64> = GucSetting::<f64>::new(1.9);
static MAX_SCAN_TUPLES: GucSetting<i32> = GucSetting::<i32>::new(-1);

pub unsafe fn init() {
GucRegistry::define_string_guc(
Expand All @@ -23,6 +24,16 @@ pub unsafe fn init() {
GucContext::Userset,
GucFlags::default(),
);
GucRegistry::define_int_guc(
"vchordrq.max_scan_tuples",
"`max_scan_tuples` argument of vchordrq.",
"`max_scan_tuples` argument of vchordrq.",
&MAX_SCAN_TUPLES,
-1,
u16::MAX as _,
GucContext::Userset,
GucFlags::default(),
);
}

pub fn probes() -> Vec<u32> {
Expand Down Expand Up @@ -54,3 +65,12 @@ pub fn probes() -> Vec<u32> {
pub fn epsilon() -> f32 {
EPSILON.get() as f32
}

pub fn max_scan_tuples() -> Option<u32> {
let x = MAX_SCAN_TUPLES.get();
if x < 0 {
None
} else {
Some(x as u32)
}
}
7 changes: 6 additions & 1 deletion src/index/am_scan.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::am_options::Opfamily;
use crate::algorithm::scan::scan;
use crate::gucs::executing::epsilon;
use crate::gucs::executing::max_scan_tuples;
use crate::gucs::executing::probes;
use crate::postgres::Relation;
use base::distance::Distance;
Expand Down Expand Up @@ -86,7 +87,11 @@ pub fn scan_next(scanner: &mut Scanner, relation: Relation) -> Option<(Pointer,
epsilon(),
);
*scanner = Scanner::Vbase {
vbase: Box::new(vbase),
vbase: if let Some(max_scan_tuples) = max_scan_tuples() {
Box::new(vbase.take(max_scan_tuples as usize))
} else {
Box::new(vbase)
},
threshold: *threshold,
recheck: *recheck,
opfamily: *opfamily,
Expand Down

0 comments on commit 7c45933

Please sign in to comment.