Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id B93079FB283 for ; Sat, 5 May 2007 21:22:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 26704-03 for ; Sat, 5 May 2007 21:22:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5272B9FB1F1 for ; Sat, 5 May 2007 21:22:53 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l460Mo4e029508; Sat, 5 May 2007 20:22:50 -0400 (EDT) To: "Aaron Bono" cc: "PostgreSQL SQL List" Subject: Re: Sequence vs. Index Scan In-reply-to: References: Comments: In-reply-to "Aaron Bono" message dated "Sat, 05 May 2007 16:05:52 -0500" Date: Sat, 05 May 2007 20:22:50 -0400 Message-ID: <29507.1178410970@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/28 X-Sequence-Number: 28309 "Aaron Bono" writes: > 9. -> Seq Scan on branch (cost=0.00..4.72 rows=1 > width=1281) (actual time=130129.988..157492.057 rows=1 loops=1) > 10. Filter: ((start_day <= now()) AND > ((end_day IS NULL) OR (end_day >= now())) AND (branch_id = > get_branch_for_zip('22151'::character varying))) There is something *awfully* wacko about that entry --- the fact that the cost estimate is less than 5 units means that the planner thinks there's 4 or fewer pages; either that's way wrong or the get_branch_for_zip function is taking enormous amounts of time per row. Have you tried timing that function on its own? One possible reason for the performance difference is if you have get_branch_for_zip marked as stable in one database and volatile in the other --- volatile would prevent it from being used in an indexqual as you'd like. regards, tom lane