Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tu7GE-0006MB-8P for pgsql-bugs@arkaria.postgresql.org; Sat, 12 Jan 2013 20:00:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tu7GD-000799-5l for pgsql-bugs@arkaria.postgresql.org; Sat, 12 Jan 2013 20:00:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tu7GC-000794-HG for pgsql-bugs@postgresql.org; Sat, 12 Jan 2013 20:00:56 +0000 Received: from mout.gmx.net ([74.208.4.201]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tu7G9-000065-S3 for pgsql-bugs@postgresql.org; Sat, 12 Jan 2013 20:00:55 +0000 Received: from mailout-us.gmx.com ([172.19.198.41]) by mrigmx.server.lan (mrigmxus001) with ESMTP (Nemesis) id 0MgL1W-1TZip02diY-00NkEx for ; Sat, 12 Jan 2013 21:00:52 +0100 Received: (qmail 24572 invoked by uid 0); 12 Jan 2013 20:00:52 -0000 Received: from 76.255.19.161 by rms-us010 with HTTP Cc: "Rodrigo Rosenfeld Rosas" ,pgsql-bugs@postgresql.org Content-Type: text/plain; charset="utf-8" Date: Sat, 12 Jan 2013 15:00:51 -0500 From: "Kevin Grittner" Message-ID: <20130112200051.255800@gmx.com> MIME-Version: 1.0 Subject: Re: wrong search_path being used To: "Andres Freund" X-Authenticated: #138763884 X-Flags: 0001 X-Mailer: GMX.com Web Mailer x-registered: 0 Content-Transfer-Encoding: 8bit X-GMX-UID: pKWDcIgC3zOlOQ09LnwhCGJ+IGRvb4De X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Andres Freund wrote: > On 2013-01-12 14:29:38 -0500, Tom Lane wrote: >> "Kevin Grittner" writes: >>> To try to get your function code to work as you expect, the >>> language would essentially need to identify which statements could >>> be pre-planned, and which would needed to be treated as raw source >>> on each execution. That would be tricky to implement, and would >>> itself have some run-time cost. At this point we've put the burden >>> on the programmer to identify this at the time the code is written, >>> rather than adding run-time expense. >> >> I think that the alternative most likely to succeed is to consider any >> change in the active value of search_path as forcing replanning of >> cached plans. This wouldn't be that hard to implement but there's >> a definite risk of loss of performance due to unnecessary replanning >> (since the path change might or might not affect the particular query). >> It's also not unlikely that it could break applications that work today, >> because they depend -- perhaps without being aware of it -- on the >> existing first-path-wins behavior. >> >> Having said that, it seems likely that more people would prefer that >> behavior than the existing one. But it hasn't been clear enough to >> justify making such a subtly incompatible change. > > Its a somewhat common practise to use SET in functions or as a > configuration parameter to functions. I think at least the latter should > still work without forcing to replan any query. Given that we advice > setting the search path for SECURITY DEFINER... > > I guess it wouldn't really be feasible to keep the search path used to > plan a query in its cached form and check that it fits the one currently > used on every use of the cached plan? The particular complaint here is about:  perform pg_catalog.set_config('search_path', text_parameter, true);  select ... from unqualified_tablename ...; The table used is based on the parameter passed on the first execution; the local search_path set on subsequent executions is ignored.  Perhaps we should just not save a plan for any function which sets a new search_path while it is executing? -Kevin -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs