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

From: "Kashmira Patel \(kupatel\)" <kupatel(at)cisco(dot)com>
To: "Andrew Sullivan" <ajs(at)crankycanuck(dot)ca>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Question about index scan vs seq scan when using count()
Date: 2006-02-23 22:55:59
Message-ID: 18AE59788A3FC640A367E5652E664D800199BF22@xmb-sjc-237.amer.cisco.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


This is how I created the index:

CREATE INDEX msgid_index ON vm_message(msgid);

I guess it doing this because its a small table then. I will try putting
more values.

Thanks,
Kashmira

-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org
[mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Andrew Sullivan
Sent: Thursday, February 23, 2006 2:47 PM
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Question about index scan vs seq scan when using
count()

On Thu, Feb 23, 2006 at 02:25:34PM -0800, Kashmira Patel (kupatel)
wrote:
>
> [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?

EXPLAIN ANALYSE will always choose the same plan as EXPLAIN. The
difference is that it shows you the estimate and actual.

I am surprised you're getting a seqscan for that, though. Is there
something about the index you're not telling us?

Is your system tuned correctly? Maybe 600 rows is so small that a
seqscan's just as fast.

A

--
Andrew Sullivan | ajs(at)crankycanuck(dot)ca
"The year's penultimate month" is not in truth a good way of saying
November.
--H.W. Fowler

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

Browse pgsql-sql by date

  From Date Subject
Next Message Owen Jacobson 2006-02-23 23:08:20 Re: Question about index scan vs seq scan when using count()
Previous Message Andrew Sullivan 2006-02-23 22:47:23 Re: Question about index scan vs seq scan when using count()