You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/05/23 14:01:51 UTC

[GitHub] willholley closed pull request #1336: Mango: implicit coverage for _id and _rev during index selection

willholley closed pull request #1336: Mango: implicit coverage for _id and _rev during index selection
URL: https://github.com/apache/couchdb/pull/1336
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/mango/src/mango_idx_view.erl b/src/mango/src/mango_idx_view.erl
index c9fe4c85dc..8956b27b05 100644
--- a/src/mango/src/mango_idx_view.erl
+++ b/src/mango/src/mango_idx_view.erl
@@ -124,7 +124,13 @@ is_usable(Idx, Selector, SortFields) ->
     % we don't need to check the selector for these
     RequiredFields1 = ordsets:subtract(lists:usort(RequiredFields), lists:usort(SortFields)),
 
-    mango_selector:has_required_fields(Selector, RequiredFields1)
+    % _id and _rev are implicitly in every document so
+    % we don't need to check the selector for these either
+    RequiredFields2 = ordsets:subtract(
+        RequiredFields1,
+        [<<"_id">>, <<"_rev">>]),
+
+    mango_selector:has_required_fields(Selector, RequiredFields2)
         andalso not is_text_search(Selector).
 
 
diff --git a/src/mango/test/12-use-correct-index-test.py b/src/mango/test/12-use-correct-index-test.py
index 5a2b24d3fd..7bb90ebf95 100644
--- a/src/mango/test/12-use-correct-index-test.py
+++ b/src/mango/test/12-use-correct-index-test.py
@@ -114,3 +114,16 @@ def test_can_query_with_range_on_secondary_column(self):
         explain = self.db.find(selector, explain=True)
         self.assertEqual(explain["index"]["ddoc"], "_design/bbb")
         self.assertEqual(explain["mrargs"]["end_key"], [10, '<MAX>'])
+
+    # all documents contain an _id and _rev field they
+    # should not be used to restrict indexes based on the
+    # fields required by the selector
+    def test_choose_index_with_id(self):
+        self.db.create_index(["name", "_id"], ddoc="aaa")
+        explain = self.db.find({"name": "Eddie"}, explain=True)
+        self.assertEqual(explain["index"]["ddoc"], '_design/aaa')
+
+    def test_choose_index_with_rev(self):
+        self.db.create_index(["name", "_rev"], ddoc="aaa")
+        explain = self.db.find({"name": "Eddie"}, explain=True)
+        self.assertEqual(explain["index"]["ddoc"], '_design/aaa')


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services