couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 02/03: Optimize all_docs queries in a single partition
Date Thu, 25 Oct 2018 22:47:37 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch feature/user-partitioned-databases-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 242f85ecaf72149af8f42aaab5804d6465b23e31
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Thu Oct 25 14:26:25 2018 -0500

    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>
---
 src/fabric/src/fabric_view_all_docs.erl | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/fabric/src/fabric_view_all_docs.erl b/src/fabric/src/fabric_view_all_docs.erl
index 6acc792..e3c6dfb 100644
--- a/src/fabric/src/fabric_view_all_docs.erl
+++ b/src/fabric/src/fabric_view_all_docs.erl
@@ -137,6 +137,31 @@ 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#mrags.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
+        _ ->
+            Args
+    end,
+    fabric_view:get_shards(Db, Args).
+
+
 handle_message({rexi_DOWN, _, {_, NodeRef}, _}, _, State) ->
     fabric_view:check_down_shards(State, NodeRef);
 


Mime
View raw message