fix LSH index not properly cleaned after tuple deletion

main
Ziyang Hu 1 year ago
parent 6c076666b6
commit 0de57c3a9f

@ -952,6 +952,7 @@ impl<'a> SessionTx<'a> {
let has_indices = !relation_store.indices.is_empty(); let has_indices = !relation_store.indices.is_empty();
let has_hnsw_indices = !relation_store.hnsw_indices.is_empty(); let has_hnsw_indices = !relation_store.hnsw_indices.is_empty();
let has_fts_indices = !relation_store.fts_indices.is_empty(); let has_fts_indices = !relation_store.fts_indices.is_empty();
let has_lsh_indices = !relation_store.lsh_indices.is_empty();
let fts_processors = self.make_fts_lsh_processors(relation_store)?; let fts_processors = self.make_fts_lsh_processors(relation_store)?;
let mut new_tuples: Vec<DataValue> = vec![]; let mut new_tuples: Vec<DataValue> = vec![];
let mut old_tuples: Vec<DataValue> = vec![]; let mut old_tuples: Vec<DataValue> = vec![];
@ -977,7 +978,7 @@ impl<'a> SessionTx<'a> {
}); });
} }
} }
if need_to_collect || has_indices || has_hnsw_indices || has_fts_indices { if need_to_collect || has_indices || has_hnsw_indices || has_fts_indices || has_lsh_indices {
if let Some(existing) = self.store_tx.get(&key, false)? { if let Some(existing) = self.store_tx.get(&key, false)? {
let mut tup = extracted.clone(); let mut tup = extracted.clone();
extend_tuple_from_v(&mut tup, &existing); extend_tuple_from_v(&mut tup, &existing);

@ -35,7 +35,7 @@ impl<'a> SessionTx<'a> {
) -> Result<()> { ) -> Result<()> {
let bytes = match bytes { let bytes = match bytes {
None => { None => {
if let Some(mut found) = inv_idx_handle.get_val_only(self, tuple)? { if let Some(mut found) = inv_idx_handle.get_val_only(self, &tuple[..inv_idx_handle.metadata.keys.len()])? {
let inv_key = inv_idx_handle.encode_key_for_store(tuple, Default::default())?; let inv_key = inv_idx_handle.encode_key_for_store(tuple, Default::default())?;
self.store_tx.del(&inv_key)?; self.store_tx.del(&inv_key)?;
match found.pop() { match found.pop() {

@ -905,6 +905,32 @@ fn test_lsh_indexing3() {
} }
} }
#[test]
fn test_lsh_indexing4() {
for i in 1..10 {
let f = i as f64 / 10.;
let db = DbInstance::new("mem", "", "").unwrap();
db.run_default(r":create a {k: String => v: String}")
.unwrap();
db.run_script(
r"::lsh create a:lsh {extractor: v, tokenizer: NGram, n_gram: 3, target_threshold: $t }",
BTreeMap::from([("t".into(), f.into())]),
ScriptMutability::Mutable
)
.unwrap();
db.run_default("?[k, v] <- [['a', 'ewiygfspeoighjsfcfxzdfncalsdf']] :put a {k => v}")
.unwrap();
db.run_default("?[k] <- [['a']] :rm a {k}")
.unwrap();
let res = db
.run_default("?[k] := ~a:lsh{k | query: 'ewiygfspeoighjsfcfxzdfncalsdf', k: 1}")
.unwrap();
assert!(res.rows.len() == 0);
}
}
#[test] #[test]
fn test_lsh_indexing() { fn test_lsh_indexing() {
let db = DbInstance::new("mem", "", "").unwrap(); let db = DbInstance::new("mem", "", "").unwrap();

Loading…
Cancel
Save