Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ez33V-0002uG-Tr for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Mar 2018 16:27:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ez33U-0002CU-Q6 for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Mar 2018 16:27:08 +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.89) (envelope-from ) id 1ez33U-0002CK-7t for pgsql-hackers@lists.postgresql.org; Thu, 22 Mar 2018 16:27:08 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ez33P-0000Oi-IL for pgsql-hackers@postgresql.org; Thu, 22 Mar 2018 16:27:07 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 2261C21A96; Thu, 22 Mar 2018 12:27:02 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Thu, 22 Mar 2018 12:27:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=SBcs9E1iNuuin+XjOSdmUmC5sz1ru 2mnFYFs+tIcfxw=; b=d/RIDiKn7ErG4EVsH5YG8PFIQDq42XIQUIyF3wyBX8bF/ /mGtfYRsz4wqAWIsV81L38/BGomcAoyXURbS/jFTCww+yKm99JqEq42bUsGU4TxM /Q7qeXVCoVtqgIPzk8xOO+Mad+u9Cyp2TJHUmJ9aWhDJbXN2Ch4d3PeIbalPjLtK LVxqvqVdYQbVcuDLYHMsMRev+mkJ6faHaSsyUUvKRCJ0/UgZomoIpfHAUWGXIasr F4YxAutpsxV4eHZnkbclk1fRxq6P8viik+XFL2DDl/4E7LHeu1ODRbxqx2IuXnEB V0KxtP1r6LVfZ9gAWks7TWsmIcQdHywYa72bhonPw== X-ME-Sender: Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 739FE7E13F; Thu, 22 Mar 2018 12:27:01 -0400 (EDT) Subject: Re: FOR EACH ROW triggers on partitioned tables To: Alvaro Herrera References: <20180321231839.5zcjxvdgwrhgjwua@alvherre.pgsql> Cc: Thomas Munro , Robert Haas , Pg Hackers , Simon Riggs From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: Date: Thu, 22 Mar 2018 12:27:00 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180321231839.5zcjxvdgwrhgjwua@alvherre.pgsql> Content-Type: multipart/mixed; boundary="------------B66B6AFF9463E5DA9B36B7A2" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------B66B6AFF9463E5DA9B36B7A2 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 3/21/18 19:18, Alvaro Herrera wrote: > Here's v8, which addresses all your comments except the doc updates. I > added a few more tests, too. Thanks for the review! I intend to commit > this shortly, probably not before Friday to give some more time for > others to review/comment. Looks good, does what it needs to do. A small fixup attached. In particular, I renamed one trigger from "f", which created confusing output, looking like a boolean column. This comment in the tests I don't understand: -- verify that the FOR UPDATE OF (columns) is propagated correctly I don't see how this applies to the tests that follow. Does this have something to do with the subsequent foreign keys patch perhaps? -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------B66B6AFF9463E5DA9B36B7A2 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="0001-fixup-Allow-FOR-EACH-ROW-triggers-on-partitioned-tab.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-fixup-Allow-FOR-EACH-ROW-triggers-on-partitioned-tab.pa"; filename*1="tch" From 37c41e1be7fbc1a02c7d543a471c84aee7b75a9f Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 22 Mar 2018 12:07:54 -0400 Subject: [PATCH] fixup! Allow FOR EACH ROW triggers on partitioned tables --- src/include/catalog/pg_constraint.h | 2 +- src/include/commands/trigger.h | 2 +- src/test/regress/expected/triggers.out | 36 +++++++++++++++++----------------- src/test/regress/sql/triggers.sql | 10 +++++----- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h index 45b26cdfa8..3957e07235 100644 --- a/src/include/catalog/pg_constraint.h +++ b/src/include/catalog/pg_constraint.h @@ -73,7 +73,7 @@ CATALOG(pg_constraint,2606) Oid conindid; /* index supporting this constraint */ /* - * if this constraint is on a partition inherited from a partitioned table, + * If this constraint is on a partition inherited from a partitioned table, * this is the OID of the corresponding constraint in the parent. */ Oid conparentid; diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index 2a6f2cd934..a5b8610fa2 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -159,7 +159,7 @@ extern PGDLLIMPORT int SessionReplicationRole; extern ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, - Oid funcid, Oid parentTriggerOid, Node *whenClause, + Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition); extern void RemoveTriggerById(Oid trigOid); diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out index 2cb56efdf9..a4e9ea03f3 100644 --- a/src/test/regress/expected/triggers.out +++ b/src/test/regress/expected/triggers.out @@ -1871,7 +1871,7 @@ drop table parted_trig; -- create table trigpart (a int, b int) partition by range (a); create table trigpart1 partition of trigpart for values from (0) to (1000); -create trigger f after insert on trigpart for each row execute procedure trigger_nothing(); +create trigger trg1 after insert on trigpart for each row execute procedure trigger_nothing(); create table trigpart2 partition of trigpart for values from (1000) to (2000); create table trigpart3 (like trigpart); alter table trigpart attach partition trigpart3 for values from (2000) to (3000); @@ -1879,32 +1879,32 @@ select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; tgrelid | tgname | tgfoid -----------+--------+----------------- - trigpart | f | trigger_nothing - trigpart1 | f | trigger_nothing - trigpart2 | f | trigger_nothing - trigpart3 | f | trigger_nothing + trigpart | trg1 | trigger_nothing + trigpart1 | trg1 | trigger_nothing + trigpart2 | trg1 | trigger_nothing + trigpart3 | trg1 | trigger_nothing (4 rows) -drop trigger f on trigpart1; -- fail -ERROR: cannot drop trigger f on table trigpart1 because trigger f on table trigpart requires it -HINT: You can drop trigger f on table trigpart instead. -drop trigger f on trigpart2; -- fail -ERROR: cannot drop trigger f on table trigpart2 because trigger f on table trigpart requires it -HINT: You can drop trigger f on table trigpart instead. -drop trigger f on trigpart3; -- fail -ERROR: cannot drop trigger f on table trigpart3 because trigger f on table trigpart requires it -HINT: You can drop trigger f on table trigpart instead. +drop trigger trg1 on trigpart1; -- fail +ERROR: cannot drop trigger trg1 on table trigpart1 because trigger trg1 on table trigpart requires it +HINT: You can drop trigger trg1 on table trigpart instead. +drop trigger trg1 on trigpart2; -- fail +ERROR: cannot drop trigger trg1 on table trigpart2 because trigger trg1 on table trigpart requires it +HINT: You can drop trigger trg1 on table trigpart instead. +drop trigger trg1 on trigpart3; -- fail +ERROR: cannot drop trigger trg1 on table trigpart3 because trigger trg1 on table trigpart requires it +HINT: You can drop trigger trg1 on table trigpart instead. drop table trigpart2; -- ok, trigger should be gone in that partition select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; tgrelid | tgname | tgfoid -----------+--------+----------------- - trigpart | f | trigger_nothing - trigpart1 | f | trigger_nothing - trigpart3 | f | trigger_nothing + trigpart | trg1 | trigger_nothing + trigpart1 | trg1 | trigger_nothing + trigpart3 | trg1 | trigger_nothing (3 rows) -drop trigger f on trigpart; -- ok, all gone +drop trigger trg1 on trigpart; -- ok, all gone select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; tgrelid | tgname | tgfoid diff --git a/src/test/regress/sql/triggers.sql b/src/test/regress/sql/triggers.sql index 4d35f39f29..edb7a2f978 100644 --- a/src/test/regress/sql/triggers.sql +++ b/src/test/regress/sql/triggers.sql @@ -1305,19 +1305,19 @@ CREATE RULE european_city_delete_rule AS ON DELETE TO european_city_view -- create table trigpart (a int, b int) partition by range (a); create table trigpart1 partition of trigpart for values from (0) to (1000); -create trigger f after insert on trigpart for each row execute procedure trigger_nothing(); +create trigger trg1 after insert on trigpart for each row execute procedure trigger_nothing(); create table trigpart2 partition of trigpart for values from (1000) to (2000); create table trigpart3 (like trigpart); alter table trigpart attach partition trigpart3 for values from (2000) to (3000); select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; -drop trigger f on trigpart1; -- fail -drop trigger f on trigpart2; -- fail -drop trigger f on trigpart3; -- fail +drop trigger trg1 on trigpart1; -- fail +drop trigger trg1 on trigpart2; -- fail +drop trigger trg1 on trigpart3; -- fail drop table trigpart2; -- ok, trigger should be gone in that partition select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; -drop trigger f on trigpart; -- ok, all gone +drop trigger trg1 on trigpart; -- ok, all gone select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; -- 2.16.2 --------------B66B6AFF9463E5DA9B36B7A2--