2023-10-26 21:33:06 +00:00
|
|
|
pub mod docids;
|
2023-05-29 11:46:41 +00:00
|
|
|
pub(crate) mod ft;
|
2024-08-20 09:20:53 +00:00
|
|
|
pub(crate) mod index;
|
2024-05-24 13:45:21 +00:00
|
|
|
pub mod planner;
|
2023-08-01 09:57:05 +00:00
|
|
|
pub mod trees;
|
2023-05-29 11:46:41 +00:00
|
|
|
|
|
|
|
use crate::err::Error;
|
2023-09-12 20:26:03 +00:00
|
|
|
use crate::idx::docids::DocId;
|
2023-05-29 11:46:41 +00:00
|
|
|
use crate::idx::ft::terms::TermId;
|
2024-08-20 10:42:58 +00:00
|
|
|
use crate::idx::trees::hnsw::ElementId;
|
2023-08-01 09:57:05 +00:00
|
|
|
use crate::idx::trees::store::NodeId;
|
2024-08-20 10:42:58 +00:00
|
|
|
use crate::idx::trees::vector::SerializedVector;
|
2023-07-18 18:32:38 +00:00
|
|
|
use crate::key::index::bc::Bc;
|
|
|
|
use crate::key::index::bd::Bd;
|
|
|
|
use crate::key::index::bf::Bf;
|
|
|
|
use crate::key::index::bi::Bi;
|
|
|
|
use crate::key::index::bk::Bk;
|
|
|
|
use crate::key::index::bl::Bl;
|
|
|
|
use crate::key::index::bo::Bo;
|
|
|
|
use crate::key::index::bp::Bp;
|
|
|
|
use crate::key::index::bs::Bs;
|
|
|
|
use crate::key::index::bt::Bt;
|
|
|
|
use crate::key::index::bu::Bu;
|
2024-08-20 10:42:58 +00:00
|
|
|
use crate::key::index::hd::Hd;
|
|
|
|
use crate::key::index::he::He;
|
|
|
|
use crate::key::index::hi::Hi;
|
|
|
|
use crate::key::index::hl::Hl;
|
|
|
|
use crate::key::index::hs::Hs;
|
|
|
|
use crate::key::index::hv::Hv;
|
2023-09-12 20:26:03 +00:00
|
|
|
use crate::key::index::vm::Vm;
|
2023-05-29 11:46:41 +00:00
|
|
|
use crate::kvs::{Key, Val};
|
|
|
|
use crate::sql::statements::DefineIndexStatement;
|
2024-08-20 10:42:58 +00:00
|
|
|
use crate::sql::{Id, Thing};
|
2023-08-29 19:21:55 +00:00
|
|
|
use revision::Revisioned;
|
2023-05-29 11:46:41 +00:00
|
|
|
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)]
|
2024-04-02 20:12:08 +00:00
|
|
|
#[non_exhaustive]
|
2023-07-11 18:22:31 +00:00
|
|
|
pub 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 {
|
2024-06-11 09:34:21 +00:00
|
|
|
pub(crate) fn new(ns: &str, db: &str, ix: &DefineIndexStatement) -> Result<Self, Error> {
|
|
|
|
Ok(Self {
|
2023-06-19 18:41:13 +00:00
|
|
|
inner: Arc::new(Inner {
|
2024-06-11 09:34:21 +00:00
|
|
|
ns: ns.to_string(),
|
|
|
|
db: db.to_string(),
|
2023-06-19 18:41:13 +00:00
|
|
|
tb: ix.what.to_string(),
|
|
|
|
ix: ix.name.to_string(),
|
|
|
|
}),
|
2024-06-11 09:34:21 +00:00
|
|
|
})
|
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
|
|
|
}
|
|
|
|
|
2023-06-21 18:31:15 +00:00
|
|
|
fn new_bo_key(&self, doc_id: DocId, term_id: TermId) -> Key {
|
|
|
|
Bo::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
doc_id,
|
|
|
|
term_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
|
|
|
}
|
2023-09-12 20:26:03 +00:00
|
|
|
|
2024-08-20 10:42:58 +00:00
|
|
|
fn new_hd_key(&self, doc_id: Option<DocId>) -> Key {
|
|
|
|
Hd::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
doc_id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_he_key(&self, element_id: ElementId) -> Key {
|
|
|
|
He::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
element_id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_hi_key(&self, id: Id) -> Key {
|
|
|
|
Hi::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
id,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_hl_key(&self, layer: u16, chunk: u32) -> Key {
|
|
|
|
Hl::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
layer,
|
|
|
|
chunk,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_hv_key(&self, vec: Arc<SerializedVector>) -> Key {
|
|
|
|
Hv::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
vec,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_hs_key(&self) -> Key {
|
|
|
|
Hs::new(
|
|
|
|
self.inner.ns.as_str(),
|
|
|
|
self.inner.db.as_str(),
|
|
|
|
self.inner.tb.as_str(),
|
|
|
|
self.inner.ix.as_str(),
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
2023-09-12 20:26:03 +00:00
|
|
|
fn new_vm_key(&self, node_id: Option<NodeId>) -> Key {
|
|
|
|
Vm::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
|
|
|
}
|
|
|
|
|
2023-08-29 19:21:55 +00:00
|
|
|
/// This trait provides `Revision` based default implementations for serialization/deserialization
|
2024-08-20 10:42:58 +00:00
|
|
|
trait VersionedStore
|
2023-05-29 11:46:41 +00:00
|
|
|
where
|
2023-08-29 19:21:55 +00:00
|
|
|
Self: Sized + Serialize + DeserializeOwned + Revisioned,
|
2023-05-29 11:46:41 +00:00
|
|
|
{
|
2024-08-20 10:42:58 +00:00
|
|
|
fn try_into(&self) -> Result<Val, Error> {
|
2023-08-29 19:21:55 +00:00
|
|
|
let mut val = Vec::new();
|
|
|
|
self.serialize_revisioned(&mut val)?;
|
|
|
|
Ok(val)
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
2024-08-20 10:42:58 +00:00
|
|
|
fn try_from(val: Val) -> Result<Self, Error> {
|
2023-08-29 19:21:55 +00:00
|
|
|
Ok(Self::deserialize_revisioned(&mut val.as_slice())?)
|
2023-05-29 11:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-20 10:42:58 +00:00
|
|
|
|
|
|
|
impl VersionedStore for Thing {}
|