Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lr3YS-0006Af-67 for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jun 2021 19:07:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lr3YR-0005DQ-4e for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jun 2021 19:07:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lr3YQ-0005DG-TA for pgsql-hackers@lists.postgresql.org; Wed, 09 Jun 2021 19:07:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lr3YO-0006PT-JW for pgsql-hackers@lists.postgresql.org; Wed, 09 Jun 2021 19:07:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 159J7mbr1428038; Wed, 9 Jun 2021 15:07:48 -0400 From: Tom Lane To: Alvaro Herrera cc: Yura Sokolov , pgsql-hackers@lists.postgresql.org Subject: Re: Add PortalDrop in exec_execute_message In-reply-to: <1422606.1623259559@sss.pgh.pa.us> References: <202106072208.jeksdphlipvp@alvherre.pgsql> <1029215.1623104149@sss.pgh.pa.us> <1422606.1623259559@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 09 Jun 2021 13:25:59 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1428036.1623265668.1@sss.pgh.pa.us> Date: Wed, 09 Jun 2021 15:07:48 -0400 Message-ID: <1428037.1623265668@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > It turns out that the problem is specific to SELECT FOR UPDATE, and > it happens because nodeLockRows is not careful to shut down the > EvalPlanQual mechanism it uses before returning NULL at the end of > a scan. If EPQ has been fired, it'll be holding a tuple slot > referencing whatever tuple it was last asked about. The attached > trivial patch seems to take care of the issue nicely, while adding > little if any overhead. (A repeat call to EvalPlanQualEnd doesn't > do much.) BTW, to be clear: I think Alvaro's change is also necessary. If libpq is going to silently do something different in pipeline mode than it does in normal mode, it should strive to minimize the semantic difference. exec_simple_query includes a PortalDrop, so we'd best do the same in pipeline mode. But this LockRows misbehavior would be visible in other operating modes anyway. regards, tom lane