Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 1E8289F9700 for ; Fri, 31 Aug 2007 21:03:49 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 91775-01 for ; Fri, 31 Aug 2007 21:03:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from itspmx51.state.ms.us (relay.ms.gov [205.144.225.177]) by postgresql.org (Postfix) with ESMTP id 8D65E9F9508 for ; Fri, 31 Aug 2007 21:03:41 -0300 (ADT) Received: from itspmx51.state.ms.us (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id E1BD15B14 for ; Thu, 31 Aug 2000 19:03:34 -0500 (CDT) Received: from rray.drdc.mstc.ms.gov (unknown [10.3.192.2]) by itspmx51.state.ms.us (Postfix) with ESMTP id CD8105B11 for ; Thu, 31 Aug 2000 19:03:34 -0500 (CDT) Received: from rray.drdc.mstc.ms.gov (localhost.localdomain [127.0.0.1]) by rray.drdc.mstc.ms.gov (8.13.8/8.13.8) with ESMTP id l8103d5i010532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 31 Aug 2007 19:03:40 -0500 Received: from localhost (rray@localhost) by rray.drdc.mstc.ms.gov (8.13.8/8.13.8/Submit) with ESMTP id l8103djE010529 for ; Fri, 31 Aug 2007 19:03:39 -0500 X-Authentication-Warning: rray.drdc.mstc.ms.gov: rray owned process doing -bs Date: Fri, 31 Aug 2007 19:03:39 -0500 (CDT) From: Richard Ray X-X-Sender: rray@rray.drdc.mstc.ms.gov To: pgsql-sql@postgresql.org Subject: Re: How to influence the planner In-Reply-To: <2005.1188596277@sss.pgh.pa.us> Message-ID: References: <373D2F52-E9CD-485A-9BF1-B019349FA5EC@seespotcode.net> <2005.1188596277@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: ClamAV 0.91.1/4112/Fri Aug 31 15:01:59 2007 on rray.drdc.mstc.ms.gov X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/275 X-Sequence-Number: 29213 On Fri, 31 Aug 2007, Tom Lane wrote: > Richard Ray writes: >> On Fri, 31 Aug 2007, Michael Glaesemann wrote: >>> EXPLAIN ANALYZE will help you see what the planner is doing to produce the >>> results. > >> mda=# EXPLAIN ANALYZE select * from t1 where length(bar) = 0 order by foo; >> QUERY PLAN >> --------------------------------------------------------------- >> Index Scan using t1_pkey on t1 (cost=0.00..46698478.18 >> rows=60038 width=334) (actual time=4612.740..2349582.520 rows=32705 >> loops=1) >> Filter: (length(bar) = 0) >> Total runtime: 2349614.258 ms >> (3 rows) > >> mda=# EXPLAIN ANALYZE select * from t1 where length(bar) = 0; >> QUERY PLAN >> --------------------------------------------------------------- >> Seq Scan on t1 (cost=100000000.00..102020349.17 rows=60038 >> width=334) (actual time=39.065..108645.233 rows=32705 loops=1) >> Filter: (length(bar) = 0) >> Total runtime: 108677.759 ms >> (3 rows) > > The problem here is you've got enable_seqscan = off. Don't do that. > That will make it use an index if it possibly can, whether using one > is a good idea or not. In this case, since the useful condition on > length(bar) is not indexable, the best available index-using scan > uses the index to implement order by foo ... which is pointless here > in terms of saving runtime. > >> I'm running PostgreSQL 8.1.0 on Fedora Core 6 > > Please update. There are a *lot* of bugs fixed in the 8.1.x series > since then. Changing to enable_seqscan = on does solve this problem, thanks Is there some method of crafting a query that will assert my wishes to the planner mda=# EXPLAIN ANALYZE select * from (select * from t1 where length(bar) = 0) a order by foo; QUERY PLAN ------------------------------------------------------------------------ Index Scan using t1_pkey on t1 (cost=0.00..46698482.18 rows=60038 width=334) (actual time=4784.869..2317363.298 rows=32705 loops=1) Filter: (length(bar) = 0) Total runtime: 2317395.137 ms (3 rows) When is enable_seqscan = off appropriate > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 7: You can help support the PostgreSQL project by donating at > > http://www.postgresql.org/about/donate >