Right now we'll use cached values if there's only one — a mapping from a value to a single entity, or an entity to a single value. That's great for most uses (reverse lookup in particular), but it means a query can drop from using the cache to not doing so simply by adding a new datom.
We use the cache by direct substitution. To use the cache more would require one of several things:
For 'output' patterns — either in pull expressions (#110) or in queries like [:find ?x ?v :where [?x :foo/bar 123] [?x :foo/multiple ?v]] — do the outermost join against the cache, not in the database.
For inner patterns, either generate a more complicated query (particularly if there are only a handful of values — WHERE datoms00.x IN (65536, 65537)) or expose the cache to SQLite via a function.
For inner patterns, generalize the concept of a binding to a set of potential bindings, just as we do for type analysis. With enough cached attributes, we'll have joins complete before runtime. This gets dangerously close to mixing algebrizing and query execution (and execution like Datomic does: its in-memory index chunks are essentially caches), and so should wait for #373.
The big question with each of these is whether it's quicker to do extra work to avoid having our very fast SQL query system do the work. My guess is no, but we'll see.
Right now we'll use cached values if there's only one — a mapping from a value to a single entity, or an entity to a single value. That's great for most uses (reverse lookup in particular), but it means a query can drop from using the cache to not doing so simply by adding a new datom.
We use the cache by direct substitution. To use the cache more would require one of several things:
[:find ?x ?v :where [?x :foo/bar 123] [?x :foo/multiple ?v]]
— do the outermost join against the cache, not in the database.WHERE datoms00.x IN (65536, 65537)
) or expose the cache to SQLite via a function.The big question with each of these is whether it's quicker to do extra work to avoid having our very fast SQL query system do the work. My guess is no, but we'll see.