deparse: infrastructure for ALTER TEXT SEARCH CONFIG support
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 23 Mar 2015 22:40:17 +0000 (19:40 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 7 Apr 2015 17:09:40 +0000 (14:09 -0300)
src/backend/commands/event_trigger.c
src/backend/commands/tsearchcmds.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/parser/gram.y
src/backend/tcop/deparse_utility.c
src/include/commands/event_trigger.h
src/include/nodes/parsenodes.h
src/include/tcop/deparse_utility.h

index c5a08c6db2ccbc13508cafdfbe30119172927e94..9c0080056dc3325d26993ad252e284471f8f59e7 100644 (file)
@@ -24,6 +24,7 @@
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_trigger.h"
+#include "catalog/pg_ts_config.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "commands/event_trigger.h"
@@ -1914,6 +1915,32 @@ EventTriggerStashCreateOpClass(CreateOpClassStmt *stmt, Oid opcoid,
    MemoryContextSwitchTo(oldcxt);
 }
 
+void
+EventTriggerStashAlterTSConfig(AlterTSConfigurationStmt *stmt, Oid cfgId,
+                              Oid *dictIds, int ndicts)
+{
+   MemoryContext   oldcxt;
+   StashedCommand *stashed;
+
+   if (currentEventTriggerState->commandCollectionInhibited)
+       return;
+
+   oldcxt = MemoryContextSwitchTo(currentEventTriggerState->cxt);
+
+   stashed = palloc0(sizeof(StashedCommand));
+   stashed->type = SCT_AlterTSConfig;
+   stashed->in_extension = creating_extension;
+   stashed->d.atscfg.tscfgOid = cfgId;
+   stashed->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
+   memcpy(stashed->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
+   stashed->d.atscfg.ndicts = ndicts;
+   stashed->parsetree = copyObject(stmt);
+
+   currentEventTriggerState->stash = lappend(currentEventTriggerState->stash,
+                                             stashed);
+
+   MemoryContextSwitchTo(oldcxt);
+}
 
 /*
  * EventTriggerStashAlterDefPrivs
@@ -2042,7 +2069,8 @@ pg_event_trigger_get_creation_commands(PG_FUNCTION_ARGS)
        if (cmd->type == SCT_Simple ||
            cmd->type == SCT_AlterTable ||
            cmd->type == SCT_AlterOpFamily ||
-           cmd->type == SCT_CreateOpClass)
+           cmd->type == SCT_CreateOpClass ||
+           cmd->type == SCT_AlterTSConfig)
        {
            const char *tag;
            char       *identity;
@@ -2063,6 +2091,10 @@ pg_event_trigger_get_creation_commands(PG_FUNCTION_ARGS)
                ObjectAddressSet(addr,
                                 OperatorClassRelationId,
                                 cmd->d.createopc.opcOid);
+           else if (cmd->type == SCT_AlterTSConfig)
+               ObjectAddressSet(addr,
+                                TSConfigRelationId,
+                                cmd->d.atscfg.tscfgOid);
 
            tag = CreateCommandTag(cmd->parsetree);
 
index 4c404e73d0913a2ea97ed66b1465577e38730081..13eff3db0849d54b585dd4459b1ad8b116424c01 100644 (file)
@@ -34,6 +34,7 @@
 #include "catalog/pg_type.h"
 #include "commands/alter.h"
 #include "commands/defrem.h"
+#include "commands/event_trigger.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
 #include "parser/parse_func.h"
@@ -1442,6 +1443,8 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
            }
        }
    }
+
+   EventTriggerStashAlterTSConfig(stmt, cfgId, dictIds, ndict);
 }
 
 /*
@@ -1509,6 +1512,8 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
 
        i++;
    }
+
+   EventTriggerStashAlterTSConfig(stmt, cfgId, NULL, 0);
 }
 
 
index 029761e74f8d7cbfebb4edbdad53e9f9ad0c508e..457735e7c24ef2405c73f2e31d585bf38e5e06a9 100644 (file)
@@ -3879,6 +3879,7 @@ _copyAlterTSConfigurationStmt(const AlterTSConfigurationStmt *from)
 {
    AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
 
+   COPY_SCALAR_FIELD(kind);
    COPY_NODE_FIELD(cfgname);
    COPY_NODE_FIELD(tokentype);
    COPY_NODE_FIELD(dicts);
index 190e50ab8c6909d62a7dbb4b40b0c6f53ff48e34..d830c4c1884aab7f8e08cf028177b81716897b8a 100644 (file)
@@ -1993,6 +1993,7 @@ static bool
 _equalAlterTSConfigurationStmt(const AlterTSConfigurationStmt *a,
                               const AlterTSConfigurationStmt *b)
 {
+   COMPARE_SCALAR_FIELD(kind);
    COMPARE_NODE_FIELD(cfgname);
    COMPARE_NODE_FIELD(tokentype);
    COMPARE_NODE_FIELD(dicts);
index 88ec83c7c3884a4a3885d2c1a2125bb00ed35d2a..36109ebdb46fbc2e1398981b0cdf738acfd86192 100644 (file)
@@ -8918,6 +8918,7 @@ AlterTSConfigurationStmt:
            ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
                {
                    AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
+                   n->kind = ALTER_TSCONFIG_ADD_MAPPING;
                    n->cfgname = $5;
                    n->tokentype = $9;
                    n->dicts = $11;
@@ -8928,6 +8929,7 @@ AlterTSConfigurationStmt:
            | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
                {
                    AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
+                   n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
                    n->cfgname = $5;
                    n->tokentype = $9;
                    n->dicts = $11;
@@ -8938,6 +8940,7 @@ AlterTSConfigurationStmt:
            | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
                {
                    AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
+                   n->kind = ALTER_TSCONFIG_REPLACE_DICT;
                    n->cfgname = $5;
                    n->tokentype = NIL;
                    n->dicts = list_make2($9,$11);
@@ -8948,6 +8951,7 @@ AlterTSConfigurationStmt:
            | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
                {
                    AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
+                   n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
                    n->cfgname = $5;
                    n->tokentype = $9;
                    n->dicts = list_make2($11,$13);
@@ -8958,6 +8962,7 @@ AlterTSConfigurationStmt:
            | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
                {
                    AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
+                   n->kind = ALTER_TSCONFIG_DROP_MAPPING;
                    n->cfgname = $5;
                    n->tokentype = $9;
                    n->missing_ok = false;
@@ -8966,6 +8971,7 @@ AlterTSConfigurationStmt:
            | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
                {
                    AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
+                   n->kind = ALTER_TSCONFIG_DROP_MAPPING;
                    n->cfgname = $5;
                    n->tokentype = $11;
                    n->missing_ok = true;
index 9a368949e8603e363eec071fad95187b1e1a1d61..b362adf66fa1d50340f23cc4cd90b65b5b9a1439 100644 (file)
@@ -6903,6 +6903,9 @@ deparse_utility_command(StashedCommand *cmd)
        case SCT_AlterDefaultPrivileges:
            tree = deparse_AlterDefaultPrivilegesStmt(cmd);
            break;
+       case SCT_AlterTSConfig:
+           tree = deparse_AlterTSConfigurationStmt(cmd);
+           break;
        default:
            elog(ERROR, "unexpected deparse node type %d", cmd->type);
    }
index 8d53e8ba83dd4599f7e177215130ad9c7753354e..b732fd9d4e3709c5557ede751406fa73f98ab26b 100644 (file)
@@ -78,6 +78,8 @@ extern void EventTriggerStashAlterOpFam(AlterOpFamilyStmt *stmt, Oid opfamoid,
                            List *operators, List *procedures);
 extern void EventTriggerStashCreateOpClass(CreateOpClassStmt *stmt, Oid opcoid,
                               List *operators, List *procedures);
+extern void EventTriggerStashAlterTSConfig(AlterTSConfigurationStmt *stmt,
+                              Oid cfgId, Oid *dicts, int ndicts);
 extern void EventTriggerStashAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt);
 
 #endif   /* EVENT_TRIGGER_H */
index beec0b33a9308b96d147602d7a6eb3916bf6e0f7..1679b9a8208cf5788f9522fefdd9422c4aaba5e9 100644 (file)
@@ -2851,9 +2851,19 @@ typedef struct AlterTSDictionaryStmt
 /*
  * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
  */
+typedef enum AlterTSConfigType
+{
+   ALTER_TSCONFIG_ADD_MAPPING,
+   ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN,
+   ALTER_TSCONFIG_REPLACE_DICT,
+   ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN,
+   ALTER_TSCONFIG_DROP_MAPPING
+} AlterTSConfigType;
+
 typedef struct AlterTSConfigurationStmt
 {
    NodeTag     type;
+   AlterTSConfigType   kind;   /* ALTER_TSCONFIG_ADD_MAPPING, etc */
    List       *cfgname;        /* qualified name (list of Value strings) */
 
    /*
index 6ee3ce2d8046797454ba053c344c1027ccd589c5..0e8026625d120dd5e2b69696f08002dab10dfba3 100644 (file)
@@ -32,7 +32,8 @@ typedef enum StashedCommandType
    SCT_Grant,
    SCT_AlterOpFamily,
    SCT_AlterDefaultPrivileges,
-   SCT_CreateOpClass
+   SCT_CreateOpClass,
+   SCT_AlterTSConfig
 } StashedCommandType;
 
 /*
@@ -91,6 +92,14 @@ typedef struct StashedCommand
            List   *procedures;
        } createopc;
 
+       /* ALTER TEXT SEARCH CONFIGURATION ADD/ALTER/DROP MAPPING */
+       struct
+       {
+           Oid     tscfgOid;
+           Oid    *dictIds;
+           int     ndicts;
+       } atscfg;
+
        /* ALTER DEFAULT PRIVILEGES */
        struct
        {