Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 09ED49FB2D9 for ; Sun, 6 May 2007 01:37:30 -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 19291-08 for ; Sun, 6 May 2007 01:37:24 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.249]) by postgresql.org (Postfix) with ESMTP id 9994B9FB2A2 for ; Sun, 6 May 2007 01:37:25 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id d17so41110and for ; Sat, 05 May 2007 21:37:25 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=F+Ai+O7c8ypl7eEAfRDE1W8stNNI1Yj/Ig5eajYFJjf285JpnsQtMbliEI+zO7c9pTjey3OrEnKQv83Yaakno/ztZXETBZUc/BABoRdiAs7FYj0GGLO1JyueVMEqirqdfTormtAvJPIQi7U+dOzmxomv3TYVtX1DhQevuAAakyA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Hxeduh/uwG6wCIlx9DUbXI3doNJr+Crlvjqs4bFe4jh9fK66ox47tXPgrjZgkE7qMQhCYUOIG9nZsq5YqmSo0fqEm5OVt3rvAfr5lzLOuTU4iE2xFQSUqyPiOjkk9KQO/l86jCM0SEIkiBQMcehLwIMCAsQyZj35vYSAEcmRbYY= Received: by 10.100.189.17 with SMTP id m17mr1326271anf.1178426245044; Sat, 05 May 2007 21:37:25 -0700 (PDT) Received: by 10.100.41.18 with HTTP; Sat, 5 May 2007 21:37:24 -0700 (PDT) Message-ID: Date: Sat, 5 May 2007 23:37:24 -0500 From: "Jaime Casanova" To: "Aaron Bono" Subject: Re: Sequence vs. Index Scan Cc: "Tom Lane" , "PostgreSQL SQL List" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <29507.1178410970@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/33 X-Sequence-Number: 28314 On 5/5/07, Aaron Bono wrote: > On 5/5/07, Tom Lane wrote: > > "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. > > > > I verified it by putting a RAISE NOTICE in the function. The fast schema > runs the function twice (odd, I would think it would run only once). The > slow schema runs it 30 times (the number of records returned + 1). I know I > put the functions into both schemas as stable and even dropped and recreated > the function. Then I verified with EMS Manager and it tells me the DDL for > the function in the database is set to stable. Is there something I can do > to tell PostgreSQL that I really did mean stable? > maybe this is silly but you can verify what the database thinks of the function selecting from pg_proc select pronamespace, provolatile from pg_proc where proname = 'get_branch_for_zip' -- regards, Jaime Casanova "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots. So far, the universe is winning." Richard Cook