Open quoll opened 3 years ago
(def d1 [[:a :p 1] [:b :p 2]]) ;; transaction 1
(def d2 [[:c :p 3] [:d :p 4]]) ;; transaction 2
(transact c {:tx-triples d1})
(transact c {:tx-triples d2})
Querying for transaction IDs:
=> (q '[:find ?e ?v ?t :where [?e :p ?v ?t]] (as-of (db c) 1))
([:a 1 1] [:b 2 1])
=> (q '[:find ?e ?v ?t :where [?e :p ?v ?t]] (as-of (db c) 2))
([:a 1 1] [:b 2 1] [:c 3 2] [:d 4 2])
Performed by looking up the queries as [?e :p ?v]
, then:
:t
valueQuerying using transaction IDs. Predicate is set to :p
:
=> (q '[:find ?e ?v :where [?e :p ?v 1]] (db c))
([:a 1] [:b 2])
=> (q '[:find ?e ?v :where [?e :p ?v 2]] (db c))
([:c 3] [:d 4])
=> (q '[:find ?e ?v :where [?e :p ?v 2]] (as-of (db c) 1))
()
Performed by looking up the queries as [?e :p ?v]
, then:
:t
valueQuerying using transaction IDs.
=> (q '[:find ?e ?p ?v :where [?e ?p ?v 1]] (db c))
([:a :p 1] [:b :p 2])
=> (q '[:find ?e ?p ?v :where [?e ?p ?v 2]] (db c))
([:c :p 3] [:d :p 4])
=> (q '[:find ?e ?v :where [?e :p ?v 2]] (as-of (db c) 1))
()
Performed by:
lower-bound
, upper-bound
.
Result is: (map (fn [id] (subvec (get-record tspo id) 1)) (range lower-bound upper-bound))
Datomic expects to bind a 4th element to a transaction "t" value. e.g.
[:entity :attr ?value ?t]
To do this, the basic graph patterns will need to result in a t-value lookup in the indexes. These are currently stored in the durable system in another index (and will require a join), and not stored at all in the in-memory index (ticket #198).
The current graph API has
resolve-triple
with 4 arguments (graph, subject, predicate, object).We should consider new arities here, though a simple extension to a 5th argument will cause problems with considering bindings of statement IDs. The new arity may need to accept 6 arguments.
[?e ?a ?v]
[?e ?a ?v _ _]
[?e ?a ?v ?t]
[?e ?a ?v _ ?t]
[?e ?a ?v :as ?stmt]
[?e ?a ?v ?stmt _]
[?e ?a ?v ?t :as ?stmt]
[?e ?a ?v ?stmt ?t]
There are 3 cases to consider:
t
value is variable: Lookup the value and return in bindings.t
is set, along with other values: Thet
value is then used as a filter (directly on statements for in-memory, and via the tSPO index for durable).t
is set, and everything else is variable: Filter for in-memory, but use the tSPO index for durable storage.Depends on
t
values from #198