You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Adam Kocoloski <ko...@apache.org> on 2014/02/11 20:13:34 UTC

Re: couchdb commit: updated refs/heads/1994-merge-rcouch to 2bf88e3

What's the rationale for this option?  When would I want to avoid using the index?

Adam

On Feb 7, 2014, at 10:00 AM, benoitc@apache.org wrote:

> Updated Branches:
>  refs/heads/1994-merge-rcouch 38a18abbc -> 2bf88e3ff
> 
> 
> add the option use_index={no,yes} (yes by default)
> 
> If use_index=no even if the view is indexed by sequence, the index won't
> be use. Instead it will fold the btree and return the changes each time
> the view map function can emit a value. (default behaviour).
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/2bf88e3f
> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2bf88e3f
> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2bf88e3f
> 
> Branch: refs/heads/1994-merge-rcouch
> Commit: 2bf88e3ff03cc674f3001ec93240378cada5bde5
> Parents: 38a18ab
> Author: Benoit Chesneau <bc...@gmail.com>
> Authored: Fri Feb 7 15:57:25 2014 +0100
> Committer: Benoit Chesneau <bc...@gmail.com>
> Committed: Fri Feb 7 15:57:25 2014 +0100
> 
> ----------------------------------------------------------------------
> apps/couch_httpd/src/couch_httpd_changes.erl | 21 +++++++++++++++------
> share/www/script/test/changes.js             |  9 +++++++++
> 2 files changed, 24 insertions(+), 6 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/2bf88e3f/apps/couch_httpd/src/couch_httpd_changes.erl
> ----------------------------------------------------------------------
> diff --git a/apps/couch_httpd/src/couch_httpd_changes.erl b/apps/couch_httpd/src/couch_httpd_changes.erl
> index 56ce559..82d9fe0 100644
> --- a/apps/couch_httpd/src/couch_httpd_changes.erl
> +++ b/apps/couch_httpd/src/couch_httpd_changes.erl
> @@ -118,6 +118,7 @@ handle_changes_req1(Req, #db{name=DbName}=Db) ->
> 
> 
> handle_changes(ChangesArgs, Req, Db) ->
> +
>     case ChangesArgs#changes_args.filter of
>         "_view" ->
>             handle_view_changes(ChangesArgs, Req, Db);
> @@ -146,18 +147,26 @@ handle_view_changes(ChangesArgs, Req, Db) ->
>     ViewOptions = parse_view_options(Query, []),
> 
>     {ok, Infos} = couch_mrview:get_info(Db, DDocId),
> -    case lists:member(<<"seq_indexed">>,
> -                      proplists:get_value(update_options, Infos, [])) of
> -        true ->
> +    IsIndexed = lists:member(<<"seq_indexed">>,
> +                             proplists:get_value(update_options, Infos,
> +                                                 [])),
> +
> +    NoIndex = couch_httpd:qs_value(Req, "use_index", "yes") =:= "no",
> +
> +    case {IsIndexed, NoIndex} of
> +        {true, false} ->
>             handle_view_changes(Db, DDocId, VName, ViewOptions, ChangesArgs,
>                                 Req);
> -        false when ViewOptions /= [] ->
> +        {true, true} when ViewOptions /= [] ->
>             ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
>             throw({bad_request, seqs_not_indexed});
> -        false ->
> +        {false, _} when ViewOptions /= [] ->
> +            ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
> +            throw({bad_request, seqs_not_indexed});
> +        {_, _} ->
>             %% old method we are getting changes using the btree instead
>             %% which is not efficient, log it
> -            ?LOG_WARN("Get view changes with seq_indexed=false.~n", []),
> +            ?LOG_WARN("Filter without using a seq_indexed view.~n", []),
>             couch_changes:handle_changes(ChangesArgs, Req, Db)
>     end.
> 
> 
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/2bf88e3f/share/www/script/test/changes.js
> ----------------------------------------------------------------------
> diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
> index 5c543f1..3419eb6 100644
> --- a/share/www/script/test/changes.js
> +++ b/share/www/script/test/changes.js
> @@ -444,6 +444,15 @@ couchTests.changes = function(debug) {
>   T(resp.results.length === 1);
>   T(resp.results[0].id === "blah");
> 
> +   var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=_view&view=changes_seq_indexed/blah&use_index=no");
> +  var resp = JSON.parse(req.responseText);
> +  T(resp.results.length === 1);
> +  T(resp.results[0].id === "blah");
> +
> +  var req = CouchDB.request("GET", '/test_suite_db/_changes?filter=_view&view=changes_seq_indexed/blah&key="test"&use_index=no');
> +  TEquals(400, req.status, "should return 400 for when use_index=no");
> +
> +
>   // test for userCtx
>   run_on_modified_server(
>     [{section: "httpd",
> 


Re: couchdb commit: updated refs/heads/1994-merge-rcouch to 2bf88e3

Posted by Benoit Chesneau <bc...@gmail.com>.
On Tue, Feb 11, 2014 at 8:56 PM, Robert Samuel Newson
<rn...@apache.org> wrote:
> Maybe.. not add it then?
>
> B.

Launching a view change trigger by default a daemon, sometimes you
don't want it, this is where the noindex can be used. Sometimes you
started a reindexation (because the view index was lost)  but ou still
need to filter from the sequence N without waiting. There are some
case where it would be useful. I would say that given the little
number of line it is using , it is also harmless.

- benoit

Re: couchdb commit: updated refs/heads/1994-merge-rcouch to 2bf88e3

Posted by Robert Samuel Newson <rn...@apache.org>.
Maybe.. not add it then?

B.

On 11 Feb 2014, at 19:42, Benoit Chesneau <bc...@gmail.com> wrote:

> On Tue, Feb 11, 2014 at 8:13 PM, Adam Kocoloski <ko...@apache.org> wrote:
>> What's the rationale for this option?  When would I want to avoid using the index?
>> 
>> Adam
>> 
> Well on small db you probably don't need it. You can manage to fold
> over all results the first time. At least it was added for such
> reason, but we can eventually removed it.
> 
> - benoit
> 
>> On Feb 7, 2014, at 10:00 AM, benoitc@apache.org wrote:
>> 
>>> Updated Branches:
>>> refs/heads/1994-merge-rcouch 38a18abbc -> 2bf88e3ff
>>> 
>>> 
>>> add the option use_index={no,yes} (yes by default)
>>> 
>>> If use_index=no even if the view is indexed by sequence, the index won't
>>> be use. Instead it will fold the btree and return the changes each time
>>> the view map function can emit a value. (default behaviour).
>>> 
>>> 
>>> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
>>> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/2bf88e3f
>>> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2bf88e3f
>>> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2bf88e3f
>>> 
>>> Branch: refs/heads/1994-merge-rcouch
>>> Commit: 2bf88e3ff03cc674f3001ec93240378cada5bde5
>>> Parents: 38a18ab
>>> Author: Benoit Chesneau <bc...@gmail.com>
>>> Authored: Fri Feb 7 15:57:25 2014 +0100
>>> Committer: Benoit Chesneau <bc...@gmail.com>
>>> Committed: Fri Feb 7 15:57:25 2014 +0100
>>> 
>>> ----------------------------------------------------------------------
>>> apps/couch_httpd/src/couch_httpd_changes.erl | 21 +++++++++++++++------
>>> share/www/script/test/changes.js             |  9 +++++++++
>>> 2 files changed, 24 insertions(+), 6 deletions(-)
>>> ----------------------------------------------------------------------
>>> 
>>> 
>>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/2bf88e3f/apps/couch_httpd/src/couch_httpd_changes.erl
>>> ----------------------------------------------------------------------
>>> diff --git a/apps/couch_httpd/src/couch_httpd_changes.erl b/apps/couch_httpd/src/couch_httpd_changes.erl
>>> index 56ce559..82d9fe0 100644
>>> --- a/apps/couch_httpd/src/couch_httpd_changes.erl
>>> +++ b/apps/couch_httpd/src/couch_httpd_changes.erl
>>> @@ -118,6 +118,7 @@ handle_changes_req1(Req, #db{name=DbName}=Db) ->
>>> 
>>> 
>>> handle_changes(ChangesArgs, Req, Db) ->
>>> +
>>>    case ChangesArgs#changes_args.filter of
>>>        "_view" ->
>>>            handle_view_changes(ChangesArgs, Req, Db);
>>> @@ -146,18 +147,26 @@ handle_view_changes(ChangesArgs, Req, Db) ->
>>>    ViewOptions = parse_view_options(Query, []),
>>> 
>>>    {ok, Infos} = couch_mrview:get_info(Db, DDocId),
>>> -    case lists:member(<<"seq_indexed">>,
>>> -                      proplists:get_value(update_options, Infos, [])) of
>>> -        true ->
>>> +    IsIndexed = lists:member(<<"seq_indexed">>,
>>> +                             proplists:get_value(update_options, Infos,
>>> +                                                 [])),
>>> +
>>> +    NoIndex = couch_httpd:qs_value(Req, "use_index", "yes") =:= "no",
>>> +
>>> +    case {IsIndexed, NoIndex} of
>>> +        {true, false} ->
>>>            handle_view_changes(Db, DDocId, VName, ViewOptions, ChangesArgs,
>>>                                Req);
>>> -        false when ViewOptions /= [] ->
>>> +        {true, true} when ViewOptions /= [] ->
>>>            ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
>>>            throw({bad_request, seqs_not_indexed});
>>> -        false ->
>>> +        {false, _} when ViewOptions /= [] ->
>>> +            ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
>>> +            throw({bad_request, seqs_not_indexed});
>>> +        {_, _} ->
>>>            %% old method we are getting changes using the btree instead
>>>            %% which is not efficient, log it
>>> -            ?LOG_WARN("Get view changes with seq_indexed=false.~n", []),
>>> +            ?LOG_WARN("Filter without using a seq_indexed view.~n", []),
>>>            couch_changes:handle_changes(ChangesArgs, Req, Db)
>>>    end.
>>> 
>>> 
>>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/2bf88e3f/share/www/script/test/changes.js
>>> ----------------------------------------------------------------------
>>> diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
>>> index 5c543f1..3419eb6 100644
>>> --- a/share/www/script/test/changes.js
>>> +++ b/share/www/script/test/changes.js
>>> @@ -444,6 +444,15 @@ couchTests.changes = function(debug) {
>>>  T(resp.results.length === 1);
>>>  T(resp.results[0].id === "blah");
>>> 
>>> +   var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=_view&view=changes_seq_indexed/blah&use_index=no");
>>> +  var resp = JSON.parse(req.responseText);
>>> +  T(resp.results.length === 1);
>>> +  T(resp.results[0].id === "blah");
>>> +
>>> +  var req = CouchDB.request("GET", '/test_suite_db/_changes?filter=_view&view=changes_seq_indexed/blah&key="test"&use_index=no');
>>> +  TEquals(400, req.status, "should return 400 for when use_index=no");
>>> +
>>> +
>>>  // test for userCtx
>>>  run_on_modified_server(
>>>    [{section: "httpd",
>>> 
>> 


Re: couchdb commit: updated refs/heads/1994-merge-rcouch to 2bf88e3

Posted by Benoit Chesneau <bc...@gmail.com>.
On Tue, Feb 11, 2014 at 8:13 PM, Adam Kocoloski <ko...@apache.org> wrote:
> What's the rationale for this option?  When would I want to avoid using the index?
>
> Adam
>
Well on small db you probably don't need it. You can manage to fold
over all results the first time. At least it was added for such
reason, but we can eventually removed it.

- benoit

> On Feb 7, 2014, at 10:00 AM, benoitc@apache.org wrote:
>
>> Updated Branches:
>>  refs/heads/1994-merge-rcouch 38a18abbc -> 2bf88e3ff
>>
>>
>> add the option use_index={no,yes} (yes by default)
>>
>> If use_index=no even if the view is indexed by sequence, the index won't
>> be use. Instead it will fold the btree and return the changes each time
>> the view map function can emit a value. (default behaviour).
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/2bf88e3f
>> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2bf88e3f
>> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2bf88e3f
>>
>> Branch: refs/heads/1994-merge-rcouch
>> Commit: 2bf88e3ff03cc674f3001ec93240378cada5bde5
>> Parents: 38a18ab
>> Author: Benoit Chesneau <bc...@gmail.com>
>> Authored: Fri Feb 7 15:57:25 2014 +0100
>> Committer: Benoit Chesneau <bc...@gmail.com>
>> Committed: Fri Feb 7 15:57:25 2014 +0100
>>
>> ----------------------------------------------------------------------
>> apps/couch_httpd/src/couch_httpd_changes.erl | 21 +++++++++++++++------
>> share/www/script/test/changes.js             |  9 +++++++++
>> 2 files changed, 24 insertions(+), 6 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/2bf88e3f/apps/couch_httpd/src/couch_httpd_changes.erl
>> ----------------------------------------------------------------------
>> diff --git a/apps/couch_httpd/src/couch_httpd_changes.erl b/apps/couch_httpd/src/couch_httpd_changes.erl
>> index 56ce559..82d9fe0 100644
>> --- a/apps/couch_httpd/src/couch_httpd_changes.erl
>> +++ b/apps/couch_httpd/src/couch_httpd_changes.erl
>> @@ -118,6 +118,7 @@ handle_changes_req1(Req, #db{name=DbName}=Db) ->
>>
>>
>> handle_changes(ChangesArgs, Req, Db) ->
>> +
>>     case ChangesArgs#changes_args.filter of
>>         "_view" ->
>>             handle_view_changes(ChangesArgs, Req, Db);
>> @@ -146,18 +147,26 @@ handle_view_changes(ChangesArgs, Req, Db) ->
>>     ViewOptions = parse_view_options(Query, []),
>>
>>     {ok, Infos} = couch_mrview:get_info(Db, DDocId),
>> -    case lists:member(<<"seq_indexed">>,
>> -                      proplists:get_value(update_options, Infos, [])) of
>> -        true ->
>> +    IsIndexed = lists:member(<<"seq_indexed">>,
>> +                             proplists:get_value(update_options, Infos,
>> +                                                 [])),
>> +
>> +    NoIndex = couch_httpd:qs_value(Req, "use_index", "yes") =:= "no",
>> +
>> +    case {IsIndexed, NoIndex} of
>> +        {true, false} ->
>>             handle_view_changes(Db, DDocId, VName, ViewOptions, ChangesArgs,
>>                                 Req);
>> -        false when ViewOptions /= [] ->
>> +        {true, true} when ViewOptions /= [] ->
>>             ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
>>             throw({bad_request, seqs_not_indexed});
>> -        false ->
>> +        {false, _} when ViewOptions /= [] ->
>> +            ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
>> +            throw({bad_request, seqs_not_indexed});
>> +        {_, _} ->
>>             %% old method we are getting changes using the btree instead
>>             %% which is not efficient, log it
>> -            ?LOG_WARN("Get view changes with seq_indexed=false.~n", []),
>> +            ?LOG_WARN("Filter without using a seq_indexed view.~n", []),
>>             couch_changes:handle_changes(ChangesArgs, Req, Db)
>>     end.
>>
>>
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/2bf88e3f/share/www/script/test/changes.js
>> ----------------------------------------------------------------------
>> diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
>> index 5c543f1..3419eb6 100644
>> --- a/share/www/script/test/changes.js
>> +++ b/share/www/script/test/changes.js
>> @@ -444,6 +444,15 @@ couchTests.changes = function(debug) {
>>   T(resp.results.length === 1);
>>   T(resp.results[0].id === "blah");
>>
>> +   var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=_view&view=changes_seq_indexed/blah&use_index=no");
>> +  var resp = JSON.parse(req.responseText);
>> +  T(resp.results.length === 1);
>> +  T(resp.results[0].id === "blah");
>> +
>> +  var req = CouchDB.request("GET", '/test_suite_db/_changes?filter=_view&view=changes_seq_indexed/blah&key="test"&use_index=no');
>> +  TEquals(400, req.status, "should return 400 for when use_index=no");
>> +
>> +
>>   // test for userCtx
>>   run_on_modified_server(
>>     [{section: "httpd",
>>
>