You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2023/02/14 15:14:46 UTC

[couchdb] 05/05: mango: Match comments with implementation for JSON index selection

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 3fa8f72ac113dff073c9a764ba9189abb29ecba7
Author: Gabor Pali <ga...@ibm.com>
AuthorDate: Tue Feb 14 12:46:28 2023 +0100

    mango: Match comments with implementation for JSON index selection
---
 src/mango/src/mango_cursor_view.erl | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index c494e3d78..a784cf6b0 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -225,7 +225,7 @@ composite_prefix([Col | Rest], Ranges) ->
 % Prefix and the FieldRanges. If that is equal, then
 % 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.
+% then choose alphabetically based on (dbname, ddocid, view_name).
 % Return the first element's Index and IndexRanges.
 %
 % In the future we can look into doing a cached parallel
@@ -247,9 +247,12 @@ choose_best_index(IndexRanges) ->
                     M when M < 0 ->
                         true;
                     M when M == 0 ->
-                        % We have no other way to choose, so at this point
-                        % select the index based on (dbname, ddocid, view_name) triple
-                        IdxA =< IdxB;
+                        % Restrict the comparison to the (dbname, ddocid, view_name)
+                        % triple -- in case of their equivalence, the original order
+                        % will be maintained.
+                        #idx{dbname = DbNameA, ddoc = DDocA, name = NameA} = IdxA,
+                        #idx{dbname = DbNameB, ddoc = DDocB, name = NameB} = IdxB,
+                        {DbNameA, DDocA, NameA} =< {DbNameB, DDocB, NameB};
                     _ ->
                         false
                 end;