From 3e0cff94a6cb7a8b793c9f15ddb2444a18ad2e35 Mon Sep 17 00:00:00 2001 From: velioglu Date: Mon, 10 Dec 2018 11:59:41 +0300 Subject: [PATCH 1/2] Add FunctionOidExtended function --- .../distributed/utils/function_utils.c | 29 ++++++++++++++++--- src/include/distributed/function_utils.h | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/utils/function_utils.c b/src/backend/distributed/utils/function_utils.c index 5007399fe..862604b02 100644 --- a/src/backend/distributed/utils/function_utils.c +++ b/src/backend/distributed/utils/function_utils.c @@ -18,11 +18,27 @@ #endif /* - * FunctionOid looks for a function that has the given name and the given number - * of arguments, and returns the corresponding function's oid. + * FunctionOid searches for a function that has the given name and the given + * number of arguments, and returns the corresponding function's oid. The + * function reports error if the target function is not found, or it found more + * matching instances. */ Oid FunctionOid(const char *schemaName, const char *functionName, int argumentCount) +{ + return FunctionOidExtended(schemaName, functionName, argumentCount, false); +} + + +/* + * FunctionOidExtended searches for a given function identified by schema, + * functionName, and argumentCount. It reports error if the function is not + * found or there are more than one match. If the missingOK parameter is set + * and there are no matches, then the function returns InvalidOid. + */ +Oid +FunctionOidExtended(const char *schemaName, const char *functionName, int argumentCount, + bool missingOK) { FuncCandidateList functionList = NULL; Oid functionOid = InvalidOid; @@ -32,14 +48,18 @@ FunctionOid(const char *schemaName, const char *functionName, int argumentCount) List *argumentList = NIL; const bool findVariadics = false; const bool findDefaults = false; - const bool missingOK = true; functionList = FuncnameGetCandidates(qualifiedFunctionNameList, argumentCount, argumentList, findVariadics, - findDefaults, missingOK); + findDefaults, true); if (functionList == NULL) { + if (missingOK) + { + return InvalidOid; + } + ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION), errmsg("function \"%s\" does not exist", functionName))); } @@ -51,6 +71,7 @@ FunctionOid(const char *schemaName, const char *functionName, int argumentCount) /* get function oid from function list's head */ functionOid = functionList->oid; + return functionOid; } diff --git a/src/include/distributed/function_utils.h b/src/include/distributed/function_utils.h index 822a38f2c..2b188548b 100644 --- a/src/include/distributed/function_utils.h +++ b/src/include/distributed/function_utils.h @@ -14,5 +14,7 @@ /* Function declaration for getting oid for the given function name */ extern Oid FunctionOid(const char *schemaName, const char *functionName, int argumentCount); +extern Oid FunctionOidExtended(const char *schemaName, const char *functionName, int + argumentCount, bool missingOK); extern ReturnSetInfo * FunctionCallGetTupleStore1(PGFunction function, Oid functionId, Datum argument); From 90704d9a52849841695ecfd5d146231d9ea87fa9 Mon Sep 17 00:00:00 2001 From: velioglu Date: Mon, 10 Dec 2018 13:27:48 +0300 Subject: [PATCH 2/2] Fix getting function oid to get hll_add_agg id --- src/backend/distributed/planner/multi_master_planner.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/planner/multi_master_planner.c b/src/backend/distributed/planner/multi_master_planner.c index 2fd728d6d..40d0dade1 100644 --- a/src/backend/distributed/planner/multi_master_planner.c +++ b/src/backend/distributed/planner/multi_master_planner.c @@ -454,8 +454,14 @@ QueryContainsAggregateWithHLL(Query *query) Oid hllId = get_extension_oid(HLL_EXTENSION_NAME, false); Oid hllSchemaOid = get_extension_schema(hllId); const char *hllSchemaName = get_namespace_name(hllSchemaOid); - Oid addFunctionId = FunctionOid(hllSchemaName, HLL_ADD_AGGREGATE_NAME, - argCount); + + /* + * If the obtained oid is InvalidOid for addFunctionId, that means + * we don't have an hll_add_agg function with the given argument count. + * So, we don't need to double check whether the obtained id is valid. + */ + Oid addFunctionId = FunctionOidExtended(hllSchemaName, HLL_ADD_AGGREGATE_NAME, + argCount, true); Oid unionFunctionId = FunctionOid(hllSchemaName, HLL_UNION_AGGREGATE_NAME, 1); if (aggref->aggfnoid == addFunctionId || aggref->aggfnoid == unionFunctionId)