You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2020/09/30 15:09:02 UTC
[couchdb] 08/08: Optimizations for reading reduce views
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 4a4515e01d82a6f88ecd3a6b61b5beeab6127424
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Sep 29 15:23:32 2020 -0500
Optimizations for reading reduce views
These are a few micro optimizations to avoid unnecessary work when
reading from a single reduce function during a view read.
---
src/couch/src/couch_query_servers.erl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/couch/src/couch_query_servers.erl b/src/couch/src/couch_query_servers.erl
index 447daea..8eb07ab 100644
--- a/src/couch/src/couch_query_servers.erl
+++ b/src/couch/src/couch_query_servers.erl
@@ -111,6 +111,8 @@ rereduce(Lang, RedSrcs, ReducedValues) ->
reduce(_Lang, [], _KVs) ->
{ok, []};
+reduce(Lang, [<<"_", _/binary>>] = RedSrcs, KVs) ->
+ builtin_reduce(reduce, RedSrcs, KVs, []);
reduce(Lang, RedSrcs, KVs) ->
{OsRedSrcs, BuiltinReds} = lists:partition(fun
(<<"_", _/binary>>) -> false;
@@ -171,7 +173,10 @@ builtin_reduce(_Re, [], _KVs, Acc) ->
{ok, lists:reverse(Acc)};
builtin_reduce(Re, [<<"_sum",_/binary>>|BuiltinReds], KVs, Acc) ->
Sum = builtin_sum_rows(KVs, 0),
- Red = check_sum_overflow(?term_size(KVs), ?term_size(Sum), Sum),
+ Red = case is_number(Sum) of
+ true -> Sum;
+ false -> check_sum_overflow(?term_size(KVs), ?term_size(Sum), Sum)
+ end,
builtin_reduce(Re, BuiltinReds, KVs, [Red|Acc]);
builtin_reduce(reduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
Count = length(KVs),