left_oper() -- search for a unary left operator (prefix operator) * Given operator name and type of arg, return oper struct. * * IMPORTANT: the returned operator (if any) is only promised to be * coercion-compatible with the input datatype. Do not use this if * you need an exact- or binary-compatible match. * * If no matching operator found, return NULL if noError is true, * raise an erro
| 527 | * must ReleaseSysCache() the entry when done with it. |
| 528 | */ |
| 529 | Operator |
| 530 | left_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location) |
| 531 | { |
| 532 | Oid operOid; |
| 533 | OprCacheKey key; |
| 534 | bool key_ok; |
| 535 | FuncDetailCode fdresult = FUNCDETAIL_NOTFOUND; |
| 536 | HeapTuple tup = NULL; |
| 537 | |
| 538 | /* |
| 539 | * Try to find the mapping in the lookaside cache. |
| 540 | */ |
| 541 | key_ok = make_oper_cache_key(pstate, &key, op, InvalidOid, arg, location); |
| 542 | |
| 543 | if (key_ok) |
| 544 | { |
| 545 | operOid = find_oper_cache_entry(&key); |
| 546 | if (OidIsValid(operOid)) |
| 547 | { |
| 548 | tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid)); |
| 549 | if (HeapTupleIsValid(tup)) |
| 550 | return (Operator) tup; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * First try for an "exact" match. |
| 556 | */ |
| 557 | operOid = OpernameGetOprid(op, InvalidOid, arg); |
| 558 | if (!OidIsValid(operOid)) |
| 559 | { |
| 560 | /* |
| 561 | * Otherwise, search for the most suitable candidate. |
| 562 | */ |
| 563 | FuncCandidateList clist; |
| 564 | |
| 565 | /* Get prefix operators of given name */ |
| 566 | clist = OpernameGetCandidates(op, 'l', false); |
| 567 | |
| 568 | /* No operators found? Then fail... */ |
| 569 | if (clist != NULL) |
| 570 | { |
| 571 | /* |
| 572 | * The returned list has args in the form (0, oprright). Move the |
| 573 | * useful data into args[0] to keep oper_select_candidate simple. |
| 574 | * XXX we are assuming here that we may scribble on the list! |
| 575 | */ |
| 576 | FuncCandidateList clisti; |
| 577 | |
| 578 | for (clisti = clist; clisti != NULL; clisti = clisti->next) |
| 579 | { |
| 580 | clisti->args[0] = clisti->args[1]; |
| 581 | } |
| 582 | |
| 583 | /* |
| 584 | * We must run oper_select_candidate even if only one candidate, |
| 585 | * otherwise we may falsely return a non-type-compatible operator. |
| 586 | */ |
no test coverage detected