Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 22159 invoked from network); 29 Apr 2009 20:37:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Apr 2009 20:37:54 -0000 Received: (qmail 40024 invoked by uid 500); 29 Apr 2009 20:37:53 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 39954 invoked by uid 500); 29 Apr 2009 20:37:53 -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 39944 invoked by uid 99); 29 Apr 2009 20:37:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2009 20:37:53 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of awolff@gmail.com designates 74.125.92.27 as permitted sender) Received: from [74.125.92.27] (HELO qw-out-2122.google.com) (74.125.92.27) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2009 20:37:45 +0000 Received: by qw-out-2122.google.com with SMTP id 5so1053185qwd.29 for ; Wed, 29 Apr 2009 13:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=quHfbIAMHp1oZRTh2Y8PmQkyQfb5s4MoTCcSQbuWlCc=; b=njNO5AVrmvyGa0WNzi5Nyq6cgF7/jBxO3HnBfIFiFs6snFvJ6HXavC22lA5lHbklRm AmapFlnzimJXDlvVBPaTYOLChAtv43P8+QsWl+AgTMTt2xh+1Zr69x4g1hjA/CmH0wtP WUQkMnT0rSqH6lH3dAaWGnMzRoJde5RRfW1eE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Ya7qhc8uQt8k5ZQSZyNRy86+Jl7c+alDhXuo6kCUmPgUkVCMMBFJtZqQ9qSdE+l3JJ mrtKBTeZJuOrLVWNT6hQ1PUSkG13CCUVhrvMsplDHLl0rChzwCIMrrMuKqrgJcdGMi2U Ar5KtHomOKjh7fWaGM29jQVhQmmMNxC/QiiUc= MIME-Version: 1.0 Received: by 10.229.80.3 with SMTP id r3mr850450qck.104.1241037444342; Wed, 29 Apr 2009 13:37:24 -0700 (PDT) In-Reply-To: <20090426180534.GA6571@uk.tiscali.com> References: <20090426180534.GA6571@uk.tiscali.com> Date: Wed, 29 Apr 2009 13:37:24 -0700 Message-ID: Subject: Re: Querying by foreign keys From: Adam Wolff To: user@couchdb.apache.org Cc: Paul Davis Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Ok, I've updated the wiki page as promised: http://wiki.apache.org/couchdb/EntityRelationship under "Querying by multiple keys" A minor correction to the preceding discussion: I think the number of keys is 2^(n-1). Brian, in your example, you would have to emit "5" as a key. My analysis of the three key case seems to confirm this. Thanks again for the input, Adam On Sun, Apr 26, 2009 at 11:05 AM, Brian Candler wrote= : > On Sat, Apr 25, 2009 at 03:48:02PM -0400, Paul Davis wrote: >> I've contemplated something like this, but I'm pretty sure it breaks >> when you start contemplating that a key may end up being [a, e] in >> which case your querying needs to account for all possible values >> between a and e. > > For a document which contains five values 1,2,3,4,5 you'd need to emit > naively the following combinations: > > 12345 > 1234 =A0 =A0* > 1235 > 1245 > 1345 > 2345 > 123 =A0 =A0 * > 124 =A0 =A0 * > 125 > 134 =A0 =A0 * > 135 > 145 > 234 =A0 =A0 * > 235 > 245 > 345 > 12 =A0 =A0 =A0* > 13 =A0 =A0 =A0* > 14 =A0 =A0 =A0* > 15 > 23 =A0 =A0 =A0* > 24 =A0 =A0 =A0* > 25 > 34 =A0 =A0 =A0* > 35 > 45 > 1 =A0 =A0 =A0 * > 2 =A0 =A0 =A0 * > 3 =A0 =A0 =A0 * > 4 =A0 =A0 =A0 * > 5 =A0 =A0 =A0 * > > That's 31 keys; however you don't need to emit the keys marked * because > they are prefixes of existing keys. That is, if you want to search for [3= ,4] > then you can search for startkey=3D[3,4,null]&endkey=3D[3,4,{}] and you w= ill hit > the other entry for 345, which by definition includes the values 3 and 4. > > Hence this gets you down to 15 keys to emit, but it's still exponential: > 2^(n-1) - 1 > > Regards, > > Brian. >