Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 93020 invoked from network); 25 Nov 2009 09:26:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 25 Nov 2009 09:26:29 -0000 Received: (qmail 34688 invoked by uid 500); 25 Nov 2009 09:26:28 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 34581 invoked by uid 500); 25 Nov 2009 09:26:27 -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 34571 invoked by uid 99); 25 Nov 2009 09:26:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Nov 2009 09:26:27 +0000 X-ASF-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of b.candler@pobox.com designates 208.72.237.25 as permitted sender) Received: from [208.72.237.25] (HELO sasl.smtp.pobox.com) (208.72.237.25) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Nov 2009 09:26:24 +0000 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 39277824CC; Wed, 25 Nov 2009 04:26:02 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:message-id:references:mime-version:content-type :in-reply-to; s=sasl; bh=B+iD5efYyFBPHHnbj9kwwMZKtZY=; b=rsPTFXc 07GxHc4DVNhJcb1CNn76QvCvhoMmnvd8FvuRr4BDLPiNKxPm0kfEzXEke9GMRQuB EVmXPLz9WIV8PPBYQyt3HzDZojSwoC6i1hM1XcPJvdntxk+lO8jGl5n5uu7jJ6Jc D9t+uzp7N7nAZkaMwjpaa/jpToTBsCdY8LBQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=date:from:to:cc :subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=sasl; b=UoADgv6TOrW76Et2VyQMmZzZThV/1PDek IhOA8ncn2UtwWJKaCGo47JaEelHaEkO20sU3AXvcz4MUL0A7o1x5tfoqrTZW+Ppq 8g9g0ikuFOcN00GYpWE6xMRfXn/4+KqeVbDxmRw3sp9unr/bKcnv3ptezYVDj/Eo eSXhm7FFVU= Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 0054F824CB; Wed, 25 Nov 2009 04:26:00 -0500 (EST) Received: from mappit (unknown [80.45.95.114]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 3237C824CA; Wed, 25 Nov 2009 04:25:57 -0500 (EST) Received: from brian by mappit with local (Exim 4.69) (envelope-from ) id 1NDE8J-00024Y-EG; Wed, 25 Nov 2009 09:25:55 +0000 Date: Wed, 25 Nov 2009 09:25:55 +0000 From: Brian Candler To: Dirkjan Ochtman Cc: dev@couchdb.apache.org Subject: Re: Improving pagination for views Message-ID: <20091125092555.GD7275@uk.tiscali.com> Mail-Followup-To: Dirkjan Ochtman , dev@couchdb.apache.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Pobox-Relay-ID: 8BB0D5BC-D9A4-11DE-9970-9F3FEE7EF46B-28021239!a-pb-sasl-quonix.pobox.com On Tue, Nov 24, 2009 at 08:33:43PM +0100, Dirkjan Ochtman wrote: > On Couch, as far as I can see, pre-issuing a count query means > actually retrieving all the row data, which doesn't seem to scale > nicely. Not true: you have a count reduce function. Because each node of the Btree contains the already-calculated reduce value, this is very efficient. At best, it just reads the value out of the root node. At worst, for a key range, it will combine (re-reduce) count values for the subtrees within the key range, and count a few loose values at each end of the range. Where it's inefficient is when retrieving: if I understand it correctly, using offset=50000 *will* require walking through 50,000 rows in the index. That's unless each Btree node has a calculated 'number of rows' value which would allow chunks of tree to be skipped over quickly. I haven't heard anyone say that it does, but I could be wrong. For now, the best advice seems to be use 'next' and 'prev' links, using descending=true to get the values for the previous page.