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 1l1uFf-0003bn-K5 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jan 2021 16:53:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l1uFe-0001I1-J6 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jan 2021 16:53:06 +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 1l1uFe-0001Ht-C6 for pgsql-hackers@lists.postgresql.org; Tue, 19 Jan 2021 16:53:06 +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 1l1uFb-0003pH-CQ for pgsql-hackers@postgresql.org; Tue, 19 Jan 2021 16:53:05 +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 10JGr2kY482866; Tue, 19 Jan 2021 11:53:02 -0500 From: Tom Lane To: David Geier cc: pgsql-hackers@postgresql.org Subject: Re: search_plan_tree(): handling of non-leaf CustomScanState nodes causes segfault In-reply-to: <478756.1611069597@sss.pgh.pa.us> References: <0253344d-9bdd-11c4-7f0d-d88c02cd7991@swarm64.com> <347100.1610995608@sss.pgh.pa.us> <3ad851cf-ce22-ace0-726d-56209e214981@swarm64.com> <416507.1611009730@sss.pgh.pa.us> <00d461cf-c919-6a3e-2dda-c1b5d2207f3d@swarm64.com> <478756.1611069597@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 19 Jan 2021 10:19:57 -0500" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <482797.1611075078.0@sss.pgh.pa.us> Date: Tue, 19 Jan 2021 11:53:02 -0500 Message-ID: <482865.1611075182@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <482797.1611075078.1@sss.pgh.pa.us> I wrote: > Now that I look at this, I strongly wonder whether whoever added > MergeAppend support here understood what they were doing. That > looks broken, because child nodes will typically be positioned on > tuples, whether or not the current top-level output came from them. > So I fear we could get a false-positive confirmation that some > tuple matches WHERE CURRENT OF. Urgh, indeed it's buggy. With the attached test script I get ... BEGIN DECLARE CURSOR f1 | f2 ----+----- 1 | one (1 row) UPDATE 1 UPDATE 1 UPDATE 1 COMMIT f1 | f2 ----+------------- 1 | one updated (1 row) f1 | f2 ----+------------- 2 | two updated (1 row) f1 | f2 ----+--------------- 3 | three updated (1 row) where clearly only the row with f1=1 should have updated (and if you leave off ORDER BY, so as to get a Merge not MergeAppend plan, indeed only that row updates). I shall go fix this, and try to improve the evidently-inadequate comments in search_plan_tree. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/plain; name="where-current-of-merge-append.sql"; charset="us-ascii" Content-ID: <482797.1611075078.2@sss.pgh.pa.us> Content-Description: where-current-of-merge-append.sql drop table if exists t1,t2,t3; create table t1 (f1 int unique, f2 text); insert into t1 values (1, 'one'); create table t2 (f1 int unique, f2 text); insert into t2 values (2, 'two'); create table t3 (f1 int unique, f2 text); insert into t3 values (3, 'three'); explain select * from t1 union all select * from t2 union all select * from t3 order by 1; begin; declare c cursor for select * from t1 union all select * from t2 union all select * from t3 order by 1; fetch 1 from c; update t1 set f2 = f2 || ' updated' where current of c; update t2 set f2 = f2 || ' updated' where current of c; update t3 set f2 = f2 || ' updated' where current of c; commit; table t1; table t2; table t3; ------- =_aaaaaaaaaa0--