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

 ##########
 File path: src/mango/src/mango_cursor_view.erl
 ##########
 @@ -124,25 +128,31 @@ composite_prefix([Col | Rest], Ranges) ->
             []
     end.
 
-
-% Low and behold our query planner. Or something.
-% So stupid, but we can fix this up later. First
-% pass: Sort the IndexRanges by (num_columns, idx_name)
-% and return the first element. Yes. Its going to
-% be that dumb for now.
+% Low and behold our query planner
+% First pass: sort the IndexRanges by KeysPrefixLength,
+% if that is equal, choose the index with the least number of 
+% fields in the index. If we still cannot break the tie, 
+% then choose alphabetically based on ddocId.
+% Return the first element.
 %
 % In the future we can look into doing a cached parallel
 % 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, KeysPrefixLengthA}, {IdxB, PrefixB, 
KeysPrefixLengthB}) ->
+        case KeysPrefixLengthA - KeysPrefixLengthB 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;
+                ColsLenA = length(mango_idx:columns(IdxA)),
+                ColsLenB = length(mango_idx:columns(IdxB)),
+                case ColsLenA - ColsLenB of
+                    M when M < 0 -> true;
 
 Review comment:
   What is the general formatting rule, when should it be on a new line?
   Does the true on line 144 also need to be on a new line?
 
----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to