couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonysu...@apache.org
Subject couchdb-mango git commit: Handle unsatisfiable [empty] ranges
Date Tue, 24 Feb 2015 06:31:18 GMT
Repository: couchdb-mango
Updated Branches:
  refs/heads/tonysun83-start-end-key-issue [created] 3611aadb2


Handle unsatisfiable [empty] ranges

Queries sometimes contain unsatisfiable ranges (i.e x < 0 and x > 0).
This is indicated by the [empty] value. In this case, we should not
perform a search and simply return 0 documents.

Fixes COUCHDB-2614


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/3611aadb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/3611aadb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/3611aadb

Branch: refs/heads/tonysun83-start-end-key-issue
Commit: 3611aadb25c425a7dc51270498d9a90e1415d90f
Parents: 931d227
Author: Tony Sun <tony.sun@cloudant.com>
Authored: Mon Feb 23 22:23:45 2015 -0800
Committer: Tony Sun <tony.sun@cloudant.com>
Committed: Mon Feb 23 22:23:45 2015 -0800

----------------------------------------------------------------------
 src/mango_cursor_view.erl | 55 +++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/3611aadb/src/mango_cursor_view.erl
----------------------------------------------------------------------
diff --git a/src/mango_cursor_view.erl b/src/mango_cursor_view.erl
index ddf1e1a..cb35968 100644
--- a/src/mango_cursor_view.erl
+++ b/src/mango_cursor_view.erl
@@ -54,10 +54,15 @@ explain(Cursor) ->
         index = Idx,
         ranges = Ranges
     } = Cursor,
-    [{range, {[
-        {start_key, mango_idx:start_key(Idx, Ranges)},
-        {end_key, mango_idx:end_key(Idx, Ranges)}
-    ]}}].
+    case Ranges of
+        [empty] ->
+            [{range, empty}];
+        _ ->
+            [{range, {[
+            {start_key, mango_idx:start_key(Idx, Ranges)},
+            {end_key, mango_idx:end_key(Idx, Ranges)}
+        ]}}]
+    end.
 
 
 execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
@@ -65,25 +70,31 @@ execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
         user_fun = UserFun,
         user_acc = UserAcc
     },
-    BaseArgs = #mrargs{
-        view_type = map,
-        reduce = false,
-        start_key = mango_idx:start_key(Idx, Cursor#cursor.ranges),
-        end_key = mango_idx:end_key(Idx, Cursor#cursor.ranges),
-        include_docs = true
-    },
-    Args = apply_opts(Cursor#cursor.opts, BaseArgs),
-    CB = fun ?MODULE:handle_message/2,
-    {ok, LastCursor} = case mango_idx:def(Idx) of
-        all_docs ->
-            fabric:all_docs(Db, CB, Cursor, Args);
+    case Cursor#cursor.ranges of
+        [empty] ->
+            % empty indicates unsatisfiable ranges, so don't perform search
+            {ok, UserAcc};
         _ ->
-            % Normal view
-            DDoc = ddocid(Idx),
-            Name = mango_idx:name(Idx),
-            fabric:query_view(Db, DDoc, Name, CB, Cursor, Args)
-    end,
-    {ok, LastCursor#cursor.user_acc}.
+            BaseArgs = #mrargs{
+                view_type = map,
+                reduce = false,
+                start_key = mango_idx:start_key(Idx, Cursor#cursor.ranges),
+                end_key = mango_idx:end_key(Idx, Cursor#cursor.ranges),
+                include_docs = true
+            },
+            Args = apply_opts(Cursor#cursor.opts, BaseArgs),
+            CB = fun ?MODULE:handle_message/2,
+            {ok, LastCursor} = case mango_idx:def(Idx) of
+                all_docs ->
+                    fabric:all_docs(Db, CB, Cursor, Args);
+                _ ->
+                    % Normal view
+                    DDoc = ddocid(Idx),
+                    Name = mango_idx:name(Idx),
+                    fabric:query_view(Db, DDoc, Name, CB, Cursor, Args)
+            end,
+            {ok, LastCursor#cursor.user_acc}
+    end.
 
 
 % Any of these indexes may be a composite index. For each


Mime
View raw message