Re: select count(*) is slow - Mailing list pgsql-performance

From aditya desai
Subject Re: select count(*) is slow
Date
Msg-id CAN0SRDHcVYtpadNDNEk7EHjX6re0UEunG-k1Vxi-ojPA5VK_1Q@mail.gmail.com
Whole thread Raw
In response to Re: select count(*) is slow  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: select count(*) is slow  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-performance
Thanks Tom. Will try with numeric. Please ignore table and index naming.

On Tue, Apr 6, 2021 at 6:55 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
aditya desai <admad123@gmail.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

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: select count(*) is slow
Next
From: Andrew Dunstan
Date:
Subject: Re: select count(*) is slow