problem with pg_statistics

From: Andre Schubert <andre(at)km3(dot)de>
To: pgsql-performance(at)postgresql(dot)org
Subject: problem with pg_statistics
Date: 2003-06-26 13:15:15
Message-ID: 20030626151515.5fd0faf0.andre@km3.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi,

i think i need a little help with a problem with pg_statistic.
Lets say i have a table to collect traffic-data.
The table has a column time_stamp of type timesamptz.
The table has a single-column index on time_stamp.
The table has around 5 million records.

If i delete all statistical data from pg_statistic and do a
explain analyze i got this result.

-------------------------------------------------------------------------
explain analyze select * from tbl_traffic where tbl_traffic.time_stamp >= '2003-05-01' and tbl_traffic.time_stamp < '2003-06-01';
NOTICE: QUERY PLAN:

Index Scan using idx_ts on tbl_traffic (cost=0.00..97005.57 rows=24586 width=72) (actual time=0.19..7532.63 rows=1231474 loops=1)
Total runtime: 8179.08 msec

EXPLAIN
-------------------------------------------------------------------------

after i do a vacuum full verbose analyze i got the following result.

-------------------------------------------------------------------------
explain analyze select * from tbl_traffic where tbl_traffic.time_stamp >= '2003-05-01' and tbl_traffic.time_stamp < '2003-06-01';
NOTICE: QUERY PLAN:

Seq Scan on tbl_traffic (cost=0.00..127224.24 rows=1197331 width=52) (actual time=0.03..14934.70 rows=1231474 loops=1)
Total runtime: 15548.35 msec

EXPLAIN
-------------------------------------------------------------------------

now i disable seqscans with set enable_seqscan to off
and i got the following.

-------------------------------------------------------------------------
explain analyze select * from tbl_traffic where tbl_traffic.time_stamp >= '2003-05-01' and tbl_traffic.time_stamp < '2003-06-01';
NOTICE: QUERY PLAN:

Index Scan using idx_ts on tbl_traffic (cost=0.00..3340294.11 rows=1197331 width=52) (actual time=0.21..7646.29 rows=1231474 loops=1)
Total runtime: 8285.92 msec

EXPLAIN
-------------------------------------------------------------------------

Could anybody explain or give some hint why the index is not used
although it is faster than a sequence-scan ?
BTW:
version
-----------------------------------------------------------
PostgreSQL 7.2 on i686-pc-linux-gnu, compiled by GCC 2.96

Thanks in advance, as

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Fernando Papa 2003-06-26 13:33:38 Re: Similar querys, better execution time on worst execution plan
Previous Message Manfred Koizar 2003-06-26 12:49:54 Re: Performance advice