anchor.diff:              f ba (ba.Length - 1)
               ba
   
  -        let getStmtForIndex p =
  -            let (ndx,b) = 
  -                match p with
  -                | plan.q.Plan (ndx,b) -> (ndx,b)
  -
  +        let getStmtForIndex ndx b =
               //printfn "ndx: %A" ndx
               //printfn "bounds: %A" b
   
  
positive.code:                 if tx then conn.exec("BEGIN TRANSACTION")
  
                  match plan with
                  | Some ndxu -> getIndexScanReader tx db coll ndxu
                  | None -> getTableScanReader tx db coll
              | None ->
                  {docs=Seq.empty; funk=(fun () -> ())}
  
negative.code:             let tblIndex = getTableNameForIndex ndx.db ndx.coll ndx.ndx
              let (normspec,weights) = getNormalizedSpec ndx
  
              // note that one of the reasons we need to do DISTINCT here is because a
              // single index in a single document can produce multiple index entries,
              // because, for example, when a value is an array, we don't just index
              // the array as a value, but we also index each of its elements.
              //
              // TODO it would be nice if the DISTINCT here was happening on the rowids, not on the blobs
  
              let f_two kmin kmax op1 op2 =
                  printfn "INDEX_SCAN_BOTH: %s %s" op1 op2
                  let sql = sprintf "SELECT DISTINCT d.bson FROM \"%s\" d INNER JOIN \"%s\" i ON (d.did = i.doc_rowid) WHERE k %s ? AND k %s ?" tblColl tblIndex op1 op2
                  let stmt = conn.prepare(sql)
                  stmt.bind_blob(1, kmin)
                  stmt.bind_blob(2, kmax)
                  stmt
   
              let f_one op k = 
                  printfn "INDEX_SCAN_ONE: %s" op
                  let sql = sprintf "SELECT DISTINCT d.bson FROM \"%s\" d INNER JOIN \"%s\" i ON (d.did = i.doc_rowid) WHERE k %s ?" tblColl tblIndex op
                  let stmt = conn.prepare(sql)
                  stmt.bind_blob(1, k)
                  stmt
  
              let f_gt_lt (kmin,kmax) = f_two kmin kmax ">" "<"
              let f_gt_lte (kmin,kmax) = f_two kmin kmax ">" "<="
              let f_gte_lt (kmin,kmax) = f_two kmin kmax ">=" "<"
              let f_gte_lte (kmin,kmax) = f_two kmin kmax ">=" "<="
  
              match b with
              | plan.bounds.Text (eq,search) -> failwith "this case is handled separately"
              | plan.bounds.GT vals ->
                  vals |> getDirs normspec |> bson.encodeMultiForIndex |> f_one ">"
              | plan.bounds.GTE vals ->
                  vals |> getDirs normspec |> bson.encodeMultiForIndex |> f_one ">="
              | plan.bounds.LT vals ->
                  vals |> getDirs normspec |> bson.encodeMultiForIndex |> f_one "<"
              | plan.bounds.LTE vals ->
                  vals |> getDirs normspec |> bson.encodeMultiForIndex |> f_one "<="
              | plan.bounds.EQ vals ->
                  let kmin = vals |> getDirs normspec |> bson.encodeMultiForIndex
                  let kmax = add_one kmin
  