Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3HZ7-0001B8-O0 for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Apr 2017 07:40:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3HZ7-0006Xz-5X for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Apr 2017 07:40:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d3HXc-0003pt-NC for pgsql-hackers@postgresql.org; Wed, 26 Apr 2017 07:39:12 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3HXV-0002gN-LO for pgsql-hackers@postgresql.org; Wed, 26 Apr 2017 07:39:12 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id A6A3321C2A6A; Wed, 26 Apr 2017 10:39:02 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Subject: Re: Cached plans and statement generalization DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1493192341; bh=/IE1BARE3qZAdEpC3tLQ/gZTTGElPrOCqNHdRiqRymQ=; h=To:References:Cc:From:Date:In-Reply-To; b=h3VVZto1SYUp44Htgcs5sNsP1z2oAzDCkBmaOmv3cXr25tuVZuhAAgwMLGD646yfr J7taHHXy4ZCF5QiUxVN94SwT+LDbXHI/US0IgyFcrBCDy4EaewCl7Jq2JZ3n3uhqbb RGASo0WJlRlUNmOpxqgleUkTdQLlrbSGRaKZYc34= To: Andres Freund , Doug Doole References: <1f4c1a22-ecbe-811d-4695-ee4701b8f6c7@postgrespro.ru> <58FFB391.5080101@postgrespro.ru> <58FFB5F0.2020900@postgrespro.ru> <20170425214746.3mngxgbo7yndfgax@alap3.anarazel.de> <20170425223448.amnhdludwondarph@alap3.anarazel.de> Cc: Serge Rielau , Pg Hackers From: Konstantin Knizhnik Message-ID: <617f73cb-b679-81e3-8c4e-92166ad4d0fc@postgrespro.ru> Date: Wed, 26 Apr 2017 10:39:05 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170425223448.amnhdludwondarph@alap3.anarazel.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 26.04.2017 01:34, Andres Freund wrote: > Hi, > > (FWIW, on this list we don't do top-quotes) > > On 2017-04-25 22:21:22 +0000, Doug Doole wrote: >> Plan invalidation was no different than for any SQL statement. DB2 keeps a >> list of the objects the statement depends on. If any of the objects changes >> in an incompatible way the plan is invalidated and kicked out of the cache. >> >> I suspect what is more interesting is plan lookup. DB2 has something called >> the "compilation environment". This is a collection of everything that >> impacts how a statement is compiled (SQL path, optimization level, etc.). >> Plan lookup is done using both the statement text and the compilation >> environment. So, for example, if my path is DOUG, MYTEAM, SYSIBM and your >> path is ANDRES, MYTEAM, SYSIBM we will have different compilation >> environments. If we both issue "SELECT * FROM T" we'll end up with >> different cache entries even if T in both of our statements resolves to >> MYTEAM.T. If I execute "SELECT * FROM T", change my SQL path and then >> execute "SELECT * FROM T" again, I have a new compilation environment so >> the second invocation of the statement will create a new entry in the >> cache. The first entry is not kicked out - it will still be there for >> re-use if I change my SQL path back to my original value (modulo LRU for >> cache memory management of course). > It's not always that simple, at least in postgres, unless you disregard > search_path. Consider e.g. cases like > > CREATE SCHEMA a; > CREATE SCHEMA b; > CREATE TABLE a.foobar(somecol int); > SET search_patch = 'b,a'; > SELECT * FROM foobar; > CREATE TABLE b.foobar(anothercol int); > SELECT * FROM foobar; -- may not be cached plan from before! > > it sounds - my memory of DB2 is very faint, and I never used it much - > like similar issues could arise in DB2 too? There is the same problem with explicitly prepared statements, isn't it? Certainly in case of using prepared statements it is responsibility of programmer to avoid such collisions. And in case of autoprepare programmer it is hidden from programming. But there is guc variable controlling autoprepare feature and by default it is switched off. So if programmer or DBA enables it, then them should take in account effects of such decision. By the way, isn't it a bug in PostgreSQL that altering search path is not invalidating cached plans? As I already mentioned, the same problem can be reproduced with explicitly prepared statements. > > Greetings, > > Andres Freund -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers