Re: Select very slow

From: Mark Kirkwood <markir(at)i4free(dot)co(dot)nz>
To: dave(at)slickness(dot)org, feblec(at)ig(dot)com(dot)br, jks(at)selectacast(dot)netT
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Select very slow
Date: 2001-03-20 08:59:58
Message-ID: 01032020595800.00632@spikey.slithery.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>
> That 'count(*)' is going to be slow.
> Try counting a column that's indexed (p.doc might work?)

That is not the case, you can convince yourself with explain - you get the
same plan(s) :

e.g : ( table dim0 with indexed column d0key ) ...

explain select count(*) from dim0 where d0key < 1000;

Aggregate (cost=96.13..96.13 rows=1 width=0)
-> Index Scan using dim0_pk on dim0 (cost=0.00..93.63 rows=1000 width=0)

explain select count(d0key) from dim0 where d0key < 1000;

Aggregate (cost=96.13..96.13 rows=1 width=4)
-> Index Scan using dim0_pk on dim0 (cost=0.00..93.63 rows=1000 width=4)

> (the tables and query snipped..).
> anyone help-me ?
>

I would try to make the primary key ( doc) a fixed length varchar(n) instead
of text if possible, as text is intended for very long strings and btree
indexes usually perform best on (small) fixed length columns.

If your key is going to be a really long string then maybe rethink the design
( use a "synthetic" key like a sequence or integer checksum of doc to index
on ).

perform a vacuum analyze and then post the output of the explain below to
this list !

explain select p.city,count(*) from sales s, person p where s.doc = p.doc
group by p.city;

Cheers

Mark

Browse pgsql-sql by date

  From Date Subject
Next Message guard 2001-03-20 10:00:55 help pgsql 7.1beta & delphi
Previous Message Rachel Coin 2001-03-20 08:48:21 Categories and subcategories