diff --git a/CHANGELOG.md b/CHANGELOG.md index c6d5f5450e..fcb823deaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,7 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Single-pattern queries run on a new streaming engine** (#473, part 2: #544, first PR). A query whose `:where` is one pattern and whose `:find` holds plain variables now runs on operators that read index keys in batches of 1,024 rows and turn ids into values only for the rows they return (#530, for these queries). A pattern with a constant attribute and value, `[?e :a C]`, reads the AVET range of `C` instead of every fact of the attribute (#518). Measured at 1M facts (#394 envelope, `[?e :name "…"]`): 344 ms → 20 µs and 142 → 3 MiB; an attribute scan of 166,666 rows 577 → 268 ms and 172 → 57 MiB; point and `:as-of` queries 10–30 % faster. Every other query, and reads inside a `WriteTransaction`, run on the existing executor as before. Results are unchanged: in tests, every query the engine runs is also run by the executor and the answers must agree, and CI runs the whole suite that way (`test-oracle` feature). - **Expressions and pseudo-attributes run on the streaming engine** (#473, part 2: #544, second PR). The engine now also runs expression clauses after its pattern (`[(> ?v 21)]`, `[(+ ?v 1) ?w]`, registered predicates), per-fact pseudo-attribute patterns on the pattern's entity (`:db/valid-from`, `:db/valid-to`, `:db/tx-count`, `:db/tx-id`), and keyword, UUID and float constants in the value position. A constant reads only the AVET ranges it can match: a keyword reads its own range and the range of refs to the entity it names, a UUID reads its ref range and the attribute's keywords, a float reads the attribute's floats. The executor's matching rules are kept (a keyword matches a ref to the entity it names, a UUID matches a keyword that names it, floats match within `f64::EPSILON`), and so are its errors (INT-026, QRY-007). `:db/valid-at`, which the executor matches against every fact of the entity, stays on the executor until joins (#545). - **Cursors stream the queries the engine runs** (#473, part 2: #544, third PR). `Minigraf::query`, `PreparedQuery::query` and `BrowserDb.query` no longer compute the whole answer at open for these queries: the cursor pulls one batch of up to 1,024 rows from the engine's operators when it runs out of rows, and `close` or dropping it stops the work. An attribute scan drained with `next_batch(1000)` holds 7 MiB at 1M and 10M facts (was 58 and 458 MiB) and runs 3–17 % faster (#394 envelope). The answer is still the database as it was when the cursor opened, whatever is written or checkpointed while it is open. A read error that happens after some rows of a `next_batch` call were gathered is returned by the next call, after those rows. No API change. -- **Joins run on the streaming engine** (#473, part 3: #545, second PR). Queries of several patterns with stored attributes, with or without expression clauses, now run on the engine. Patterns run in the planner's order: the first is a scan, and each later one is an `IndexNestedLoopJoin` when its entity is a variable already bound (one entity range per row, committed and pending), or a `HashJoin` otherwise (value and attribute positions, cross products), built on the side with the smaller estimate. Joins follow the executor's rules (#545, first PR): floats are equal by IEEE `==`, a keyword equals a ref to the entity it names, and a variable keeps the value of its first pattern in the `:where` text. Measured at 1M facts (#394 envelope, p50 and peak RSS): `[:p :follows ?f] [?f :name ?n]` 796 ms → 50 µs and 322 → 4 MiB; `[:p :manager ?b] [?s :manager ?b] [?s :name ?n]` 1.67 s → 148 ms and 392–462 → 14 MiB; `[?e :follows ?f] [?f :group 7] [?f :name ?n]` 2.6 s → 1.1 s and 468–480 → 42 MiB. Pseudo-attribute patterns in a query of several patterns, `:db/valid-at`, `or`, `not`, rules and aggregates still run on the executor. Results are unchanged (`test-oracle`). +- **Joins run on the streaming engine** (#473, part 3: #545, second PR). Queries of several patterns with stored attributes, with or without expression clauses, now run on the engine. Patterns run in the planner's order: the first is a scan, and each later one is an `IndexNestedLoopJoin` when its entity is a variable already bound (one entity range per row, committed and pending), or a `HashJoin` otherwise (value and attribute positions, cross products), built on the side with the smaller estimate. Joins follow the executor's rules (#545, first PR): floats are equal by IEEE `==`, a keyword equals a ref to the entity it names, and a variable keeps the value of its first pattern in the `:where` text. Measured at 1M facts (#394 envelope, p50 and peak RSS): `[:p :follows ?f] [?f :name ?n]` 796 ms → 50 µs and 322 → 4 MiB; `[:p :manager ?b] [?s :manager ?b] [?s :name ?n]` 1.67 s → 148 ms and 392–462 → 14 MiB; `[?e :follows ?f] [?f :group 7] [?f :name ?n]` 2.6 s → 1.1 s and 468–480 → 42 MiB. `or`, `not`, rules and aggregates still run on the executor. Results are unchanged (`test-oracle`). +- **Pseudo-attributes across joins and `:db/valid-at` run on the streaming engine** (#473, part 3: #545, third PR). A per-fact pseudo-attribute pattern (`:db/valid-from`, `:db/valid-to`, `:db/tx-count`, `:db/tx-id`) reads, as the executor does, the fact of the last pattern before it in the planner's order that matched its entity: the scans of those patterns fill metadata columns and the pattern picks one per row. The engine runs it when its entity term is the entity term of an earlier pattern, or when no pattern with a stored attribute runs before it; then, and for every `:db/valid-at` pattern, it joins with every visible fact of its entity, as `[e _ _]` would, with the metadata or the query's valid time as a column. Other shapes (a pseudo-attribute pattern on an entity that no earlier pattern has as its entity, a `_` entity) stay on the executor; that the answer depends on the plan order is tracked in #594. Measured at 10M facts (#394 envelope, p50 and peak RSS): `[:p :follows ?f] [?f :name ?n] [?f :db/tx-count ?t]` 34 s → 56 µs and 6.0–7.5 GiB → 4 MiB (3.2 s → 56 µs at 1M). Results are unchanged (`test-oracle`). - **Committed reads hide superseded history on index keys** (#379). A query's committed facts are now reduced to the ones that survive net-assert (each fact's assertion from its newest transaction, unless that transaction retracted it; #435) while walking the index keys, before any fact is built. Only surviving entries are decoded and translated through the dictionary. A transaction that retracted a triple hides everything older in it, and a long run of hidden entries is skipped with one `seek`. `:as-of N` point and attribute queries now take the same index path instead of reading every fact in the file. On a checkpointed file with 2,000 superseded values, a point query takes 1.03 ms instead of 4.61 ms, an attribute scan 1.24 ms instead of 5.87 ms, and an `:as-of` point query 23 µs instead of 5.6 ms (at depth 1). Results are unchanged: the executor still applies net-assert to committed and pending facts together, and a pending fact is always newer than a committed one. - **B+tree reads no longer follow leaf sibling links** (v8 storage format, PR 1 of 5; #374). Every index scan uses a cursor that walks down from the root and keeps the path, with a forward `seek` that climbs only as far as needed. This prepares for copy-on-write index pages, which cannot keep sibling links. The file format and query results are unchanged. Concurrent 100k-fact scans take 25–37 % less time and checkpointing after one fact at 10k facts 9 % less; single point lookups and attribute scans are 2–6 % slower (about 0.4 µs per lookup). A corrupted child pointer now fails with STG-013 (wrong page type) or INT-049 (cycle) instead of following a bad link. diff --git a/CLAUDE.md b/CLAUDE.md index 97c1e556dc..a608f0e99d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -139,7 +139,7 @@ cargo run < demos/demo_negation.txt - `prepared.rs`: `BindValue`, `PreparedQuery` — parse-once/execute-many with named `$slot` bind slots; `prepare_query`, `substitute` - `magic_sets.rs`: Magic-sets rewriting for demand-driven recursive rule evaluation (not applied to rules with `not`/`not-join`) -3a. **`src/query/engine/`** — Streaming query engine (#473), beside the executor until #551: `plan.rs` (which queries it runs: patterns with stored attributes and expression clauses in `optimizer::plan` order, or one pattern with per-fact pseudo-attribute patterns on its entity; plain `:find` variables, today), `scan.rs` (one pattern over committed key ranges via `CommittedReader::key_source`/`live_keys`, AVET ranges for cross-kind constants, then the pending range by whole runs; one entity per probe for a join), `join.rs` (`IndexNestedLoopJoin` when the pattern's entity is bound, `HashJoin` otherwise; `JoinKey`: floats by IEEE `==`, a keyword equals a ref to the entity it names), `filter.rs` (`Filter`/`Bind` and pseudo-attribute columns over batches), `cell.rs`/`batch.rs` (id cells in columnar batches of 1,024), `ids.rs` (DICT and provisional ids, `keyword_eid`), `project.rs` (ids → values for returned rows only), `oracle.rs` (with `cfg(test)` or the `test-oracle` feature, every engine query also runs on the executor and must agree). `mod.rs`: `Operator` (`next_batch`/`close`/`counters`), `Stream` (the operator tree over an owned `Snapshot`, pulled one batch at a time). `DatalogExecutor::open` / `execute_query` try it first: a cursor gets the `Stream` (`Answer::Stream`), `execute` drains it. +3a. **`src/query/engine/`** — Streaming query engine (#473), beside the executor until #551: `plan.rs` (which queries it runs: patterns and expression clauses in `optimizer::plan` order; a pseudo-attribute pattern reads the metadata column of the last earlier pattern that matched its entity, chosen per row, or joins as `[e _ _]` when none runs before it, as `:db/valid-at` always does; plain `:find` variables, today), `scan.rs` (one pattern over committed key ranges via `CommittedReader::key_source`/`live_keys`, AVET ranges for cross-kind constants, then the pending range by whole runs; one entity per probe for a join), `join.rs` (`IndexNestedLoopJoin` when the pattern's entity is bound, `HashJoin` otherwise; `JoinKey`: floats by IEEE `==`, a keyword equals a ref to the entity it names), `filter.rs` (`Filter`/`Bind` and pseudo-attribute steps over batches), `cell.rs`/`batch.rs` (id cells in columnar batches of 1,024), `ids.rs` (DICT and provisional ids, `keyword_eid`), `project.rs` (ids → values for returned rows only), `oracle.rs` (with `cfg(test)` or the `test-oracle` feature, every engine query also runs on the executor and must agree). `mod.rs`: `Operator` (`next_batch`/`close`/`counters`), `Stream` (the operator tree over an owned `Snapshot`, pulled one batch at a time). `DatalogExecutor::open` / `execute_query` try it first: a cursor gets the `Stream` (`Answer::Stream`), `execute` drains it. 4. **`src/temporal.rs`** — UTC-only timestamp parsing (avoids chrono CVE GHSA-wcg3-cvx6-7396) diff --git a/ROADMAP.md b/ROADMAP.md index ebaee99292..48a54058b4 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -93,7 +93,7 @@ Scope — format and storage integrity: Scope — query API: -- Cursor API: `Minigraf::query` and `PreparedQuery::query` return an owned `Cursor` that delivers rows in batches, with the answer fixed at open (#432; Rust API done on `v3`). The binding cursor objects follow. Behind the cursor, the streaming engine (#473) produces rows as they are pulled for the queries it runs (one pattern with expressions and pseudo-attributes, #544; joins of patterns and expressions, #545); pseudo-attributes across joins, negation, aggregates, rules and transaction reads move to it in #545–#551, without API changes. Operators do not spill: memory follows operator state, with an opt-in per-query limit (`QRY-012`, #549). +- Cursor API: `Minigraf::query` and `PreparedQuery::query` return an owned `Cursor` that delivers rows in batches, with the answer fixed at open (#432; Rust API done on `v3`). The binding cursor objects follow. Behind the cursor, the streaming engine (#473) produces rows as they are pulled for the queries it runs (one pattern with expressions and pseudo-attributes, #544; joins of patterns, expressions and pseudo-attributes, `:db/valid-at`, #545); negation, aggregates, rules and transaction reads move to it in #546–#551, without API changes. Operators do not spill: memory follows operator state, with an opt-in per-query limit (`QRY-012`, #549). - Fact-log iterator: `Minigraf::fact_log(&FactFilter)` streams every fact version (assertions and retractions, with `tx_count`, `tx_id` and valid-time bounds) in transaction order or storage order, filtered by attribute, attribute prefix, entity and tx range, with memory bounded by a window rather than the database (#430; Rust API done on `v3`). An open log pins its generation: checkpoints run but do not reuse its pages (#543; `API-013` deprecated). A raw log writer (#431) completes the extract-transform-load path; the binding objects follow with #462. - Read-only open: `OpenOptions::read_only` takes a shared lock, so several readers can hold a file at once, writes nothing to the file or its WAL (a WAL is applied in memory, a v7 file is read without migrating), and refuses writes with `API-014` (#429; Rust API done on `v3`). The bindings' `open_with_options` follows. - Raw log writer: `LogWriter` builds a new database from `FactRecord`s with their `tx_count`, `tx_id`, valid-time windows and assertion flags kept, gaps allowed (a purged transaction stays a hole for `:as-of`), at `.partial` renamed into place by `finish` (#431; Rust API done on `v3`). Completes extract (#429, #430), transform, load. The binding objects follow. diff --git a/docs/BENCHMARKS.md b/docs/BENCHMARKS.md index ec64008590..c0bfc117e5 100644 --- a/docs/BENCHMARKS.md +++ b/docs/BENCHMARKS.md @@ -114,7 +114,21 @@ Queries of several patterns run on the engine since #545 PR 2: an `IndexNestedLo | `join_3_scan` peak RSS | 48–67 → 14 MiB | 468–480 → 42 MiB | | point, `:as-of`, `:valid-at`, hot entity, attribute scan | unchanged | unchanged | -`join_2` probes one entity's range for its one outer row. `join_3_selective` joins on the value position, so it is a `HashJoin` that reads every `:manager` fact into its table: a value probe would need AVET over pending facts, which the pending store does not have (decision 3 of the #545 plan). `join_3_scan` scans the AVET range of `:group 7`, joins `:follows` on its value with a `HashJoin` built on those rows (it streams every `:follows` fact), then probes `:name` per row. 10M runs with #545's last PR. +`join_2` probes one entity's range for its one outer row. `join_3_selective` joins on the value position, so it is a `HashJoin` that reads every `:manager` fact into its table: a value probe would need AVET over pending facts, which the pending store does not have (decision 3 of the #545 plan). `join_3_scan` scans the AVET range of `:group 7`, joins `:follows` on its value with a `HashJoin` built on those rows (it streams every `:follows` fact), then probes `:name` per row. + +At 10M facts with PR 3 (same server, two rounds; the PR 2 code is unchanged for these shapes, and both builds agree within 2%): `join_2` 51 µs and 4 MiB; `join_3_selective` 2.48–2.52 s and 66 MiB, its `HashJoin` table holding the 10M-fact graph's 1.67M `:manager` facts; `join_3_scan` 13.6 s and 59–63 MiB. The 10M figures in the first table above, before #545 and on the laptop, are 6.50 s, 13.5 s and 20.9 s with 2.3–3.6 GiB of RSS. + +#### Pseudo-attributes across joins (#545 PR 3) + +`join_2_pseudo` is `[:p{m} :follows ?f] [?f :name ?n] [?f :db/tx-count ?t]` with `:valid-at :any-valid-time` (1 row). Before PR 3 a pseudo-attribute pattern in a query of several patterns sent the whole query to the executor, which materialises every fact. A/B on the same idle server, `v3` (86ad20b, with the envelope shape added) on one socket and PR 3 on the other, swapped for the second round; p50 of each round, peak RSS. + +| `join_2_pseudo` | 100K | 1M | 10M | +|---|---:|---:|---:| +| p50, `v3` → PR 3 | 211 ms → 40–58 µs | 3.19 s → 55–56 µs | 33.8–34.1 s → 56 µs | +| peak RSS | 122 → 4 MiB | 857–858 → 4 MiB | 6.0–7.5 GiB → 4 MiB | +| every other shape | unchanged | unchanged | unchanged | + +The pseudo-attribute pattern reads the `:db/tx-count` column that the `:name` probe fills for its one row. ### Python FFI round trip diff --git a/docs/TEST_COVERAGE.md b/docs/TEST_COVERAGE.md index d0ffd18624..243e766406 100644 --- a/docs/TEST_COVERAGE.md +++ b/docs/TEST_COVERAGE.md @@ -14,7 +14,7 @@ This covers the unreleased file-format-v8 work (#287, #371): the index-key value - **Multi-value and index-key correctness** (`tests/multi_value_test.rs`, 10 tests): same-transaction multi-valued facts surviving query-time dedup, retracting several values of one attribute in one call, valid-time stints (facts differing only in valid time), maximum-value-size boundaries, and format v8 index keys (value bytes + assert/retract flag) (#287, #371). - **Storage correctness**: packed pages, B+tree indexes and range scans, cache behavior, file-header validation, migration (including v7→v8 index rebuild and v1–v6 rejection via `STG-028`), WAL replay, checksums, corruption handling, and fault injection. - **Reliability and concurrency**: concurrent reads and writes, rollback behavior, same-process handle exclusion, cross-process locking, PID namespaces, NFS and container lock behavior, SIGKILL recovery, and queries seeing each concurrent transaction whole and reading one state for all their patterns, including while a checkpoint runs (`tests/snapshot_atomicity_test.rs`, #554, #555, #558). Generation pins (#543): a pinned generation's pages are never written by later saves or index rebuilds and are reused once the pin is dropped (by page id, `storage::persistent_facts`, `storage::pins`, `storage::page`); fact logs stay correct while checkpoints, rebuilds and concurrent writers run, and see whole transactions only (`tests/fact_log_test.rs`). Query and prepared-query cursors keep their answer and their pages across writes, checkpoints and index rebuilds, and the file stops growing once they close (`tests/cursor_test.rs`); a snapshot leaves out facts appended after it on every scan (`graph::storage`); a crash at every write point of a save with a pinned generation loses no fact and no page, and the reopened database reuses the quarantined ids (`storage::persistent_facts`); the browser withholds free pages a pinned generation may read and releases them once out of force (`storage::pins::split_released`, and a `#[wasm_bindgen_test]` with an open `BrowserDb` cursor). -- **Streaming query engine** (#473, #544): every query the engine runs is also run by the existing executor under `cfg(test)` and the `test-oracle` feature, and the answers must agree (`query::engine::oracle`); CI runs the whole suite with the feature, so the model-based, property, golden-corpus and integration suites check the engine. `query::engine::tests` reaches every index choice, net-assert of pending records over committed ones, `:as-of`, valid time, long strings and reads of several batches, in memory, across checkpoints and after reopen, expression filters and bindings (including rebinding and failing expressions), pseudo-attribute columns, keyword/UUID/float constants against keywords, refs and UUID-named keywords, and checks which queries stay on the executor and that INT-026 and QRY-007 come first. Resumed `live_keys` reads equal one live read over random histories (`storage::persistent_facts`). Lazy cursors (`cursor::tests`, #544 PR 3): one pull reads one internal batch of the scan (operator counters), rows left in a batch need no pull, a closed stream reads nothing more, a filter's counters chain, and a cursor's answer is unchanged by writes and by checkpoints that free the leaves it has yet to read (file-backed) or by later writes (in memory); a read error after some rows are gathered comes on the next call, then the cursor ends (`query::engine::tests`). DICT lookups are cached for one pull only, and provisional ids keep their values across pulls (`query::engine::ids`). Joins (#545 PR 2): the oracle matrix adds two- and three-pattern joins on the entity (`IndexNestedLoopJoin`), value and attribute positions (`HashJoin`), cross products, keywords and refs of one entity in both text orders, UUID-named keywords, attributes that name entities, floats `0.0`/`-0.0`, long strings committed and pending, and expressions between joins, at every temporal; joins whose answers span many batches (one probe with more than a batch of matches, cross products, tables built on either side); the planner's join choice; a keyword's entity id (`query::engine::ids`). +- **Streaming query engine** (#473, #544): every query the engine runs is also run by the existing executor under `cfg(test)` and the `test-oracle` feature, and the answers must agree (`query::engine::oracle`); CI runs the whole suite with the feature, so the model-based, property, golden-corpus and integration suites check the engine. `query::engine::tests` reaches every index choice, net-assert of pending records over committed ones, `:as-of`, valid time, long strings and reads of several batches, in memory, across checkpoints and after reopen, expression filters and bindings (including rebinding and failing expressions), pseudo-attribute columns, keyword/UUID/float constants against keywords, refs and UUID-named keywords, and checks which queries stay on the executor and that INT-026 and QRY-007 come first. Resumed `live_keys` reads equal one live read over random histories (`storage::persistent_facts`). Lazy cursors (`cursor::tests`, #544 PR 3): one pull reads one internal batch of the scan (operator counters), rows left in a batch need no pull, a closed stream reads nothing more, a filter's counters chain, and a cursor's answer is unchanged by writes and by checkpoints that free the leaves it has yet to read (file-backed) or by later writes (in memory); a read error after some rows are gathered comes on the next call, then the cursor ends (`query::engine::tests`). DICT lookups are cached for one pull only, and provisional ids keep their values across pulls (`query::engine::ids`). Joins (#545 PR 2): the oracle matrix adds two- and three-pattern joins on the entity (`IndexNestedLoopJoin`), value and attribute positions (`HashJoin`), cross products, keywords and refs of one entity in both text orders, UUID-named keywords, attributes that name entities, floats `0.0`/`-0.0`, long strings committed and pending, and expressions between joins, at every temporal; joins whose answers span many batches (one probe with more than a batch of matches, cross products, tables built on either side); the planner's join choice; a keyword's entity id (`query::engine::ids`). Pseudo-attributes across joins (#545 PR 3): the metadata of the last pattern before them that matched their entity, chosen per row (a pattern on another entity variable that equals theirs on some rows only, constant entities), pseudo-attribute patterns planned before any pattern with a stored attribute (joined with every fact of their entity, including cross products), and `:db/valid-at` at every temporal with variables, `nil` and integer constants; which pseudo-attribute shapes stay on the executor. - **Join rules** (`tests/join_rules_test.rs`, 10 tests; #545): a join on a float value pairs `0.0` with `-0.0`, through the hash key and as a shared variable, and a float constant still matches within epsilon; a variable bound to a keyword by one pattern and to the ref of the same entity by another returns the kind from the first pattern in `:where` text order, when the planner runs the patterns in another order, through the attribute position, before and after a rule call, and with a repeated pattern; an expression binding is kept by a later join, and a pseudo-attribute pattern never replaces a value (native plan order only: under `wasm` the pattern runs first and binds the variable). Under the `test-oracle` feature the joins among them also run on the streaming engine. A unit test checks that `-0.0` and `0.0` hash alike. - **Public diagnostics**: structured parser, query, storage, WAL, API, and internal error codes; the error-code registry is checked against [`ERROR_REFERENCE.md`](ERROR_REFERENCE.md). - **Compatibility and quality**: golden-file corpus of released file formats, cross-platform format compatibility, property-based tests, long-haul smoke coverage, a weekly soak at 10M facts with a 5-hour churn (#392), XTDB/Datomic semantic compatibility, grammar conformance, and rustdoc examples. diff --git a/examples/perf_envelope.rs b/examples/perf_envelope.rs index f95600b8f3..71c9c56081 100644 --- a/examples/perf_envelope.rs +++ b/examples/perf_envelope.rs @@ -488,6 +488,14 @@ fn shapes(e: usize, tx_half: u64, hot_tx_half: u64) -> Vec { // Not checked: depends on how :follows maps onto group 7. rows: usize::MAX, }, + Shape { + name: "join_2_pseudo", + query: format!( + "[:find ?n ?t :valid-at :any-valid-time \ + :where [:p{m} :follows ?f] [?f :name ?n] [?f :db/tx-count ?t]]" + ), + rows: 1, + }, Shape { name: "recursive_ancestors", query: format!("[:find ?b :where (boss :p{leaf} ?b)]"), diff --git a/src/query/engine/filter.rs b/src/query/engine/filter.rs index ff8b62005b..0bc3f4320a 100644 --- a/src/query/engine/filter.rs +++ b/src/query/engine/filter.rs @@ -5,8 +5,8 @@ //! the row; a binding expression's result becomes a cell again. use super::batch::Batch; -use super::cell::{Cell, Scalar}; -use super::plan::{Step, Term, Vars}; +use super::cell::{Cell, join_eq}; +use super::plan::{Entity, Step, Term, Vars}; use super::project::value; use super::{Counters, Ctx, Operator}; use crate::query::datalog::executor::{eval_expr, is_truthy}; @@ -63,13 +63,17 @@ impl Operator for Apply { /// Apply `step` to `batch`. fn apply(step: &Step, mut batch: Batch, ctx: &mut Ctx<'_>) -> Result { match step { - Step::Pseudo { col, value } => { - let meta = batch.cols.get(*col).cloned().unwrap_or_default(); + Step::Pseudo { + cols, + entity, + value, + } => { + let meta = pick(cols, entity.as_ref(), &batch, ctx)?; match value { Term::Any => {} Term::Bind(slot) => batch.set_col(*slot, meta), Term::Const(n) => { - let want = n.map(|n| Cell::Val(Scalar::Int(n))); + let want = n.clone().map(Cell::Val); let keep: Vec = meta.iter().map(|c| want.as_ref() == Some(c)).collect(); batch.retain(&keep); } @@ -112,6 +116,57 @@ fn apply(step: &Step, mut batch: Batch, ctx: &mut Ctx<'_>) -> Result { Ok(batch) } +/// The metadata a pseudo-attribute pattern reads in each row of `batch`: +/// from the first of `cols` with no entity, or whose entity is join-equal to +/// `entity` (decision 4 of the #545 plan). +fn pick( + cols: &[(Option, usize)], + entity: Option<&Entity>, + batch: &Batch, + ctx: &mut Ctx<'_>, +) -> Result> { + if let [(None, col)] = cols { + return Ok(batch.cols.get(*col).cloned().unwrap_or_default()); + } + let mut out = Vec::with_capacity(batch.len); + for i in 0..batch.len { + let want = match entity { + Some(e) => entity_cell(e, batch, i, ctx)?, + None => None, + }; + for (e, col) in cols { + let matched = match (e, &want) { + (None, _) => true, + (Some(e), Some(w)) => match entity_cell(e, batch, i, ctx)? { + Some(c) => join_eq(&c, w, true, ctx)?, + None => false, + }, + (Some(_), None) => false, + }; + if matched { + if let Some(c) = batch.cols.get(*col).and_then(|c| c.get(i)) { + out.push(c.clone()); + } + break; + } + } + } + Ok(out) +} + +/// The cell of `entity` in row `i`. +fn entity_cell( + entity: &Entity, + batch: &Batch, + i: usize, + ctx: &mut Ctx<'_>, +) -> Result> { + Ok(match entity { + Entity::Slot(s) => batch.cols.get(*s).and_then(|c| c.get(i)).cloned(), + Entity::Const(u) => Some(Cell::Eid(ctx.ids.eid(ctx.keys, u)?)), + }) +} + /// `expr` over row `i`, or `None` where the executor's evaluation fails. fn eval( expr: &Expr, diff --git a/src/query/engine/plan.rs b/src/query/engine/plan.rs index 4fce570511..8e8b8b554e 100644 --- a/src/query/engine/plan.rs +++ b/src/query/engine/plan.rs @@ -1,11 +1,9 @@ //! Planner v2 (#473 spec §6.3): which queries the engine runs, and their //! operator trees. //! -//! The engine runs a query whose `:where` holds patterns with a stored -//! attribute and expression clauses, and whose `:find` holds plain -//! variables (#545); or one such pattern, pseudo-attribute patterns on its -//! entity and expression clauses (#544). Every other query runs on the -//! existing executor (spec §9). +//! The engine runs a query whose `:where` holds patterns and expression +//! clauses, and whose `:find` holds plain variables (#545). Every other query +//! runs on the existing executor (spec §9). //! //! Clauses run in the order `optimizer::plan` gives the executor, so an //! expression sees the same variables, and a binding expression overwrites a @@ -13,7 +11,17 @@ //! `Scan`; each later one a join: an `IndexNestedLoopJoin` when its entity is //! a variable already bound, a `HashJoin` otherwise (decision 3 of the #545 //! plan). - +//! +//! A per-fact pseudo-attribute pattern reads, as the executor does, the fact +//! of the last pattern with a stored attribute before it that matched the +//! same entity (decision 4 of the #545 plan): one of the metadata columns +//! those patterns' scans fill, chosen per row. The engine runs it when the +//! pattern's entity term is the entity term of such a pattern, so that one +//! always exists, or when no such pattern runs before it. A pseudo-attribute +//! pattern of the second kind, and every `:db/valid-at` pattern, joins with +//! every visible fact of its entity, as `[e _ _]` does. + +use super::cell::Scalar; use crate::graph::types::{EntityId, Value}; use crate::query::datalog::executor::Binders; use crate::query::datalog::matcher::edn_to_entity_id; @@ -79,13 +87,22 @@ pub(crate) enum Valid { Any, } -/// A per-fact pseudo-attribute: fact metadata as an integer column. +/// A pseudo-attribute: fact metadata as an integer column, or the query's +/// valid time (`nil` under `:any-valid-time`) for `:db/valid-at`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum Meta { ValidFrom, ValidTo, TxCount, TxId, + ValidAt, +} + +/// The entity a pattern matched, in a row: a slot, or a constant. +#[derive(Debug, Clone)] +pub(crate) enum Entity { + Slot(usize), + Const(EntityId), } /// What a `Scan` reads. @@ -105,12 +122,14 @@ pub(crate) struct ScanSpec { /// A clause after the scan, in the executor's order. #[derive(Debug, Clone)] pub(crate) enum Step { - /// A pseudo-attribute pattern on the scanned fact: its value term over - /// the metadata column `col`. A constant other than an integer never - /// matches. + /// A pseudo-attribute pattern: its value term over a metadata column. + /// The row's column is the first of `cols` with no entity, or whose + /// entity is join-equal to `entity`. A constant other than an integer or + /// `nil` never matches. Pseudo { - col: usize, - value: Term>, + cols: Vec<(Option, usize)>, + entity: Option, + value: Term>, }, /// `[(pred …)]`: keeps the rows where the expression is truthy. Filter(Expr, Vars), @@ -218,106 +237,104 @@ pub(crate) fn plan(query: &DatalogQuery) -> Option { { return None; } - // Pseudo-attribute patterns read the fact of the one real pattern; across - // joins they wait for #545's last part. - let real = query - .where_clauses - .iter() - .filter(|c| matches!(c, WhereClause::Pattern(p) if matches!(p.attribute, AttributeSpec::Real(_)))) - .count(); - let pseudo = query.where_clauses.iter().any( - |c| matches!(c, WhereClause::Pattern(p) if matches!(p.attribute, AttributeSpec::Pseudo(_))), - ); - if real > 1 && pseudo { - return None; - } let mut binders = Binders::new(&query.where_clauses, Vec::new()); let (planned, _) = optimizer::plan(query.where_clauses.clone()); - let mut planned = planned.into_iter().map(|(c, _)| c); - let Some(WhereClause::Pattern(p)) = planned.next() else { - return None; - }; - let AttributeSpec::Real(attribute) = &p.attribute else { - return None; - }; - binders.pattern(&p); - let rest: Vec = planned.collect(); + let all: Vec = planned.into_iter().map(|(c, _)| c).collect(); + let (forms, needs) = pseudo_forms(&all)?; let mut slots = Slots::default(); - let e = term(&p.entity, &mut slots, OTHER, entity_const)?; - let a = term(attribute, &mut slots, ATTRIBUTE, attribute_const)?; - let v = term(&p.value, &mut slots, OTHER, value_const)?; - - // A pseudo-attribute pattern reads the metadata of the fact the scan - // matched only when its entity is the scan's entity term; any other - // pseudo-attribute pattern joins over every fact (#545). - let mut meta: Vec<(Meta, usize)> = Vec::new(); - for c in &rest { - let WhereClause::Pattern(q) = c else { - continue; - }; - let AttributeSpec::Pseudo(pa) = &q.attribute else { - continue; - }; - let m = meta_of(pa)?; - if !same_entity(&p.entity, &q.entity) { - return None; - } - if !meta.iter().any(|(mm, _)| *mm == m) { - meta.push((m, slots.add(OTHER))); - } - } - // An expression that rebinds the entity variable would send a later - // pseudo-attribute pattern to another entity. - if !meta.is_empty() - && rest.iter().any(|c| { - matches!(c, WhereClause::Expr { binding: Some(out), .. } - if matches!(&p.entity, EdnValue::Symbol(s) if s == out)) - }) - { - return None; - } - let scan = ScanSpec { - e, - a, - v, - meta: meta.clone(), - as_of, - valid, - width: slots.len(), - }; - - let mut outer_patterns = vec![WhereClause::Pattern(p.clone())]; - let mut steps = Vec::with_capacity(rest.len()); - for c in rest { - steps.push(match c { - WhereClause::Pattern(q) => match &q.attribute { - AttributeSpec::Pseudo(pa) => { - binders.pattern(&q); - let m = meta_of(pa)?; - let col = meta.iter().find(|(mm, _)| *mm == m)?.1; - let value = term(&q.value, &mut slots, OTHER, |c| { - Some(match c { - EdnValue::Integer(n) => Some(*n), - _ => None, + // Each clause placed so far. + let mut done: Vec = Vec::with_capacity(all.len()); + let mut outer_patterns: Vec = Vec::new(); + let mut scan = None; + let mut steps = Vec::with_capacity(all.len()); + for (i, c) in all.into_iter().enumerate() { + let need = needs.get(i).map_or(&[][..], Vec::as_slice); + let mut metas: Vec<(Meta, usize)> = Vec::new(); + let mut entity = None; + match c { + WhereClause::Pattern(q) => { + let rebind = binders.pattern(&q); + let form = forms.get(&i); + if let Some(PseudoForm::Fast { cols }) = form { + let cols = cols + .iter() + .map(|&(j, compare)| { + let (metas, entity) = done.get(j)?; + let col = metas.iter().find(|(m, _)| Some(*m) == meta(&q))?.1; + let entity = if compare { Some(entity.clone()?) } else { None }; + Some((entity, col)) }) - })?; - Step::Pseudo { col, value } + .collect::>>()?; + let entity = entity_of(&q.entity, &slots); + let value = term(&q.value, &mut slots, OTHER, pseudo_const)?; + steps.push(Step::Pseudo { + cols, + entity, + value, + }); + done.push((metas, None)); + continue; + } + // A pattern with a stored attribute, or a pseudo-attribute + // pattern read as `[e _ _]` and its metadata. + let any = EdnValue::Symbol("_".to_string()); + let (attribute, scanned) = match &q.attribute { + AttributeSpec::Real(a) => (a.clone(), q.clone()), + AttributeSpec::Pseudo(_) => ( + any.clone(), + Pattern::new(q.entity.clone(), any.clone(), any.clone()), + ), + }; + let mut wants: Vec = need.to_vec(); + if let Some(m) = form.and(meta(&q)) { + wants.push(m); } - AttributeSpec::Real(attribute) => { - let rebind = binders.pattern(&q); - let mut join = join(&q, attribute, &mut slots, &rebind, as_of, valid)?; + if scan.is_none() { + let e = term(&scanned.entity, &mut slots, OTHER, entity_const)?; + let a = term(&attribute, &mut slots, ATTRIBUTE, attribute_const)?; + let v = term(&scanned.value, &mut slots, OTHER, value_const)?; + metas = wants.iter().map(|&m| (m, slots.add(OTHER))).collect(); + scan = Some(ScanSpec { + e, + a, + v, + meta: metas.clone(), + as_of, + valid, + width: slots.len(), + }); + } else { + let mut join = join(&scanned, &attribute, &mut slots, &rebind, as_of, valid)?; + for &m in &wants { + let local = join.inner.width; + join.inner.width += 1; + join.inner.meta.push((m, local)); + join.new.push(local); + metas.push((m, slots.add(OTHER))); + } if let JoinKind::Hash { build_inner } = &mut join.kind { *build_inner = optimizer::branch_cost(&[WhereClause::Pattern(q.clone())]) <= optimizer::branch_cost(&outer_patterns); } - outer_patterns.push(WhereClause::Pattern(q)); - Step::Join(join) + steps.push(Step::Join(join)); + } + entity = entity_of(&q.entity, &slots); + outer_patterns.push(WhereClause::Pattern(q.clone())); + if form.is_some() { + let col = metas.last()?.1; + let value = term(&q.value, &mut slots, OTHER, pseudo_const)?; + steps.push(Step::Pseudo { + cols: vec![(None, col)], + entity: None, + value, + }); } - }, + } WhereClause::Expr { expr, binding } => { + // A clause before the first pattern sees no variable. let vars = expr_vars(&expr, &slots); - match binding { + let step = match binding { None => Step::Filter(expr, vars), Some(out) => { binders.expression(&out); @@ -336,11 +353,15 @@ pub(crate) fn plan(query: &DatalogQuery) -> Option { }; Step::Bind(expr, vars, slot) } - } + }; + scan.as_ref()?; + steps.push(step); } _ => return None, - }); + } + done.push((metas, entity)); } + let scan = scan?; let mut find = Vec::with_capacity(query.find.len()); for spec in &query.find { @@ -471,28 +492,133 @@ fn value_const(c: &EdnValue) -> Option { }) } -/// The metadata column of a per-fact pseudo-attribute; `None` for -/// `:db/valid-at`, which the executor matches against every fact of the -/// entity (a join, #545). -fn meta_of(pa: &PseudoAttr) -> Option { - match pa { - PseudoAttr::ValidFrom => Some(Meta::ValidFrom), - PseudoAttr::ValidTo => Some(Meta::ValidTo), - PseudoAttr::TxCount => Some(Meta::TxCount), - PseudoAttr::TxId => Some(Meta::TxId), - PseudoAttr::ValidAt => None, +/// The pseudo-attribute of `p`, or `None` for a stored attribute. +fn meta(p: &Pattern) -> Option { + let AttributeSpec::Pseudo(pa) = &p.attribute else { + return None; + }; + Some(match pa { + PseudoAttr::ValidFrom => Meta::ValidFrom, + PseudoAttr::ValidTo => Meta::ValidTo, + PseudoAttr::TxCount => Meta::TxCount, + PseudoAttr::TxId => Meta::TxId, + PseudoAttr::ValidAt => Meta::ValidAt, + }) +} + +/// A clause the planner has placed: the metadata slots its scan fills, and +/// its entity. +type Ran = (Vec<(Meta, usize)>, Option); + +/// The form of each pseudo-attribute pattern, by clause index. +type Forms = HashMap; + +/// How a pseudo-attribute pattern runs. +enum PseudoForm { + /// It reads the metadata of an earlier pattern: of the first of `cols` + /// (clause indexes, last first) that matched its entity, where the flag + /// says whether the entity must be compared. The last one is the latest + /// pattern with the same entity term, which always did. + Fast { cols: Vec<(usize, bool)> }, + /// It joins with every visible fact of its entity. + Join, +} + +/// The form of each pseudo-attribute pattern of `all` (clauses in plan +/// order), by index, and the metadata each pattern's scan must fill; `None` +/// when one of them reads a pattern chosen by the row in a way the engine +/// does not reproduce, so the executor runs the query. +fn pseudo_forms(all: &[WhereClause]) -> Option<(Forms, Vec>)> { + let pattern = |c: &WhereClause| match c { + WhereClause::Pattern(p) => Some(p.clone()), + _ => None, + }; + let patterns: Vec> = all.iter().map(pattern).collect(); + let mut forms = HashMap::new(); + let mut needs = vec![Vec::new(); all.len()]; + for (i, q) in patterns.iter().enumerate() { + let Some(m) = q.as_ref().and_then(meta) else { + continue; + }; + let Some(q) = q else { continue }; + // Earlier patterns with a stored attribute: the executor's per-entity + // metadata of the fact each matched, the latest kept. + let reals: Vec<(usize, &Pattern)> = patterns + .iter() + .take(i) + .enumerate() + .filter_map(|(j, p)| p.as_ref().map(|p| (j, p))) + .filter(|(_, p)| matches!(p.attribute, AttributeSpec::Real(_))) + .collect(); + if m == Meta::ValidAt || reals.is_empty() { + forms.insert(i, PseudoForm::Join); + continue; + } + let last = reals + .iter() + .rposition(|(_, p)| same_entity(&p.entity, &q.entity))?; + let mut cols = Vec::new(); + for &(j, p) in reals.iter().skip(last + 1).rev() { + match (&p.entity, &q.entity) { + (EdnValue::Symbol(s), _) if s == "_" || s.starts_with("?_") => return None, + (EdnValue::Symbol(_), _) | (_, EdnValue::Symbol(_)) => cols.push((j, true)), + // Two constants naming different entities. + _ => {} + } + } + cols.push((reals.get(last)?.0, false)); + for &(j, _) in &cols { + if let Some(n) = needs.get_mut(j) + && !n.contains(&m) + { + n.push(m); + } + } + forms.insert(i, PseudoForm::Fast { cols }); + } + // An expression that rebinds an entity variable would send a later + // pseudo-attribute pattern to the metadata of another entity. + if !forms.is_empty() + && all.iter().any(|c| { + matches!(c, WhereClause::Expr { binding: Some(out), .. } + if patterns.iter().flatten().any( + |p| matches!(&p.entity, EdnValue::Symbol(s) if s == out))) + }) + { + return None; + } + Some((forms, needs)) +} + +/// The entity `edn` gives a row: a bound variable's slot, or a constant. +fn entity_of(edn: &EdnValue, slots: &Slots) -> Option { + match edn { + EdnValue::Symbol(s) => slots.by_var.get(s).map(|&s| Entity::Slot(s)), + EdnValue::Keyword(_) | EdnValue::Uuid(_) => edn_to_entity_id(edn).ok().map(Entity::Const), + _ => None, } } -/// Whether a pseudo-attribute pattern's entity `pseudo` resolves to the -/// entity of the fact the scan pattern's entity `scan` matched. -fn same_entity(scan: &EdnValue, pseudo: &EdnValue) -> bool { - match (scan, pseudo) { +/// A constant in a pseudo-attribute pattern's value position: an integer, or +/// `nil` (the valid time under `:any-valid-time`); anything else never +/// matches. +fn pseudo_const(c: &EdnValue) -> Option> { + Some(match c { + EdnValue::Integer(n) => Some(Scalar::Int(*n)), + EdnValue::Nil => Some(Scalar::Null), + _ => None, + }) +} + +/// Whether two entity terms name the same entity in every row: one +/// variable, or constants naming one entity. +fn same_entity(a: &EdnValue, b: &EdnValue) -> bool { + match (a, b) { (EdnValue::Symbol(s), EdnValue::Symbol(t)) => { s.starts_with('?') && !s.starts_with("?_") && s == t } (EdnValue::Keyword(_) | EdnValue::Uuid(_), EdnValue::Keyword(_) | EdnValue::Uuid(_)) => { - edn_to_entity_id(scan).ok() == edn_to_entity_id(pseudo).ok() + edn_to_entity_id(a).ok() == edn_to_entity_id(b).ok() } _ => false, } diff --git a/src/query/engine/scan.rs b/src/query/engine/scan.rs index e7ae266c8d..bf55ce8ba6 100644 --- a/src/query/engine/scan.rs +++ b/src/query/engine/scan.rs @@ -169,10 +169,11 @@ impl Operator for Scan { { for &(m, slot) in &self.spec.meta { let n = match m { - Meta::ValidFrom => kf.vf, - Meta::ValidTo => kf.vt, - Meta::TxCount => kf.tx_count.cast_signed(), - Meta::TxId => keys.tx_id_of(kf.tx_count)?.cast_signed(), + Meta::ValidFrom => Some(kf.vf), + Meta::ValidTo => Some(kf.vt), + Meta::TxCount => Some(kf.tx_count.cast_signed()), + Meta::TxId => Some(keys.tx_id_of(kf.tx_count)?.cast_signed()), + Meta::ValidAt => valid, }; set(&mut row, slot, n); } @@ -210,10 +211,11 @@ impl Operator for Scan { })? { for &(m, slot) in &self.spec.meta { let n = match m { - Meta::ValidFrom => f.valid_from, - Meta::ValidTo => f.valid_to, - Meta::TxCount => f.tx_count.cast_signed(), - Meta::TxId => f.tx_id.cast_signed(), + Meta::ValidFrom => Some(f.valid_from), + Meta::ValidTo => Some(f.valid_to), + Meta::TxCount => Some(f.tx_count.cast_signed()), + Meta::TxId => Some(f.tx_id.cast_signed()), + Meta::ValidAt => valid, }; set(&mut row, slot, n); } @@ -245,9 +247,11 @@ impl Operator for Scan { } } -fn set(row: &mut [Option], slot: usize, n: i64) { +/// Fill a metadata slot: an integer, or `nil` for the valid time under +/// `:any-valid-time`. +fn set(row: &mut [Option], slot: usize, n: Option) { if let Some(s) = row.get_mut(slot) { - *s = Some(Cell::Val(Scalar::Int(n))); + *s = Some(Cell::Val(n.map_or(Scalar::Null, Scalar::Int))); } } diff --git a/src/query/engine/tests.rs b/src/query/engine/tests.rs index 82b4ea0673..542242a6ff 100644 --- a/src/query/engine/tests.rs +++ b/src/query/engine/tests.rs @@ -194,6 +194,40 @@ fn queries(tx: u64) -> Vec { "[?e :person/age ?v] [?e :db/tx-count _] [?e :db/tx-count ?t]", ), ]; + // Pseudo-attributes across joins (#545): the metadata of the last + // pattern before them, in plan order, that matched their entity, chosen + // per row; pseudo-attribute patterns with no such pattern before them + // join with every fact of their entity. + let pseudo_joins = [ + "[?e :person/name ?n] [?e :person/age ?a] [?e :db/tx-count ?t]", + "[?e :person/age ?a] [?e :db/tx-count ?t] [?e :person/name ?n] [?e :db/valid-from ?f]", + "[?e :person/friend ?f] [?f :person/name ?n] [?f :db/tx-count ?t]", + "[?e :person/friend ?f] [?f :person/name ?n] [?e :db/valid-from ?t]", + "[?e :person/self ?x] [?x :person/age ?a] [?e :db/tx-count ?t]", + "[?e :person/friend ?x] [?x :person/self ?y] [?x :db/valid-to ?t]", + "[:p1 :person/age ?a] [?e :person/friend :p1] [:p1 :db/tx-count ?t]", + "[?e :person/self ?x] [:p1 :person/age ?a] [:p1 :db/tx-count ?t]", + "[?e :person/self ?x] [:p1 :person/age ?a] [?e :db/tx-count ?t]", + "[?e :person/friend :p1] [:p1 :person/age ?a] [?e :db/tx-count ?t]", + "[?e :db/tx-count ?t] [?e :person/age ?a]", + "[?e :db/tx-count 1] [?e :person/name ?n]", + "[?e :db/tx-count 2] [?f :db/tx-count 2] [?e :person/self ?f]", + "[?e :db/valid-from ?f] [?e :db/valid-to ?u]", + "[:p1 :db/tx-count ?t]", + "[?e :person/age ?a] [?f :person/age ?a] [?f :db/tx-count ?t] [?e :db/tx-count ?t]", + "[?e :person/age ?a] [(+ ?a 1) ?b] [?e :db/tx-id ?t] [(> ?t 0)]", + ]; + // `:db/valid-at`: the query's valid time, once per visible fact of the + // entity. + let valid_at = [ + "[?e :person/name ?n] [?e :db/valid-at ?t]", + "[?e :db/valid-at ?t]", + "[:p1 :db/valid-at ?t] [:p1 :person/age ?a]", + "[?e :person/friend ?f] [?f :db/valid-at ?t]", + "[?e :person/name ?n] [?e :db/valid-at nil]", + "[?e :person/name ?n] [?e :db/valid-at 5]", + "[?e :person/age ?a] [?e :db/valid-at ?a]", + ]; let pseudo_temporals = [ ":valid-at :any-valid-time".to_string(), format!(":as-of {} :valid-at :any-valid-time", tx / 2), @@ -220,6 +254,22 @@ fn queries(tx: u64) -> Vec { )); } } + for clauses in pseudo_joins { + let find = vars_of(clauses); + for temporal in &pseudo_temporals { + out.push(format!( + "(query [:find {find} {temporal} :where {clauses}])" + )); + } + } + for clauses in valid_at { + let find = vars_of(clauses); + for temporal in temporals(tx) { + out.push(format!( + "(query [:find {find} {temporal} :where {clauses}])" + )); + } + } out } @@ -363,9 +413,10 @@ fn engine_reads_many_batches() { assert_eq!(rows(&db, "(query [:find ?e :where [?e :big/n 2999]])"), 1); } -/// The executor still runs what the engine does not: aggregates, `:as-of` a timestamp, `:db/valid-at`, pseudo-attributes of -/// another entity, a pseudo-attribute pattern planned first, an expression -/// rebinding the entity before a pseudo-attribute pattern. +/// The executor still runs what the engine does not: aggregates, `:as-of` a +/// timestamp, a pseudo-attribute pattern whose metadata comes from a pattern +/// chosen per row in a way the engine does not reproduce (another entity's +/// pattern before it, a `_` entity), an expression rebinding an entity. #[test] fn other_queries_stay_on_the_executor() { let db = Minigraf::in_memory().unwrap(); @@ -373,18 +424,16 @@ fn other_queries_stay_on_the_executor() { for q in [ "(query [:find (count ?e) :where [?e :person/name ?n]])", "(query [:find ?e :as-of \"2099-01-01T00:00:00Z\" :where [?e :person/name ?n]])", - "(query [:find ?e ?t :where [?e :person/name ?n] [?e :db/valid-at ?t]])", "(query [:find ?e ?t :valid-at :any-valid-time \ :where [?e :person/friend ?f] [?f :db/tx-count ?t]])", - "(query [:find ?e ?t :valid-at :any-valid-time \ - :where [?e :db/tx-count 1] [?e :person/name ?t]])", "(query [:find ?e ?t :valid-at :any-valid-time \ :where [_ :person/name ?e] [_ :db/tx-count ?t]])", "(query [:find ?n ?t :valid-at :any-valid-time \ :where [?e :person/name ?n] [(+ 1 2) ?e] [?e :db/tx-count ?t]])", - // Pseudo-attributes across joins wait for #545's last part. "(query [:find ?e ?t :valid-at :any-valid-time \ - :where [?e :person/name ?n] [?e :person/age ?a] [?e :db/tx-count ?t]])", + :where [?e :person/name \"n1\"] [_ :person/age ?a] [?e :db/tx-count ?t]])", + "(query [:find ?e ?t :valid-at :any-valid-time \ + :where [?e :person/age ?a] [(+ ?a 1) ?b] [?b :db/tx-count ?t]])", ] { let before = runs(); db.execute(q).unwrap();