infrastructure for ALTER OPERATOR FAMILY
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 13 Mar 2015 17:17:58 +0000 (14:17 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 7 Apr 2015 17:09:39 +0000 (14:09 -0300)
src/backend/commands/event_trigger.c
src/backend/commands/opclasscmds.c
src/backend/tcop/deparse_utility.c
src/include/catalog/opfam_internal.h [new file with mode: 0644]
src/include/commands/event_trigger.h
src/include/tcop/deparse_utility.h

index 8111c55e915286df711de9a16f94ecfc325425e1..1fa0d95962d68302cf9f444e319223eccb750ede 100644 (file)
@@ -20,6 +20,7 @@
 #include "catalog/objectaccess.h"
 #include "catalog/pg_event_trigger.h"
 #include "catalog/pg_namespace.h"
+#include "catalog/pg_opfamily.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_trigger.h"
 #include "catalog/pg_type.h"
@@ -1855,6 +1856,37 @@ EventTriggerStashGrant(InternalGrant *istmt)
    MemoryContextSwitchTo(oldcxt);
 }
 
+/*
+ * EventTriggerStashAlterOpFam
+ *         Save data about an ALTER OPERATOR FAMILY ADD/DROP command being
+ *         executed
+ */
+void
+EventTriggerStashAlterOpFam(AlterOpFamilyStmt *stmt, Oid opfamoid,
+                           List *operators, List *procedures)
+{
+   MemoryContext   oldcxt;
+   StashedCommand *stashed;
+
+   if (currentEventTriggerState->commandCollectionInhibited)
+       return;
+
+   oldcxt = MemoryContextSwitchTo(currentEventTriggerState->cxt);
+
+   stashed = palloc(sizeof(StashedCommand));
+   stashed->type = SCT_AlterOpFamily;
+   stashed->in_extension = creating_extension;
+   stashed->d.opfam.opfamOid = opfamoid;
+   stashed->d.opfam.operators = operators;     /* XXX prolly need to copy */
+   stashed->d.opfam.procedures = procedures;   /* XXX ditto */
+   stashed->parsetree = copyObject(stmt);
+
+   currentEventTriggerState->stash = lappend(currentEventTriggerState->stash,
+                                             stashed);
+
+   MemoryContextSwitchTo(oldcxt);
+}
+
 Datum
 pg_event_trigger_get_creation_commands(PG_FUNCTION_ARGS)
 {
@@ -1934,7 +1966,8 @@ pg_event_trigger_get_creation_commands(PG_FUNCTION_ARGS)
        MemSet(nulls, 0, sizeof(nulls));
 
        if (cmd->type == SCT_Simple ||
-           cmd->type == SCT_AlterTable)
+           cmd->type == SCT_AlterTable ||
+           cmd->type == SCT_AlterOpFamily)
        {
            const char *tag;
            char       *identity;
@@ -1947,6 +1980,10 @@ pg_event_trigger_get_creation_commands(PG_FUNCTION_ARGS)
                ObjectAddressSet(addr,
                                 cmd->d.alterTable.classId,
                                 cmd->d.alterTable.objectId);
+           else if (cmd->type == SCT_AlterOpFamily)
+               ObjectAddressSet(addr,
+                                OperatorFamilyRelationId,
+                                cmd->d.opfam.opfamOid);
 
            tag = CreateCommandTag(cmd->parsetree);
 
index c327cc0473e0dcf453410af54759b245cf6af592..d5ca502530e4ca9adfa36facfb7751121cbd5203 100644 (file)
@@ -25,6 +25,7 @@
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
 #include "catalog/objectaccess.h"
+#include "catalog/opfam_internal.h"
 #include "catalog/pg_amop.h"
 #include "catalog/pg_amproc.h"
 #include "catalog/pg_namespace.h"
 #include "utils/tqual.h"
 
 
-/*
- * We use lists of this struct type to keep track of both operators and
- * procedures while building or adding to an opfamily.
- */
-typedef struct
-{
-   Oid         object;         /* operator or support proc's OID */
-   int         number;         /* strategy or support proc number */
-   Oid         lefttype;       /* lefttype */
-   Oid         righttype;      /* righttype */
-   Oid         sortfamily;     /* ordering operator's sort opfamily, or 0 */
-} OpFamilyMember;
-
-
 static void AlterOpFamilyAdd(List *opfamilyname, Oid amoid, Oid opfamilyoid,
                 int maxOpNumber, int maxProcNumber,
                 List *items);
index 9f05d0e09625c0274ee32c8e49e1370971fd068c..195b06f705659d332f697b18c7deda05b8e253b4 100644 (file)
@@ -6299,7 +6299,8 @@ deparse_simple_command(StashedCommand *cmd)
            break;
 
        case T_AlterOpFamilyStmt:
-           elog(ERROR, "unimplemented deparse of %s", CreateCommandTag(parsetree));
+           /* handled elsewhere */
+           elog(ERROR, "unexpected command type %s", CreateCommandTag(parsetree));
            break;
 
        case T_AlterTSDictionaryStmt:
@@ -6422,6 +6423,9 @@ deparse_utility_command(StashedCommand *cmd)
        case SCT_Grant:
            tree = deparse_GrantStmt(cmd);
            break;
+       case SCT_AlterOpFamily:
+           tree = deparse_AlterOpFamily(cmd);
+           break;
        default:
            elog(ERROR, "unexpected deparse node type %d", cmd->type);
    }
diff --git a/src/include/catalog/opfam_internal.h b/src/include/catalog/opfam_internal.h
new file mode 100644 (file)
index 0000000..f01dcbe
--- /dev/null
@@ -0,0 +1,28 @@
+/*-------------------------------------------------------------------------
+ *
+ * opfam_internal.h
+ *
+ * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/catalog/opfam_internal.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef OPFAM_INTERNAL_H
+#define OPFAM_INTERNAL_H
+
+/*
+ * We use lists of this struct type to keep track of both operators and
+ * procedures while building or adding to an opfamily.
+ */
+typedef struct
+{
+   Oid         object;         /* operator or support proc's OID */
+   int         number;         /* strategy or support proc number */
+   Oid         lefttype;       /* lefttype */
+   Oid         righttype;      /* righttype */
+   Oid         sortfamily;     /* ordering operator's sort opfamily, or 0 */
+} OpFamilyMember;
+
+#endif     /* OPFAM_INTERNAL_H */
index 932630f0701b36dac636350f85b547e5d888f9d0..a8435e323cbc84f778c4a960b569fb6c539e621e 100644 (file)
@@ -74,5 +74,7 @@ extern void EventTriggerAlterTableStashSubcmd(Node *subcmd, Oid relid,
 extern void EventTriggerAlterTableEnd(void);
 
 extern void EventTriggerStashGrant(InternalGrant *istmt);
+extern void EventTriggerStashAlterOpFam(AlterOpFamilyStmt *stmt, Oid opfamoid,
+                           List *operators, List *procedures);
 
 #endif   /* EVENT_TRIGGER_H */
index 7f70ede53945d9e99e361fa1cbf0015a7bdc25f4..6aa5fa56524193bf65cb68d3e2336d87dd565787 100644 (file)
@@ -29,7 +29,8 @@ typedef enum StashedCommandType
 {
    SCT_Simple,
    SCT_AlterTable,
-   SCT_Grant
+   SCT_Grant,
+   SCT_AlterOpFamily
 } StashedCommandType;
 
 /*
@@ -71,6 +72,14 @@ typedef struct StashedCommand
            InternalGrant *istmt;
            const char *type;
        } grant;
+
+       /* ALTER OPERATOR FAMILY */
+       struct
+       {
+           Oid     opfamOid;
+           List   *operators;
+           List   *procedures;
+       } opfam;
    } d;
 } StashedCommand;