diff --git a/src/query/datalog/executor.rs b/src/query/datalog/executor.rs index 2bdde43fd0..38cb7c11cc 100644 --- a/src/query/datalog/executor.rs +++ b/src/query/datalog/executor.rs @@ -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}; @@ -57,14 +56,17 @@ pub struct DatalogExecutor { rules: Arc>, // RwLock pre-wired for 7.7b register_aggregate API. functions: Arc>, + indexes: Arc, } 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), } } @@ -76,10 +78,12 @@ impl DatalogExecutor { rules: Arc>, functions: Arc>, ) -> Self { + let indexes = storage.pending_indexes_snapshot(); DatalogExecutor { storage, rules, functions, + indexes: Arc::new(indexes), } } @@ -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( diff --git a/src/query/datalog/matcher.rs b/src/query/datalog/matcher.rs index 4aa776d3ea..d6e61725c3 100644 --- a/src/query/datalog/matcher.rs +++ b/src/query/datalog/matcher.rs @@ -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; @@ -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, } 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), } } @@ -37,6 +43,7 @@ impl PatternMatcher { PatternMatcher { storage: MatcherStorage::Slice(facts), valid_at_value: Value::Null, + indexes: Arc::new(Indexes::new()), } } @@ -46,6 +53,7 @@ impl PatternMatcher { PatternMatcher { storage: MatcherStorage::Slice(facts), valid_at_value: valid_at, + indexes: Arc::new(Indexes::new()), } }