Re: select count(*) is slow

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: aditya desai <admad123(at)gmail(dot)com>
Cc: Pgsql Performance <pgsql-performance(at)lists(dot)postgresql(dot)org>
Subject: Re: select count(*) is slow
Date: 2021-04-06 13:25:53
Message-ID: 970586.1617715553@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

aditya desai <admad123(at)gmail(dot)com> writes:
> Below query takes 12 seconds. We have an index on postcode.

> select count(*) from table where postcode >= '00420' AND postcode <= '00500'

That query does not match this index:

> CREATE INDEX Table_i1
> ON table USING btree
> ((postcode::numeric));

You could either change postcode to numeric, change all your queries
of this sort to include the cast explicitly, or make an index that
doesn't have a cast.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message aditya desai 2021-04-06 13:30:26 Re: select count(*) is slow
Previous Message aditya desai 2021-04-06 13:19:16 Re: Substitute for synonym in Oracle after migration to postgres