diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2021-02-26 12:37:04 -0600 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2021-02-26 13:24:06 -0600 |
commit | ec4b2132918338d893a800a823cf5f12d5b2efd5 (patch) | |
tree | dd60cca6bff8c820fd6dfe222dab73368b6d9b22 | |
parent | 73875b5233138dcdd965bbd36d9581ca625e3a2d (diff) | |
download | couchdb-ec4b2132918338d893a800a823cf5f12d5b2efd5.tar.gz |
Fix ebtree:lookup_multi/3
If one of the provided lookup keys doesn't exist in the ebtree, it can
inadvertently prevent a second lookup key from being found if it the
first key greater than the missing lookup key is equal to the second
lookup key.
-rw-r--r-- | src/ebtree/src/ebtree.erl | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/ebtree/src/ebtree.erl b/src/ebtree/src/ebtree.erl index bbb0ca897..8c921d1a3 100644 --- a/src/ebtree/src/ebtree.erl +++ b/src/ebtree/src/ebtree.erl @@ -173,18 +173,17 @@ lookup_multi_fold(_, {_, [], _} = Acc) -> {stop, Acc}; lookup_multi_fold({visit, Key1, Value}, {Tree, [Key2 | Rest], Acc}) -> - {NewKeys, NewAcc} = case collate(Tree, Key1, Key2) of + case collate(Tree, Key1, Key2) of lt -> % Still looking for the next user key - {[Key2 | Rest], Acc}; + {ok, {Tree, [Key2 | Rest], Acc}}; eq -> % Found a requested key - {Rest, [{Key2, Value} | Acc]}; + {ok, {Tree, Rest, [{Key2, Value} | Acc]}}; gt -> % The user key wasn't found so we drop it - {Rest, Acc} - end, - {ok, {Tree, NewKeys, NewAcc}}; + lookup_multi_fold({visit, Key1, Value}, {Tree, Rest, Acc}) + end; lookup_multi_fold({traverse, FKey, LKey, R}, {Tree, [UKey | Rest], Acc}) -> case collate(Tree, FKey, UKey, [gt]) of |