From 9c7f40ffadf577e402c9147dc3b8ac15074982e6 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 3 Dec 2026 05:03:37 +0530 Subject: [PATCH] Clarify query-engine planner and scan comments --- src/query/engine/ids.rs | 9 ++++----- src/query/engine/mod.rs | 7 +++---- src/query/engine/plan.rs | 9 +++++---- src/query/engine/recursive.rs | 9 +++++---- src/query/engine/scan.rs | 17 +++++++---------- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/query/engine/ids.rs b/src/query/engine/ids.rs index 5ebe89c071..00e8eaef83 100644 --- a/src/query/engine/ids.rs +++ b/src/query/engine/ids.rs @@ -37,9 +37,8 @@ pub(crate) struct IdSpace { /// What `provisional` and `dict` hold (#549 spec ยง3.2). held_provisional: Held, held_dict: Held, - /// What value probes read once for the whole query (#721), made by the - /// first query that needs it: boxed, it keeps every `Stream` within the - /// allocator's thread cache. + /// Cache shared by value probes in one query (#721). It is allocated on + /// first use; boxing keeps `Stream` small enough for the allocator's thread cache. probes: Option>, } @@ -86,12 +85,12 @@ impl IdSpace { self.probes = None; } - /// What value probes have read so far, if any. + /// Return the value-probe cache if it has been allocated. pub(crate) fn probes(&self) -> Option<&super::scan::Probes> { self.probes.as_deref() } - /// What value probes read, to add to. + /// Get or create the value-probe cache. pub(crate) fn probes_mut(&mut self) -> &mut super::scan::Probes { let meter = self.held_provisional.meter(); self.probes diff --git a/src/query/engine/mod.rs b/src/query/engine/mod.rs index 82c9f873fa..e10d1252eb 100644 --- a/src/query/engine/mod.rs +++ b/src/query/engine/mod.rs @@ -53,9 +53,8 @@ use std::sync::Arc; #[cfg(any(test, feature = "test-hooks"))] thread_local! { - /// Path events of queries this thread ran (#863): which of the paths a - /// nightly acceptance test guards each query took. Counted only in test - /// and `test-hooks` builds; `path_event` is a no-op otherwise. + /// Per-thread counts of query execution events checked by nightly tests + /// (#863). Only test and `test-hooks` builds count these events. static PATH_EVENTS: std::cell::RefCell> = const { std::cell::RefCell::new(std::collections::BTreeMap::new()) }; } @@ -69,7 +68,7 @@ pub(crate) fn path_event(name: &'static str) { let _ = name; } -/// This thread's path events since the last call, which clears them (#863). +/// Return and reset this thread's event counts (#863). #[cfg(any(test, feature = "test-hooks"))] pub(crate) fn take_path_events() -> std::collections::BTreeMap<&'static str, u64> { PATH_EVENTS.with(|m| m.take()) diff --git a/src/query/engine/plan.rs b/src/query/engine/plan.rs index 7bc8679581..c14e365193 100644 --- a/src/query/engine/plan.rs +++ b/src/query/engine/plan.rs @@ -140,8 +140,9 @@ impl ScanSpec { } } -/// The logical candidate stays on the hash path until snapshot resolution -/// certifies the complete effective grouping tuple (#641, #781). +/// A plan can propose ordered grouping. Use hash grouping unless snapshot +/// resolution confirms that equal values for the full effective grouping +/// key are adjacent (#641, #781). #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum Grouping { Hash, @@ -149,8 +150,8 @@ pub(crate) enum Grouping { Ordered, } -/// The comparator of a certified partition prefix. DICT ids prove adjacency, -/// not semantic UUID or keyword order. +/// How to compare a certified partition prefix. The DICT ID comparison +/// establishes adjacency, not sort order by UUID or keyword value. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum PartitionOrder { Values, diff --git a/src/query/engine/recursive.rs b/src/query/engine/recursive.rs index 66d6b1fb64..46c871fc74 100644 --- a/src/query/engine/recursive.rs +++ b/src/query/engine/recursive.rs @@ -211,10 +211,11 @@ fn heads( Ok((out, held)) } -/// Reconsider each round, before opening operators. A small relation can -/// avoid the initial whole-attribute read of an in-memory value probe. -/// Committed databases keep AVET probes; a value map already built is free -/// to reuse. The cap bounds both costing work and the alternative's seed. +/// Reconsider the plan before opening operators in each round. A small +/// relation can avoid the first whole-attribute read of an in-memory value +/// probe. Keep the AVET path for populated committed generations or when +/// a value map has already been built. Limit the work of estimating cost +/// and the number of rows that seed the alternative. fn choose_run<'a>( run: &'a RuleRun, rels: &Relations, diff --git a/src/query/engine/scan.rs b/src/query/engine/scan.rs index fc47150b32..964c5d8aa0 100644 --- a/src/query/engine/scan.rs +++ b/src/query/engine/scan.rs @@ -46,11 +46,9 @@ pub(crate) struct Scan { counters: Counters, } -/// What value probes read once for the whole query (#721), so that a rule -/// run in every round, or a body run per outer row, reads it once. +/// Cache value-probe data across rule rounds and outer rows (#721). pub(crate) struct Probes { - /// Per attribute, its pending facts and the committed triples they - /// decide. + /// Pending facts and the committed triples they shadow, by attribute. values: HashMap>, /// Per attribute id, whether any of its live committed values is a /// keyword. @@ -87,13 +85,13 @@ impl Probes { } } -/// An attribute's reads for value probes. +/// Data cached for value probes on one attribute. struct Values { /// Its live pending facts, by their encoded value. pending: HashMap, Vec>, /// Whether any of them has a keyword value. keywords: bool, - /// The committed triples a pending record of it decides. + /// Committed triples shadowed by pending records. shadow: Arc>>, } @@ -107,13 +105,12 @@ enum State { Done, } -/// Where the read of derived rows is. +/// Position in the derived-row scan. #[derive(Default)] struct Derived { - /// The relation read, as an index into the spec's. + /// Index of the relation in the scan specification. k: usize, - /// The next position: in the relation's rows, or in its rows of the - /// entity read. + /// Offset of the next row in the relation, or among rows for this entity. at: usize, /// The entity read (a probe's, or a constant's) and the cell of an /// exact value constant, resolved on the first pull.