Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 1167363378D for ; Tue, 25 May 2010 10:41:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 56235-05 for ; Tue, 25 May 2010 13:41:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from campbell-lange.net (campbell-lange.net [93.191.37.68]) by mail.postgresql.org (Postfix) with ESMTP id 98567633450 for ; Tue, 25 May 2010 10:41:02 -0300 (ADT) Received: from tyler by campbell-lange.net with local (Exim 4.69) (envelope-from ) id 1OGuNQ-0006oG-Ux for pgsql-performance@postgresql.org; Tue, 25 May 2010 14:41:00 +0100 Date: Tue, 25 May 2010 14:41:00 +0100 From: Tyler Hildebrandt To: pgsql-performance@postgresql.org Subject: Re: Query timing increased from 3s to 55s when used as a function instead of select Message-ID: <20100525134100.GA25592@campbell-lange.net> References: <20100525095943.GA18600@campbell-lange.net> <20100525103026.GA25341@a-kretschmer.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100525103026.GA25341@a-kretschmer.de> User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_20=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/176 X-Sequence-Number: 38760 > I think, your problem is here: > > SELECT INTO current_user * FROM > fn_medirota_validate_rota_master(in_currentuser); > > > The planner has no knowledge about how many rows this functions returns > if he don't know the actual parameter. Because of this, this query > enforce a seq-scan. Try to rewrite that to something like: > > execute 'select * from fn_medirota_validate_rota_master(' || > in_currentuser' || ')' into current_user > Thanks for your response. This doesn't seem to solve our issue, unfortunately. As a side to that, we have the fn_medirota_validate_rota_master calls in a large amount of our other functions that are running very well. -- Tyler Hildebrandt Software Developer tyler@campbell-lange.net Campbell-Lange Workshop www.campbell-lange.net 020 7631 1555 3 Tottenham Street London W1T 2AF Registered in England No. 04551928