Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bn3Ne-0008Ki-N7 for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Sep 2016 12:45:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bn3Ne-0007Bg-3c for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Sep 2016 12:45:34 +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 1bn3Nc-0007AG-DL for pgsql-hackers@postgreSQL.org; Thu, 22 Sep 2016 12:45:32 +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.84_2) (envelope-from ) id 1bn3NG-0004EQ-JR for pgsql-hackers@postgreSQL.org; Thu, 22 Sep 2016 12:45:31 +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 u8MCj8g4032469 for ; Thu, 22 Sep 2016 08:45:08 -0400 From: Tom Lane To: pgsql-hackers@postgreSQL.org Subject: Executor's internal ParamExecData Params versus EvalPlanQual Date: Thu, 22 Sep 2016 08:45:08 -0400 Message-ID: <32468.1474548308@sss.pgh.pa.us> X-Pg-Spam-Score: -5.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 I looked into the misbehavior reported in bug #14328, https://www.postgresql.org/message-id/20160919160136.1348.55251@wrigleys.postgresql.org What is happening is that during the EvalPlanQual recheck to see whether the updated row still satisfies the SELECT's quals, we run ExecInitCteScan and then CteScanNext in the EPQ-created copy of the plan tree. This should result in a fresh scan of the underlying CTE ... but it does not, because ExecInitCteScan sees the communication value estate->es_param_exec_vals[node->cteParam] already set and decides it is not a leader node, but rather a follower of the outer-query CTE Scan node that it's a doppelganger of. That one's already at EOF so the node->leader->eof_cte test fails in CteScanNext and it returns nothing. The reason this happens is that EvalPlanQualBegin copies down all the es_param_exec_vals values from the outer query into the EPQ execution state. That's OK for most uses of es_param_exec_vals values, but not at all for cteParam Params, which are used as internal communication variables within a plan tree. I believe that recursive unions are probably broken in EPQ rechecks in the same way, since they use a Param for similar intra-plan communication purposes, but haven't bothered to devise a test case to prove it. I think the most robust way to fix this is to explicitly mark es_param_exec_vals entries as to whether they should be copied down to the EPQ execution state. There is room in struct ParamExecData to fit a uint8 or uint16 field into existing pad space, so we could add a flags field and then use one bit of it for this purpose without causing any ABI breaks in the back branches. A simpler fix would be to decide that we never need to copy any es_param_exec_vals entries into the EPQ execution state. I think that that would work, but it would provoke extra evaluations of InitPlan subplans, and I'm hesitant to make such a significant behavioral change without a lot more analysis. Comments? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers