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
| 1057 | * - ay 6/95 |
| 1058 | */ |
| 1059 | FuncCandidateList |
| 1060 | func_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 | /* |
no test coverage detected