]> granicus.if.org Git - postgresql/blobdiff - src/backend/commands/aggregatecmds.c
Update copyright via script for 2017
[postgresql] / src / backend / commands / aggregatecmds.c
index 894c89df947d33de129520cb9f681dd23f2e084e..02ea254cd498f02d7ac0a47f3a0b5b57d50183bb 100644 (file)
@@ -4,7 +4,7 @@
  *
  *       Routines for aggregate-manipulation commands
  *
- * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -22,7 +22,6 @@
  */
 #include "postgres.h"
 
-#include "access/heapam.h"
 #include "access/htup_details.h"
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
@@ -52,8 +51,7 @@
  * "parameters" is a list of DefElem representing the agg's definition clauses.
  */
 ObjectAddress
-DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
-                               const char *queryString)
+DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters)
 {
        char       *aggName;
        Oid                     aggNamespace;
@@ -61,6 +59,9 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
        char            aggKind = AGGKIND_NORMAL;
        List       *transfuncName = NIL;
        List       *finalfuncName = NIL;
+       List       *combinefuncName = NIL;
+       List       *serialfuncName = NIL;
+       List       *deserialfuncName = NIL;
        List       *mtransfuncName = NIL;
        List       *minvtransfuncName = NIL;
        List       *mfinalfuncName = NIL;
@@ -74,6 +75,7 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
        int32           mtransSpace = 0;
        char       *initval = NULL;
        char       *minitval = NULL;
+       char       *parallel = NULL;
        int                     numArgs;
        int                     numDirectArgs = 0;
        oidvector  *parameterTypes;
@@ -86,6 +88,7 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
        Oid                     mtransTypeId = InvalidOid;
        char            transTypeType;
        char            mtransTypeType = 0;
+       char            proparallel = PROPARALLEL_UNSAFE;
        ListCell   *pl;
 
        /* Convert list of names to a name and namespace */
@@ -124,6 +127,12 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                        transfuncName = defGetQualifiedName(defel);
                else if (pg_strcasecmp(defel->defname, "finalfunc") == 0)
                        finalfuncName = defGetQualifiedName(defel);
+               else if (pg_strcasecmp(defel->defname, "combinefunc") == 0)
+                       combinefuncName = defGetQualifiedName(defel);
+               else if (pg_strcasecmp(defel->defname, "serialfunc") == 0)
+                       serialfuncName = defGetQualifiedName(defel);
+               else if (pg_strcasecmp(defel->defname, "deserialfunc") == 0)
+                       deserialfuncName = defGetQualifiedName(defel);
                else if (pg_strcasecmp(defel->defname, "msfunc") == 0)
                        mtransfuncName = defGetQualifiedName(defel);
                else if (pg_strcasecmp(defel->defname, "minvfunc") == 0)
@@ -165,6 +174,8 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                        initval = defGetString(defel);
                else if (pg_strcasecmp(defel->defname, "minitcond") == 0)
                        minitval = defGetString(defel);
+               else if (pg_strcasecmp(defel->defname, "parallel") == 0)
+                       parallel = defGetString(defel);
                else
                        ereport(WARNING,
                                        (errcode(ERRCODE_SYNTAX_ERROR),
@@ -274,10 +285,10 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                                         errmsg("basetype is redundant with aggregate input type specification")));
 
                numArgs = list_length(args);
-               interpret_function_parameter_list(args,
+               interpret_function_parameter_list(pstate,
+                                                                                 args,
                                                                                  InvalidOid,
                                                                                  true, /* is an aggregate */
-                                                                                 queryString,
                                                                                  &parameterTypes,
                                                                                  &allParameterTypes,
                                                                                  &parameterModes,
@@ -316,6 +327,27 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                                                        format_type_be(transTypeId))));
        }
 
+       if (serialfuncName && deserialfuncName)
+       {
+               /*
+                * Serialization is only needed/allowed for transtype INTERNAL.
+                */
+               if (transTypeId != INTERNALOID)
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+                                        errmsg("serialization functions may be specified only when the aggregate transition data type is %s",
+                                                       format_type_be(INTERNALOID))));
+       }
+       else if (serialfuncName || deserialfuncName)
+       {
+               /*
+                * Cannot specify one function without the other.
+                */
+               ereport(ERROR,
+                               (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+                                errmsg("must specify both or neither of serialization and deserialization functions")));
+       }
+
        /*
         * If a moving-aggregate transtype is specified, look that up.  Same
         * restrictions as for transtype.
@@ -367,6 +399,20 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                (void) OidInputFunctionCall(typinput, minitval, typioparam, -1);
        }
 
+       if (parallel)
+       {
+               if (pg_strcasecmp(parallel, "safe") == 0)
+                       proparallel = PROPARALLEL_SAFE;
+               else if (pg_strcasecmp(parallel, "restricted") == 0)
+                       proparallel = PROPARALLEL_RESTRICTED;
+               else if (pg_strcasecmp(parallel, "unsafe") == 0)
+                       proparallel = PROPARALLEL_UNSAFE;
+               else
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_SYNTAX_ERROR),
+                                        errmsg("parameter \"parallel\" must be SAFE, RESTRICTED, or UNSAFE")));
+       }
+
        /*
         * Most of the argument-checking is done inside of AggregateCreate
         */
@@ -383,6 +429,9 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                                                   variadicArgType,
                                                   transfuncName,               /* step function name */
                                                   finalfuncName,               /* final function name */
+                                                  combinefuncName,             /* combine function name */
+                                                  serialfuncName,              /* serial function name */
+                                                  deserialfuncName,    /* deserial function name */
                                                   mtransfuncName,              /* fwd trans function name */
                                                   minvtransfuncName,   /* inv trans function name */
                                                   mfinalfuncName,              /* final function name */
@@ -394,5 +443,6 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
                                                   mtransTypeId,                /* transition data type */
                                                   mtransSpace, /* transition space */
                                                   initval,             /* initial condition */
-                                                  minitval);   /* initial condition */
+                                                  minitval,    /* initial condition */
+                                                  proparallel);                /* parallel safe? */
 }