couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [1/5] couchdb-mango git commit: add prototype for mango catch-all feature
Date Wed, 27 Jan 2016 13:30:22 GMT
Repository: couchdb-mango
Updated Branches:
  refs/heads/mango-catch-all [created] 854a0b5ba


add prototype for mango catch-all feature


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

Branch: refs/heads/mango-catch-all
Commit: 4821d3f720eacd08b6de6344d422fd71d9db6743
Parents: db3116c
Author: Robert Kowalski <robertkowalski@apache.org>
Authored: Mon Jan 4 13:05:25 2016 +0100
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Mon Jan 4 13:15:42 2016 +0100

----------------------------------------------------------------------
 src/mango_cursor.erl | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/4821d3f7/src/mango_cursor.erl
----------------------------------------------------------------------
diff --git a/src/mango_cursor.erl b/src/mango_cursor.erl
index 6cb7fee..40b7208 100644
--- a/src/mango_cursor.erl
+++ b/src/mango_cursor.erl
@@ -48,11 +48,16 @@ create(Db, Selector0, Opts) ->
 
     UsableFilter = fun(I) -> mango_idx:is_usable(I, Selector) end,
     UsableIndexes = lists:filter(UsableFilter, SortIndexes),
-    if UsableIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, selector_unsupported})
-    end,
 
-    create_cursor(Db, UsableIndexes, Selector, Opts).
+    case length(UsableIndexes) of
+        0 ->
+            % fallback to _id > null for better usability
+            NewSelector = {[{<<"$and">>, [Selector, {[{<<"_id">>,
{[{<<"$gt">>, null}]}}]}]}]},
+            couch_log:notice("no matching index found, create an index to optimize query
time", []),
+            create(Db, NewSelector, Opts);
+        _ ->
+            create_cursor(Db, UsableIndexes, Selector, Opts)
+    end.
 
 
 explain(#cursor{}=Cursor) ->


Mime
View raw message