File size: 2,215 Bytes
84d2a97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::collections::HashSet;

use common::types::PointOffsetType;

use crate::types::{FieldCondition, IsEmptyCondition, IsNullCondition};

pub(super) mod facet_index;
mod field_index_base;
pub mod full_text_index;
pub mod geo_hash;
pub mod geo_index;
mod histogram;
mod immutable_point_to_values;
pub mod index_selector;
pub mod map_index;
mod mmap_point_to_values;
pub mod numeric_index;
mod stat_tools;

pub mod binary_index;
#[cfg(test)]
mod tests;
mod utils;

pub use field_index_base::*;

#[derive(Debug, Clone, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum PrimaryCondition {
    Condition(FieldCondition),
    IsEmpty(IsEmptyCondition),
    IsNull(IsNullCondition),
    Ids(HashSet<PointOffsetType>),
    HasVector(String),
}

#[derive(Debug, Clone)]
pub struct PayloadBlockCondition {
    pub condition: FieldCondition,
    pub cardinality: usize,
}

#[derive(Debug, Clone)]
pub struct CardinalityEstimation {
    /// Conditions that could be used to make a primary point selection.
    pub primary_clauses: Vec<PrimaryCondition>,
    /// Minimal possible matched points in best case for a query
    pub min: usize,
    /// Expected number of matched points for a query, assuming even random distribution if stored data
    pub exp: usize,
    /// The largest possible number of matched points in a worst case for a query
    pub max: usize,
}

impl CardinalityEstimation {
    pub const fn exact(count: usize) -> Self {
        CardinalityEstimation {
            primary_clauses: vec![],
            min: count,
            exp: count,
            max: count,
        }
    }

    /// Generate estimation for unknown filter
    pub const fn unknown(total: usize) -> Self {
        CardinalityEstimation {
            primary_clauses: vec![],
            min: 0,
            exp: total / 2,
            max: total,
        }
    }

    /// Push a primary clause to the estimation
    pub fn with_primary_clause(mut self, clause: PrimaryCondition) -> Self {
        self.primary_clauses.push(clause);
        self
    }

    #[cfg(test)]
    pub const fn equals_min_exp_max(&self, other: &Self) -> bool {
        self.min == other.min && self.exp == other.exp && self.max == other.max
    }
}