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

From Andrew Sullivan
Subject Re: Question about index scan vs seq scan when using count()
Date
Msg-id 20060223221223.GF11392@phlogiston.dyndns.org
Whole thread Raw
In response to Question about index scan vs seq scan when using count()  ("Kashmira Patel \(kupatel\)" <kupatel@cisco.com>)
List pgsql-sql
On Thu, Feb 23, 2006 at 01:44:43PM -0800, Kashmira Patel (kupatel) wrote:
> My understanding of this statement is that if I use count() without a
> WHERE clause, then essentially, it is applied to the entire table and
> hence requires a seq scan.
> But it should not require a seq scan if I have a condition. 

It may not require it, but it might select it anyway.

> 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?

A
-- 
Andrew Sullivan  | ajs@crankycanuck.ca
It is above all style through which power defers to reason.    --J. Robert Oppenheimer


pgsql-sql by date:

Previous
From: "Kashmira Patel \(kupatel\)"
Date:
Subject: 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()