X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0A6B2D1B26C for ; Fri, 2 Jul 2004 10:00:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18639-05 for ; Fri, 2 Jul 2004 13:00:33 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 0D84DD1B1D5 for ; Fri, 2 Jul 2004 10:00:27 -0300 (ADT) Received: (qmail 25503 invoked by uid 500); 2 Jul 2004 13:07:10 -0000 Date: Fri, 2 Jul 2004 08:07:10 -0500 From: Bruno Wolff III To: Peter Alberer Cc: pgsql-performance@postgresql.org Subject: Re: Mysterious performance of query because of plsql function in where condition Message-ID: <20040702130710.GA25007@wolff.to> Mail-Followup-To: Peter Alberer , pgsql-performance@postgresql.org References: <000001c46009$062e8260$5be0d089@ekelhardt> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000001c46009$062e8260$5be0d089@ekelhardt> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.1 tagged_above=0.0 required=5.0 tests=MAILTO_TO_SPAM_ADDR X-Spam-Level: * X-Archive-Number: 200407/7 X-Sequence-Number: 7398 On Fri, Jul 02, 2004 at 09:48:48 +0200, Peter Alberer wrote: > > Postgres seems to execute the function "submission_status" for every row > of > the submissions table (~1500 rows). The query therefore takes quite a > lot > time, although in fact no row is returned from the assignments table > when > the condition package_id=949589 is used. If submission_status is invertable you might want to create the inverse function, mark it immutable and call it with 'closed'. That would allow the optimizer to compare submissions.submission_id to a constant. Another option would be be to create an index on submission_status(submissions.submission_id).