Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLWMw-0005oC-Mj for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jun 2017 15:07:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dLWMw-0004hq-9U for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jun 2017 15:07:34 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dLWLL-00047L-AI for pgsql-hackers@postgresql.org; Thu, 15 Jun 2017 15:05:55 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLWLH-0000wf-WE for pgsql-hackers@postgresql.org; Thu, 15 Jun 2017 15:05:54 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 6289A21C2028; Thu, 15 Jun 2017 18:05:49 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Date: Thu, 15 Jun 2017 18:05:48 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1497539149; bh=1czSro2P9b0rlr6Z7h3IO8TQCMgcfcu1aO4omgdWtdg=; h=From:To:Cc:Subject:In-Reply-To:References; b=R1CApOQNEvEgGVNbTo6IBAKMhHSOdV62p62K/Jfocad7COCObyZMQqBHfufb3IFfC HTT2lRnMycHx/s6o5VmBoacY/Mt/OKxTCp90qeIK6w3wUK6W/tRGCN6+0ojH85MbIg 6qkGbJaW/jyBOnj6E9w6qNnvfFqq/TSks1Xhsvuk= From: Ildus Kurbangaliev To: Etsuro Fujita Cc: Ashutosh Bapat , Dilip Kumar , PostgreSQL Hackers , Robert Haas Subject: Re: Bug in ExecModifyTable function and trigger issues for foreign tables Message-ID: <20170615180548.5e142ddc@wp.localdomain> In-Reply-To: References: <20170514150525.0346ba72@postgrespro.ru> <20170515121638.0c076bcc@wp.localdomain> <20170515165455.545dd3d6@wp.localdomain> <20170516150516.1b616230@wp.localdomain> Organization: Postgres Professional X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Mon, 5 Jun 2017 17:25:27 +0900 Etsuro Fujita wrote: > On 2017/06/02 18:10, Etsuro Fujita wrote: > > On 2017/05/16 21:36, Etsuro Fujita wrote: > >> One approach I came up with to fix this issue is to rewrite the > >> targetList entries of an inherited UPDATE/DELETE properly using > >> rewriteTargetListUD, when generating a plan for each child table > >> in inheritance_planner. Attached is a WIP patch for that. Maybe > >> I am missing something, though. > > > > While updating the patch, I noticed the patch rewrites the UPDATE > > targetList incorrectly in some cases; rewrite_inherited_tlist I > > added to adjust_appendrel_attrs (1) removes all junk items from the > > targetList and (2) adds junk items for the child table using > > rewriteTargetListUD, but it's wrong to drop all junk items in cases > > where there are junk items for some other reasons than > > rewriteTargetListUD. Consider junk items containing MULTIEXPR > > SubLink. One way I came up with to fix this is to change (1) to > > only remove junk items with resname; since junk items added by > > rewriteTargetListUD should have resname (note: we would need > > resname to call ExecFindJunkAttributeInTlist at execution time!) > > while other junk items wouldn't have resname (see > > transformUpdateTargetList), we could correctly replace junk items > > added by rewriteTargetListUD for the parent with ones for the > > child, by that change. I might be missing something, though. > > Comments welcome. > > I updated the patch that way. Please find attached an updated > version. > > Other changes: > * Moved the initialization for "tupleid" I added in ExecModifyTable > as discussed before, which I think is essentially the same as > proposed by Ildus in [1], since I think that would be more consistent > with "oldtuple". > * Added regression tests. > > Anyway I'll add this to the next commitfest. > > Best regards, > Etsuro Fujita > > [1] > https://www.postgresql.org/message-id/20170514150525.0346ba72%40postgrespro.ru Checked the latest patch. Looks good. Shouldn't this patch be backported to 9.6 and 10beta? The bug affects them too. -- --- Ildus Kurbangaliev Postgres Professional: http://www.postgrespro.com Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers