Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dAukv-0000zT-DO for pgsql-hackers@arkaria.postgresql.org; Wed, 17 May 2017 08:56:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dAuku-0002OC-4Q for pgsql-hackers@arkaria.postgresql.org; Wed, 17 May 2017 08:56:28 +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 1dAuks-0002Ln-1h for pgsql-hackers@postgresql.org; Wed, 17 May 2017 08:56:26 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dAukj-00054M-TN for pgsql-hackers@postgresql.org; Wed, 17 May 2017 08:56:24 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id CA08F21C0689; Wed, 17 May 2017 11:56:14 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Date: Wed, 17 May 2017 11:54:37 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1495011374; bh=lK9qYHMqJruc1ZWpAUCe260/1QUciqqr20P4apymwgI=; h=From:To:Cc:Subject:In-Reply-To:References; b=DJhjRIgxQBNV+yw0wr0qLbm42XjuezDpyeAzLwzHYkAAlULVRvK9Zn0fOgcYbsr/P 61DsIB1dXIKnD9sY6PAz1kc+LTBAMwqXH+d0jqmvpvxesRumSfKGw/0peHn9RdcGNG iDyFpg3KsJ3PxxilXp5je7o/rZOmx2YKtbl2iRi0= From: Ildus Kurbangaliev To: Michael Paquier Cc: Etsuro Fujita , Ashutosh Bapat , Dilip Kumar , PostgreSQL Hackers Subject: Re: Bug in ExecModifyTable function and trigger issues for foreign tables Message-ID: <20170517115437.710dedb9@wp.localdomain> In-Reply-To: References: <20170514150525.0346ba72@postgrespro.ru> <20170515121638.0c076bcc@wp.localdomain> <20170515165455.545dd3d6@wp.localdomain> <20170516150516.1b616230@wp.localdomain> <20170516172600.291220dc@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 X-Pg-Spam-Score: -2.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 On Wed, 17 May 2017 15:28:24 +0900 Michael Paquier wrote: > On Tue, May 16, 2017 at 11:26 PM, Ildus Kurbangaliev > wrote: > > On Tue, 16 May 2017 21:36:11 +0900 > > Etsuro Fujita wrote: > >> On 2017/05/16 21:11, Ashutosh Bapat wrote: > >> > On Tue, May 16, 2017 at 5:35 PM, Ildus Kurbangaliev > >> > wrote: > >> > >> >> I agree. Maybe this issue should be added to Postgresql Open > >> >> Items? I think there should be some complex solution that fixes > >> >> not only triggers for foreign tables at table partitioning, but > >> >> covers other possible not working cases. > >> > >> > I doubt if this is an open item, since DMLs on foreign tables are > >> > supported since 9.3 and support to add foreign tables to > >> > inheritance was added back in 9.5. > >> > >> I think this issue was introduced by the latter, so that was my > >> fault. > >> > >> 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. > > Could this patch include some regression tests to see at what extent > it has been tested? We surely don't want to see that broken again in > the future as well. (Nit: I did not look at the patch in details yet) > > > I tested the patch, looks good. > > What kind of tests did you do? I tested update triggers for foreign table when regular table is a parent and foreign table is a child. Case like this: explain verbose update parent set val = random(); QUERY PLAN ------------------------------------------------------------------------------- Update on public.parent (cost=0.00..258.63 rows=5535 width=10) Update on public.parent Update on public.child1 Foreign Update on public.ftable // we have triggers on ftable here > > junkfilter = resultRelInfo->ri_junkFilter; > + tupleid = NULL; > estate->es_result_relation_info = resultRelInfo; > Er, what is that? That fixes the bug when tupleid from regular tuple is used to get oldtuple for triggers of foreign table. -- --- 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