Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d392y-0000Ba-Pn for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Apr 2017 22:35:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d392x-0003jQ-Us for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Apr 2017 22:34:59 +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 1d392w-0003jG-VY for pgsql-hackers@postgresql.org; Tue, 25 Apr 2017 22:34:59 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d392p-0000Wb-0Q for pgsql-hackers@postgresql.org; Tue, 25 Apr 2017 22:34:58 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 8052621459; Tue, 25 Apr 2017 18:34:49 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 25 Apr 2017 18:34:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=TO1OhGPQRAWfAKwUbZ JyweJfYP3ZfwI2E849l9DYtv4=; b=X/Xy/P6o3HQN3uMk2ZCLFulq3Lui2Eq1CG 5lNODgNOt5Ck0aOriWnve7jFOJjthw5JwucNOr3amRiGQiMst3CXZdIUdYUGzQwn NPoi8xOkBOkghL8Z6W5R81IB0OPGswrW/84vj8mt6b0Xfv2J/voTIHwdJNVo6jl0 qAxqI2hZAhS2aBO9jS/ODiLEVvOBuUTfbKWfThKZrjw4/aXsG5IILfw1tG2nbXdu BPCrFKUxZpPuY3/+cSgoVqiwxVRQ8N9QVzNgCZK7gCju4V7cBolxZB86fbPYgm3v QJ4V8pY3EtQzAQV0j/b/AVQ/pKvrSXiT+8xTeyRO3iLiL4m6eqlw== X-ME-Sender: X-Sasl-enc: uu8ZGgUMbIm3jvg0Pur2lcVxrfAb9nKw4Z/ggX60BTq1 1493159689 Received: from intern.anarazel.de (unknown [208.72.138.107]) by mail.messagingengine.com (Postfix) with ESMTPA id 381DD24370; Tue, 25 Apr 2017 18:34:49 -0400 (EDT) Date: Tue, 25 Apr 2017 15:34:48 -0700 From: Andres Freund To: Doug Doole Cc: Konstantin Knizhnik , Serge Rielau , Pg Hackers Subject: Re: Cached plans and statement generalization Message-ID: <20170425223448.amnhdludwondarph@alap3.anarazel.de> References: <1f4c1a22-ecbe-811d-4695-ee4701b8f6c7@postgrespro.ru> <58FFB391.5080101@postgrespro.ru> <58FFB5F0.2020900@postgrespro.ru> <20170425214746.3mngxgbo7yndfgax@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -2.6 (--) 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 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? Greetings, Andres Freund -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers