summaryrefslogtreecommitdiff
path: root/src/mango/src/mango_cursor_view.erl
diff options
context:
space:
mode:
authorGabor Pali <gabor.pali@ibm.com>2023-05-11 03:27:29 +0200
committerNick Vatamaniuc <nickva@users.noreply.github.com>2023-05-11 12:55:24 -0400
commita854625d74a5b3847b99c6f536187723821d0aae (patch)
tree22229beeafdf5e1c650825026986ab1070061c46 /src/mango/src/mango_cursor_view.erl
parent98fc76d67230a4472c9ef8597dd80d01f7eee224 (diff)
downloadcouchdb-a854625d74a5b3847b99c6f536187723821d0aae.tar.gz
fix(mango): covering indexes for partitioned databases
The previous work that introduced the keys-only covering indexes did not count with the case that database might be partitioned. And since they use a different format for their own local indexes and the code does not handle that, it will crash. When indexes are defined globally for the partitioned databases, there is no problem because the view row does not include information about the partition, i.e. it is transparent. Add the missing support for these scenarios and extend the test suite to cover them as well. That latter required some changes to the base classes in the integration test suite as it apparently completely misses out on running test cases for partitioned databases.
Diffstat (limited to 'src/mango/src/mango_cursor_view.erl')
-rw-r--r--src/mango/src/mango_cursor_view.erl19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index e044c56fc..82b4008bb 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -435,7 +435,12 @@ match_and_extract_doc(Doc, Selector, Fields) ->
end.
-spec derive_doc_from_index(#idx{}, #view_row{}) -> term().
-derive_doc_from_index(Index, #view_row{id = DocId, key = Keys}) ->
+derive_doc_from_index(Index, #view_row{id = DocId, key = KeyData}) ->
+ Keys =
+ case KeyData of
+ {p, _Partition, KeyValues} -> KeyValues;
+ KeyValues -> KeyValues
+ end,
Columns = mango_idx:columns(Index),
lists:foldr(
fun({Column, Key}, Doc) -> mango_doc:set_field(Doc, Column, Key) end,
@@ -862,6 +867,18 @@ derive_doc_from_index_test() ->
Doc = {[{<<"_id">>, DocId}, {<<"field2">>, key2}, {<<"field1">>, key1}]},
?assertEqual(Doc, derive_doc_from_index(Index, ViewRow)).
+derive_doc_from_index_partitioned_test() ->
+ Index =
+ #idx{
+ type = <<"json">>,
+ def = {[{<<"fields">>, {[{<<"field1">>, undefined}, {<<"field2">>, undefined}]}}]}
+ },
+ DocId = doc_id,
+ Keys = [key1, key2],
+ ViewRow = #view_row{id = DocId, key = {p, partition, Keys}},
+ Doc = {[{<<"_id">>, DocId}, {<<"field2">>, key2}, {<<"field1">>, key1}]},
+ ?assertEqual(Doc, derive_doc_from_index(Index, ViewRow)).
+
composite_indexes_test() ->
?assertEqual([], composite_indexes([], [])),
Index1 =