Use an union instead of a sort for OR ops

This commit is contained in:
Clément Renault 2020-01-15 15:14:24 +01:00
parent db625a08f7
commit 5f9a3546e0
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -332,25 +332,27 @@ pub fn traverse_query_tree<'o, 'txn>(
println!("{:1$}OR", "", depth * 2); println!("{:1$}OR", "", depth * 2);
let before = Instant::now(); let before = Instant::now();
let mut ids = Vec::new(); let mut results = Vec::new();
for op in operations { for op in operations {
let docids = match cache.get(op) { if cache.get(op).is_none() {
Some(docids) => docids, let docids = match op {
None => { Operation::And(ops) => execute_and(reader, ctx, cache, postings, depth + 1, &ops)?,
let docids = match op { Operation::Or(ops) => execute_or(reader, ctx, cache, postings, depth + 1, &ops)?,
Operation::And(ops) => execute_and(reader, ctx, cache, postings, depth + 1, &ops)?, Operation::Query(query) => execute_query(reader, ctx, postings, depth + 1, &query)?,
Operation::Or(ops) => execute_or(reader, ctx, cache, postings, depth + 1, &ops)?, };
Operation::Query(query) => execute_query(reader, ctx, postings, depth + 1, &query)?, cache.insert(op, docids);
}; }
cache.entry(op).or_insert(docids)
}
};
ids.extend_from_slice(docids.as_ref());
} }
let docids = SetBuf::from_dirty(ids); for op in operations {
if let Some(docids) = cache.get(op) {
results.push(docids.as_ref());
}
}
let op = sdset::multi::Union::new(results);
let docids = op.into_set_buf();
println!("{:3$}--- OR fetched {} documents in {:.02?}", "", docids.len(), before.elapsed(), depth * 2); println!("{:3$}--- OR fetched {} documents in {:.02?}", "", docids.len(), before.elapsed(), depth * 2);