8000 fix(query): pass real indexes to optimizer for index hints (issue #30) by adityamukho · Pull Request #69 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/query/datalog/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use super::types::{
};
use crate::graph::FactStorage;
use crate::graph::types::{Fact, TransactOptions, TxId, Value, tx_id_now};
use crate::storage::index::Indexes;
use anyhow::{Result, anyhow};
use std::sync::{Arc, RwLock};

Expand Down Expand Up @@ -57,14 +56,17 @@ pub struct DatalogExecutor {
rules: Arc<RwLock<RuleRegistry>>,
// RwLock pre-wired for 7.7b register_aggregate API.
functions: Arc<RwLock<FunctionRegistry>>,
indexes: Arc<crate::storage::index::Indexes>,
}

impl DatalogExecutor {
pub fn new(storage: FactStorage) -> Self {
let indexes = storage.pending_indexes_snapshot();
DatalogExecutor {
storage,
rules: Arc::new(RwLock::new(RuleRegistry::new())),
functions: Arc::new(RwLock::new(FunctionRegistry::with_builtins())),
indexes: Arc::new(indexes),
}
}

Expand All @@ -76,10 +78,12 @@ impl DatalogExecutor {
rules: Arc<RwLock<RuleRegistry>>,
functions: Arc<RwLock<FunctionRegistry>>,
) -> Self {
let indexes = storage.pending_indexes_snapshot();
DatalogExecutor {
storage,
rules,
functions,
indexes: Arc::new(indexes),
}
}

Expand Down Expand Up @@ -257,8 +261,7 @@ impl DatalogExecutor {
let patterns = query.get_patterns();

// Plan patterns: assign index hints and reorder by selectivity.
// Phase 6.1: Indexes::new() is a placeholder; Phase 6.2 will pass real indexes.
let planned_patterns = optimizer::plan(patterns, &Indexes::new());
let planned_patterns = optimizer::plan(patterns, &self.indexes);

// Match all patterns in planned order and get bindings
let bindings = matcher.match_patterns(
Expand Down
8 changes: 8 additions & 0 deletions src/query/datalog/matcher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::types::{AttributeSpec, EdnValue, Pattern, PseudoAttr};
use crate::graph::FactStorage;
use crate::graph::types::{EntityId, Fact, Value};
use crate::storage::index::Indexes;
use std::collections::HashMap;
use std::sync::Arc;
use uuid::Uuid;
Expand All @@ -19,13 +20,18 @@ pub struct PatternMatcher {
storage: MatcherStorage,
/// The `:db/valid-at` value for this query context (Value::Null when not set).
pub(crate) valid_at_value: Value,
#[allow(dead_code)]
/// Indexes for index-guided lookups (Phase 6.2)
indexes: Arc<Indexes>,
}

impl PatternMatcher {
pub fn new(storage: FactStorage) -> Self {
let indexes = storage.pending_indexes_snapshot();
PatternMatcher {
storage: MatcherStorage::Owned(storage),
valid_at_value: Value::Null,
indexes: Arc::new(indexes),
}
}

Expand All @@ -37,6 +43,7 @@ impl PatternMatcher {
PatternMatcher {
storage: MatcherStorage::Slice(facts),
valid_at_value: Value::Null,
indexes: Arc::new(Indexes::new()),
}
}

Expand All @@ -46,6 +53,7 @@ impl PatternMatcher {
PatternMatcher {
storage: MatcherStorage::Slice(facts),
valid_at_value: valid_at,
indexes: Arc::new(Indexes::new()),
}
}

Expand Down
Loading
0