8000 Clarify query-engine planner and scan comments by adityamukho · Pull Request #988 · 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: 4 additions & 5 deletions src/query/engine/ids.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<super::scan::Probes>>,
}

Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/query/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::collections::BTreeMap<&'static str, u64>> =
const { std::cell::RefCell::new(std::collections::BTreeMap::new()) };
}
Expand All @@ -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())
Expand Down
9 changes: 5 additions & 4 deletions src/query/engine/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,18 @@ 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,
Candidate,
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,
Expand Down
9 changes: 5 additions & 4 deletions src/query/engine/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 7 additions & 10 deletions src/query/engine/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Arc<Values>>,
/// Per attribute id, whether any of its live committed values is a
/// keyword.
Expand Down Expand Up @@ -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<u8>, Vec<Fact>>,
/// 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<HashSet<Vec<u8>>>,
}

Expand All @@ -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.
Expand Down
Loading
0