     (fn [spec index] (index-delete index spec record))))
 
 (defn- root-plan [db [attr dir :as order]]
-  (if (and order (index-get db {:on attr}))
-    {:action  :index-scan
-     :attr    attr
-     :dir     dir
-     :ordered true}
-    {:action  :db-scan
-     :ordered false}))
+  (cond
+    (= attr :id)
+      {:action  :rmap-scan
+       :dir     dir
+       :ordered true}
+    (and order (index-get db {:on attr}))
+      {:action  :index-scan
+       :attr    attr
+       :dir     dir
+       :ordered true}
+    :no-index
+      {:action  :db-scan
+       :ordered false}))
 
 (defn- filter-plan [source where]
   (if-not where

        indexed (index aval)]
    (index-flatten1 indexed)))

(defmethod exec :index-multilookup [db {:keys [attr in]}]
  (let [index    (index-get db {:on attr})
        indexeds (map index in)]
    (index-flatten indexeds)))

(def- one-sided-op-fns
  {:< < :<= <= :> > :>= >=})

(def- two-sided-op-fns
  {:>< [> <] :>=< [>= <] :><= [> <=] :>=<= [>= <=]})

(defmethod exec :index-range [db {:keys [attr dir op aval]}]
  (let [index     (index-get db {:on attr})
        subseq-fn (if (= dir :asc) subseq rsubseq)
        pairs     (if-let [op-fn (one-sided-op-fns op)]
                    (subseq-fn index op-fn aval)
                    (let [[op-fn1 op-fn2] (two-sided-op-fns op)
                          [aval1  aval2]   aval]
                      (subseq-fn index op-fn1 aval1 op-fn2 aval2)))
        indexeds  (map val pairs)]
    (index-flatten indexeds)))

(defmethod exec :union [db {:keys [source]}]
  (union-stream (map #(exec db %) source)))

(defmethod exec :db-scan [{:keys [rmap]} plan]
  (vals rmap))

(defmethod exec :rmap-scan [{:keys [rmap]} {:keys [dir]}]
  (let [seq-fn (if (= dir :asc) seq rseq)]
    (map val (seq-fn rmap))))

(defmethod exec :index-scan [db {:keys [attr dir]}]
  (let [index    (index-get db {:on attr})
        seq-fn   (if (= dir :asc) seq rseq)
