tonysun83 commented on a change in pull request #962: Mango: generate a warning
instead of an error when an user-specified index cannot be used
URL: https://github.com/apache/couchdb/pull/962#discussion_r153708120
##########
File path: src/mango/src/mango_cursor.erl
##########
@@ -150,12 +151,54 @@ group_indexes_by_type(Indexes) ->
end, ?CURSOR_MODULES).
-maybe_add_warning(UserFun, #idx{type = IndexType}, UserAcc) ->
- case IndexType of
+maybe_add_warning(UserFun, #cursor{index = Index, opts = Opts}, UserAcc) ->
+ UseIndexInvalid = case lists:keyfind(use_index, 1, Opts) of
+ {use_index, []} ->
+ [];
+ {use_index, [DesignId]} ->
+ case filter_indexes([Index], DesignId) of
+ [] ->
+ [fmt("_design/~s was not used because it does not contain
a valid index for this query.",
+ [ddoc_name(DesignId)])];
+ _ ->
+ []
+ end;
+ {use_index, [DesignId, ViewName]} ->
+ case filter_indexes([Index], DesignId, ViewName) of
+ [] ->
+ [fmt("_design/~s, ~s was not used because it is not a
valid index for this query.",
+ [ddoc_name(DesignId), ViewName])];
+ _ ->
+ []
+ end
+ end,
+
+ NoIndex = case Index#idx.type of
<<"special">> ->
- Arg = {add_key, warning, <<"no matching index found, create an
index to optimize query time">>},
- {_Go, UserAcc0} = UserFun(Arg, UserAcc),
- UserAcc0;
+ [<<"no matching index found, create an index to optimize query
time">>];
_ ->
- UserAcc
- end.
\ No newline at end of file
+ []
+ end,
+
+ maybe_add_warning_int(UseIndexInvalid ++ NoIndex, UserFun, UserAcc).
Review comment:
Do we really need to append two messages and then take the head of that list
later? I feel like it's either going to be a
1) "we used a diff index" warning or
2) "no indexes found, we used all docs" warning.
Instead of returning empty lists, perhaps you could just move the NoIndex
value as the return value for the case clauses. That way no need to add and
then take the head.
Ex:
```
{use_index, []} ->
NoIndex;
````
----------------------------------------------------------------
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