diff options
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r-- | src/backend/commands/functioncmds.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index dbbb2d3f88a..efc3aa4b9cc 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -465,7 +465,8 @@ compute_common_attribute(DefElem *defel, DefElem **leakproof_item, List **set_items, DefElem **cost_item, - DefElem **rows_item) + DefElem **rows_item, + DefElem **parallel_item) { if (strcmp(defel->defname, "volatility") == 0) { @@ -513,6 +514,13 @@ compute_common_attribute(DefElem *defel, *rows_item = defel; } + else if (strcmp(defel->defname, "parallel") == 0) + { + if (*parallel_item) + goto duplicate_error; + + *parallel_item = defel; + } else return false; @@ -544,6 +552,27 @@ interpret_func_volatility(DefElem *defel) } } +static char +interpret_func_parallel(DefElem *defel) +{ + char *str = strVal(defel->arg); + + if (strcmp(str, "safe") == 0) + return PROPARALLEL_SAFE; + else if (strcmp(str, "unsafe") == 0) + return PROPARALLEL_UNSAFE; + else if (strcmp(str, "restricted") == 0) + return PROPARALLEL_RESTRICTED; + else + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("parallel option \"%s\" not recognized", + str))); + return PROPARALLEL_UNSAFE; /* keep compiler quiet */ + } +} + /* * Update a proconfig value according to a list of VariableSetStmt items. * @@ -592,7 +621,8 @@ compute_attributes_sql_style(List *options, bool *leakproof_p, ArrayType **proconfig, float4 *procost, - float4 *prorows) + float4 *prorows, + char *parallel_p) { ListCell *option; DefElem *as_item = NULL; @@ -606,6 +636,7 @@ compute_attributes_sql_style(List *options, List *set_items = NIL; DefElem *cost_item = NULL; DefElem *rows_item = NULL; + DefElem *parallel_item = NULL; foreach(option, options) { @@ -650,7 +681,8 @@ compute_attributes_sql_style(List *options, &leakproof_item, &set_items, &cost_item, - &rows_item)) + &rows_item, + ¶llel_item)) { /* recognized common option */ continue; @@ -712,6 +744,8 @@ compute_attributes_sql_style(List *options, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ROWS must be positive"))); } + if (parallel_item) + *parallel_p = interpret_func_parallel(parallel_item); } @@ -858,6 +892,7 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString) HeapTuple languageTuple; Form_pg_language languageStruct; List *as_clause; + char parallel; /* Convert list of names to a name and namespace */ namespaceId = QualifiedNameGetCreationNamespace(stmt->funcname, @@ -878,13 +913,14 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString) proconfig = NULL; procost = -1; /* indicates not set */ prorows = -1; /* indicates not set */ + parallel = PROPARALLEL_UNSAFE; /* override attributes from explicit list */ compute_attributes_sql_style(stmt->options, &as_clause, &language, &transformDefElem, &isWindowFunc, &volatility, &isStrict, &security, &isLeakProof, - &proconfig, &procost, &prorows); + &proconfig, &procost, &prorows, ¶llel); /* Look up the language and validate permissions */ languageTuple = SearchSysCache1(LANGNAME, PointerGetDatum(language)); @@ -1061,6 +1097,7 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString) isLeakProof, isStrict, volatility, + parallel, parameterTypes, PointerGetDatum(allParameterTypes), PointerGetDatum(parameterModes), @@ -1141,6 +1178,7 @@ AlterFunction(AlterFunctionStmt *stmt) List *set_items = NIL; DefElem *cost_item = NULL; DefElem *rows_item = NULL; + DefElem *parallel_item = NULL; ObjectAddress address; rel = heap_open(ProcedureRelationId, RowExclusiveLock); @@ -1178,7 +1216,8 @@ AlterFunction(AlterFunctionStmt *stmt) &leakproof_item, &set_items, &cost_item, - &rows_item) == false) + &rows_item, + ¶llel_item) == false) elog(ERROR, "option \"%s\" not recognized", defel->defname); } @@ -1250,6 +1289,8 @@ AlterFunction(AlterFunctionStmt *stmt) tup = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val, repl_null, repl_repl); } + if (parallel_item) + procForm->proparallel = interpret_func_parallel(parallel_item); /* Do the update */ simple_heap_update(rel, &tup->t_self, tup); |