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

 ##########
 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 ColPrefixLength based on how close the number of fields
+        % the index has to the number of Prefixes the index can use
+        ColPrefixLength = abs(length(Cols) - length(FieldKeys)),
 
 Review comment:
   1) This should be ``` length(Prefix)``` instead of ```length(FieldKeys)```?
   
   2) Not sure abs would work here because of the following scenario:
   IdxA has columns [a,b,c]
   IdxB has columns [a,b,c,d]
   Now are selector queries on a,b,c,f,g
   ColPrefixLength for IdxA becomes 2, ColPrefLength for IdxB becomes 1, then 
that would lead to IdxB being preferred, whereas IdxA should be used.
 
----------------------------------------------------------------
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