Received: from maia.hub.org (maia-1.hub.org [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E17B76336E2 for ; Thu, 13 May 2010 04:48:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 51321-03 for ; Thu, 13 May 2010 07:47:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sargon.lncsa.com (mail.lncsa.com [213.215.28.11]) by mail.postgresql.org (Postfix) with ESMTP id 2D7DB6325A4 for ; Thu, 13 May 2010 04:47:53 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id E8BCB30254BA for ; Thu, 13 May 2010 09:47:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id egpf4svmOJVd for ; Thu, 13 May 2010 09:47:51 +0200 (CEST) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id C894D30254B8 for ; Thu, 13 May 2010 09:47:51 +0200 (CEST) Date: Thu, 13 May 2010 09:47:13 +0200 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: Re: best paging strategies for large datasets? Message-ID: <20100513074712.GB19779@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org References: <20100512054144.GA8762@apartia.fr> <4BEBAC15.4030105@bankir.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4BEBAC15.4030105@bankir.ru> User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.001 tagged_above=-5 required=5 tests=BAYES_20=-0.001 X-Spam-Level: X-Archive-Number: 201005/58 X-Sequence-Number: 34106 On Thu, May 13, 2010 at 11:36:53AM +0400, silly sad wrote: > 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. Yes, rendering the results throught ajax is a good idea, but one has to be careful not to expose one's LIMIT and OFFSET to the client, but only the "page" number. Or else the client could query the whole data set. A lot of "professional" web site have that hole.