X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D40A830FC24 for ; Thu, 26 Jun 2003 13:15:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48130-10 for ; Thu, 26 Jun 2003 10:15:19 -0300 (ADT) Received: from server.beierfeld.kabeljournal.de (pD9E1AEC9.dip.t-dialin.net [217.225.174.201]) by svr1.postgresql.org (Postfix) with SMTP id 6EA7830FC38 for ; Thu, 26 Jun 2003 10:15:17 -0300 (ADT) Received: (qmail 24209 invoked from network); 26 Jun 2003 13:15:16 -0000 Received: from station158.beierfeld.kabeljournal.de (192.168.128.158) by server.beierfeld.kabeljournal.de with SMTP; 26 Jun 2003 13:15:16 -0000 Date: Thu, 26 Jun 2003 15:15:15 +0200 From: Andre Schubert To: pgsql-performance@postgresql.org Subject: problem with pg_statistics Message-Id: <20030626151515.5fd0faf0.andre@km3.de> Organization: km3 teledienst GmbH X-Mailer: Sylpheed version 0.9.1 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200306/177 X-Sequence-Number: 2261 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