problem with pg_statistics

Поиск
Список
Период
Сортировка
От Andre Schubert
Тема problem with pg_statistics
Дата
Msg-id 20030626151515.5fd0faf0.andre@km3.de
обсуждение исходный текст
Ответы Re: problem with pg_statistics  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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=1231474loops=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=1231474loops=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

В списке pgsql-performance по дате отправления:

Предыдущее
От: Manfred Koizar
Дата:
Сообщение: Re: Performance advice
Следующее
От: "Fernando Papa"
Дата:
Сообщение: Re: Similar querys, better execution time on worst execution plan