rudb_exec/register.rs
1//! The one place every seam registry in the process is assembled.
2//!
3//! Registration is an explicit call in an explicit file, not a linker trick and not a macro that
4//! collects implementations behind the reader's back. The list is a public artifact: `EXPLAIN`
5//! prints from it, `rudb_strategies()` reads it, and `rudb-bench sweep --seam` enumerates it. A
6//! list that is assembled by magic is a list nobody can check, and the first question about a
7//! benchmark number is what produced it.
8//!
9//! This file is where a researcher who has written an implementation adds their one line. The rest
10//! of their work is one file in one crate behind one seam trait.
11//!
12//! # What is registered
13//!
14//! One seam of the twenty seven. `chunk.compaction` has three implementations in `rudb-pipeline`
15//! and this is where they are put in front of the engine. The other twenty six are named in
16//! `SeamId` with the milestone that owes them written on each, which
17//! [`SeamId::milestone`](rudb_seam::SeamId) answers and `rudb_strategies()` prints, so that table
18//! reads as a list of what is planned rather than as an empty one.
19//!
20//! A seam that is registered here is also a seam a query can pin, which means the typed registry
21//! has to be reachable by the operator that chooses from it as well as by the erased list that
22//! `EXPLAIN` prints. That is why each one gets a named accessor next to the line that adds it.
23
24use std::sync::{Arc, OnceLock};
25
26use rudb_pipeline::Compaction;
27use rudb_seam::{Registries, Registry};
28
29/// Every registry in the process, assembled the first time somebody asks.
30///
31/// Built once and immutable after. A registry that could gain an entry after a query has planned
32/// against it is a registry that makes two runs of the same query incomparable, and comparing runs
33/// is the entire point of having one.
34///
35/// Public because `EXPLAIN` prints the seam section out of it and `EXPLAIN` is rendered above this
36/// crate, in `rudb`. The optimizer cannot reach it, being under this crate in the layer rule, so the
37/// caller that has both hands it over.
38pub fn registries() -> &'static Registries {
39 static REGISTRIES: OnceLock<Registries> = OnceLock::new();
40 REGISTRIES.get_or_init(assemble)
41}
42
43/// The chunk compaction seam, which is what a filter chooses from once per query.
44///
45/// The same object the erased list holds, so what `EXPLAIN` prints and what runs cannot drift.
46pub(crate) fn compaction() -> &'static Arc<Registry<dyn Compaction>> {
47 static COMPACTION: OnceLock<Arc<Registry<dyn Compaction>>> = OnceLock::new();
48 COMPACTION.get_or_init(|| Arc::new(rudb_pipeline::compaction()))
49}
50
51/// One line per crate that owns implementations of a seam.
52fn assemble() -> Registries {
53 let mut registries = Registries::new();
54 registries.add(compaction().clone());
55 registries
56}