anchor.diff:          F0(C, KV, Reds, Acc)
       end,
       do_pipe(Rest, F1).
  +
  +set_namespace_range(Options, undefined) -> Options;
  +set_namespace_range(Options, NS) ->
  +    %% FIXME depending on order we might need to swap keys
  +    SK = select_gt(
  +           proplists:get_value(start_key, Options, <<"">>),
  +           <<NS/binary, "/">>),
  +    EK = select_lt(
  +           proplists:get_value(end_key, Options, <<NS/binary, "0">>),
  +           <<NS/binary, "0">>),
  +    [{start_key, SK}, {end_key_gt, EK}].
  +
  +select_gt(V1, V2) when V1 < V2 -> V2;
  +select_gt(V1, _V2) -> V1.
  +
  +select_lt(V1, V2) when V1 > V2 -> V2;
  +select_lt(V1, _V2) -> V1.
  
positive.code: skip_deleted(Case, A, B, C) ->
      {Case, A, B, C}.
  
  pipe(Filters, Final) ->
      Wrap =
          fun
  
negative.code:     FoldFun = pipe([fun skip_deleted/4], InFun),
      {ok, _LastReduce, OutAcc} = couch_btree:fold(
          Db#db.local_tree, FoldFun, InAcc, Options),
      {ok, 0, OutAcc};
  enum_docs(Db, NS, InFun, InAcc, Options0) ->
      FoldFun = pipe([
          fun skip_deleted/4,
          stop_on_leaving_namespace(NS)], InFun),
      Options = set_namespace_range(Options0, NS),
      {ok, LastReduce, OutAcc} = couch_btree:fold(
          Db#db.id_tree, FoldFun, InAcc, Options),
      {ok, enum_docs_reduce_to_count(LastReduce), OutAcc}.
  
  extract_namespace(Options0) ->
      case proplists:split(Options0, [namespace]) of
  