Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 2511 invoked from network); 25 Apr 2009 18:02:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 25 Apr 2009 18:02:28 -0000 Received: (qmail 25079 invoked by uid 500); 25 Apr 2009 18:02:27 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 24991 invoked by uid 500); 25 Apr 2009 18:02:27 -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 24981 invoked by uid 99); 25 Apr 2009 18:02:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Apr 2009 18:02:27 +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 paul.joseph.davis@gmail.com designates 74.125.46.30 as permitted sender) Received: from [74.125.46.30] (HELO yw-out-2324.google.com) (74.125.46.30) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Apr 2009 18:02:19 +0000 Received: by yw-out-2324.google.com with SMTP id 2so759605ywt.5 for ; Sat, 25 Apr 2009 11:01:58 -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:content-type :content-transfer-encoding; bh=v+7S0BJf+ZdivjT7NIzGj3BsKj7DOBRwwIOk2+yBCC8=; b=QyjK3PzTH8zJJfsF8G24KQjho02ok/e6pen/GhAni5UVZMqG6CL9TDAVM1cQ3zEdeZ TyRVSUB4d/8eD9jjRw7PVIq7OLFB14pO+Xo95f0VKfrE03hOPEOSDSt1LyUNIQBj9BYS fs8ZB6802IBzOlLy9Tt9cgh0muCszh2Seac6w= 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 :content-type:content-transfer-encoding; b=ej0NxltF5nZf7VCZ7F7LJDB0DRStZSIZyYjmakQ1aCyAFD0d6waNpyIb5cxHn55a0G zn61WmuRasrmNytjyf+LtsjR08I/yQkd42EIdj1fSj84MX6u1GRO0ANqs/87Yej/sHvD OJ8K+Yz4xsRGZ6SNgvwApjyBZeY6cLu1kgXXU= MIME-Version: 1.0 Received: by 10.101.71.3 with SMTP id y3mr5144855ank.158.1240682518849; Sat, 25 Apr 2009 11:01:58 -0700 (PDT) In-Reply-To: References: Date: Sat, 25 Apr 2009 14:01:58 -0400 Message-ID: Subject: Re: Querying by foreign keys From: Paul Davis To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Adam, Yeah, this is one of the harder bits to do in CouchDB at the moment. Your two best bets are either to use something like couchdb-lucene or as you mentioned to pay attention to the key frequencies for smarter retrieval and then do client side filtering. HTH, Paul Davis On Sat, Apr 25, 2009 at 1:27 PM, Adam Wolff wrote: > Hi list, > I have a little query problem that would be easy to solve in SQL, but > seems hard in CouchDB. I have data that looks like this: > doc1: { > =A0 keys : [1,2,3], > =A0 data : .... > } > doc2: { > =A0 keys : [1,3,5], > =A0 data : .... > } > ... > > I'd like a view of my documents that lets me filter on multiple keys, > so a query of keys=3D[1] yields doc1,doc2, as does a query of > keys=3D[1,3]. keys=3D[2] would just fetch doc1, etc. Documents commonly > have 1-5 keys, but may have thousands. > > In SQL, this would be easy to model by making a table of doc.id,key. > In couch, the only way I can think of to truly index all the > combinations of the keys is to emit the n! combinations of the keys, > which seems like a bad idea. (Maybe it's not though?) > > So far, the best solution we've thought of is to emit the document for > each key. We would use the information about key frequency to be smart > about fetching an initial list of documents, and then do the rest of > the filtering in the app. > > Any advice here? I looked at > http://wiki.apache.org/couchdb/EntityRelationship, but there's no > entry on querying by foreign keys. If we come up with something good > (or even just definitive), of course I'll add it to the wiki. > > Thanks! > A >