Re: Seq Scan

From: "John D(dot) Burger" <john(at)mitre(dot)org>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Seq Scan
Date: 2007-06-01 17:03:42
Message-ID: 2E99D81C-596B-473D-8555-750AF0CC182A@mitre.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tyler Durden wrote:

> I'm having some problems in performance in a simple select count(id)
> from.... I have 700 000 records in one table, and when I do:
>
> # explain select (id) from table_name;
> -[ RECORD
> 1 ]----------------------------------------------------------------
> QUERY PLAN | Seq Scan on table_name (cost=0.00..8601.30
> rows=266730 width=4)
>
> I had created an index for id(btree), but still shows "Seq Scan".
> What I'm doing wrong?

You mention SELECT COUNT(ID), but your example shows SELECT ID. In
either case, the planner is choosing the correct plan. Indexes exist
to save the engine from visiting every row in the table, but both of
these queries require every row to be visited anyway.

Perhaps you think that these queries can be satisfied without
visiting the actual table rows at all, using only the index. This is
incorrect - PG doesn't work that way.

- John Burger
MITRE

In response to

  • Seq Scan at 2007-06-01 16:49:34 from Tyler Durden

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2007-06-01 17:07:00 Re: warm standby server stops doingcheckpointsafterawhile
Previous Message Joshua D. Drake 2007-06-01 17:02:41 Re: Seq Scan