pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
Date: Fri, 26 Jun 2015 18:31:00 -0300
Message-ID: <20150626213100.GU3289@postgresql.org> (raw)
In-Reply-To: <CAB7nPqQSDPX5C6HWY7KZp-2Jh1QwSUk-hJ-mXG0vWGjWveqvOA@mail.gmail.com>
References: <CAB7nPqQNS36enM2R=6P9FvKUu7t3k=2EjFkFBPnby==pLFqQ+w@mail.gmail.com>
	<20150525155248.GG5885@postgresql.org>
	<CAB7nPqR3oeggsoVqKrgvoS=mJCfH1qMbFHjCGj2RVLu0Nf7Sjg@mail.gmail.com>
	<CAB7nPqSLYNb3PN18ZoFHHbsb4D6A8WZNYKV_xPidG+K0o5GmMg@mail.gmail.com>
	<CAB7nPqT2SZ39N_wH+WK8JGPKO3LCyWQiLoxgcgq_UyPJNc8hSg@mail.gmail.com>
	<20150604212429.GN133018@postgresql.org>
	<CAB7nPqT71m-VGHk1qdV7LMAgxBVM+5xHfu-nA_RBBi6BMJbm7g@mail.gmail.com>
	<20150621192520.GG133018@postgresql.org>
	<CAB7nPqQSDPX5C6HWY7KZp-2Jh1QwSUk-hJ-mXG0vWGjWveqvOA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

remove-commandCollected.patch (text/x-diff, 5.6K) download 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);

view thread (14+ messages)  latest in thread

Message-ID: <20150626213100.GU3289@postgresql.org>
Permalink:  ../20150626213100.GU3289@postgresql.org/
Also on:    postgresql.org/message-id/20150626213100.GU3289@postgresql.org

 ·  · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: alvherre@2ndquadrant.com, michael.paquier@gmail.com
  Subject: Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
  In-Reply-To: <20150626213100.GU3289@postgresql.org>
  References: <CAB7nPqQNS36enM2R=6P9FvKUu7t3k=2EjFkFBPnby==pLFqQ+w@mail.gmail.com> <20150525155248.GG5885@postgresql.org> <CAB7nPqR3oeggsoVqKrgvoS=mJCfH1qMbFHjCGj2RVLu0Nf7Sjg@mail.gmail.com> <CAB7nPqSLYNb3PN18ZoFHHbsb4D6A8WZNYKV_xPidG+K0o5GmMg@mail.gmail.com> <CAB7nPqT2SZ39N_wH+WK8JGPKO3LCyWQiLoxgcgq_UyPJNc8hSg@mail.gmail.com> <20150604212429.GN133018@postgresql.org> <CAB7nPqT71m-VGHk1qdV7LMAgxBVM+5xHfu-nA_RBBi6BMJbm7g@mail.gmail.com> <20150621192520.GG133018@postgresql.org> <CAB7nPqQSDPX5C6HWY7KZp-2Jh1QwSUk-hJ-mXG0vWGjWveqvOA@mail.gmail.com> <20150626213100.GU3289@postgresql.org>

* 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