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

 ##########
 File path: src/mango/src/mango_cursor_view.erl
 ##########
 @@ -135,14 +139,16 @@ composite_prefix([Col | Rest], Ranges) ->
 % reduce view read on each index with the ranges to find
 % the one that has the fewest number of rows or something.
 choose_best_index(_DbName, IndexRanges) ->
-    Cmp = fun({A1, A2}, {B1, B2}) ->
-        case length(A2) - length(B2) of
+    Cmp = fun({IdxA, PrefixA, ScoreA}, {IdxB, PrefixB, ScoreB}) ->
+        case length(PrefixA) - length(PrefixB) of
             N when N < 0 -> true;
             N when N == 0 ->
                 % This is a really bad sort and will end
                 % up preferring indices based on the
                 % (dbname, ddocid, view_name) triple
-                A1 =< B1;
+                %IdxA =< IdxB;
+                %prefer using the index with the lower score
+                ScoreA =< ScoreB;
 
 Review comment:
   Score is a bit opaque. I'd just call it length and say that we prefer using 
the index with the least number of fields. Also I wouldn't bother calculating 
it in composite indices just to use it here and then have to ignore the return 
value. You've got all the info here so I'd just calclulate it on the fly.
 
----------------------------------------------------------------
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