pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedIncorrect processing of CREATE TRANSFORM with DDL deparding
14+ messages / 3 participants
[nested] [flat]
* Incorrect processing of CREATE TRANSFORM with DDL deparding
@ 2015-05-25 05:05 Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 14+ messages in thread
From: Michael Paquier @ 2015-05-25 05:05 UTC (permalink / raw)
To: pgsql-bugs
Hi all,
In ProcessUtilitySlow()@utility.c, for a node T_CreateTransformStmt,
process does not return ObjectAddress. This makes process inconsistent
with the other commands and the ObjectAddress passed to
EventTriggerCollectSimpleCommand is not initialized.
Coverity has pointed out the error, I just some legwork to sort out a fix.
Regards,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
20150525_transform_ddl_deparse.patch (text/x-diff, 1.7K) download
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 3d220e9..21d995b 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1740,7 +1740,7 @@ check_transform_function(Form_pg_proc procstruct)
/*
* CREATE TRANSFORM
*/
-Oid
+ObjectAddress
CreateTransform(CreateTransformStmt *stmt)
{
Oid typeid;
@@ -1938,7 +1938,7 @@ CreateTransform(CreateTransformStmt *stmt)
heap_close(relation, RowExclusiveLock);
- return transformid;
+ return myself;
}
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 7db9f96..0dabcc1 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1438,7 +1438,7 @@ ProcessUtilitySlow(Node *parsetree,
break;
case T_CreateTransformStmt:
- CreateTransform((CreateTransformStmt *) parsetree);
+ address = CreateTransform((CreateTransformStmt *) parsetree);
break;
case T_AlterOpFamilyStmt:
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index dcb6c08..9b81c16 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -51,7 +51,7 @@ extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
extern ObjectAddress CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid);
-extern Oid CreateTransform(CreateTransformStmt *stmt);
+extern ObjectAddress CreateTransform(CreateTransformStmt *stmt);
extern void DropTransformById(Oid transformOid);
extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
oidvector *proargtypes, Oid nspOid);
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
@ 2015-05-25 15:52 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Alvaro Herrera @ 2015-05-25 15:52 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs
Michael Paquier wrote:
> Hi all,
>
> In ProcessUtilitySlow()@utility.c, for a node T_CreateTransformStmt,
> process does not return ObjectAddress. This makes process inconsistent
> with the other commands and the ObjectAddress passed to
> EventTriggerCollectSimpleCommand is not initialized.
> Coverity has pointed out the error, I just some legwork to sort out a fix.
Yeah, I had noticed this and was pretty annoyed because we ended up in
precisely the situation we didn't want to be: new code is added to
ProcessUtility that is not handled by the deparse framework. (I
don't know whether TRANSFORM went in first or deparse, but it doesn't
really matter.)
The fix as you say is pretty trivial, but I would like to use this is a
test case to ensure that we will catch all these mistakes in the future
too not only this particular one.
--
Á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
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-05-25 21:47 ` Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 02:02 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Stephen Frost <sfrost@snowman.net>
0 siblings, 2 replies; 14+ messages in thread
From: Michael Paquier @ 2015-05-25 21:47 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
On Tue, May 26, 2015 at 12:52 AM, Alvaro Herrera wrote:
> Michael Paquier wrote:
>> In ProcessUtilitySlow()@utility.c, for a node T_CreateTransformStmt,
>> process does not return ObjectAddress. This makes process inconsistent
>> with the other commands and the ObjectAddress passed to
>> EventTriggerCollectSimpleCommand is not initialized.
>> Coverity has pointed out the error, I just some legwork to sort out a fix.
>
> Yeah, I had noticed this and was pretty annoyed because we ended up in
> precisely the situation we didn't want to be: new code is added to
> ProcessUtility that is not handled by the deparse framework. (I
> don't know whether TRANSFORM went in first or deparse, but it doesn't
> really matter.)
>
> The fix as you say is pretty trivial, but I would like to use this is a
> test case to ensure that we will catch all these mistakes in the future
> too not only this particular one.
I guess that you could add an assertion at the bottom of
ProcessUtilitySlow() as well to check code paths where ObjectAddress
is not initialized correctly.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
@ 2015-05-26 01:49 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
1 sibling, 1 reply; 14+ messages in thread
From: Michael Paquier @ 2015-05-26 01:49 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
On Tue, May 26, 2015 at 6:47 AM, Michael Paquier wrote:
> On Tue, May 26, 2015 at 12:52 AM, Alvaro Herrera wrote:
>> Michael Paquier wrote:
>>> In ProcessUtilitySlow()@utility.c, for a node T_CreateTransformStmt,
>>> process does not return ObjectAddress. This makes process inconsistent
>>> with the other commands and the ObjectAddress passed to
>>> EventTriggerCollectSimpleCommand is not initialized.
>>> Coverity has pointed out the error, I just some legwork to sort out a fix.
>>
>> Yeah, I had noticed this and was pretty annoyed because we ended up in
>> precisely the situation we didn't want to be: new code is added to
>> ProcessUtility that is not handled by the deparse framework. (I
>> don't know whether TRANSFORM went in first or deparse, but it doesn't
>> really matter.)
>>
>> The fix as you say is pretty trivial, but I would like to use this is a
>> test case to ensure that we will catch all these mistakes in the future
>> too not only this particular one.
>
> I guess that you could add an assertion at the bottom of
> ProcessUtilitySlow() as well to check code paths where ObjectAddress
> is not initialized correctly.
I got a second look at this code this morning and I think that the
handling of InvalidObjectAddress is incorrect. For example, running a
CTAS IF NOT EXISTS on a object that already exists will make
ExecCreateTableAs return InvalidObjectAddress, and then the
EventTriggerCollectSimpleCommand() tries to register an event based on
it. Also, commandCollected is actually not necessary if we rely on the
fact that address is initialized as InvalidObjectAddress.
The patch attached simplifies the code accordingly, making it more
readable IMO for the utility.c part. Thoughts?
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
20150526_ddl_deparse_simplify.patch (text/x-diff, 7.0K) 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/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 3d220e9..21d995b 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1740,7 +1740,7 @@ check_transform_function(Form_pg_proc procstruct)
/*
* CREATE TRANSFORM
*/
-Oid
+ObjectAddress
CreateTransform(CreateTransformStmt *stmt)
{
Oid typeid;
@@ -1938,7 +1938,7 @@ CreateTransform(CreateTransformStmt *stmt)
heap_close(relation, RowExclusiveLock);
- return transformid;
+ return myself;
}
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 7db9f96..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:
@@ -1438,13 +1432,12 @@ ProcessUtilitySlow(Node *parsetree,
break;
case T_CreateTransformStmt:
- CreateTransform((CreateTransformStmt *) parsetree);
+ address = CreateTransform((CreateTransformStmt *) parsetree);
break;
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);
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index dcb6c08..9b81c16 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -51,7 +51,7 @@ extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
extern ObjectAddress CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid);
-extern Oid CreateTransform(CreateTransformStmt *stmt);
+extern ObjectAddress CreateTransform(CreateTransformStmt *stmt);
extern void DropTransformById(Oid transformOid);
extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
oidvector *proargtypes, Oid nspOid);
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
@ 2015-06-03 05:35 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-04 21:24 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 14+ messages in thread
From: Michael Paquier @ 2015-06-03 05:35 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
On Tue, May 26, 2015 at 10:49 AM, Michael Paquier <michael.paquier@gmail.com
> wrote:
> On Tue, May 26, 2015 at 6:47 AM, Michael Paquier wrote:
> > On Tue, May 26, 2015 at 12:52 AM, Alvaro Herrera wrote:
> >> Michael Paquier wrote:
> >>> In ProcessUtilitySlow()@utility.c, for a node T_CreateTransformStmt,
> >>> process does not return ObjectAddress. This makes process inconsistent
> >>> with the other commands and the ObjectAddress passed to
> >>> EventTriggerCollectSimpleCommand is not initialized.
> >>> Coverity has pointed out the error, I just some legwork to sort out a
> fix.
> >>
> >> Yeah, I had noticed this and was pretty annoyed because we ended up in
> >> precisely the situation we didn't want to be: new code is added to
> >> ProcessUtility that is not handled by the deparse framework. (I
> >> don't know whether TRANSFORM went in first or deparse, but it doesn't
> >> really matter.)
> >>
> >> The fix as you say is pretty trivial, but I would like to use this is a
> >> test case to ensure that we will catch all these mistakes in the future
> >> too not only this particular one.
> >
> > I guess that you could add an assertion at the bottom of
> > ProcessUtilitySlow() as well to check code paths where ObjectAddress
> > is not initialized correctly.
>
> I got a second look at this code this morning and I think that the
> handling of InvalidObjectAddress is incorrect. For example, running a
> CTAS IF NOT EXISTS on a object that already exists will make
> ExecCreateTableAs return InvalidObjectAddress, and then the
> EventTriggerCollectSimpleCommand() tries to register an event based on
> it. Also, commandCollected is actually not necessary if we rely on the
> fact that address is initialized as InvalidObjectAddress.
>
> The patch attached simplifies the code accordingly, making it more
> readable IMO for the utility.c part. Thoughts?
>
Attached is an updated patch with some tests for test_ddl_deparse. Creating
a TRANSFORM is actually possible with the SQL language (bug?) by using some
of the in-core system functions. The important point being that the FROM
SQL function uses internal as argument, and returns internal, and that the
TO SQL function uses internal as argument, and returns a result of the data
type of the transform.
Hence, something like that works:
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
That's grotty, OK, but the point is to test the code path for TRANSFORMS.
We could as well create some dummy functions directly in
test_ddl_deparse.c. Let me know if this would work better, but I
And I actually bumped into a bug with this fake test case:
DROP TRANSFORM FOR int LANGUAGE SQL;
+ ERROR: requested object address for unsupported object class 32: text
result "unrecognized object 3576 16551 0"
What happens is that the handling for transforms in getObjectIdentityParts
is missing. This is fixed as well in the attached.
Regards,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
20150603_transform_ddl_deparse_v3.patch (text/x-patch, 10.6K) download
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index c37e38f..e852121 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -634,6 +634,10 @@ static const struct object_type_map
/* OCLASS_POLICY */
{
"policy", OBJECT_POLICY
+ },
+ /* OCLASS_TRANSFORM */
+ {
+ "transform", OBJECT_TRANSFORM
}
};
@@ -4521,6 +4525,40 @@ getObjectIdentityParts(const ObjectAddress *object,
break;
}
+ case OCLASS_TRANSFORM:
+ {
+ Relation transformDesc;
+ HeapTuple tup;
+ Form_pg_transform transform;
+ char *transformType;
+ char *transformLang;
+
+ transformDesc = heap_open(TransformRelationId, AccessShareLock);
+
+ tup = get_catalog_object_by_oid(transformDesc, object->objectId);
+
+ if (!HeapTupleIsValid(tup))
+ elog(ERROR, "could not find tuple for transform %u",
+ object->objectId);
+
+ transform = (Form_pg_transform) GETSTRUCT(tup);
+
+ transformType = format_type_be_qualified(transform->trftype);
+ transformLang = get_language_name(transform->trflang, false);
+
+ appendStringInfo(&buffer, "for %s on language %s",
+ transformType,
+ transformLang);
+ if (objname)
+ {
+ *objname = lappend(*objname, pstrdup(transformType));
+ *objname = lappend(*objname, pstrdup(transformLang));
+ }
+
+ heap_close(transformDesc, AccessShareLock);
+ }
+ break;
+
default:
appendStringInfo(&buffer, "unrecognized object %u %u %d",
object->classId,
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/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 4accf76..dbbb2d3 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1740,7 +1740,7 @@ check_transform_function(Form_pg_proc procstruct)
/*
* CREATE TRANSFORM
*/
-Oid
+ObjectAddress
CreateTransform(CreateTransformStmt *stmt)
{
Oid typeid;
@@ -1938,7 +1938,7 @@ CreateTransform(CreateTransformStmt *stmt)
heap_close(relation, RowExclusiveLock);
- return transformid;
+ return myself;
}
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 7db9f96..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:
@@ -1438,13 +1432,12 @@ ProcessUtilitySlow(Node *parsetree,
break;
case T_CreateTransformStmt:
- CreateTransform((CreateTransformStmt *) parsetree);
+ address = CreateTransform((CreateTransformStmt *) parsetree);
break;
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);
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index dcb6c08..9b81c16 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -51,7 +51,7 @@ extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
extern ObjectAddress CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid);
-extern Oid CreateTransform(CreateTransformStmt *stmt);
+extern ObjectAddress CreateTransform(CreateTransformStmt *stmt);
extern void DropTransformById(Oid transformOid);
extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
oidvector *proargtypes, Oid nspOid);
diff --git a/src/test/modules/test_ddl_deparse/Makefile b/src/test/modules/test_ddl_deparse/Makefile
index 13b985a..8ea6f39 100644
--- a/src/test/modules/test_ddl_deparse/Makefile
+++ b/src/test/modules/test_ddl_deparse/Makefile
@@ -15,6 +15,7 @@ REGRESS = test_ddl_deparse \
create_domain \
create_sequence_1 \
create_table \
+ create_transform \
alter_table \
create_view \
create_trigger \
diff --git a/src/test/modules/test_ddl_deparse/expected/create_transform.out b/src/test/modules/test_ddl_deparse/expected/create_transform.out
new file mode 100644
index 0000000..0d1cc36
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/expected/create_transform.out
@@ -0,0 +1,13 @@
+--
+-- CREATE_TRANSFORM
+--
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
+NOTICE: DDL test: type simple, tag CREATE TRANSFORM
+DROP TRANSFORM FOR int LANGUAGE SQL;
diff --git a/src/test/modules/test_ddl_deparse/sql/create_transform.sql b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
new file mode 100644
index 0000000..0968702
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
@@ -0,0 +1,14 @@
+--
+-- CREATE_TRANSFORM
+--
+
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
+
+DROP TRANSFORM FOR int LANGUAGE SQL;
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
@ 2015-06-04 21:24 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-05 01:53 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Alvaro Herrera @ 2015-06-04 21:24 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs
Michael Paquier wrote:
> And I actually bumped into a bug with this fake test case:
> DROP TRANSFORM FOR int LANGUAGE SQL;
> + ERROR: requested object address for unsupported object class 32: text
> result "unrecognized object 3576 16551 0"
> What happens is that the handling for transforms in getObjectIdentityParts
> is missing. This is fixed as well in the attached.
Oh, interesting. We need one or two extra lines in the
object_address.sql test as well, I guess.
--
Á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
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-04 21:24 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-06-05 01:53 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-21 19:25 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 14+ messages in thread
From: Michael Paquier @ 2015-06-05 01:53 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
On Fri, Jun 5, 2015 at 6:24 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
>
> Michael Paquier wrote:
>
> > And I actually bumped into a bug with this fake test case:
> > DROP TRANSFORM FOR int LANGUAGE SQL;
> > + ERROR: requested object address for unsupported object class 32: text
> > result "unrecognized object 3576 16551 0"
> > What happens is that the handling for transforms in getObjectIdentityParts
> > is missing. This is fixed as well in the attached.
>
> Oh, interesting. We need one or two extra lines in the
> object_address.sql test as well, I guess.
Ah, so that's where it is... Attached is an updated patch with this
stuff. I noticed a couple of code paths where OCLASS_TRANSFORM was
missing as well.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
20150605_transform_ddl_deparse_v4.patch (text/x-patch, 17.3K) download
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index c37e38f..3c33f9c 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -634,6 +634,10 @@ static const struct object_type_map
/* OCLASS_POLICY */
{
"policy", OBJECT_POLICY
+ },
+ /* OCLASS_TRANSFORM */
+ {
+ "transform", OBJECT_TRANSFORM
}
};
@@ -1854,7 +1858,10 @@ pg_get_object_address(PG_FUNCTION_ARGS)
* object type. Most use a simple string Values list, but there are some
* exceptions.
*/
- if (type == OBJECT_TYPE || type == OBJECT_DOMAIN || type == OBJECT_CAST ||
+ if (type == OBJECT_TYPE ||
+ type == OBJECT_DOMAIN ||
+ type == OBJECT_CAST ||
+ type == OBJECT_TRANSFORM ||
type == OBJECT_DOMCONSTRAINT)
{
Datum *elems;
@@ -1946,6 +1953,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
case OBJECT_CAST:
case OBJECT_USER_MAPPING:
case OBJECT_DEFACL:
+ case OBJECT_TRANSFORM:
if (list_length(args) != 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -3599,6 +3607,10 @@ getObjectTypeDescription(const ObjectAddress *object)
appendStringInfoString(&buffer, "policy");
break;
+ case OCLASS_TRANSFORM:
+ appendStringInfoString(&buffer, "transform");
+ break;
+
default:
appendStringInfo(&buffer, "unrecognized %u", object->classId);
break;
@@ -4521,6 +4533,40 @@ getObjectIdentityParts(const ObjectAddress *object,
break;
}
+ case OCLASS_TRANSFORM:
+ {
+ Relation transformDesc;
+ HeapTuple tup;
+ Form_pg_transform transform;
+ char *transformLang;
+ char *transformType;
+
+ transformDesc = heap_open(TransformRelationId, AccessShareLock);
+
+ tup = get_catalog_object_by_oid(transformDesc, object->objectId);
+
+ if (!HeapTupleIsValid(tup))
+ elog(ERROR, "could not find tuple for transform %u",
+ object->objectId);
+
+ transform = (Form_pg_transform) GETSTRUCT(tup);
+
+ transformType = format_type_be_qualified(transform->trftype);
+ transformLang = get_language_name(transform->trflang, false);
+
+ appendStringInfo(&buffer, "for %s on language %s",
+ transformType,
+ transformLang);
+ if (objname)
+ {
+ *objname = list_make1(transformType);
+ *objargs = list_make1(pstrdup(transformLang));
+ }
+
+ heap_close(transformDesc, AccessShareLock);
+ }
+ break;
+
default:
appendStringInfo(&buffer, "unrecognized object %u %u %d",
object->classId,
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/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 4accf76..dbbb2d3 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1740,7 +1740,7 @@ check_transform_function(Form_pg_proc procstruct)
/*
* CREATE TRANSFORM
*/
-Oid
+ObjectAddress
CreateTransform(CreateTransformStmt *stmt)
{
Oid typeid;
@@ -1938,7 +1938,7 @@ CreateTransform(CreateTransformStmt *stmt)
heap_close(relation, RowExclusiveLock);
- return transformid;
+ return myself;
}
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 7db9f96..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:
@@ -1438,13 +1432,12 @@ ProcessUtilitySlow(Node *parsetree,
break;
case T_CreateTransformStmt:
- CreateTransform((CreateTransformStmt *) parsetree);
+ address = CreateTransform((CreateTransformStmt *) parsetree);
break;
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);
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index dcb6c08..9b81c16 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -51,7 +51,7 @@ extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
extern ObjectAddress CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid);
-extern Oid CreateTransform(CreateTransformStmt *stmt);
+extern ObjectAddress CreateTransform(CreateTransformStmt *stmt);
extern void DropTransformById(Oid transformOid);
extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
oidvector *proargtypes, Oid nspOid);
diff --git a/src/test/modules/test_ddl_deparse/Makefile b/src/test/modules/test_ddl_deparse/Makefile
index 13b985a..8ea6f39 100644
--- a/src/test/modules/test_ddl_deparse/Makefile
+++ b/src/test/modules/test_ddl_deparse/Makefile
@@ -15,6 +15,7 @@ REGRESS = test_ddl_deparse \
create_domain \
create_sequence_1 \
create_table \
+ create_transform \
alter_table \
create_view \
create_trigger \
diff --git a/src/test/modules/test_ddl_deparse/expected/create_transform.out b/src/test/modules/test_ddl_deparse/expected/create_transform.out
new file mode 100644
index 0000000..0d1cc36
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/expected/create_transform.out
@@ -0,0 +1,13 @@
+--
+-- CREATE_TRANSFORM
+--
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
+NOTICE: DDL test: type simple, tag CREATE TRANSFORM
+DROP TRANSFORM FOR int LANGUAGE SQL;
diff --git a/src/test/modules/test_ddl_deparse/sql/create_transform.sql b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
new file mode 100644
index 0000000..0968702
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
@@ -0,0 +1,14 @@
+--
+-- CREATE_TRANSFORM
+--
+
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
+
+DROP TRANSFORM FOR int LANGUAGE SQL;
diff --git a/src/test/regress/expected/object_address.out b/src/test/regress/expected/object_address.out
index 365dcca..034c0b1 100644
--- a/src/test/regress/expected/object_address.out
+++ b/src/test/regress/expected/object_address.out
@@ -32,6 +32,9 @@ CREATE SERVER "integer" FOREIGN DATA WRAPPER addr_fdw;
CREATE USER MAPPING FOR regtest_addr_user SERVER "integer";
ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user IN SCHEMA public GRANT ALL ON TABLES TO regtest_addr_user;
ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user REVOKE DELETE ON TABLES FROM regtest_addr_user;
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
-- test some error cases
SELECT pg_get_object_address('stone', '{}', '{}');
ERROR: unrecognized object type "stone"
@@ -76,7 +79,7 @@ BEGIN
('operator'), ('operator class'), ('operator family'), ('rule'), ('trigger'),
('text search parser'), ('text search dictionary'),
('text search template'), ('text search configuration'),
- ('policy'), ('user mapping'), ('default acl'),
+ ('policy'), ('user mapping'), ('default acl'), ('transform'),
('operator of access method'), ('function of access method')
LOOP
FOR names IN VALUES ('{eins}'), ('{addr_nsp, zwei}'), ('{eins, zwei, drei}')
@@ -261,6 +264,12 @@ WARNING: error for default acl,{addr_nsp,zwei},{}: argument list length must be
WARNING: error for default acl,{addr_nsp,zwei},{integer}: unrecognized default ACL object type i
WARNING: error for default acl,{eins,zwei,drei},{}: argument list length must be exactly 1
WARNING: error for default acl,{eins,zwei,drei},{integer}: unrecognized default ACL object type i
+WARNING: error for transform,{eins},{}: argument list length must be exactly 1
+WARNING: error for transform,{eins},{integer}: type "eins" does not exist
+WARNING: error for transform,{addr_nsp,zwei},{}: name list length must be exactly 1
+WARNING: error for transform,{addr_nsp,zwei},{integer}: name list length must be exactly 1
+WARNING: error for transform,{eins,zwei,drei},{}: name list length must be exactly 1
+WARNING: error for transform,{eins,zwei,drei},{integer}: name list length must be exactly 1
WARNING: error for operator of access method,{eins},{}: name list length must be at least 3
WARNING: error for operator of access method,{eins},{integer}: name list length must be at least 3
WARNING: error for operator of access method,{addr_nsp,zwei},{}: name list length must be at least 3
@@ -363,7 +372,8 @@ WITH objects (type, name, args) AS (VALUES
('default acl', '{regtest_addr_user}', '{r}'),
-- extension
-- event trigger
- ('policy', '{addr_nsp, gentable, genpol}', '{}')
+ ('policy', '{addr_nsp, gentable, genpol}', '{}'),
+ ('transform', '{int}', '{sql}')
)
SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.subobjid)).*,
-- test roundtrip through pg_identify_object_as_address
@@ -411,11 +421,12 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.subobjid)).*,
operator family | pg_catalog | integer_ops | pg_catalog.integer_ops USING btree | t
policy | | | genpol on addr_nsp.gentable | t
collation | pg_catalog | "default" | pg_catalog."default" | t
+ transform | | | for integer on language sql | t
text search dictionary | addr_nsp | addr_ts_dict | addr_nsp.addr_ts_dict | t
text search parser | addr_nsp | addr_ts_prs | addr_nsp.addr_ts_prs | t
text search configuration | addr_nsp | addr_ts_conf | addr_nsp.addr_ts_conf | t
text search template | addr_nsp | addr_ts_temp | addr_nsp.addr_ts_temp | t
-(40 rows)
+(41 rows)
---
--- Cleanup resources
diff --git a/src/test/regress/sql/object_address.sql b/src/test/regress/sql/object_address.sql
index 9cf8097..68e7cb0 100644
--- a/src/test/regress/sql/object_address.sql
+++ b/src/test/regress/sql/object_address.sql
@@ -36,6 +36,9 @@ CREATE SERVER "integer" FOREIGN DATA WRAPPER addr_fdw;
CREATE USER MAPPING FOR regtest_addr_user SERVER "integer";
ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user IN SCHEMA public GRANT ALL ON TABLES TO regtest_addr_user;
ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user REVOKE DELETE ON TABLES FROM regtest_addr_user;
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
-- test some error cases
SELECT pg_get_object_address('stone', '{}', '{}');
@@ -74,7 +77,7 @@ BEGIN
('operator'), ('operator class'), ('operator family'), ('rule'), ('trigger'),
('text search parser'), ('text search dictionary'),
('text search template'), ('text search configuration'),
- ('policy'), ('user mapping'), ('default acl'),
+ ('policy'), ('user mapping'), ('default acl'), ('transform'),
('operator of access method'), ('function of access method')
LOOP
FOR names IN VALUES ('{eins}'), ('{addr_nsp, zwei}'), ('{eins, zwei, drei}')
@@ -162,7 +165,8 @@ WITH objects (type, name, args) AS (VALUES
('default acl', '{regtest_addr_user}', '{r}'),
-- extension
-- event trigger
- ('policy', '{addr_nsp, gentable, genpol}', '{}')
+ ('policy', '{addr_nsp, gentable, genpol}', '{}'),
+ ('transform', '{int}', '{sql}')
)
SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.subobjid)).*,
-- test roundtrip through pg_identify_object_as_address
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-04 21:24 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-05 01:53 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
@ 2015-06-21 19:25 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-22 02:29 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Alvaro Herrera @ 2015-06-21 19:25 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs
Michael Paquier wrote:
> On Fri, Jun 5, 2015 at 6:24 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
> >
> > Michael Paquier wrote:
> >
> > > And I actually bumped into a bug with this fake test case:
> > > DROP TRANSFORM FOR int LANGUAGE SQL;
> > > + ERROR: requested object address for unsupported object class 32: text
> > > result "unrecognized object 3576 16551 0"
> > > What happens is that the handling for transforms in getObjectIdentityParts
> > > is missing. This is fixed as well in the attached.
> >
> > Oh, interesting. We need one or two extra lines in the
> > object_address.sql test as well, I guess.
>
> Ah, so that's where it is... Attached is an updated patch with this
> stuff. I noticed a couple of code paths where OCLASS_TRANSFORM was
> missing as well.
Thanks, pushed that part of it. Looking at the event trigger bits next.
--
Á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
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-04 21:24 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-05 01:53 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-21 19:25 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-06-22 02:29 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-26 21:31 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 14+ messages in thread
From: Michael Paquier @ 2015-06-22 02:29 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
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.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
20150622_transform_ddl_deparse_v5.patch (text/x-diff, 9.1K) 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/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 4accf76..dbbb2d3 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1740,7 +1740,7 @@ check_transform_function(Form_pg_proc procstruct)
/*
* CREATE TRANSFORM
*/
-Oid
+ObjectAddress
CreateTransform(CreateTransformStmt *stmt)
{
Oid typeid;
@@ -1938,7 +1938,7 @@ CreateTransform(CreateTransformStmt *stmt)
heap_close(relation, RowExclusiveLock);
- return transformid;
+ return myself;
}
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 7db9f96..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:
@@ -1438,13 +1432,12 @@ ProcessUtilitySlow(Node *parsetree,
break;
case T_CreateTransformStmt:
- CreateTransform((CreateTransformStmt *) parsetree);
+ address = CreateTransform((CreateTransformStmt *) parsetree);
break;
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);
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index dcb6c08..9b81c16 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -51,7 +51,7 @@ extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
extern ObjectAddress CreateCast(CreateCastStmt *stmt);
extern void DropCastById(Oid castOid);
-extern Oid CreateTransform(CreateTransformStmt *stmt);
+extern ObjectAddress CreateTransform(CreateTransformStmt *stmt);
extern void DropTransformById(Oid transformOid);
extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
oidvector *proargtypes, Oid nspOid);
diff --git a/src/test/modules/test_ddl_deparse/Makefile b/src/test/modules/test_ddl_deparse/Makefile
index 13b985a..8ea6f39 100644
--- a/src/test/modules/test_ddl_deparse/Makefile
+++ b/src/test/modules/test_ddl_deparse/Makefile
@@ -15,6 +15,7 @@ REGRESS = test_ddl_deparse \
create_domain \
create_sequence_1 \
create_table \
+ create_transform \
alter_table \
create_view \
create_trigger \
diff --git a/src/test/modules/test_ddl_deparse/expected/create_transform.out b/src/test/modules/test_ddl_deparse/expected/create_transform.out
new file mode 100644
index 0000000..0d1cc36
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/expected/create_transform.out
@@ -0,0 +1,13 @@
+--
+-- CREATE_TRANSFORM
+--
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
+NOTICE: DDL test: type simple, tag CREATE TRANSFORM
+DROP TRANSFORM FOR int LANGUAGE SQL;
diff --git a/src/test/modules/test_ddl_deparse/sql/create_transform.sql b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
new file mode 100644
index 0000000..0968702
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
@@ -0,0 +1,14 @@
+--
+-- CREATE_TRANSFORM
+--
+
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+ FROM SQL WITH FUNCTION varchar_transform(internal),
+ TO SQL WITH FUNCTION int4recv(internal));
+
+DROP TRANSFORM FOR int LANGUAGE SQL;
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-04 21:24 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-05 01:53 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-21 19:25 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-22 02:29 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
@ 2015-06-26 21:31 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-26 23:03 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Alvaro Herrera @ 2015-06-26 21:31 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-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);
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-04 21:24 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-05 01:53 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-21 19:25 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-22 02:29 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-06-26 21:31 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-06-26 23:03 ` Michael Paquier <michael.paquier@gmail.com>
0 siblings, 0 replies; 14+ messages in thread
From: Michael Paquier @ 2015-06-26 23:03 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
On Sat, Jun 27, 2015 at 6:31 AM, Alvaro Herrera wrote:
> 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.
OK, but actually what does it mean to register an event on an invalid
object. You cannot get a definition from it, right? Hence you cannot
register an event assigned to it.
> I just noticed I neglected to credit for authorship in the commit
> message, sorry about that :-(
Don't worry. That's fine as-is.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
@ 2015-05-26 02:02 ` Stephen Frost <sfrost@snowman.net>
2015-05-26 14:41 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 1 reply; 14+ messages in thread
From: Stephen Frost @ 2015-05-26 02:02 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs
* Michael Paquier (michael.paquier@gmail.com) wrote:
> On Tue, May 26, 2015 at 12:52 AM, Alvaro Herrera wrote:
> > Michael Paquier wrote:
> >> In ProcessUtilitySlow()@utility.c, for a node T_CreateTransformStmt,
> >> process does not return ObjectAddress. This makes process inconsistent
> >> with the other commands and the ObjectAddress passed to
> >> EventTriggerCollectSimpleCommand is not initialized.
> >> Coverity has pointed out the error, I just some legwork to sort out a fix.
> >
> > Yeah, I had noticed this and was pretty annoyed because we ended up in
> > precisely the situation we didn't want to be: new code is added to
> > ProcessUtility that is not handled by the deparse framework. (I
> > don't know whether TRANSFORM went in first or deparse, but it doesn't
> > really matter.)
> >
> > The fix as you say is pretty trivial, but I would like to use this is a
> > test case to ensure that we will catch all these mistakes in the future
> > too not only this particular one.
>
> I guess that you could add an assertion at the bottom of
> ProcessUtilitySlow() as well to check code paths where ObjectAddress
> is not initialized correctly.
I seem to recall that being in one of the variations of this patch and I
tend to agree that it makes sense...
That said, I'm really not all that happy with the split between
ProcessUtility() and ProcessUtilitySlow(). I've not said anything since
I haven't got any great solutions to the issue, but it really is pretty
grotty. I realize it might take a few extra cycles, but my thinking is
along the lines of having an array or similar which we scan that
indicates what is supported by deparse/event triggers, what isn't, etc,
and then we operate based on that.. Perhaps an array which is indexed
based on the NodeTag enum? I realize that'd be a stupidly large array,
of, I dunno, 8k or more, but it'd surely make ProcessUtility a heck of a
lot shorter/simpler..
Considering the line count between the two is over 1000, perhaps it'd be
a net savings in size, if not speed.
Just a few off-the-cuff thoughts.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 02:02 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Stephen Frost <sfrost@snowman.net>
@ 2015-05-26 14:41 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-27 01:46 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Stephen Frost <sfrost@snowman.net>
0 siblings, 1 reply; 14+ messages in thread
From: Alvaro Herrera @ 2015-05-26 14:41 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs
Stephen Frost wrote:
> That said, I'm really not all that happy with the split between
> ProcessUtility() and ProcessUtilitySlow(). I've not said anything since
> I haven't got any great solutions to the issue, but it really is pretty
> grotty. I realize it might take a few extra cycles, but my thinking is
> along the lines of having an array or similar which we scan that
> indicates what is supported by deparse/event triggers, what isn't, etc,
> and then we operate based on that.. Perhaps an array which is indexed
> based on the NodeTag enum?
That doesn't work. Consider DropStmt for example; it is supported for
some object types, but not supported by others. There are a few other
commands for which this happens too. Also, NodeTag contains tags for
everything that can be a node: plan nodes for example, and for those it
doesn't even make sense to consider whether event triggers are
supported.
I suppose you could create a node type T_UtilityStmt and make all the
command nodes be sub-types of that one. But, except for the
ProcessUtility{Slow} code, it would be a loss in maintainability, ISTM,
and it would increase the size of every single utility node.
Now maybe with that you could get rid of (or centralize) various arrays;
see for example ObjectTypeMap and event_trigger_support, the calls to
pg_strcasecmp() in check_ddl_tag, EventTriggerSupportsObjectType() and
EventTriggerSupportsObjectClass() and
EventTriggerSupportsGrantObjectType() ...
Anyway this would solve the problem at hand anyway.
--
Á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
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Incorrect processing of CREATE TRANSFORM with DDL deparding
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-26 02:02 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Stephen Frost <sfrost@snowman.net>
2015-05-26 14:41 ` Re: Incorrect processing of CREATE TRANSFORM with DDL deparding Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-05-27 01:46 ` Stephen Frost <sfrost@snowman.net>
0 siblings, 0 replies; 14+ messages in thread
From: Stephen Frost @ 2015-05-27 01:46 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs
Alvaro,
* Alvaro Herrera (alvherre@2ndquadrant.com) wrote:
> Stephen Frost wrote:
> > That said, I'm really not all that happy with the split between
> > ProcessUtility() and ProcessUtilitySlow(). I've not said anything since
> > I haven't got any great solutions to the issue, but it really is pretty
> > grotty. I realize it might take a few extra cycles, but my thinking is
> > along the lines of having an array or similar which we scan that
> > indicates what is supported by deparse/event triggers, what isn't, etc,
> > and then we operate based on that.. Perhaps an array which is indexed
> > based on the NodeTag enum?
>
> That doesn't work. Consider DropStmt for example; it is supported for
> some object types, but not supported by others. There are a few other
> commands for which this happens too. Also, NodeTag contains tags for
> everything that can be a node: plan nodes for example, and for those it
> doesn't even make sense to consider whether event triggers are
> supported.
Yeah, good points, all of them.
> I suppose you could create a node type T_UtilityStmt and make all the
> command nodes be sub-types of that one. But, except for the
> ProcessUtility{Slow} code, it would be a loss in maintainability, ISTM,
> and it would increase the size of every single utility node.
>
> Now maybe with that you could get rid of (or centralize) various arrays;
> see for example ObjectTypeMap and event_trigger_support, the calls to
> pg_strcasecmp() in check_ddl_tag, EventTriggerSupportsObjectType() and
> EventTriggerSupportsObjectClass() and
> EventTriggerSupportsGrantObjectType() ...
>
> Anyway this would solve the problem at hand anyway.
I certainly agree that being able to centralize those arrays would be
nice. It has definitely struck me, more than once, that we've got quite
a few different arrays hanging around that might be better combined into
one or at least kept in the same area. If nothing else, it might help
minimize cases where individuals forget to update one or another of the
arrays.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
end of thread, other threads:[~2015-06-26 23:03 UTC | newest]
Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-05-25 05:05 Incorrect processing of CREATE TRANSFORM with DDL deparding Michael Paquier <michael.paquier@gmail.com>
2015-05-25 15:52 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-25 21:47 ` Michael Paquier <michael.paquier@gmail.com>
2015-05-26 01:49 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-03 05:35 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-04 21:24 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-05 01:53 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-21 19:25 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-22 02:29 ` Michael Paquier <michael.paquier@gmail.com>
2015-06-26 21:31 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-26 23:03 ` Michael Paquier <michael.paquier@gmail.com>
2015-05-26 02:02 ` Stephen Frost <sfrost@snowman.net>
2015-05-26 14:41 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-05-27 01:46 ` Stephen Frost <sfrost@snowman.net>
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