X-Original-To: pgsql-admin@postgresql.org Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by postgresql.org (Postfix) with ESMTP id 8FE1E475ECE for ; Fri, 21 Mar 2003 13:15:15 -0500 (EST) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.4) with ESMTP-TLS id 1671135; Fri, 21 Mar 2003 10:51:25 -0800 Message-ID: <3E7B561E.8070805@joeconway.com> Date: Fri, 21 Mar 2003 10:12:46 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Jodi Kanter , Postgres Admin List Subject: Re: indexes not being used! References: <004101c2efc0$65e6d0a0$de138f80@virginia.edu> <3E7B3365.5090603@joeconway.com> <007701c2efc3$f5bed260$de138f80@virginia.edu> <14197.1048269769@sss.pgh.pa.us> In-Reply-To: <14197.1048269769@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200303/348 X-Sequence-Number: 7988 Tom Lane wrote: > Jodi Kanter writes: > >>I apologize if this is the wrong list. I have posted explain analyzes below. > > > Given the small size of the tables, I think the planner is doing the > right thing not to use indexes. Seqscans are probably less I/O until > the tables get a lot bigger. If you want to convince yourself of this, try EXPLAIN ANALYZE on your query with enable_seqscan set to off (discard the first result however, because in either case some caching will happen). For example: regression=# select * from foo; f0 | f1 | f2 ----+------+------- 1 | cat1 | 1.21 2 | cat1 | 1.24 3 | cat1 | 1.18 4 | cat1 | 1.26 5 | cat1 | 1.15 6 | cat2 | 1.15 7 | cat2 | 1.26 8 | cat2 | 1.32 9 | cat2 | 1.3 10 | cat3 | 3.333 (10 rows) regression=# VACUUM ANALYZE; VACUUM regression=# create index foo_idx on foo(f0); CREATE INDEX regression=# explain analyze select * from foo where f0 = 1; QUERY PLAN -------------------------------------------------------------------------------------------- Seq Scan on foo (cost=0.00..1.12 rows=2 width=20) (actual time=0.03..0.05 rows=1 loops=1) Filter: (f0 = 1) Total runtime: 0.22 msec (3 rows) regression=# set enable_seqscan to off; SET regression=# explain analyze select * from foo where f0 = 1; QUERY PLAN ------------------------------------------------------------------------------------------------------------ Index Scan using foo_idx on foo (cost=0.00..3.01 rows=2 width=20) (actual time=0.06..0.07 rows=1 loops=1) Index Cond: (f0 = 1) Total runtime: 0.20 msec (3 rows) regression=# set enable_seqscan to on; SET regression=# explain analyze select * from foo where f0 = 1; QUERY PLAN -------------------------------------------------------------------------------------------- Seq Scan on foo (cost=0.00..1.12 rows=2 width=20) (actual time=0.03..0.05 rows=1 loops=1) Filter: (f0 = 1) Total runtime: 0.14 msec (3 rows) HTH, Joe