Re: Poor select count(*) performance - Mailing list pgsql-general

From Scott Marlowe
Subject Re: Poor select count(*) performance
Date
Msg-id dcc563d10902231756t66feaa14jfac9ae3e81fc43c1@mail.gmail.com
Whole thread Raw
In response to Poor select count(*) performance  (Mike Ivanov <mike@thelinguist.com>)
List pgsql-general
On Mon, Feb 23, 2009 at 6:44 PM, Mike Ivanov <mike@thelinguist.com> wrote:
> Hi there,
>
> I'm sorry for a stupid question but I'm really stuck.
>
> A query:
>
> SELECT COUNT(*) FROM "lingq_card" WHERE "lingq_card"."context_id" = ...;
>
> An hour ago it took 8 seconds, one minute ago the same query took just only
> 7 milliseconds.

The two common causes are caching and changing query plans.

How many rows did it have to hit, did it use an index, which index did
it use, and were the rows it needed already in the pg shared_buffers
OR the OS / kernel file system cache when retrieved?

pgsql-general by date:

Previous
From: Mike Ivanov
Date:
Subject: Poor select count(*) performance
Next
From: Greg Smith
Date:
Subject: Re: High cpu usage after many inserts