You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/04/05 14:59:14 UTC

[GitHub] garrensmith commented on a change in pull request #469: Choose index based on fields match

garrensmith commented on a change in pull request #469: Choose index based on fields match
URL: https://github.com/apache/couchdb/pull/469#discussion_r109939494
 
 

 ##########
 File path: src/mango/src/mango_cursor_view.erl
 ##########
 @@ -107,10 +107,14 @@ execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
 % check FieldRanges for a, b, c, and d and return
 % the longest prefix of columns found.
 composite_indexes(Indexes, FieldRanges) ->
-    lists:foldl(fun(Idx, Acc) ->
+    FieldKeys = [Key || {Key, _} <- FieldRanges],
+    SortedIndexes = lists:foldl(fun(Idx, Acc) ->
         Cols = mango_idx:columns(Idx),
         Prefix = composite_prefix(Cols, FieldRanges),
-        [{Idx, Prefix} | Acc]
+        % create a score based on how close the number of fields
+        % the index has to the number of fields in the selector
+        Score = length(Cols) - length(FieldKeys),
 
 Review comment:
   I've made an attempt at fixing this. I'm not 100% I fully understood this. In the situation of [a, b, c] and [a, d, e] I've defaulted to the indices names. The only problem with that is there is a possibility of a doc being in one index but not in another and this could lead to unexpected results for a user. 
 
----------------------------------------------------------------
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