   both index nodes and partitions."
   [store node fields record-keys]
   (when node
-    (case (:data/type node)
-      :merkle-db/index
-        (mapcat
-          (fn read-child
-            [[child-link record-keys]]
-            (when (seq record-keys)
-              (let [child (graph/get-link! store node child-link)]
-                (read-batch store child fields (map first record-keys)))))
-          (assign-records node (map vector record-keys)))
-
-      :merkle-db/partition
-        (part/read-batch store node fields record-keys)
-
-      (throw (ex-info (str "Unsupported index-tree node type: "
-                           (pr-str (:data/type node)))
-                      {:data/type (:data/type node)})))))
+    (mapcat
+      (fn read-part
+        [[part record-keys]]
+        (part/read-batch store part fields record-keys))
+      (find-partitions
+        store
+        (fn search-children
+          [index record-keys]
+          (->> (map vector record-keys)
+               (assign-records index)
+               (map (fn unwrap [[cl rkv]] [cl (mapv first rkv)]))))
+        node record-keys))))
 
 
 (defn read-range

      boundaries)))


(defn read-all
  "Read a lazy sequence of key/map tuples which contain the requested field data
  for every record in the subtree. This function works on both index nodes and
  partitions."
  [store node fields]
  (when node
    (case (:data/type node)
      :merkle-db/index
        (mapcat
          (fn read-child
            [child-link]
            (let [child (graph/get-link! store node child-link)]
              (read-all store child fields)))
          (::children node))

      :merkle-db/partition
        (part/read-all store node fields)

      (throw (ex-info (str "Unsupported index-tree node type: "
                           (pr-str (:data/type node)))
                      {:data/type (:data/type node)})))))


(defn read-batch

  all records in that range direction."
  [store node fields min-k max-k]
  (when node
    (mapcat
      (fn read-part
        [[part _]]
        (part/read-range store part fields min-k max-k))
      (find-partitions
        store
        (fn search-children
          [index _]
          (map vector (children-in-range index min-k max-k)))
        node nil))))



