Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id AE5AC96C49C for ; Sat, 18 Feb 2012 12:03:01 -0400 (AST) Received: from mailout04.ims-firmen.de ([213.174.32.250]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RymkU-0001ov-RV for pgsql-performance@postgresql.org; Sat, 18 Feb 2012 16:03:00 +0000 Received: from mailin02.ims-firmen.de ([192.168.1.111]) by mailout02.ims-firmen.de with esmtp (envelope-from ) id 1RymkH-0000q8-Gt for pgsql-performance@postgresql.org; Sat, 18 Feb 2012 17:02:45 +0100 Received: from [87.170.212.208] (helo=a-kretschmer.de) by mailin02.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1RymkH-0007jy-B9 for pgsql-performance@postgresql.org; Sat, 18 Feb 2012 17:02:45 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1RymkG-0006BL-EQ for pgsql-performance@postgresql.org; Sat, 18 Feb 2012 17:02:44 +0100 Date: Sat, 18 Feb 2012 17:02:44 +0100 From: Andreas Kretschmer To: pgsql-performance@postgresql.org Subject: Re: Query slow as Function Message-ID: <20120218160244.GA23315@tux> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/131 X-Sequence-Number: 46303 Steve Horn wrote: > Execute the function: select * from geocode_carrier_route_by_geocode('xyz'); > > This query takes 500 milliseconds to run. My question of course is why? Wild guess: The planner doesn't know the actual value of the input-parameter, so the planner doesn't use the Index. > > Related: If I create a function and assign LANGUAGE 'sql', my function runs in > the expected 10 milliseconds. Is there some overhead to using the plpgsql > language? The planner, in this case, knows the actual value. > > Thanks for any help in clarifying my understanding! You can check the plan with the auto_explain - Extension, and you can force the planner to create a plan based on the actual input-value by using dynamic SQL (EXECUTE 'your query string' inside the function) As i said, wild guess ... Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°