Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 05C1A790B for ; Sat, 27 Aug 2011 04:53:08 +0000 (UTC) Received: (qmail 96429 invoked by uid 500); 27 Aug 2011 04:53:02 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 95964 invoked by uid 500); 27 Aug 2011 04:52:55 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 95935 invoked by uid 99); 27 Aug 2011 04:52:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2011 04:52:52 +0000 X-ASF-Spam-Status: No, hits=-2000.5 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2011 04:52:49 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 33AEFD2388 for ; Sat, 27 Aug 2011 04:52:29 +0000 (UTC) Date: Sat, 27 Aug 2011 04:52:29 +0000 (UTC) From: "Prudhvi (JIRA)" To: dev@couchdb.apache.org Message-ID: <895435676.20417.1314420749208.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (COUCHDB-834) startkey_docid/endkey_docid don't work without an exact startkey/endkey match MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/COUCHDB-834?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13092196#comment-13092196 ] Prudhvi commented on COUCHDB-834: --------------------------------- @paul thank you for the explanation, my view emits [ param1, param2 ] -> value you said it internally stores as [ key, docid ] where key is [ param1, param2 ] --> [ [ "other", "two" ] , doc_id1 ] , [ [ "other", "two" ] , doc_id2 ] , [ [ "other", "two" ] , doc_id3 ] we are querying the view for pagination with startkey=[ "other" ], endkey=[ "other", {} ], and startkey_docid = doc_id2 . since the first two params are exactly same it should consider the third param (doc_id) for exact match. However its ignoring the third param(doc_id), we expected a list of results with doc_id2 row as first row. its returning a list with doc_id1 as first row. This is confusing as we queried for doc_id2 as first row in the result for pagination. @randall may be it needs to be a feature ticket or could be a bug. how can we query for pagination when multiple keys exists? > startkey_docid/endkey_docid don't work without an exact startkey/endkey match > ----------------------------------------------------------------------------- > > Key: COUCHDB-834 > URL: https://issues.apache.org/jira/browse/COUCHDB-834 > Project: CouchDB > Issue Type: Bug > Components: JavaScript View Server > Affects Versions: 1.0 > Reporter: Mathias Meyer > > This issue popped up when I wanted to paginate through a list of documents using a combined array key, using a startkey and endkey that's based solely on the first part of said key. First part is a reference to a different document, second part is a timestamp to keep the list sorted by creation time. The list of documents can be fetched using startkey=["key"] and endkey=["key", {}] > Now, I wanted to add pagination to this list, only fetching so many documents starting at startkey_docid, which failed using this setup. It seems (and Jan validated that assumption by analyzing the source) that both startkey needs to be an exact match for startkey_docid to have any effect. If there's no exact match, CouchDB will silently ignore the startkey_docid, a behaviour that's undocumented and to be quite frank, unintuitive. > Consider the following two documents, both pointing to the same other_id: > {"_id": "one", "other_id": "other", "second_key": "one"} > {"_id": "two", "other_id": "other", "second_key": "two"} > And a simple map/reduce function that just emits the combined key: > { > "other_documents": { > "reduce": "_sum", > "map": " function(doc) { \n emit([doc.other_id, doc.second_key], 1);\n }\n" > } > } > Querying the view like this gives the expected results: > curl 'http://localhost:5984/startkey_bug/_design/other_documents/_view/other_documents?reduce=false&startkey=\["other"\]&endkey=\["other",\{\}\]' > {"total_rows":2,"offset":0,"rows":[ > {"id":"one","key":["other","one"],"value":1}, > {"id":"two","key":["other","two"],"value":1} > ]} > If I add in a startkey_docid of two, I'd expect CouchDB to skip to the second result in the list, skipping the first, but it doesn't: > curl 'http://localhost:5984/startkey_bug/_design/other_documents/_view/other_documents?reduce=false&startkey=\["other"\]&endkey=\["other",\{\}\]&startkey_docid=two' > {"total_rows":2,"offset":0,"rows":[ > {"id":"one","key":["other","one"],"value":1}, > {"id":"two","key":["other","two"],"value":1} > ]} > However, it does what I'd expect when I specify an exact startkey (the endkey is still the same): > curl 'http://localhost:5984/startkey_bug/_design/other_documents/_view/other_documents?reduce=false&startkey=\["other","one"\]&endkey=\["other",\{\}\]&startkey_docid=two' > {"total_rows":2,"offset":1,"rows":[ > {"id":"two","key":["other","two"],"value":1} > ]} > If you add in an exact endkey, the situation doesn't change, and the result is as expected. > Having an exact startkey is an acceptable workaround, but I'd still say this behaviour is not intuitive, and either should be fixed to work the same in all of the above situations. If not, at least the documentation should properly reflect these situation, explaining the proper workarounds. > Update: I just checked how this works out when using descending=true, the same is true for the swapped endkey and startkey parameters. Specifying and endkey_docid requires to specify an exact endkey match. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira