title: Recursive Datalog queries for Datomic really slow
body: <p>I'm currently evaluating Datomic for the use-case of storing and querying parsed symbols that form an ontology. In total there are 225122 symbols (entities) in the database (so it's a rather big ontology, but shouldn't be a big deal for a DB).</p>
  
  <p>The structure is pretty standard, symbols have</p>
  
  <ol>
  <li><em>parent</em> symbols that contain them (like in sub-symbol etc)</li>
  <li><em>supersymbols</em> (symbols they inherit from)</li>
  </ol>
  
  <p>To have nice access to the symbols, we have a unique <code>name</code> for each symbol. This adds up to the following Datomic schema:</p>
  
  <pre><code>[{:db/ident :ml/name,
    :db/valueType :db.type/string,
    :db/cardinality :db.cardinality/one,
    :db/unique :db.unique/identity}
   {:db/ident :ml/parent,
    :db/valueType :db.type/ref,
    :db/index true,
    :db/cardinality :db.cardinality/one}
   {:db/ident :ml/superclass,
    :db/valueType :db.type/ref,
    :db/index true,
    :db/cardinality :db.cardinality/one}]
  </code></pre>
  
  <p>Now I have the most basic recursive query "give me all symbols that are (transitively) contained in symbol <code>p</code>". In Datomic terms:</p>
  
  <pre><code>(def rules
    '[
      [(ubersymbol ?c ?p) (?c :ml/parent ?p)]
      [(ubersymbol ?c ?p) (?c :ml/parent ?c1) (ubersymbol ?c1 ?p) ]
      ])
  (q '[:find ?c ?n :in $ % :where
       (ubersymbol ?c ?d) [?d :ml/name "name of a root symbol"] [?c :ml/name ?n]]
     current-db rules)
  </code></pre>
  
  <p>The query itself (so a mid-sized symbol) takes between <strong>5</strong> and <strong>5.5</strong> seconds and returns 80 hits. <strong>Not milliseconds, but real seconds</strong>. And this is only the most basic query I want to ask about the dataset (it's intended to be used from a web-tool to help modellers understand the structure of the ontology).</p>
  
  <p>I'm running <code>datomic-pro-0.9.5554</code>, with a memory database and use the peer library (I started the server as described in the <a href="http://docs.datomic.com/first-db.html" rel="noreferrer">"getting started"</a> guide.</p>
  
  <p>Help is really appreciated to make a case for Datomic.</p>
  
  <p>markus</p>