davisp commented on a change in pull request #469: Choose index based on fields
match
URL: https://github.com/apache/couchdb/pull/469#discussion_r113814830
##########
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
Review comment:
I have to stare at the above code but I'm pretty sure this logic boils down
to "prefer the index with the fewest extra columns" which while legit is hard
to follow based on the variable names.
----------------------------------------------------------------
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