Skip site navigation (1) Skip section navigation (2)

Re: Yet again on indices...

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Jean-Paul ARGUDO <jean-paul(dot)argudo(at)idealx(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>, <sdinot(at)idealx(dot)com>,<dbarth(at)idealx(dot)com>
Subject: Re: Yet again on indices...
Date: 2002-02-27 15:03:37
Message-ID: 20020227065743.O2599-100000@megazone23.bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Wed, 27 Feb 2002, Jean-Paul ARGUDO wrote:

> EXPLAIN SELECT t12_bskid, t12_pnb, t12_lne, t12_tck
> FROM T12_20011231
> WHERE t12_bskid >= 1
> ORDER BY t12_bskid, t12_pnb, t12_tck, t12_lne;
>
> NOTICE:  QUERY PLAN:
>
> Sort  (cost=3006.13..3006.13 rows=25693 width=46)
>   ->  Seq Scan on t12_20011231  (cost=0.00..1124.20 rows=25693 width=46)
>
> => not good, table t12_20011231 as 26K tuples :-(

>
> => create index t12_idx_bskid_20011231 on t12_20011231 (t12_bskid);
>
> Sort  (cost=3006.13..3006.13 rows=25693 width=46)
>   ->  Seq Scan on t12_20011231  (cost=0.00..1124.20 rows=25693 width=46)
>
> => probably statistic refresh to be done:
> $ /usr/local/pgsql/bin/vacuumdb --analyze dbks
>
> Sort  (cost=3006.13..3006.13 rows=25693 width=46)
>   ->  Seq Scan on t12_20011231  (cost=0.00..1124.20 rows=25693 width=46)
>
>
> => Uh? Seq scan cheaper than index???
>
> => let's disable seqscan to read cost of index:
> postgresql.conf : enable_seqscan = false
>
> Sort  (cost=3126.79..3126.79 rows=25693 width=46)
>   ->  Index Scan using t12_idx_bskid_20011231 on t12_20011231
> (cost=0.00..1244.86 rows=25693 width=46)
>
> => Uh? seq scan'cost is lower than index scan??  => mailto hackers
>
> ----
>

> What's your opinion?

Well you didn't send the schema, or explain analyze results to show
which is actually faster, but...

Sequence scan *can be* faster than index scan when a large portion of the
table is going to be read.  If the data is randomly distributed,
eventually you end up reading most/all of the table blocks anyway to get
the validity information for the rows and you're doing it in random order,
plus you're reading parts of the index as well. How many rows are in
the table, and how many match t12_bskid >=1?


In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2002-02-27 15:13:35
Subject: Re: Refactoring of command.c
Previous:From: Jean-Paul ARGUDODate: 2002-02-27 14:59:00
Subject: Re: Yet again on indices...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group