Re: Question about index scan vs seq scan when using count() - Mailing list pgsql-sql

From Kashmira Patel \(kupatel\)
Subject Re: Question about index scan vs seq scan when using count()
Date
Msg-id 18AE59788A3FC640A367E5652E664D800199BEE8@xmb-sjc-237.amer.cisco.com
Whole thread Raw
In response to Question about index scan vs seq scan when using count()  ("Kashmira Patel \(kupatel\)" <kupatel@cisco.com>)
Responses Re: Question about index scan vs seq scan when using count()  (Andrew Sullivan <ajs@crankycanuck.ca>)
List pgsql-sql
> For example: I have a table vm_message with an index on column msgid.
> Will the following do a sequential scan or an index?
>
> select count(*) from vm_message where msgid = 3;

How much of the table is that?  How many rows?  EXPLAIN ANALYSE will
tell you if you have the right plan (estimate vs. actual).  The real
question is, are you sure an indexscan is faster?

[Kashmira] I did do an EXPLAIN ANALYZE as well, it also showed a
sequential scan. The table has about 600+ rows, with around 6 of them
matching the given id. Wouldn't an index scan be faster in this case?
Also, I have two more indices defined on this table, for other types of
queries I do on it. Would they be causing a problem? In general, is
there a rule of thumb as to when an index scan would be better than a
sequential scan?

Thanks,
Kashmira


pgsql-sql by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: Question about index scan vs seq scan when using count()
Next
From: "Kashmira Patel \(kupatel\)"
Date:
Subject: Re: Question about index scan vs seq scan when using count()