Commit 296f3a60 authored by Alvaro Herrera's avatar Alvaro Herrera

Support more commands in event triggers

COMMENT, SECURITY LABEL, and GRANT/REVOKE now also fire
ddl_command_start and ddl_command_end event triggers, when they operate
on database-local objects.

Reviewed-By: Michael Paquier, Andres Freund, Stephen Frost
parent 88e98230
This diff is collapsed.
...@@ -267,8 +267,12 @@ check_ddl_tag(const char *tag) ...@@ -267,8 +267,12 @@ check_ddl_tag(const char *tag)
pg_strcasecmp(tag, "REFRESH MATERIALIZED VIEW") == 0 || pg_strcasecmp(tag, "REFRESH MATERIALIZED VIEW") == 0 ||
pg_strcasecmp(tag, "ALTER DEFAULT PRIVILEGES") == 0 || pg_strcasecmp(tag, "ALTER DEFAULT PRIVILEGES") == 0 ||
pg_strcasecmp(tag, "ALTER LARGE OBJECT") == 0 || pg_strcasecmp(tag, "ALTER LARGE OBJECT") == 0 ||
pg_strcasecmp(tag, "COMMENT") == 0 ||
pg_strcasecmp(tag, "GRANT") == 0 ||
pg_strcasecmp(tag, "REVOKE") == 0 ||
pg_strcasecmp(tag, "DROP OWNED") == 0 || pg_strcasecmp(tag, "DROP OWNED") == 0 ||
pg_strcasecmp(tag, "IMPORT FOREIGN SCHEMA") == 0) pg_strcasecmp(tag, "IMPORT FOREIGN SCHEMA") == 0 ||
pg_strcasecmp(tag, "SECURITY LABEL") == 0)
return EVENT_TRIGGER_COMMAND_TAG_OK; return EVENT_TRIGGER_COMMAND_TAG_OK;
/* /*
...@@ -1149,6 +1153,34 @@ EventTriggerSupportsObjectClass(ObjectClass objclass) ...@@ -1149,6 +1153,34 @@ EventTriggerSupportsObjectClass(ObjectClass objclass)
return true; return true;
} }
bool
EventTriggerSupportsGrantObjectType(GrantObjectType objtype)
{
switch (objtype)
{
case ACL_OBJECT_DATABASE:
case ACL_OBJECT_TABLESPACE:
/* no support for global objects */
return false;
case ACL_OBJECT_COLUMN:
case ACL_OBJECT_RELATION:
case ACL_OBJECT_SEQUENCE:
case ACL_OBJECT_DOMAIN:
case ACL_OBJECT_FDW:
case ACL_OBJECT_FOREIGN_SERVER:
case ACL_OBJECT_FUNCTION:
case ACL_OBJECT_LANGUAGE:
case ACL_OBJECT_LARGEOBJECT:
case ACL_OBJECT_NAMESPACE:
case ACL_OBJECT_TYPE:
return true;
default:
Assert(false);
return true;
}
}
/* /*
* Prepare event trigger state for a new complete query to run, if necessary; * Prepare event trigger state for a new complete query to run, if necessary;
* returns whether this was done. If it was, EventTriggerEndCompleteQuery must * returns whether this was done. If it was, EventTriggerEndCompleteQuery must
......
...@@ -513,14 +513,6 @@ standard_ProcessUtility(Node *parsetree, ...@@ -513,14 +513,6 @@ standard_ProcessUtility(Node *parsetree,
ExecuteTruncate((TruncateStmt *) parsetree); ExecuteTruncate((TruncateStmt *) parsetree);
break; break;
case T_CommentStmt:
CommentObject((CommentStmt *) parsetree);
break;
case T_SecLabelStmt:
ExecSecLabelStmt((SecLabelStmt *) parsetree);
break;
case T_CopyStmt: case T_CopyStmt:
{ {
uint64 processed; uint64 processed;
...@@ -548,11 +540,6 @@ standard_ProcessUtility(Node *parsetree, ...@@ -548,11 +540,6 @@ standard_ProcessUtility(Node *parsetree,
DeallocateQuery((DeallocateStmt *) parsetree); DeallocateQuery((DeallocateStmt *) parsetree);
break; break;
case T_GrantStmt:
/* no event triggers for global objects */
ExecuteGrantStmt((GrantStmt *) parsetree);
break;
case T_GrantRoleStmt: case T_GrantRoleStmt:
/* no event triggers for global objects */ /* no event triggers for global objects */
GrantRole((GrantRoleStmt *) parsetree); GrantRole((GrantRoleStmt *) parsetree);
...@@ -783,6 +770,19 @@ standard_ProcessUtility(Node *parsetree, ...@@ -783,6 +770,19 @@ standard_ProcessUtility(Node *parsetree,
* in some cases, so we "fast path" them in the other cases. * in some cases, so we "fast path" them in the other cases.
*/ */
case T_GrantStmt:
{
GrantStmt *stmt = (GrantStmt *) parsetree;
if (EventTriggerSupportsGrantObjectType(stmt->objtype))
ProcessUtilitySlow(parsetree, queryString,
context, params,
dest, completionTag);
else
ExecuteGrantStmt((GrantStmt *) parsetree);
}
break;
case T_DropStmt: case T_DropStmt:
{ {
DropStmt *stmt = (DropStmt *) parsetree; DropStmt *stmt = (DropStmt *) parsetree;
...@@ -835,6 +835,32 @@ standard_ProcessUtility(Node *parsetree, ...@@ -835,6 +835,32 @@ standard_ProcessUtility(Node *parsetree,
} }
break; break;
case T_CommentStmt:
{
CommentStmt *stmt = (CommentStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objtype))
ProcessUtilitySlow(parsetree, queryString,
context, params,
dest, completionTag);
else
CommentObject((CommentStmt *) parsetree);
break;
}
case T_SecLabelStmt:
{
SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objtype))
ProcessUtilitySlow(parsetree, queryString,
context, params,
dest, completionTag);
else
ExecSecLabelStmt(stmt);
break;
}
default: default:
/* All other statement types have event trigger support */ /* All other statement types have event trigger support */
ProcessUtilitySlow(parsetree, queryString, ProcessUtilitySlow(parsetree, queryString,
...@@ -1315,6 +1341,14 @@ ProcessUtilitySlow(Node *parsetree, ...@@ -1315,6 +1341,14 @@ ProcessUtilitySlow(Node *parsetree,
ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree); ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
break; break;
case T_CommentStmt:
CommentObject((CommentStmt *) parsetree, NULL);
break;
case T_GrantStmt:
ExecuteGrantStmt((GrantStmt *) parsetree);
break;
case T_DropOwnedStmt: case T_DropOwnedStmt:
DropOwnedObjects((DropOwnedStmt *) parsetree); DropOwnedObjects((DropOwnedStmt *) parsetree);
break; break;
...@@ -1331,6 +1365,10 @@ ProcessUtilitySlow(Node *parsetree, ...@@ -1331,6 +1365,10 @@ ProcessUtilitySlow(Node *parsetree,
AlterPolicy((AlterPolicyStmt *) parsetree); AlterPolicy((AlterPolicyStmt *) parsetree);
break; break;
case T_SecLabelStmt:
ExecSecLabelStmt((SecLabelStmt *) parsetree;
break;
default: default:
elog(ERROR, "unrecognized node type: %d", elog(ERROR, "unrecognized node type: %d",
(int) nodeTag(parsetree)); (int) nodeTag(parsetree));
......
...@@ -48,6 +48,7 @@ extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId); ...@@ -48,6 +48,7 @@ extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
extern bool EventTriggerSupportsObjectType(ObjectType obtype); extern bool EventTriggerSupportsObjectType(ObjectType obtype);
extern bool EventTriggerSupportsObjectClass(ObjectClass objclass); extern bool EventTriggerSupportsObjectClass(ObjectClass objclass);
extern bool EventTriggerSupportsGrantObjectType(GrantObjectType objtype);
extern void EventTriggerDDLCommandStart(Node *parsetree); extern void EventTriggerDDLCommandStart(Node *parsetree);
extern void EventTriggerDDLCommandEnd(Node *parsetree); extern void EventTriggerDDLCommandEnd(Node *parsetree);
extern void EventTriggerSQLDrop(Node *parsetree); extern void EventTriggerSQLDrop(Node *parsetree);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment