Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 96D08633625 for ; Thu, 13 May 2010 04:37:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 64643-03 for ; Thu, 13 May 2010 07:37:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moon.antora.ru (moon.antora.ru [89.111.189.180]) by mail.postgresql.org (Postfix) with ESMTP id 625E26325A4 for ; Thu, 13 May 2010 04:37:00 -0300 (ADT) Envelope-to: pgsql-sql@postgresql.org Received: from moon.inner.space ([10.1.1.5] helo=moon.antora.ru) by moon.antora.ru with esmtp (Exim 4.67) (envelope-from ) id 1OCSyX-0001kd-3b for pgsql-sql@postgresql.org; Thu, 13 May 2010 11:36:57 +0400 Received: from [192.168.1.6] [178.34.32.84] by moon.antora.ru (Axigen) with (DHE-RSA-AES256-SHA encrypted) ESMTPSA id 1824B3; Thu, 13 May 2010 11:36:56 +0400 Message-ID: <4BEBAC15.4030105@bankir.ru> Date: Thu, 13 May 2010 11:36:53 +0400 From: silly sad User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.5) Gecko/20100111 Thunderbird/3.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: best paging strategies for large datasets? References: <20100512054144.GA8762@apartia.fr> In-Reply-To: <20100512054144.GA8762@apartia.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-5 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201005/56 X-Sequence-Number: 34104 On 05/12/10 09:41, Louis-David Mitterrand wrote: > Hi, > > I have a large dataset (page 1 at http://www.cruisefish.net/stat.md) and > am in the process of developping a pager to let users leaf through it > (30K rows). > > Ideally I'd like to know when requesting any 'page' of data where I am > within the dataset: how many pages are available each way, etc. > > Of course that can be done by doing a count(*) query before requesting a > limit/offset subset. But the main query is already quite slow, so I'd > like to minimize them. nowadays i tend to bet on AJAX. in other words i propose to move some calculations to a client side at all. and this particular situation might looks similar to the following: First u count(*) the rows and select a requested page returning to a client the count result bundled "with a page of rows" (1) client renders the acquired rows (2)__memorize__ what part of the data he just got (3) and stores the count result to calculate "the pager div" all the subsequent clicks on "the pager div" should not immediately generate requests and decides if the request is needed.