Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1elbyF-0001am-2o for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Feb 2018 14:54:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elbyD-0003qg-E1 for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Feb 2018 14:54:09 +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 1elbyD-0003qX-8N for pgsql-bugs@lists.postgresql.org; Tue, 13 Feb 2018 14:54:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1elbyA-0007L3-5P for pgsql-bugs@lists.postgresql.org; Tue, 13 Feb 2018 14:54:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w1DErxvw029609; Tue, 13 Feb 2018 09:54:00 -0500 From: Tom Lane To: Andrew Gierth cc: Marko Tiikkaja , pgsql-bugs@lists.postgresql.org, dejan.petrovic@islonline.com, Peter Eisentraut Subject: Re: BUG #15060: Row in table not found when using pg function in an expression In-reply-to: <87vaf1qfps.fsf@news-spur.riddles.org.uk> References: <151844034484.1446.1721073839109092583@wrigleys.postgresql.org> <876072rphi.fsf@news-spur.riddles.org.uk> <12102.1518466287@sss.pgh.pa.us> <87vaf1qfps.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Tue, 13 Feb 2018 12:35:25 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29607.1518533639.1@sss.pgh.pa.us> Date: Tue, 13 Feb 2018 09:53:59 -0500 Message-ID: <29608.1518533639@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "Marko" == Marko Tiikkaja writes: > Marko> I'm not sure I understand. When's the snapshot used for planning > Marko> actually taken here? > GetCachedPlan will use either whatever snapshot is already set, if there > is one, or it will set one of its own (actually at least two: separate > snapshots for revalidate + parse analysis and for planning). Hm. So we could improve on the fix I proposed earlier if there were a way to tell GetCachedPlan "take a new snapshot even though there is an active snapshot". It's still expensive, but at least the code path where we use an existing generic plan doesn't get any added cost. CC'ing Peter because of this part: > The recent introduction of procedures exposes this interesting little > variation in behavior (pg11 only): > ... > I assume that what's going on here is that the commit, which ends the > transaction in which the DO was invoked and begins a new one, doesn't > set a new active snapshot in the new transaction, and so planning of the > perform in the second case is taking new snapshots inside GetCachedPlan. I find this concerning. No part of plpgsql, or any other PL, has ever before executed without the constant presence of an ActiveSnapshot. It seems likely to me that this will expose, if not outright bugs, at least strange differences in behavior between "procedure" code and "function" code. Perhaps the commit-and-restart-transaction code ought to include pushing a new ActiveSnapshot. regards, tom lane