MCPcopy Create free account
hub / github.com/apache/cloudberry / func_select_candidate

Function func_select_candidate

src/backend/parser/parse_func.c:1059–1412  ·  view source on GitHub ↗

func_select_candidate() * Given the input argtype array and more than one candidate * for the function, attempt to resolve the conflict. * * Returns the selected candidate if the conflict can be resolved, * otherwise returns NULL. * * Note that the caller has already determined that there is no candidate * exactly matching the input argtypes, and has pruned away any "candidates" * that

Source from the content-addressed store, hash-verified

1057 * - ay 6/95
1058 */
1059FuncCandidateList
1060func_select_candidate(int nargs,
1061 Oid *input_typeids,
1062 FuncCandidateList candidates)
1063{
1064 FuncCandidateList current_candidate,
1065 first_candidate,
1066 last_candidate;
1067 Oid *current_typeids;
1068 Oid current_type;
1069 int i;
1070 int ncandidates;
1071 int nbestMatch,
1072 nmatch,
1073 nunknowns;
1074 Oid input_base_typeids[FUNC_MAX_ARGS];
1075 TYPCATEGORY slot_category[FUNC_MAX_ARGS],
1076 current_category;
1077 bool current_is_preferred;
1078 bool slot_has_preferred_type[FUNC_MAX_ARGS];
1079 bool resolved_unknowns;
1080
1081 /* protect local fixed-size arrays */
1082 if (nargs > FUNC_MAX_ARGS)
1083 ereport(ERROR,
1084 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
1085 errmsg_plural("cannot pass more than %d argument to a function",
1086 "cannot pass more than %d arguments to a function",
1087 FUNC_MAX_ARGS,
1088 FUNC_MAX_ARGS)));
1089
1090 /*
1091 * If any input types are domains, reduce them to their base types. This
1092 * ensures that we will consider functions on the base type to be "exact
1093 * matches" in the exact-match heuristic; it also makes it possible to do
1094 * something useful with the type-category heuristics. Note that this
1095 * makes it difficult, but not impossible, to use functions declared to
1096 * take a domain as an input datatype. Such a function will be selected
1097 * over the base-type function only if it is an exact match at all
1098 * argument positions, and so was already chosen by our caller.
1099 *
1100 * While we're at it, count the number of unknown-type arguments for use
1101 * later.
1102 */
1103 nunknowns = 0;
1104 for (i = 0; i < nargs; i++)
1105 {
1106 if (input_typeids[i] != UNKNOWNOID)
1107 input_base_typeids[i] = getBaseType(input_typeids[i]);
1108 else
1109 {
1110 /* no need to call getBaseType on UNKNOWNOID */
1111 input_base_typeids[i] = UNKNOWNOID;
1112 nunknowns++;
1113 }
1114 }
1115
1116 /*

Callers 2

oper_select_candidateFunction · 0.85
func_get_detailFunction · 0.85

Calls 7

getBaseTypeFunction · 0.85
TypeCategoryFunction · 0.85
IsPreferredTypeFunction · 0.85
can_coerce_typeFunction · 0.85
errcodeFunction · 0.50
errmsg_pluralFunction · 0.50

Tested by

no test coverage detected