* get_sort_group_operators - get default sorting/grouping operators for type * * We fetch the "<", "=", and ">" operators all at once to reduce lookup * overhead (knowing that most callers will be interested in at least two). * However, a given datatype might have only an "=" operator, if it is * hashable but not sortable. (Other combinations of present and missing * operators shouldn't hap
| 189 | * coercion steps. |
| 190 | */ |
| 191 | void |
| 192 | get_sort_group_operators(Oid argtype, |
| 193 | bool needLT, bool needEQ, bool needGT, |
| 194 | Oid *ltOpr, Oid *eqOpr, Oid *gtOpr, |
| 195 | bool *isHashable) |
| 196 | { |
| 197 | TypeCacheEntry *typentry; |
| 198 | int cache_flags; |
| 199 | Oid lt_opr; |
| 200 | Oid eq_opr; |
| 201 | Oid gt_opr; |
| 202 | bool hashable; |
| 203 | |
| 204 | /* |
| 205 | * Look up the operators using the type cache. |
| 206 | * |
| 207 | * Note: the search algorithm used by typcache.c ensures that the results |
| 208 | * are consistent, ie all from matching opclasses. |
| 209 | */ |
| 210 | if (isHashable != NULL) |
| 211 | cache_flags = TYPECACHE_LT_OPR | TYPECACHE_EQ_OPR | TYPECACHE_GT_OPR | |
| 212 | TYPECACHE_HASH_PROC; |
| 213 | else |
| 214 | cache_flags = TYPECACHE_LT_OPR | TYPECACHE_EQ_OPR | TYPECACHE_GT_OPR; |
| 215 | |
| 216 | typentry = lookup_type_cache(argtype, cache_flags); |
| 217 | lt_opr = typentry->lt_opr; |
| 218 | eq_opr = typentry->eq_opr; |
| 219 | gt_opr = typentry->gt_opr; |
| 220 | hashable = OidIsValid(typentry->hash_proc); |
| 221 | |
| 222 | /* Report errors if needed */ |
| 223 | if ((needLT && !OidIsValid(lt_opr)) || |
| 224 | (needGT && !OidIsValid(gt_opr))) |
| 225 | ereport(ERROR, |
| 226 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 227 | errmsg("could not identify an ordering operator for type %s", |
| 228 | format_type_be(argtype)), |
| 229 | errhint("Use an explicit ordering operator or modify the query."))); |
| 230 | if (needEQ && !OidIsValid(eq_opr)) |
| 231 | ereport(ERROR, |
| 232 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 233 | errmsg("could not identify an equality operator for type %s", |
| 234 | format_type_be(argtype)))); |
| 235 | |
| 236 | /* Return results as needed */ |
| 237 | if (ltOpr) |
| 238 | *ltOpr = lt_opr; |
| 239 | if (eqOpr) |
| 240 | *eqOpr = eq_opr; |
| 241 | if (gtOpr) |
| 242 | *gtOpr = gt_opr; |
| 243 | if (isHashable) |
| 244 | *isHashable = hashable; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | /* given operator tuple, return the operator OID */ |
no test coverage detected