Re: Performance : Optimize query

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Areski <areski5(at)hotmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Performance : Optimize query
Date: 2002-11-13 15:19:47
Message-ID: 20021113071630.N79695-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 13 Nov 2002, Areski wrote:

> Hi Everybody,
>
>
> I have this following query : select count(*) from "Data" where
> "IDOrigin"='29';
> It's take more less 2 minutes to run... It's really slow...
> Some one maybe knows about how to optimize "select count"
>
> Below, there are the expalin analyse of the query.
>
>
> EXPLAIN ANALYZE select count(*) from "Data" where "IDOrigin"='29';
> NOTICE: QUERY PLAN:
>
> Aggregate (cost=108945.77..108945.77 rows=1 width=0) (actual
> time=108845.29..108845.30 rows=1 loops=1)
> -> Seq Scan on Data (cost=0.00..107152.11 rows=717462 width=0) (actual
> time=18233.46..106927.60 rows=1457826 loops=1)
> Total runtime: 108845.50 msec.

Let's go through the normal stuff :)

Have you used vacuum analyze recently? How many rows are in the table?
How many rows actually have IDOrigin=29 (ie, is 717462 a valid estimate)?
If it's not a reasonable estimate, you might want to raise the number of
statistic buckets the column is getting (alter table "Data" alter
column "IDOrigin" SET STATISTICS <number> where the default value is 10)
and running vacuum analyze again.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Nigel J. Andrews 2002-11-13 15:29:05 Planner's choice
Previous Message Stephan Szabo 2002-11-13 15:15:51 Re: error: lost syncronization with server