        (not (in? vars symbol))))
 
 
-;; (defn -q-clause [where vars data]
-;;   (let [bound   (filter #(bound? % vars) where)
-;;         unbound (filter #(unbound? % vars) where)
-;;         bound-vals (into {} (for [var bound]
-;;                               [var (build-var var data)]))]
-;;     ...
-
-;; (defn -q [ins->sources where vars data])
-  
-
-;; (defn q [query & sources]
-;;   (-q (zipmap (:in query '[$]) sources)
-;;       (:where query)
-;;       [] []))
-
-;; (defn aconj [arr x]
-;;   (datascript.btset/insert arr (alength arr) #js [x]))
-
-
-
-;; (defn get-avet [db a v]
-;;   (->> (slice (.-avet db) (Datom. nil a v nil nil))
-;;        (mapv #(vector (.-e %)))))
-
-;; (defn get-aevt [db a es]
-;;   (let [lookup-hash (hash-attr #(nth % 0) es)
-;;         lookup-map  (:hash-table lookup-hash)
-;; ;;                     {:min (aget (first es) 0)
-;; ;;                      :max (aget (nth es (dec (count es))) 0)}
-;;         datoms      (slice (.-aevt db)
-;;                       (Datom. (:min lookup-hash) a nil nil nil)
-;;                       (Datom. (:max lookup-hash) a nil nil nil))]
-;;     (->>
-;; ;;       (loop [_res (transient [])
-;; ;;              _ds  datoms
-;; ;;              _es  es]
-;; ;;         (let [_fd (first _ds)
-;; ;;               _fe (first _es)]
-;; ;;           (if (and _fd _fe)
-;; ;;             (condp == (cmp-val (.-e _fd) (aget _fe 0))
-;; ;;               0  (recur (conj! _res #js [(aget _fe 0) (.-v _fd)]) (next _ds) (next _es))
-;; ;;               -1 (recur _res (next _ds) _es)
-;; ;;               1  (recur _res _ds (next _es))
-;; ;;               )
-;; ;;             _res)))
-
-;;       (reduce (fn [acc d]
-;;                 (if-let [datas (get lookup-map (.-e d))]
-;;                   (reduce (fn [acc data]
-;;                             (conj! acc (conj data (.-v d))))
-;;                     acc datas)
-;;                   acc))
-;;         (transient []) datoms)
-;;       (persistent!))))
-
-;; (defn search [db]
-;;   (->> (get-avet db :name "Ivan")
-;;        (get-aevt db :age)))
-

  (let [context (-q {'$ db}
                    '[[$ ?e :name "Ivan"]
                      [$ ?e :age ?a]])
        res (-collect [#js[]] (:rels context) '[?e ?a])]
;;    (.timeEnd js/console "search")  
    res))


;;        _             (.timeEnd js/console "new-tuples")
        ]
;;    (.timeEnd js/console "hash-join")
    (Relation. (into {}
                     (map vector (concat keep-attrs1 keep-attrs2) (range)))
               new-tuples)))


#_(hash-join (Relation. '{?e 0 ?a 1 ?v 2}
                      [#js [1 :name "Ivan"]
                       #js [2 :name "Igor"]
                       #js [3 :name "Petr"]])
           (Relation. '{?e 0 ?a2 1 ?v2 2}
                      [#js [1 :age 15]
                       #js [3 :age 25]]))

