pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: pgsql-sql@postgresql.org
Subject: Re: Question about index scan vs seq scan when using count()
Date: Thu, 23 Feb 2006 17:12:23 -0500
Message-ID: <20060223221223.GF11392@phlogiston.dyndns.org> (raw)
In-Reply-To: <18AE59788A3FC640A367E5652E664D800199BEA7@xmb-sjc-237.amer.cisco.com>
References: <18AE59788A3FC640A367E5652E664D800199BEA7@xmb-sjc-237.amer.cisco.com>

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



view thread (7+ messages)  latest in thread

Message-ID: <20060223221223.GF11392@phlogiston.dyndns.org>
Permalink:  ../20060223221223.GF11392@phlogiston.dyndns.org/
Also on:    postgresql.org/message-id/20060223221223.GF11392@phlogiston.dyndns.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ajs@crankycanuck.ca
  Subject: Re: Question about index scan vs seq scan when using count()
  In-Reply-To: <20060223221223.GF11392@phlogiston.dyndns.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox