Re: Question about index scan vs seq scan when using count()

From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Question about index scan vs seq scan when using count()
Date: 2006-02-23 22:12:23
Message-ID: 20060223221223.GF11392@phlogiston.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)crankycanuck(dot)ca
It is above all style through which power defers to reason.
--J. Robert Oppenheimer

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Kashmira Patel (kupatel) 2006-02-23 22:25:34 Re: Question about index scan vs seq scan when using count()
Previous Message Kashmira Patel (kupatel) 2006-02-23 21:44:43 Question about index scan vs seq scan when using count()