|
21 | 21 | #include "access/htup_details.h" |
22 | 22 | #include "catalog/namespace.h" |
23 | 23 | #include "catalog/pg_proc.h" |
| 24 | +#include "catalog/pg_type.h" |
| 25 | +#include "nodes/value.h" |
24 | 26 | #include "parser/parse_func.h" |
25 | 27 | #include "utils/lsyscache.h" |
26 | 28 | #include "utils/syscache.h" |
27 | 29 |
|
28 | 30 | #include "distributed/deparser.h" |
| 31 | +#include "distributed/listutils.h" |
29 | 32 | #include "distributed/version_compat.h" |
30 | 33 |
|
31 | 34 | /* forward declaration for qualify functions */ |
32 | 35 | static void QualifyFunction(ObjectWithArgs *func, ObjectType type); |
33 | 36 | static void QualifyFunctionSchemaName(ObjectWithArgs *func, ObjectType type); |
| 37 | +static void QualifySupportFunctionName(DefElem *supportDefElem); |
34 | 38 |
|
35 | 39 |
|
36 | 40 | /* AssertObjectTypeIsFunctionType asserts we aren't receiving something we shouldn't */ |
@@ -59,6 +63,48 @@ QualifyAlterFunctionStmt(Node *node) |
59 | 63 | AssertObjectTypeIsFunctional(stmt->objtype); |
60 | 64 |
|
61 | 65 | QualifyFunction(stmt->func, stmt->objtype); |
| 66 | + |
| 67 | + DefElem *action = NULL; |
| 68 | + foreach_declared_ptr(action, stmt->actions) |
| 69 | + { |
| 70 | + if (strcmp(action->defname, "support") == 0) |
| 71 | + { |
| 72 | + QualifySupportFunctionName(action); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +/* |
| 79 | + * QualifySupportFunctionName makes the support function name of an |
| 80 | + * ALTER FUNCTION .. SUPPORT .. statement fully qualified, so the workers |
| 81 | + * resolve the same function the coordinator does regardless of search_path. |
| 82 | + */ |
| 83 | +static void |
| 84 | +QualifySupportFunctionName(DefElem *supportDefElem) |
| 85 | +{ |
| 86 | + List *supportName = castNode(List, supportDefElem->arg); |
| 87 | + char *schemaName = NULL; |
| 88 | + char *functionName = NULL; |
| 89 | + |
| 90 | + DeconstructQualifiedName(supportName, &schemaName, &functionName); |
| 91 | + if (schemaName != NULL) |
| 92 | + { |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + /* support functions take a single internal argument, see interpret_func_support */ |
| 97 | + Oid argTypes[1] = { INTERNALOID }; |
| 98 | + Oid supportOid = LookupFuncName(supportName, 1, argTypes, true); |
| 99 | + if (!OidIsValid(supportOid)) |
| 100 | + { |
| 101 | + /* postgres reports the missing function when it executes the statement */ |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + schemaName = get_namespace_name(get_func_namespace(supportOid)); |
| 106 | + supportDefElem->arg = (Node *) list_make2(makeString(schemaName), |
| 107 | + makeString(pstrdup(functionName))); |
62 | 108 | } |
63 | 109 |
|
64 | 110 |
|
|
0 commit comments