Re: select count(*) from anIntColumn where int_value = 0;

From: Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>
To: David Teran <david(dot)teran(at)cluster9(dot)com>
Cc: PgSQL Performance ML <pgsql-performance(at)postgresql(dot)org>
Subject: Re: select count(*) from anIntColumn where int_value = 0;
Date: 2004-02-11 13:11:13
Message-ID: Pine.LNX.4.44.0402111408350.27123-100000@kix.fsv.cvut.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello,

If you has index on id, then you can use
SELECT id FROM tabulka ORDER BY id DESC LIMIT 1;

See 4.8. FAQ

Regards
Pavel Stehule

On Wed, 11 Feb 2004, David Teran wrote:

> Hi
>
> we have a table with about 4 million rows. One column has an int value,
> there is a btree index on it. We tried to execute the following
> statement and it is very slow on a dual G5 2GHZ with 4 GB of RAM.
>
> explain analyze select count(*) from job_property where int_value = 0;
>
> Aggregate (cost=144348.80..144348.80 rows=1 width=0) (actual
> time=13536.852..13536.852 rows=1 loops=1)
> -> Seq Scan on job_property (cost=0.00..144255.15 rows=37459
> width=0) (actual time=19.422..13511.653 rows=42115 loops=1)
> Filter: (int_value = 0)
> Total runtime: 13560.862 ms
>
>
>
> Is this more or less normal or can we optimize this a little bit?
> FrontBase (which we compare currently) takes 2 seconds first time and
> about 0.2 seconds on second+ queries.
>
> regards David
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Rigmor Ukuhe 2004-02-11 13:12:00 Re: select count(*) from anIntColumn where int_value = 0; is very slow
Previous Message David Teran 2004-02-11 13:03:15 select count(*) from anIntColumn where int_value = 0; is very slow