Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8bDK-0006zm-38 for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jun 2015 21:31:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z8bDJ-0002dO-F7 for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jun 2015 21:31:09 +0000 Received: from makus.postgresql.org ([174.143.35.229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Z8bDI-0002dE-HK for pgsql-bugs@postgresql.org; Fri, 26 Jun 2015 21:31:08 +0000 Received: from smtp-auth.no-ip.com ([8.23.224.61] helo=out.smtp-auth.no-ip.com) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1Z8bDE-0007uf-VF for pgsql-bugs@postgresql.org; Fri, 26 Jun 2015 21:31:07 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [181.226.157.110]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 9C13A400D39; Fri, 26 Jun 2015 14:31:02 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 7C5973ED5; Fri, 26 Jun 2015 18:31:00 -0300 (CLT) Date: Fri, 26 Jun 2015 18:31:00 -0300 From: Alvaro Herrera To: Michael Paquier Cc: PostgreSQL mailing lists Subject: Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Message-ID: <20150626213100.GU3289@postgresql.org> References: <20150525155248.GG5885@postgresql.org> <20150604212429.GN133018@postgresql.org> <20150621192520.GG133018@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2B/JsCI69OhZNC5r" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --2B/JsCI69OhZNC5r Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Michael Paquier wrote: > On Mon, Jun 22, 2015 at 4:25 AM, Alvaro Herrera wrote: > > Thanks, pushed that part of it. Looking at the event trigger bits next. > > Thanks for looking at that. Not sure if that's useful, but attached is > a rebased version of the rest. Pushed the fixes to transform and the new test file, thanks; didn't push the other changes for ObjectAddressEq() and the changes in ProcessUtilitySlow. These are attached. I don't want to lose that stuff: I would like to have an assertion that verifies that the branch in the large switch has at least given some thought to command collection (precisely to prevent bugs of the type being fixed here.) One problem is cases that return InvalidObjectAddress because of IF NOT EXISTS, for instance, so it's not just a one-line assert addition. I just noticed I neglected to credit for authorship in the commit message, sorry about that :-( -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --2B/JsCI69OhZNC5r Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="remove-commandCollected.patch" diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index cc10c5e..1c4f12d 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -1657,6 +1657,10 @@ EventTriggerCollectSimpleCommand(ObjectAddress address, MemoryContext oldcxt; CollectedCommand *command; + /* ignore if no objects to operate on */ + if (ObjectAddressEq(address, InvalidObjectAddress)) + return; + /* ignore if event trigger context not set, or collection disabled */ if (!currentEventTriggerState || currentEventTriggerState->commandCollectionInhibited) diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 0dabcc1..21aa7dc 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -912,8 +912,7 @@ ProcessUtilitySlow(Node *parsetree, bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL); bool isCompleteQuery = (context <= PROCESS_UTILITY_QUERY); bool needCleanup; - bool commandCollected = false; - ObjectAddress address; + ObjectAddress address = InvalidObjectAddress; ObjectAddress secondaryObject = InvalidObjectAddress; /* All event trigger calls are done only when isCompleteQuery is true */ @@ -938,7 +937,6 @@ ProcessUtilitySlow(Node *parsetree, * EventTriggerCollectSimpleCommand called by * CreateSchemaCommand */ - commandCollected = true; break; case T_CreateStmt: @@ -1026,9 +1024,9 @@ ProcessUtilitySlow(Node *parsetree, /* * The multiple commands generated here are stashed - * individually, so disable collection below. + * individually, so collection is disabled. */ - commandCollected = true; + address = InvalidObjectAddress; } break; @@ -1106,7 +1104,6 @@ ProcessUtilitySlow(Node *parsetree, } /* ALTER TABLE stashes commands internally */ - commandCollected = true; break; case T_AlterDomainStmt: @@ -1272,7 +1269,7 @@ ProcessUtilitySlow(Node *parsetree, */ EventTriggerCollectSimpleCommand(address, secondaryObject, parsetree); - commandCollected = true; + address = InvalidObjectAddress; EventTriggerAlterTableEnd(); } break; @@ -1317,13 +1314,11 @@ ProcessUtilitySlow(Node *parsetree, case T_DropUserMappingStmt: RemoveUserMapping((DropUserMappingStmt *) parsetree); /* no commands stashed for DROP */ - commandCollected = true; break; case T_ImportForeignSchemaStmt: ImportForeignSchema((ImportForeignSchemaStmt *) parsetree); /* commands are stashed inside ImportForeignSchema */ - commandCollected = true; break; case T_CompositeTypeStmt: /* CREATE TYPE (composite) */ @@ -1353,7 +1348,7 @@ ProcessUtilitySlow(Node *parsetree, EventTriggerCollectSimpleCommand(address, secondaryObject, parsetree); /* stashed internally */ - commandCollected = true; + address = InvalidObjectAddress; EventTriggerAlterTableEnd(); break; @@ -1430,7 +1425,6 @@ ProcessUtilitySlow(Node *parsetree, case T_CreateOpClassStmt: DefineOpClass((CreateOpClassStmt *) parsetree); /* command is stashed in DefineOpClass */ - commandCollected = true; break; case T_CreateOpFamilyStmt: @@ -1444,7 +1438,6 @@ ProcessUtilitySlow(Node *parsetree, case T_AlterOpFamilyStmt: AlterOpFamily((AlterOpFamilyStmt *) parsetree); /* commands are stashed in AlterOpFamily */ - commandCollected = true; break; case T_AlterTSDictionaryStmt: @@ -1458,13 +1451,11 @@ ProcessUtilitySlow(Node *parsetree, case T_AlterTableMoveAllStmt: AlterTableMoveAll((AlterTableMoveAllStmt *) parsetree); /* commands are stashed in AlterTableMoveAll */ - commandCollected = true; break; case T_DropStmt: ExecDropStmt((DropStmt *) parsetree, isTopLevel); /* no commands stashed for DROP */ - commandCollected = true; break; case T_RenameStmt: @@ -1488,19 +1479,16 @@ ProcessUtilitySlow(Node *parsetree, case T_GrantStmt: ExecuteGrantStmt((GrantStmt *) parsetree); /* commands are stashed in ExecGrantStmt_oids */ - commandCollected = true; break; case T_DropOwnedStmt: DropOwnedObjects((DropOwnedStmt *) parsetree); /* no commands stashed for DROP */ - commandCollected = true; break; case T_AlterDefaultPrivilegesStmt: ExecAlterDefaultPrivilegesStmt((AlterDefaultPrivilegesStmt *) parsetree); EventTriggerCollectAlterDefPrivs((AlterDefaultPrivilegesStmt *) parsetree); - commandCollected = true; break; case T_CreatePolicyStmt: /* CREATE POLICY */ @@ -1525,9 +1513,8 @@ ProcessUtilitySlow(Node *parsetree, * Remember the object so that ddl_command_end event triggers have * access to it. */ - if (!commandCollected) - EventTriggerCollectSimpleCommand(address, secondaryObject, - parsetree); + EventTriggerCollectSimpleCommand(address, secondaryObject, + parsetree); if (isCompleteQuery) { diff --git a/src/include/catalog/objectaddress.h b/src/include/catalog/objectaddress.h index 37808c0..de8015d 100644 --- a/src/include/catalog/objectaddress.h +++ b/src/include/catalog/objectaddress.h @@ -40,6 +40,11 @@ extern const ObjectAddress InvalidObjectAddress; #define ObjectAddressSet(addr, class_id, object_id) \ ObjectAddressSubSet(addr, class_id, object_id, 0) +#define ObjectAddressEq(addr, addr2) \ + ((addr).classId == (addr2).classId && \ + (addr).objectId == (addr2).objectId && \ + (addr).objectSubId == (addr2).objectSubId) + extern ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok); --2B/JsCI69OhZNC5r Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --2B/JsCI69OhZNC5r--