2023-05-29 11:46:41 +00:00
|
|
|
mod bkeys;
|
|
|
|
pub(crate) mod btree;
|
|
|
|
pub(crate) mod ft;
|
2023-06-19 18:41:13 +00:00
|
|
|
pub(crate) mod planner;
|
2023-05-29 11:46:41 +00:00
|
|
|
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::err::Error;
|
|
|
|
use crate::idx::btree::NodeId;
|
|
|
|
use crate::idx::ft::docids::DocId;
|
|
|
|
use crate::idx::ft::terms::TermId;
|
2023-06-19 18:41:13 +00:00
|
|
|
use crate::key::bc::Bc;
|
2023-05-29 11:46:41 +00:00
|
|
|
use crate::key::bd::Bd;
|
2023-06-19 18:41:13 +00:00
|
|
|
use crate::key::bf::Bf;
|
2023-05-29 11:46:41 +00:00
|
|
|
use crate::key::bi::Bi;
|
|
|
|
use crate::key::bk::Bk;
|
|
|
|
use crate::key::bl::Bl;
|
|
|
|
use crate::key::bp::Bp;
|
|
|
|
use crate::key::bs::Bs;
|
|
|
|
use crate::key::bt::Bt;
|
|
|
|
use crate::key::bu::Bu;
|
|
|
|
use crate::kvs::{Key, Val};
|
|
|
|
use crate::sql::statements::DefineIndexStatement;
|
|
|
|
use roaring::RoaringTreemap;
|
|
|
|
use serde::de::DeserializeOwned;
|
2023-06-19 18:41:13 +00:00
|
|
|
use serde::Serialize;
|
|
|
|
use std::sync::Arc;
|
2023-05-29 11:46:41 +00:00
|
|
|
|
2023-06-19 18:41:13 +00:00
|
|
|
#[derive(Debug, Clone, Default)]
|
2023-05-29 11:46:41 +00:00
|
|
|
pub(crate) struct IndexKeyBase {
|
2023-06-19 18:41:13 +00:00
|
|
|
inner: Arc<Inner>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct Inner {
|
2023-05-29 11:46:41 +00:00
|
|
|
ns: String,
|
|
|
|
db: String,
|
|
|
|
tb: String,
|
|
|
|
ix: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IndexKeyBase {
|
|
|
|
pub(crate) fn new(opt: &Options, ix: &DefineIndexStatement) -> Self {
|
|
|
|
Self {
|
2023-06-19 18:41:13 +00:00
|
|
|
inner: Arc::new(Inner {
|
|
|
|
ns: opt.ns().to_string(),
|
|
|
|
db: opt.db().to_string(),
|
|
|
|
tb: ix.what.to_string(),
|
|
|
|
ix: ix.name.to_string(),
|
|
|
|
}),
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:41:13 +00:00
|
|
|
fn new_bc_key(&self, term_id: TermId) -> Key {
|
|
|
|
Bc::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
term_id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
2023-05-29 11:46:41 +00:00
|
|
|
fn new_bd_key(&self, node_id: Option<NodeId>) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bd::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bi_key(&self, doc_id: DocId) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bi::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
doc_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bk_key(&self, doc_id: DocId) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bk::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
doc_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bl_key(&self, node_id: Option<NodeId>) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bl::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bp_key(&self, node_id: Option<NodeId>) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bp::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bf_key(&self, term_id: TermId, doc_id: DocId) -> Key {
|
|
|
|
Bf::new(
|
2023-06-19 18:41:13 +00:00
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
2023-05-29 11:46:41 +00:00
|
|
|
term_id,
|
|
|
|
doc_id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:41:13 +00:00
|
|
|
fn new_bt_key(&self, node_id: Option<NodeId>) -> Key {
|
|
|
|
Bt::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
node_id,
|
2023-05-29 11:46:41 +00:00
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bs_key(&self) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bs::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_bu_key(&self, term_id: TermId) -> Key {
|
2023-06-19 18:41:13 +00:00
|
|
|
Bu::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
term_id,
|
|
|
|
)
|
|
|
|
.into()
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This trait provides `bincode` based default implementations for serialization/deserialization
|
|
|
|
trait SerdeState
|
|
|
|
where
|
|
|
|
Self: Sized + Serialize + DeserializeOwned,
|
|
|
|
{
|
|
|
|
fn try_to_val(&self) -> Result<Val, Error> {
|
|
|
|
Ok(bincode::serialize(self)?)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn try_from_val(val: Val) -> Result<Self, Error> {
|
|
|
|
Ok(bincode::deserialize(&val)?)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SerdeState for RoaringTreemap {}
|