Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 66B7E10DDE for ; Thu, 3 Apr 2014 12:54:32 +0000 (UTC) Received: (qmail 78750 invoked by uid 500); 3 Apr 2014 12:54:24 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 78279 invoked by uid 500); 3 Apr 2014 12:54:21 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 78257 invoked by uid 99); 3 Apr 2014 12:54:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Apr 2014 12:54:19 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [216.109.115.22] (HELO nm14-vm7.access.bullet.mail.bf1.yahoo.com) (216.109.115.22) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Apr 2014 12:54:11 +0000 Received: from [66.196.81.161] by nm14.access.bullet.mail.bf1.yahoo.com with NNFMP; 03 Apr 2014 12:53:48 -0000 Received: from [66.196.81.138] by tm7.access.bullet.mail.bf1.yahoo.com with NNFMP; 03 Apr 2014 12:53:48 -0000 Received: from [127.0.0.1] by omp1014.access.mail.bf1.yahoo.com with NNFMP; 03 Apr 2014 12:53:48 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 958966.32695.bm@omp1014.access.mail.bf1.yahoo.com Received: (qmail 78684 invoked by uid 60001); 3 Apr 2014 12:53:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sbcglobal.net; s=s1024; t=1396529627; bh=goMG3xAlPkj2g8/JOYBveOwqILm3ZrHT6JLCCFkSfic=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=glsFkRu/A802osyIzk4rt9kWDkKylGD5olLp/sWus425gBxvQaPGu8/E/s1TttSSogEgBBZ45sMsJH06CleZ6iu60YRd0QaB2Fhzu+W2q+fccugr8qCsN9TR24H2XyKFkZmhoA/vCDNubJER7HS1hD/lwyq+lo2VisHR6rC3P8c= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=sbcglobal.net; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=tJmJomoYL4lvM9oRaBZ9qdnJtgQeovch0JSP7lkmX7iVRtgsryLAWaDveo6Xmuzrj35IFzbUgRwJHCBsmpJnUE7IMty5JR8Wtm6rqiVra2JdPvm758Fd8Kkj43vG40jgvRSI4aL6ToOMylAJQl7T0mWtI5YXkuimVlmoqmPqwcU=; X-YMail-OSG: BF4HdbcVM1nhzZaVpqX1SFvBPSlnL8a7chw26Wr1ZBdZhKs hyUDR3psn7ms5aS2bTWjpWJP6Q7tQyj1TMbfp52lt1kSctpq0co.ZudqYYYO tC8oW3zZdm0pD5uSLLudvT2ZKQqTKGXsmkor2d1RuByW7KnoLCArlhOUPR1z 2TULnT45OvqQrGdDIvx7E4Bmj6S2OrKM2MMtQPlT9pq3Z7Z8dRPrHXujgY8k 7yLai66fDWuUfIN_dx8Zy4qdsdgmdRk2jhvGNOB5J.U6Vrl_i9.jFE4Wsz_d dFEof5O3IokwjajdSTot511DaT8IqRacJEnhdlIoM1PqnsK.R0lYyWo.VamU 0jwm9pxwa9KIldjFoKLg9iCESPD5Zh9IaG7VcaUlf.N5eLhQk7AZNOthOL7l fXlvdAzWe59bOQRBJIbMkhU.mPNgE56pJkeuPh_tqIOv9xpDakodEjQQRaej LNtE3LOjk_SMal7ho06hNDpCuTZlBhesY5oSB0c.mTs2K9kbAa7sVMRuUzrY BXF9uKbq7LGIz_hpLyd.03ZC6FCLOU7xLVSJM.PzuTcHcxULQqyRtejpgMbm hY.x0sF32hA-- Received: from [99.189.12.49] by web181702.mail.ne1.yahoo.com via HTTP; Thu, 03 Apr 2014 05:53:47 PDT X-Rocket-MIMEInfo: 002.001,SSBoYXZlIGJlZW4gZm9sbG93aW5nIHRoaXMsIGFuZCB3YXMgd29uZGVyaW5nIGFib3V0IGl0LgoKVGhlIGRvY3VtZW50YXRpb24gZG9lc24ndCBzYXkgYW55dGhpbmcgYWJvdXQgdGhlIHNlY29uZCBhcmcgKGkuZS4gdmFsdWUpIG9mIHRoZSBlbWl0IGNhbGwgYmVpbmcgdXNlZCBmb3Igc29ydGluZy7CoCBIb3dldmVyIGl0IHdvcmtzIHRoYXQgd2F5IGV2ZXJ5IHRpbWUsIGFuZCBJIGNhbiBmaW5kIG5vIHNpdHVhdGlvbiB3aGVyZSBpdCBkb2Vzbid0IGhhcHBlbi4KCkFyZSB5b3Ugc2F5aW5nIHRoYXQgaXQgaXMBMAEBAQE- X-Mailer: YahooMailWebService/0.8.182.648 References: <0F9923A3-3054-4695-A66B-F8A3E0FD475D@apache.org> <2CEABFBA-FBE9-42CC-817F-24A56B6DF36E@yahoo.com> Message-ID: <1396529627.10521.YahooMailNeo@web181702.mail.ne1.yahoo.com> Date: Thu, 3 Apr 2014 05:53:47 -0700 (PDT) From: Scott Weber Reply-To: Scott Weber Subject: Re: question about "complex" range queries To: COUCHDB In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-1672125993-556949270-1396529627=:10521" X-Virus-Checked: Checked by ClamAV on apache.org ---1672125993-556949270-1396529627=:10521 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I have been following this, and was wondering about it.=0A=0AThe documentat= ion doesn't say anything about the second arg (i.e. value) of the emit call= being used for sorting.=C2=A0 However it works that way every time, and I = can find no situation where it doesn't happen.=0A=0AAre you saying that it = is NOT something that should be relied on?=0A=0AI also notice that the docu= ments are sent into the view already sorted by their _id.=C2=A0 Is that a b= ehavior that CAN be replied on?=0A=0ASee my samples below:=0A=0A=0ATwo of m= y docs:=0A{=C2=A0=C2=A0 "_id": "a",=C2=A0=C2=A0 "_rev": "1-a50d41b0fdfaaca4= e679c7f2c6a1722d",=0A=C2=A0=C2=A0 "items": [=C2=A0=C2=A0 =0A=0A=C2=A0 { "b"= : "5"}, {"a": "6"}, {"c": "4"}, { "x": "1" }, { "w": "3" }, { "z": "2" }=0A= ]=C2=A0 }=0A=0A=0A{=C2=A0 "_id": "b", "_rev": "1-82a40a986a557f05352dbcb1fb= 07b26e",=0A=C2=A0=C2=A0 "items": [=0A=C2=A0=C2=A0 {"m": "5" },{ "l": "6" },= { "n": "4"}=0A] }=0A=0A=0AThe temp view:=0Afunction(doc) {=C2=A0=C2=A0=C2= =A0 var x;=0Afor (x =3D 0; x < doc.items.length; x++) {=C2=A0 emit("1", doc= .items[x]); =C2=A0 }=0A}=0A=0A=0AThe output:=C2=A0 =0A=0A{"total_rows":9,"o= ffset":0,"rows":[=0A{"id":"a","key":"1","value":{"a":"6"}},=0A{"id":"a","ke= y":"1","value":{"b":"5"}},=0A{"id":"a","key":"1","value":{"c":"4"}},=0A{"id= ":"a","key":"1","value":{"w":"3"}},=0A{"id":"a","key":"1","value":{"x":"1"}= },=0A{"id":"a","key":"1","value":{"z":"2"}},=0A{"id":"b","key":"1","value":= {"l":"6"}},=0A{"id":"b","key":"1","value":{"m":"5"}},=0A{"id":"b","key":"1"= ,"value":{"n":"4"}}=0A]}=0A=0A=0A-Scott=0A=0A=0A=0A________________________= ________=0A=0AFrom: Robert Samuel Newson =0A>Date: Apri= l 3, 2014, 3:30:14 AM CDT=0A>To: user@couchdb.apache.org, "Rian R. Maloney"= =0A>Subject: Re: question about "complex" range qu= eries=0A>Reply-To: user@couchdb.apache.org=0A=0A>Sorry, but the value is no= t included in the ordering of the views, what you=E2=80=99re seeing there i= s an artifact of how multiple emits from the same document (where the emitt= ed key is the same *and* the tie-breaking _id is also the same) are handled= .=0A>=0A>B.=0A>=0A>On 3 Apr 2014, at 01:52, Rian R. Maloney wrote:=0A>=0A>=0A>=0A>This is NOT what I am seeing ( just trying = to understand how this example is not sorted on value). Here is my test cas= e:=0A>=C2=A0=0A>1) create database called test=0A>2) create 1 doc with _id = =3D test and a field called stuff =3D"this is test data"=0A>3) =C2=A0create= the following map:=0A>=C2=A0=0A>function(doc) {=0A>=C2=A0=0A>=C2=A0for( va= r i =3D 1;i < 5;i++ )=0A>=C2=A0{=0A>=C2=A0=C2=A0=C2=A0=C2=A0data =3D {};=0A= >=C2=A0=C2=A0=C2=A0=C2=A0data.sortkey =3D i;=0A>=C2=A0=C2=A0=C2=A0=C2=A0dat= a.stuff =3D doc.stuff;=0A>=C2=A0=C2=A0=C2=A0=C2=A0emit( doc._id, data );=0A= >=C2=A0}=0A>=C2=A0for( var i =3D 4;i > 0;i-- )=0A>=C2=A0{=0A>=C2=A0=C2=A0= =C2=A0=C2=A0data =3D {};=0A>=C2=A0=C2=A0=C2=A0=C2=A0data.sortkey =3D i;=0A>= =C2=A0=C2=A0=C2=A0=C2=A0data.stuff =3D doc.stuff;=0A>=C2=A0=C2=A0=C2=A0=C2= =A0emit( doc._id, data );=0A>=C2=A0}=0A>=C2=A0=0A>=C2=A0=0A>Result:=0A>{"to= tal_rows":8,"offset":0,"rows":[=0A>{"id":"test","key":"test","value":{"sort= key":1,"stuff":"this is test data"}},=0A>{"id":"test","key":"test","value":= {"sortkey":1,"stuff":"this is test data"}},=0A>{"id":"test","key":"test","v= alue":{"sortkey":2,"stuff":"this is test data"}},=0A>{"id":"test","key":"te= st","value":{"sortkey":2,"stuff":"this is test data"}},=0A>{"id":"test","ke= y":"test","value":{"sortkey":3,"stuff":"this is test data"}},=0A>{"id":"tes= t","key":"test","value":{"sortkey":3,"stuff":"this is test data"}},=0A>{"id= ":"test","key":"test","value":{"sortkey":4,"stuff":"this is test data"}},= =0A>{"id":"test","key":"test","value":{"sortkey":4,"stuff":"this is test da= ta"}}=0A>]}=0A>=C2=A0=0A>But if value was not included in the sort, it woul= d be:=0A>=C2=A0=0A>{"total_rows":8,"offset":0,"rows":[=0A>{"id":"test","key= ":"test","value":{"sortkey":1,"stuff":"this is test data"}},=0A>{"id":"test= ","key":"test","value":{"sortkey":2,"stuff":"this is test data"}},=0A>{"id"= :"test","key":"test","value":{"sortkey":3,"stuff":"this is test data"}},=0A= >{"id":"test","key":"test","value":{"sortkey":4,"stuff":"this is test data"= }},{"id":"test","key":"test","value":{"sortkey":1,"stuff":"this is test dat= a"}},{"id":"test","key":"test","value":{"sortkey":2,"stuff":"this is test d= ata"}},{"id":"test","key":"test","value":{"sortkey":3,"stuff":"this is test= data"}},{"id":"test","key":"test","value":{"sortkey":4,"stuff":"this is te= st data"}},=0A>]}=0A>On Wednesday, April 2, 2014 6:07 PM, Ryan Ramage wrote:=0A>=C2=A0=0A>The emitted value does not affect th= e sort.=0A>=C2=A0=0A>=C2=A0=0A>If you wanted to keep sorting add your sort = field in an array key, so move=0A>from=0A>=C2=A0=0A>emit(doc.key, doc.value= )=0A>=C2=A0=0A>=C2=A0=0A>to=0A>=C2=A0=0A>emit([doc.key, doc.value], doc.val= ue)=0A>=C2=A0=0A>=C2=A0=0A>=C2=A0=0A>On Wed, Apr 2, 2014 at 4:57 PM, wrote:=0A>=C2=A0=0A>Thanks Robert. Let me clarify. Is th= e value included in the sort? I have=0A>10 entries all with identical keys.= The behavior I am seeing indicates the=0A>contents of the emitted value is= included in the sort criteria and if so=0A>can I count on this? Bottom lin= e I am trying to sort on 2 fields, one is a=0A>key and the other is the beg= inning of the value. I also don't want to sort=0A>the results in a list due= to performance constraints=0A>=C2=A0=0A>Thanks=0A>=C2=A0=0A>On Apr 2, 2014= , at 5:45 PM, Robert Samuel Newson =0A>wrote:=0A>=C2=A0= =0A>A view is a single dimension index, ordered by the full key in=0A>accor= dance with the rules enumerated here:=0A>https://wiki.apache.org/couchdb/Vi= ew_collation#Collation_Specification=0A>=C2=A0=0A>For example;=0A>=C2=A0=0A= >9 sorts after false=0A>999 sorts after 9=0A>"foo" sorts after 999=0A>["foo= "] sorts after "foo"=0A>["foo", "bar"] sorts after ["foo"]=0A>=C2=A0=0A>B.= =0A>=C2=A0=0A>On 2 Apr 2014, at 23:29, rian.maloney@yahoo.com wrote:=0A>=C2= =A0=0A>I have a quick question related to this. What exactly is sorted? My= =0A>test cases indicated the key AND the entire value is sorted as if it wa= s=0A>one big string.=0A>=C2=A0=0A>Thanks=0A>Rian=0A>=C2=A0=0A>On Apr 2, 201= 4, at 2:31 AM, Nick North wrote:=0A>=C2=A0=0A>It doesn'= t work quite like this. There is a single order across all=0A>possible keys= , including both simple and complex keys, as described=0A>here.=0A>In the case of keys that are lists,= the two lists are compared element=0A>by=0A>element and the sort order is = the sort order of the first unequal=0A>elements.=0A>=C2=A0=0A>In your examp= le, if a key has its first element between a1 and a2 (and=0A>a1=0A>and a2 a= re different), then the second element will not be inspected at=0A>all, so = it does not matter whether it is between b1 and b2 or not. In=0A>fact=0A>th= e second element will only be inspected if the first element is=0A>either a= 1=0A>or a2.=0A>=C2=A0=0A>This is usually the behaviour we want. For example= , dates are often=0A>represented as lists of [year, month, day]. Then you c= an pull out all=0A>the=0A>documents in a date range by specifying start dat= e and end date as=0A>startkey=0A>and endkey. For example, if these are [201= 2, 4, 5] and [2014, 8, 3]=0A>respectively, we want to include [2013, 3, 6] = in the output even=0A>though its=0A>second element does not lie between the= second elements of the keys.=0A>=C2=A0=0A>Nick=0A>=C2=A0=0A>=C2=A0=0A>On 2= April 2014 03:56, Schroiff, Klaus =0A>wrote:= =0A>=C2=A0=0A>Hi,=0A>=C2=A0=0A>Let's assume that I have the following view = function:=0A>=C2=A0=0A>function(doc) { emit([a, b], whatever) } }=0A>=C2=A0= =0A>In the query I'm running something like=0A>startkey=3D[a1, b1] & endkey= =3D[a2,b2]=0A>Thus there're TWO explicit ranges here - a1->a2 and b1->b2.= =0A>=C2=A0=0A>What is the expected result ?=0A>=C2=A0=0A>My understanding:= =0A>The query is executed in two phases=0A>In the first phase, the index is= filtered for qualifying results=0A>where the=0A>first key ranges from a1 t= o a2=0A>In the second phase, these filtered results are filtered once more= =0A>according to the range of the second emitted key from b1 to b2.=0A>Thus= essentially an "AND" operation.=0A>The filtering is performed using lexico= graphical rules.=0A>=C2=A0=0A>Is that correct ? The doc about complex keys = is a bit slim.=0A>=C2=A0=0A>Thanks=0A>=C2=A0=0A>Klaus=0A>=C2=A0=0A>=C2=A0 ---1672125993-556949270-1396529627=:10521--