tonysun83 commented on a change in pull request #866: Fix incorrect index 
selection when sort specified
URL: https://github.com/apache/couchdb/pull/866#discussion_r143022334
 
 

 ##########
 File path: src/mango/src/mango_idx.erl
 ##########
 @@ -70,13 +70,33 @@ get_usable_indexes(Db, Selector0, Opts) ->
         ?MANGO_ERROR({no_usable_index, no_index_matching_name})
     end,
 
-    SortIndexes = mango_idx:for_sort(FilteredIndexes, Opts),
-    if SortIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, missing_sort_index})
+    UsableFilter = fun(I) -> mango_idx:is_usable(I, Selector) end,
+    UsableIndexes0 = lists:filter(UsableFilter, FilteredIndexes),
+
+    UsableIndexes1 = case has_use_index(Opts) of
+        true ->
+            UsableFilteredIndexes = 
mango_cursor:maybe_filter_indexes_by_ddoc(UsableIndexes0, Opts),
 
 Review comment:
   maybe this can be written as:
   ```
   case mango_cursor:maybe_filter_indexes_by_ddoc(UsableIndexes0, Opts) of
       [] -> ?MANGO_ERROR({no_usable_index, no_usable_index_matching_name});
       UsableFilteredIndexes -> UsableFilteredIndexes
   end;
   ```
 
----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to