summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2018-10-25 14:26:25 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-01-18 12:35:38 -0600
commitdc53a3f88781d4065d09b8f3940d8eff920965b5 (patch)
tree09ff6eb7707affd0dd7432c721c1b184bd7e2700
parentcada5c5928d4141ecb7db9cb38882866edf91744 (diff)
downloadcouchdb-dc53a3f88781d4065d09b8f3940d8eff920965b5.tar.gz
Optimize all_docs queries in a single partition
If a user specifies document ids that scope the query to a single partition key we can automatically determine that we only need to consuly a single shard range. Co-authored-by: Robert Newson <rnewson@apache.org>
-rw-r--r--src/fabric/src/fabric_view_all_docs.erl26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/fabric/src/fabric_view_all_docs.erl b/src/fabric/src/fabric_view_all_docs.erl
index 263538f65..fdc3bd988 100644
--- a/src/fabric/src/fabric_view_all_docs.erl
+++ b/src/fabric/src/fabric_view_all_docs.erl
@@ -135,6 +135,32 @@ go(DbName, _Options, Workers, QueryArgs, Callback, Acc0) ->
{ok, Resp}
end.
+shards(Db, Args) ->
+ DbPartitioned = fabric_util:is_partitioned(Db),
+ Partition = couch_mrview_util:get_extra(Args, partition),
+ NewArgs = case {DbPartitioned, Partition} of
+ {true, undefined} ->
+ % If a user specifies the same partition on both
+ % the start and end keys we can optimize the
+ % query by limiting to the partition shard.
+ Start = couch_partition:extract(Args#mrargs.start_key),
+ End = couch_partition:extract(Args#mrargs.end_key),
+ case {Start, End} of
+ {{Partition, SK}, {Partition, EK}} ->
+ A1 = Args#mrargs{
+ start_key = SK,
+ end_key = EK
+ },
+ couch_mrview_util:set_extra(A1, partition, Partition);
+ _ ->
+ Args
+ end;
+ _ ->
+ Args
+ end,
+ fabric_view:get_shards(Db, NewArgs).
+
+
handle_message({rexi_DOWN, _, {_, NodeRef}, _}, _, State) ->
fabric_view:check_down_shards(State, NodeRef);