Re: Paged Query

Lists: pgsql-performance
From: Misa Simic <misa(dot)simic(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Paged Query
Date: 2012-07-09 22:24:31
Message-ID: -6943177787207849568@unknownmsgid
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

Hi Andrew,

Sure... We are sending data in Json to clients

{
total:6784,
data:[50 rows for desired page]
}

SELECT count(*) FROM table - without where, without joins used to have
bad performance... However, in real scenario we have never had the case
without joins and where... Join columns are always indexed, and we
always try to put indexes on columns what will mostly be used in where
in usual queries...

So far we haven't met performance problems...

But to be honest with you, total info very rarely in our responses is
bigger then 10k, and mainly is less then 1k... what is really small
number todays.. (even tables have few million rows, but restrictions
always reduce "desired" total data on less then 1000...)

When users want to work on something on every day basis... Usually they
want "immediatly", things, what are just for them...draft things on
what they worked in last few days, or assigned just to them etc etc...

When they need to pass trough some process once a month... And
performance is "slow" - usually they don't bother... Every day tasks is
what is important and what we care about to have good performance...

In very rarely cases, when we know, performance must be slow from many
reasons - we are lying :) - return first page, (hopefully with data
what user looking for), and return 1000 as total... Return result to
user, and async run CalculateTotalForThisCaseAndCache it... On first
next request for the same thing (but other page) if calculation is
done, return results from cache (with real total number)... But it is
really on very exceptional basis then on regular...

Cheers

Misa

Sent from my Windows Phone
From: Andrew Dunstan
Sent: 09/07/2012 19:47
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: [PERFORM] Paged Query

On 07/09/2012 01:41 PM, Misa Simic wrote:
>
>
> From my experience users even very rare go to ending pages... easier
> to them would be to sort data by field to get those rows in very first
> pages...
>
>

Yeah, the problem really is that most client code wants to know how many
pages there are, even if it only wants one page right now.

cheers

andrew


From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Misa Simic <misa(dot)simic(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Paged Query
Date: 2012-07-09 23:50:29
Message-ID: 4FFB6E45.50708@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

On 07/10/2012 06:24 AM, Misa Simic wrote:
> Hi Andrew,
>
> Sure... We are sending data in Json to clients
>
> {
> total:6784,
> data:[50 rows for desired page]
> }
>
> SELECT count(*) FROM table - without where, without joins used to have
> bad performance... However, in real scenario we have never had the case
> without joins and where... Join columns are always indexed, and we
> always try to put indexes on columns what will mostly be used in where
> in usual queries...

When/if you do need a count of a single table without any filters, a
common trick is to use table statistics to return an approximation. If
your autovaccum is running regularly it's usually a very good
approximation, too.

Sounds like this hack may become unnecessary in 9.2 though.

--
Craig Ringer


From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
Cc: Misa Simic <misa(dot)simic(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Paged Query
Date: 2012-07-10 00:34:14
Message-ID: CAMkU=1zgPkk0vv_7DVkKuPv7woKp9k_8o9o4oDUBHH+4Vg0HmA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

On Mon, Jul 9, 2012 at 4:50 PM, Craig Ringer <ringerc(at)ringerc(dot)id(dot)au> wrote:
>
>
> When/if you do need a count of a single table without any filters, a common
> trick is to use table statistics to return an approximation. If your
> autovaccum is running regularly it's usually a very good approximation, too.
>
> Sounds like this hack may become unnecessary in 9.2 though.

Index only scans in 9.2 are nice, but they don't fundamentally change
this type of thing.

Cheers,

Jeff