pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedSeq Scan
3+ messages / 3 participants
[nested] [flat]
* Seq Scan
@ 2007-06-01 16:48 Tyler Durden <tylersticky@gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Tyler Durden @ 2007-06-01 16:48 UTC (permalink / raw)
To: pgsql-performance
Hi,
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?
Thanks,
Tyler
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Seq Scan
@ 2007-06-01 16:59 Dan Harris <fbsd@drivefaster.net>
parent: Tyler Durden <tylersticky@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Dan Harris @ 2007-06-01 16:59 UTC (permalink / raw)
To: pgsql-performance
Tyler Durden wrote:
> Hi,
> 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?
>
> Thanks,
> Tyler
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
select count(*) will *always* do a sequential scan, due to the MVCC
architecture. See archives for much discussion about this.
-Dan
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Seq Scan
@ 2007-06-01 17:03 Michael Glaesemann <grzm@seespotcode.net>
parent: Tyler Durden <tylersticky@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Michael Glaesemann @ 2007-06-01 17:03 UTC (permalink / raw)
To: Tyler Durden <tylersticky@gmail.com>; +Cc: pgsql-performance
On Jun 1, 2007, at 11:48 , Tyler Durden wrote:
> I'm having some problems in performance in a simple select count(id)
> from....
Unrestricted count() (i.e., no WHERE clause) will perform a
sequential scan. If you're looking for faster ways to store table row
count information, please search the archives, as this has been
discussed many times before.
> # explain select (id) from table_name;
> -[ RECORD
> 1 ]----------------------------------------------------------------
> QUERY PLAN | Seq Scan on table_name (cost=0.00..8601.30
> rows=266730 width=4)
The query returns the id column value for each row in the table. The
fastest way to do this is visiting every row., i.e., a sequential
scan. Using an index would require (1) looking in the index and (2)
looking up the corresponding row.
Michael Glaesemann
grzm seespotcode net
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-06-01 17:03 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-06-01 16:48 Seq Scan Tyler Durden <tylersticky@gmail.com>
2007-06-01 16:59 ` Dan Harris <fbsd@drivefaster.net>
2007-06-01 17:03 ` Michael Glaesemann <grzm@seespotcode.net>
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