pub struct SelectivityEstimator { /* private fields */ }Expand description
Selective Estimator
Provide selective estimates based on statistical information and heuristic rules.
Implementations§
Source§impl SelectivityEstimator
impl SelectivityEstimator
Sourcepub fn new(stats_manager: Arc<StatisticsManager>) -> Self
pub fn new(stats_manager: Arc<StatisticsManager>) -> Self
Create a new selective estimator.
Sourcepub fn with_feedback(
stats_manager: Arc<StatisticsManager>,
feedback: Arc<SelectivityFeedbackManager>,
) -> Self
pub fn with_feedback( stats_manager: Arc<StatisticsManager>, feedback: Arc<SelectivityFeedbackManager>, ) -> Self
Create a selective estimator wired to a feedback correction manager.
When feedback is enabled, estimate_from_expression consults the
corrected selectivity for the normalized condition key first and
registers newly estimated conditions for later correction.
Sourcepub fn feedback_manager(&self) -> Option<&Arc<SelectivityFeedbackManager>>
pub fn feedback_manager(&self) -> Option<&Arc<SelectivityFeedbackManager>>
Return the underlying feedback correction manager, if any.
Sourcepub fn snapshot(&self) -> SelectivitySnapshot
pub fn snapshot(&self) -> SelectivitySnapshot
Capture the learned corrections for one planning decision to read through. Empty when no feedback manager is attached.
Sourcepub fn estimate_readonly(
&self,
space: Option<&str>,
expr: &Expression,
tag_name: Option<&str>,
snapshot: &SelectivitySnapshot,
) -> f64
pub fn estimate_readonly( &self, space: Option<&str>, expr: &Expression, tag_name: Option<&str>, snapshot: &SelectivitySnapshot, ) -> f64
Estimate a predicate without touching shared feedback state.
Unlike estimate_from_expression,
this neither registers the condition nor refreshes its baseline: the
snapshotted correction (if any) applies to the fresh estimate, so
repeated calls stay identical until execution feedback lands.
Sourcepub fn estimate_equality_selectivity(
&self,
space: Option<&str>,
tag_name: Option<&str>,
property_name: &str,
value: Option<&Value>,
) -> f64
pub fn estimate_equality_selectivity( &self, space: Option<&str>, tag_name: Option<&str>, property_name: &str, value: Option<&Value>, ) -> f64
Estimated Equivalence Condition Selectivity
If there is histogram statistical information, use the histogram for an accurate estimation. Otherwise, if basic statistical information is available, use 1 divided by the number of distinct values. Otherwise the default value of 0.1 is used
Sourcepub fn estimate_equality_selectivity_simple(
&self,
space: Option<&str>,
tag_name: Option<&str>,
property_name: &str,
) -> f64
pub fn estimate_equality_selectivity_simple( &self, space: Option<&str>, tag_name: Option<&str>, property_name: &str, ) -> f64
Estimated Equivalence Condition Selectivity (simplified version, without values)
Sourcepub fn estimate_range_selectivity(
&self,
space: Option<&str>,
tag_name: Option<&str>,
property_name: &str,
range: &RangeCondition,
) -> f64
pub fn estimate_range_selectivity( &self, space: Option<&str>, tag_name: Option<&str>, property_name: &str, range: &RangeCondition, ) -> f64
Conditional selectivity of the estimation range
If there is histogram statistical information, the calculations are based on that histogram. Otherwise, use the default value of 1/3.
Sourcepub fn estimate_range_selectivity_with_bounds(
&self,
min_val: f64,
max_val: f64,
range_size: f64,
) -> f64
pub fn estimate_range_selectivity_with_bounds( &self, min_val: f64, max_val: f64, range_size: f64, ) -> f64
Conditional Selectivity of Estimation Ranges (with Boundary Values)
Adjust the selectivity based on the size of the scope.
Sourcepub fn estimate_ordered_comparison(
&self,
space: Option<&str>,
tag_name: Option<&str>,
property_name: &str,
bound: Option<f64>,
greater_than: bool,
) -> f64
pub fn estimate_ordered_comparison( &self, space: Option<&str>, tag_name: Option<&str>, property_name: &str, bound: Option<f64>, greater_than: bool, ) -> f64
Range-comparison selectivity from the sampled min/max envelope.
Linear interpolation over [min, max] assuming uniform distribution:
prop > bound covers (max - bound) / (max - min) of the range.
Falls back to the fixed heuristics when no envelope is available.
Sourcepub fn estimate_less_than_selectivity(&self, value: Option<f64>) -> f64
pub fn estimate_less_than_selectivity(&self, value: Option<f64>) -> f64
Estimated to be less than conditional selectivity
If there is statistical information available, the calculations are based on histograms. Otherwise, assume that the data is evenly distributed, and return 1/3.
Sourcepub fn estimate_greater_than_selectivity(&self, value: Option<f64>) -> f64
pub fn estimate_greater_than_selectivity(&self, value: Option<f64>) -> f64
The estimate is greater than the condition selectivity.
Sourcepub fn estimate_like_selectivity(&self, pattern: &str) -> f64
pub fn estimate_like_selectivity(&self, pattern: &str) -> f64
Estimating the selectivity of LIKE conditions
Adjust the selectivity based on the prefix and suffix wildcards of the pattern:
- prefix%: high selectivity (about 0.1)
- %suffix: medium selectivity (about 0.2)
- %substring%: less selective (about 0.5)
- No wildcard: exact match (about 0.05)
Sourcepub fn estimate_in_selectivity(&self, list_size: usize) -> f64
pub fn estimate_in_selectivity(&self, list_size: usize) -> f64
Estimating the selectivity of the IN list
Assuming that the selectivity of each value is the same, the total selectivity = number of values * selectivity of a single value.
Sourcepub fn estimate_is_null_selectivity(&self) -> f64
pub fn estimate_is_null_selectivity(&self) -> f64
Estimated IS NULL selectivity
Sourcepub fn estimate_is_not_null_selectivity(&self) -> f64
pub fn estimate_is_not_null_selectivity(&self) -> f64
The “IS NOT NULL” condition is used for selection purposes.
Sourcepub fn estimate_not_selectivity(&self, inner_selectivity: f64) -> f64
pub fn estimate_not_selectivity(&self, inner_selectivity: f64) -> f64
Estimated NOT conditional selectivity
The selectivity of the NOT condition = 1 – the selectivity of the original condition
Sourcepub fn estimate_from_expression(
&self,
space: Option<&str>,
expr: &Expression,
tag_name: Option<&str>,
) -> f64
pub fn estimate_from_expression( &self, space: Option<&str>, expr: &Expression, tag_name: Option<&str>, ) -> f64
Estimating selectivity from expressions
This is the main entry method, which distributes the data to the specific estimation methods based on the type of the expression.
When a feedback correction manager is attached, the normalized condition key is looked up first: a registered correction overrides the histogram / heuristic estimate. Otherwise the estimate is computed and registered so later executions can correct it.
Trait Implementations§
Source§impl Clone for SelectivityEstimator
impl Clone for SelectivityEstimator
Auto Trait Implementations§
impl !RefUnwindSafe for SelectivityEstimator
impl !UnwindSafe for SelectivityEstimator
impl Freeze for SelectivityEstimator
impl Send for SelectivityEstimator
impl Sync for SelectivityEstimator
impl Unpin for SelectivityEstimator
impl UnsafeUnpin for SelectivityEstimator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.