From: Bruce Momjian <bruce@momjian.us>
To: bricklen <bricklen@gmail.com>
Cc: Neil Whelchel <neil.whelchel@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Slow count(*) again...
Date: Thu, 21 Oct 2010 00:07:22 -0400 (EDT)
Message-ID: <201010210407.o9L47M912017@momjian.us> (raw)
In-Reply-To: <AANLkTimXSWapozrZNdiRXDSm2hdsha1As94NwuS967As@mail.gmail.com>
bricklen wrote:
> On Sat, Oct 9, 2010 at 4:26 PM, Neil Whelchel <neil.whelchel@gmail.com> wrote:
> > Maybe an
> > estimate(*) that works like count but gives an answer from the index without
> > checking visibility? I am sure that this would be good enough to make a page
> > list, it is really no big deal if it errors on the positive side, maybe the
> > list of pages has an extra page off the end. I can live with that. What I
> > can't live with is taking 13 seconds to get a page of results from 850,000
> > rows in a table.
> > -Neil-
> >
>
> FWIW, Michael Fuhr wrote a small function to parse the EXPLAIN plan a
> few years ago and it works pretty well assuming your stats are up to
> date.
>
> http://markmail.org/message/gknqthlwry2eoqey
What I recommend is to execute the query with EXPLAIN, and look at the
estimated rows and costs. If the row number is large, just round it to
the nearest thousand and return it to the application as a count ---
this is what Google does for searches (just try it).
If the row count/cost are low, run the query and return an exact count.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: bruce@momjian.us, bricklen@gmail.com, neil.whelchel@gmail.com
Subject: Re: Slow count(*) again...
In-Reply-To: <201010210407.o9L47M912017@momjian.us>
References: <AANLkTimXSWapozrZNdiRXDSm2hdsha1As94NwuS967As@mail.gmail.com> <201010210407.o9L47M912017@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox