pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Geier <david@swarm64.com>
Cc: pgsql-hackers@postgresql.org
Subject: Re: search_plan_tree(): handling of non-leaf CustomScanState nodes causes segfault
Date: Tue, 19 Jan 2021 11:53:02 -0500
Message-ID: <482865.1611075182@sss.pgh.pa.us> (raw)
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>

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

Attachments:

where-current-of-merge-append.sql (text/plain, 692B) download 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;

view thread (13+ messages)

Message-ID: <482865.1611075182@sss.pgh.pa.us>
Permalink:  ../482865.1611075182@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/482865.1611075182@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david@swarm64.com
  Subject: Re: search_plan_tree(): handling of non-leaf CustomScanState nodes causes segfault
  In-Reply-To: <482865.1611075182@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox