PostgreSQL Source Code git master
Loading...
Searching...
No Matches
parse_oper.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
#include "lib/stringinfo.h"
#include "nodes/nodeFuncs.h"
#include "parser/parse_coerce.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
#include "utils/builtins.h"
#include "utils/hsearch.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/typcache.h"
Include dependency graph for parse_oper.c:

Go to the source code of this file.

Data Structures

struct  OprCacheKey
 
struct  OprCacheEntry
 

Macros

#define MAX_CACHED_PATH_LEN   16
 

Typedefs

typedef struct OprCacheKey OprCacheKey
 
typedef struct OprCacheEntry OprCacheEntry
 

Functions

static Oid binary_oper_exact (List *opname, Oid arg1, Oid arg2)
 
static FuncDetailCode oper_select_candidate (int nargs, Oid *input_typeids, FuncCandidateList candidates, Oid *operOid)
 
static void op_error (ParseState *pstate, List *op, Oid arg1, Oid arg2, FuncDetailCode fdresult, int fgc_flags, int location)
 
static int oper_lookup_failure_details (int fgc_flags, bool is_unary_op)
 
static bool make_oper_cache_key (ParseState *pstate, OprCacheKey *key, List *opname, Oid ltypeId, Oid rtypeId, int location)
 
static Oid find_oper_cache_entry (OprCacheKey *key)
 
static void make_oper_cache_entry (OprCacheKey *key, Oid opr_oid)
 
static void InvalidateOprCacheCallBack (Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
 
Oid LookupOperName (ParseState *pstate, List *opername, Oid oprleft, Oid oprright, bool noError, int location)
 
Oid LookupOperWithArgs (ObjectWithArgs *oper, bool noError)
 
void get_sort_group_operators (Oid argtype, bool needLT, bool needEQ, bool needGT, Oid *ltOpr, Oid *eqOpr, Oid *gtOpr, bool *isHashable)
 
Oid oprid (Operator op)
 
Oid oprfuncid (Operator op)
 
Operator oper (ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
 
Operator compatible_oper (ParseState *pstate, List *op, Oid arg1, Oid arg2, bool noError, int location)
 
Oid compatible_oper_opid (List *op, Oid arg1, Oid arg2, bool noError)
 
Operator left_oper (ParseState *pstate, List *op, Oid arg, bool noError, int location)
 
const charop_signature_string (List *op, Oid arg1, Oid arg2)
 
Exprmake_op (ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
 
Exprmake_scalar_array_op (ParseState *pstate, List *opname, bool useOr, Node *ltree, Node *rtree, int location)
 

Variables

static HTABOprCacheHash = NULL
 

Macro Definition Documentation

◆ MAX_CACHED_PATH_LEN

#define MAX_CACHED_PATH_LEN   16

Definition at line 50 of file parse_oper.c.

Typedef Documentation

◆ OprCacheEntry

◆ OprCacheKey

Function Documentation

◆ binary_oper_exact()

static Oid binary_oper_exact ( List opname,
Oid  arg1,
Oid  arg2 
)
static

Definition at line 266 of file parse_oper.c.

267{
268 Oid result;
269 bool was_unknown = false;
270
271 /* Unspecified type for one of the arguments? then use the other */
272 if ((arg1 == UNKNOWNOID) && (arg2 != InvalidOid))
273 {
274 arg1 = arg2;
275 was_unknown = true;
276 }
277 else if ((arg2 == UNKNOWNOID) && (arg1 != InvalidOid))
278 {
279 arg2 = arg1;
280 was_unknown = true;
281 }
282
284 if (OidIsValid(result))
285 return result;
286
287 if (was_unknown)
288 {
289 /* arg1 and arg2 are the same here, need only look at arg1 */
291
292 if (basetype != arg1)
293 {
295 if (OidIsValid(result))
296 return result;
297 }
298 }
299
300 return InvalidOid;
301}
#define OidIsValid(objectId)
Definition c.h:858
uint32 result
Oid getBaseType(Oid typid)
Definition lsyscache.c:2754
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition namespace.c:1834
#define InvalidOid
unsigned int Oid
static int fb(int x)

References fb(), getBaseType(), InvalidOid, OidIsValid, OpernameGetOprid(), and result.

Referenced by oper().

◆ compatible_oper()

Operator compatible_oper ( ParseState pstate,
List op,
Oid  arg1,
Oid  arg2,
bool  noError,
int  location 
)

Definition at line 459 of file parse_oper.c.

461{
464
465 /* oper() will find the best available match */
466 optup = oper(pstate, op, arg1, arg2, noError, location);
467 if (optup == (Operator) NULL)
468 return (Operator) NULL; /* must be noError case */
469
470 /* but is it good enough? */
472 if (IsBinaryCoercible(arg1, opform->oprleft) &&
473 IsBinaryCoercible(arg2, opform->oprright))
474 return optup;
475
476 /* nope... */
478
479 if (!noError)
482 errmsg("operator requires run-time type coercion: %s",
484 parser_errposition(pstate, location)));
485
486 return (Operator) NULL;
487}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
static void * GETSTRUCT(const HeapTupleData *tuple)
static char * errmsg
bool IsBinaryCoercible(Oid srctype, Oid targettype)
int parser_errposition(ParseState *pstate, int location)
Definition parse_node.c:106
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition parse_oper.c:376
const char * op_signature_string(List *op, Oid arg1, Oid arg2)
Definition parse_oper.c:615
END_CATALOG_STRUCT typedef FormData_pg_operator * Form_pg_operator
Definition pg_operator.h:87
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265

References ereport, errcode(), errmsg, ERROR, fb(), Form_pg_operator, GETSTRUCT(), IsBinaryCoercible(), op_signature_string(), oper(), parser_errposition(), and ReleaseSysCache().

Referenced by compatible_oper_opid().

◆ compatible_oper_opid()

Oid compatible_oper_opid ( List op,
Oid  arg1,
Oid  arg2,
bool  noError 
)

Definition at line 497 of file parse_oper.c.

498{
500 Oid result;
501
503 if (optup != NULL)
504 {
505 result = oprid(optup);
507 return result;
508 }
509 return InvalidOid;
510}
Oid oprid(Operator op)
Definition parse_oper.c:241
Operator compatible_oper(ParseState *pstate, List *op, Oid arg1, Oid arg2, bool noError, int location)
Definition parse_oper.c:459

References compatible_oper(), fb(), InvalidOid, oprid(), ReleaseSysCache(), and result.

Referenced by addTargetToSortList(), and ComputeIndexAttrs().

◆ find_oper_cache_entry()

static Oid find_oper_cache_entry ( OprCacheKey key)
static

Definition at line 1032 of file parse_oper.c.

1033{
1035
1036 if (OprCacheHash == NULL)
1037 {
1038 /* First time through: initialize the hash table */
1039 HASHCTL ctl;
1040
1041 ctl.keysize = sizeof(OprCacheKey);
1042 ctl.entrysize = sizeof(OprCacheEntry);
1043 OprCacheHash = hash_create("Operator lookup cache", 256,
1045
1046 /* Arrange to flush cache on pg_operator and pg_cast changes */
1049 (Datum) 0);
1052 (Datum) 0);
1053 }
1054
1055 /* Look for an existing entry */
1057 key,
1058 HASH_FIND, NULL);
1059 if (oprentry == NULL)
1060 return InvalidOid;
1061
1062 return oprentry->opr_oid;
1063}
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:889
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition dynahash.c:360
@ HASH_FIND
Definition hsearch.h:108
#define HASH_ELEM
Definition hsearch.h:90
#define HASH_BLOBS
Definition hsearch.h:92
void CacheRegisterSyscacheCallback(SysCacheIdentifier cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1813
static void InvalidateOprCacheCallBack(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
static HTAB * OprCacheHash
Definition parse_oper.c:974
uint64_t Datum
Definition postgres.h:70
tree ctl
Definition radixtree.h:1838
Size keysize
Definition hsearch.h:69

References CacheRegisterSyscacheCallback(), ctl, fb(), HASH_BLOBS, hash_create(), HASH_ELEM, HASH_FIND, hash_search(), InvalidateOprCacheCallBack(), InvalidOid, HASHCTL::keysize, and OprCacheHash.

Referenced by left_oper(), and oper().

◆ get_sort_group_operators()

void get_sort_group_operators ( Oid  argtype,
bool  needLT,
bool  needEQ,
bool  needGT,
Oid ltOpr,
Oid eqOpr,
Oid gtOpr,
bool isHashable 
)

Definition at line 183 of file parse_oper.c.

187{
188 TypeCacheEntry *typentry;
189 int cache_flags;
190 Oid lt_opr;
191 Oid eq_opr;
192 Oid gt_opr;
193 bool hashable;
194
195 /*
196 * Look up the operators using the type cache.
197 *
198 * Note: the search algorithm used by typcache.c ensures that the results
199 * are consistent, ie all from matching opclasses.
200 */
201 if (isHashable != NULL)
204 else
206
207 typentry = lookup_type_cache(argtype, cache_flags);
208 lt_opr = typentry->lt_opr;
209 eq_opr = typentry->eq_opr;
210 gt_opr = typentry->gt_opr;
211 hashable = OidIsValid(typentry->hash_proc);
212
213 /* Report errors if needed */
214 if ((needLT && !OidIsValid(lt_opr)) ||
215 (needGT && !OidIsValid(gt_opr)))
218 errmsg("could not identify an ordering operator for type %s",
219 format_type_be(argtype)),
220 errhint("Use an explicit ordering operator or modify the query.")));
221 if (needEQ && !OidIsValid(eq_opr))
224 errmsg("could not identify an equality operator for type %s",
225 format_type_be(argtype))));
226
227 /* Return results as needed */
228 if (ltOpr)
229 *ltOpr = lt_opr;
230 if (eqOpr)
231 *eqOpr = eq_opr;
232 if (gtOpr)
233 *gtOpr = gt_opr;
234 if (isHashable)
235 *isHashable = hashable;
236}
int errhint(const char *fmt,...) pg_attribute_printf(1
char * format_type_be(Oid type_oid)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition typcache.c:389
#define TYPECACHE_EQ_OPR
Definition typcache.h:138
#define TYPECACHE_GT_OPR
Definition typcache.h:140
#define TYPECACHE_LT_OPR
Definition typcache.h:139
#define TYPECACHE_HASH_PROC
Definition typcache.h:142

References TypeCacheEntry::eq_opr, ereport, errcode(), errhint(), errmsg, ERROR, fb(), format_type_be(), TypeCacheEntry::gt_opr, TypeCacheEntry::hash_proc, lookup_type_cache(), TypeCacheEntry::lt_opr, OidIsValid, TYPECACHE_EQ_OPR, TYPECACHE_GT_OPR, TYPECACHE_HASH_PROC, and TYPECACHE_LT_OPR.

Referenced by addTargetToGroupList(), addTargetToSortList(), init_grouping_targets(), makeSortGroupClauseForSetOp(), and std_typanalyze().

◆ InvalidateOprCacheCallBack()

static void InvalidateOprCacheCallBack ( Datum  arg,
SysCacheIdentifier  cacheid,
uint32  hashvalue 
)
static

Definition at line 1087 of file parse_oper.c.

1089{
1090 HASH_SEQ_STATUS status;
1092
1094
1095 /* Currently we just flush all entries; hard to be smarter ... */
1096 hash_seq_init(&status, OprCacheHash);
1097
1098 while ((hentry = (OprCacheEntry *) hash_seq_search(&status)) != NULL)
1099 {
1101 &hentry->key,
1102 HASH_REMOVE, NULL) == NULL)
1103 elog(ERROR, "hash table corrupted");
1104 }
1105}
#define Assert(condition)
Definition c.h:943
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition dynahash.c:1352
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition dynahash.c:1317
#define elog(elevel,...)
Definition elog.h:228
@ HASH_REMOVE
Definition hsearch.h:110

References Assert, elog, ERROR, fb(), HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), and OprCacheHash.

Referenced by find_oper_cache_entry().

◆ left_oper()

Operator left_oper ( ParseState pstate,
List op,
Oid  arg,
bool  noError,
int  location 
)

Definition at line 529 of file parse_oper.c.

530{
531 Oid operOid;
533 bool key_ok;
534 int fgc_flags = 0;
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 {
546 if (OidIsValid(operOid))
547 {
550 return (Operator) tup;
551 }
552 }
553
554 /*
555 * First try for an "exact" match.
556 */
558 if (!OidIsValid(operOid))
559 {
560 /*
561 * Otherwise, search for the most suitable candidate.
562 */
564
565 /* Get prefix operators of given name */
566 clist = OpernameGetCandidates(op, 'l', false, &fgc_flags);
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 */
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 */
588 }
589 }
590
591 if (OidIsValid(operOid))
593
595 {
596 if (key_ok)
598 }
599 else if (!noError)
600 op_error(pstate, op, InvalidOid, arg,
601 fdresult, fgc_flags, location);
602
603 return (Operator) tup;
604}
Datum arg
Definition elog.c:1323
#define HeapTupleIsValid(tuple)
Definition htup.h:78
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok, int *fgc_flags)
Definition namespace.c:1947
FuncDetailCode
Definition parse_func.h:23
@ FUNCDETAIL_NOTFOUND
Definition parse_func.h:24
static void make_oper_cache_entry(OprCacheKey *key, Oid opr_oid)
static FuncDetailCode oper_select_candidate(int nargs, Oid *input_typeids, FuncCandidateList candidates, Oid *operOid)
Definition parse_oper.c:317
static bool make_oper_cache_key(ParseState *pstate, OprCacheKey *key, List *opname, Oid ltypeId, Oid rtypeId, int location)
Definition parse_oper.c:988
static void op_error(ParseState *pstate, List *op, Oid arg1, Oid arg2, FuncDetailCode fdresult, int fgc_flags, int location)
Definition parse_oper.c:635
static Oid find_oper_cache_entry(OprCacheKey *key)
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition namespace.h:39
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References arg, _FuncCandidateList::args, fb(), find_oper_cache_entry(), FUNCDETAIL_NOTFOUND, HeapTupleIsValid, InvalidOid, make_oper_cache_entry(), make_oper_cache_key(), ObjectIdGetDatum(), OidIsValid, op_error(), oper_select_candidate(), OpernameGetCandidates(), OpernameGetOprid(), and SearchSysCache1().

Referenced by generate_operator_name(), and make_op().

◆ LookupOperName()

Oid LookupOperName ( ParseState pstate,
List opername,
Oid  oprleft,
Oid  oprright,
bool  noError,
int  location 
)

Definition at line 102 of file parse_oper.c.

104{
105 Oid result;
106
107 result = OpernameGetOprid(opername, oprleft, oprright);
108 if (OidIsValid(result))
109 return result;
110
111 /* we don't use op_error here because only an exact match is wanted */
112 if (!noError)
113 {
114 if (!OidIsValid(oprright))
117 errmsg("postfix operators are not supported"),
118 parser_errposition(pstate, location)));
119
122 errmsg("operator does not exist: %s",
123 op_signature_string(opername, oprleft, oprright)),
124 parser_errposition(pstate, location)));
125 }
126
127 return InvalidOid;
128}

References ereport, errcode(), errmsg, ERROR, fb(), InvalidOid, OidIsValid, op_signature_string(), OpernameGetOprid(), parser_errposition(), and result.

Referenced by AggregateCreate(), DefineOpClass(), LookupOperWithArgs(), and OperatorLookup().

◆ LookupOperWithArgs()

Oid LookupOperWithArgs ( ObjectWithArgs oper,
bool  noError 
)

Definition at line 136 of file parse_oper.c.

137{
138 TypeName *oprleft,
139 *oprright;
140 Oid leftoid,
141 rightoid;
142
143 Assert(list_length(oper->objargs) == 2);
144 oprleft = linitial_node(TypeName, oper->objargs);
145 oprright = lsecond_node(TypeName, oper->objargs);
146
147 if (oprleft == NULL)
149 else
151
152 if (oprright == NULL)
154 else
156
157 return LookupOperName(NULL, oper->objname, leftoid, rightoid,
158 noError, -1);
159}
Oid LookupOperName(ParseState *pstate, List *opername, Oid oprleft, Oid oprright, bool noError, int location)
Definition parse_oper.c:102
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition parse_type.c:232
static int list_length(const List *l)
Definition pg_list.h:152
#define linitial_node(type, l)
Definition pg_list.h:181
#define lsecond_node(type, l)
Definition pg_list.h:186

References Assert, fb(), InvalidOid, linitial_node, list_length(), LookupOperName(), LookupTypeNameOid(), lsecond_node, and oper().

Referenced by AlterOperator(), AlterOpFamilyAdd(), DefineOpClass(), and get_object_address().

◆ make_op()

Expr * make_op ( ParseState pstate,
List opname,
Node ltree,
Node rtree,
Node last_srf,
int  location 
)

Definition at line 711 of file parse_oper.c.

713{
714 Oid ltypeId,
715 rtypeId;
720 int nargs;
721 List *args;
722 Oid rettype;
723 OpExpr *result;
724
725 /* Check it's not a postfix operator */
726 if (rtree == NULL)
729 errmsg("postfix operators are not supported")));
730
731 /* Select the operator */
732 if (ltree == NULL)
733 {
734 /* prefix operator */
737 tup = left_oper(pstate, opname, rtypeId, false, location);
738 }
739 else
740 {
741 /* otherwise, binary operator */
744 tup = oper(pstate, opname, ltypeId, rtypeId, false, location);
745 }
746
748
749 /* Check it's not a shell */
750 if (!RegProcedureIsValid(opform->oprcode))
753 errmsg("operator is only a shell: %s",
755 opform->oprleft,
756 opform->oprright)),
757 parser_errposition(pstate, location)));
758
759 /* Do typecasting and build the expression tree */
760 if (ltree == NULL)
761 {
762 /* prefix operator */
765 declared_arg_types[0] = opform->oprright;
766 nargs = 1;
767 }
768 else
769 {
770 /* otherwise, binary operator */
774 declared_arg_types[0] = opform->oprleft;
775 declared_arg_types[1] = opform->oprright;
776 nargs = 2;
777 }
778
779 /*
780 * enforce consistency with polymorphic argument and return types,
781 * possibly adjusting return type or declared_arg_types (which will be
782 * used as the cast destination by make_fn_arguments)
783 */
786 nargs,
787 opform->oprresult,
788 false);
789
790 /* perform the necessary typecasting of arguments */
792
793 /* and build the expression node */
795 result->opno = oprid(tup);
796 result->opfuncid = opform->oprcode;
797 result->opresulttype = rettype;
798 result->opretset = get_func_retset(opform->oprcode);
799 /* opcollid and inputcollid will be set by parse_collate.c */
800 result->args = args;
801 result->location = location;
802
803 /* if it returns a set, check that's OK */
804 if (result->opretset)
805 {
806 check_srf_call_placement(pstate, last_srf, location);
807 /* ... and remember it for error checks at higher levels */
808 pstate->p_last_srf = (Node *) result;
809 }
810
812
813 return (Expr *) result;
814}
#define RegProcedureIsValid(p)
Definition c.h:862
bool get_func_retset(Oid funcid)
Definition lsyscache.c:1973
Oid exprType(const Node *expr)
Definition nodeFuncs.c:42
#define makeNode(_type_)
Definition nodes.h:161
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
void make_fn_arguments(ParseState *pstate, List *fargs, Oid *actual_arg_types, Oid *declared_arg_types)
void check_srf_call_placement(ParseState *pstate, Node *last_srf, int location)
Operator left_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location)
Definition parse_oper.c:529
#define list_make1(x1)
Definition pg_list.h:244
#define list_make2(x1, x2)
Definition pg_list.h:246
Definition pg_list.h:54
Definition nodes.h:135
Node * p_last_srf
Definition parse_node.h:252
Definition ltree.h:43

References check_srf_call_placement(), enforce_generic_type_consistency(), ereport, errcode(), errmsg, ERROR, exprType(), fb(), Form_pg_operator, get_func_retset(), GETSTRUCT(), InvalidOid, left_oper(), list_make1, list_make2, make_fn_arguments(), makeNode, op_signature_string(), oper(), oprid(), ParseState::p_last_srf, parser_errposition(), RegProcedureIsValid, ReleaseSysCache(), and result.

Referenced by make_distinct_op(), make_row_comparison_op(), transformAExprIn(), transformAExprNullIf(), and transformAExprOp().

◆ make_oper_cache_entry()

static void make_oper_cache_entry ( OprCacheKey key,
Oid  opr_oid 
)
static

Definition at line 1071 of file parse_oper.c.

1072{
1074
1076
1078 key,
1079 HASH_ENTER, NULL);
1080 oprentry->opr_oid = opr_oid;
1081}
@ HASH_ENTER
Definition hsearch.h:109

References Assert, fb(), HASH_ENTER, hash_search(), and OprCacheHash.

Referenced by left_oper(), and oper().

◆ make_oper_cache_key()

static bool make_oper_cache_key ( ParseState pstate,
OprCacheKey key,
List opname,
Oid  ltypeId,
Oid  rtypeId,
int  location 
)
static

Definition at line 988 of file parse_oper.c.

990{
991 char *schemaname;
992 char *opername;
993
994 /* deconstruct the name list */
995 DeconstructQualifiedName(opname, &schemaname, &opername);
996
997 /* ensure zero-fill for stable hashing */
998 MemSet(key, 0, sizeof(OprCacheKey));
999
1000 /* save operator name and input types into key */
1001 strlcpy(key->oprname, opername, NAMEDATALEN);
1002 key->left_arg = ltypeId;
1003 key->right_arg = rtypeId;
1004
1005 if (schemaname)
1006 {
1008
1009 /* search only in exact schema given */
1010 setup_parser_errposition_callback(&pcbstate, pstate, location);
1011 key->search_path[0] = LookupExplicitNamespace(schemaname, false);
1013 }
1014 else
1015 {
1016 /* get the active search path */
1017 if (fetch_search_path_array(key->search_path,
1019 return false; /* oops, didn't fit */
1020 }
1021
1022 return true;
1023}
#define MemSet(start, val, len)
Definition c.h:1107
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Definition namespace.c:3457
void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p)
Definition namespace.c:3373
int fetch_search_path_array(Oid *sarray, int sarray_len)
Definition namespace.c:4931
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition parse_node.c:156
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition parse_node.c:140
#define MAX_CACHED_PATH_LEN
Definition parse_oper.c:50
#define NAMEDATALEN
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45

References cancel_parser_errposition_callback(), DeconstructQualifiedName(), fb(), fetch_search_path_array(), LookupExplicitNamespace(), MAX_CACHED_PATH_LEN, MemSet, NAMEDATALEN, setup_parser_errposition_callback(), and strlcpy().

Referenced by left_oper(), and oper().

◆ make_scalar_array_op()

Expr * make_scalar_array_op ( ParseState pstate,
List opname,
bool  useOr,
Node ltree,
Node rtree,
int  location 
)

Definition at line 821 of file parse_oper.c.

825{
826 Oid ltypeId,
827 rtypeId,
828 atypeId,
834 List *args;
835 Oid rettype;
837
840
841 /*
842 * The right-hand input of the operator will be the element type of the
843 * array. However, if we currently have just an untyped literal on the
844 * right, stay with that and hope we can resolve the operator.
845 */
846 if (atypeId == UNKNOWNOID)
848 else
849 {
851 if (!OidIsValid(rtypeId))
854 errmsg("op ANY/ALL (array) requires array on right side"),
855 parser_errposition(pstate, location)));
856 }
857
858 /* Now resolve the operator */
859 tup = oper(pstate, opname, ltypeId, rtypeId, false, location);
861
862 /* Check it's not a shell */
863 if (!RegProcedureIsValid(opform->oprcode))
866 errmsg("operator is only a shell: %s",
868 opform->oprleft,
869 opform->oprright)),
870 parser_errposition(pstate, location)));
871
875 declared_arg_types[0] = opform->oprleft;
876 declared_arg_types[1] = opform->oprright;
877
878 /*
879 * enforce consistency with polymorphic argument and return types,
880 * possibly adjusting return type or declared_arg_types (which will be
881 * used as the cast destination by make_fn_arguments)
882 */
885 2,
886 opform->oprresult,
887 false);
888
889 /*
890 * Check that operator result is boolean
891 */
892 if (rettype != BOOLOID)
895 errmsg("op ANY/ALL (array) requires operator to yield boolean"),
896 parser_errposition(pstate, location)));
897 if (get_func_retset(opform->oprcode))
900 errmsg("op ANY/ALL (array) requires operator not to return a set"),
901 parser_errposition(pstate, location)));
902
903 /*
904 * Now switch back to the array type on the right, arranging for any
905 * needed cast to be applied. Beware of polymorphic operators here;
906 * enforce_generic_type_consistency may or may not have replaced a
907 * polymorphic type with a real one.
908 */
910 {
911 /* assume the actual array type is OK */
913 }
914 else
915 {
920 errmsg("could not find array type for data type %s",
922 parser_errposition(pstate, location)));
923 }
926
927 /* perform the necessary typecasting of arguments */
929
930 /* and build the expression node */
932 result->opno = oprid(tup);
933 result->opfuncid = opform->oprcode;
934 result->hashfuncid = InvalidOid;
935 result->negfuncid = InvalidOid;
936 result->useOr = useOr;
937 /* inputcollid will be set by parse_collate.c */
938 result->args = args;
939 result->location = location;
940
942
943 return (Expr *) result;
944}
Oid get_base_element_type(Oid typid)
Definition lsyscache.c:3065
Oid get_array_type(Oid typid)
Definition lsyscache.c:3020

References enforce_generic_type_consistency(), ereport, errcode(), errmsg, ERROR, exprType(), fb(), Form_pg_operator, format_type_be(), get_array_type(), get_base_element_type(), get_func_retset(), GETSTRUCT(), InvalidOid, list_make2, make_fn_arguments(), makeNode, OidIsValid, op_signature_string(), oper(), oprid(), parser_errposition(), RegProcedureIsValid, ReleaseSysCache(), and result.

Referenced by transformAExprIn(), transformAExprOpAll(), and transformAExprOpAny().

◆ op_error()

static void op_error ( ParseState pstate,
List op,
Oid  arg1,
Oid  arg2,
FuncDetailCode  fdresult,
int  fgc_flags,
int  location 
)
static

Definition at line 635 of file parse_oper.c.

638{
642 errmsg("operator is not unique: %s",
644 errdetail("Could not choose a best candidate operator."),
645 errhint("You might need to add explicit type casts."),
646 parser_errposition(pstate, location)));
647 else
650 errmsg("operator does not exist: %s",
653 parser_errposition(pstate, location)));
654}
int errdetail(const char *fmt,...) pg_attribute_printf(1
@ FUNCDETAIL_MULTIPLE
Definition parse_func.h:25
static int oper_lookup_failure_details(int fgc_flags, bool is_unary_op)
Definition parse_oper.c:660

References ereport, errcode(), errdetail(), errhint(), errmsg, ERROR, fb(), FUNCDETAIL_MULTIPLE, op_signature_string(), oper_lookup_failure_details(), and parser_errposition().

Referenced by left_oper(), and oper().

◆ op_signature_string()

const char * op_signature_string ( List op,
Oid  arg1,
Oid  arg2 
)

Definition at line 615 of file parse_oper.c.

616{
618
620
621 if (OidIsValid(arg1))
623
625
627
628 return argbuf.data; /* return palloc'd string buffer */
629}
char * NameListToString(const List *names)
Definition namespace.c:3666
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

References appendStringInfo(), appendStringInfoString(), fb(), format_type_be(), initStringInfo(), NameListToString(), and OidIsValid.

Referenced by compatible_oper(), LookupOperName(), make_op(), make_scalar_array_op(), op_error(), and ValidateOperatorReference().

◆ oper()

Operator oper ( ParseState pstate,
List opname,
Oid  ltypeId,
Oid  rtypeId,
bool  noError,
int  location 
)

Definition at line 376 of file parse_oper.c.

378{
379 Oid operOid;
381 bool key_ok;
382 int fgc_flags = 0;
385
386 /*
387 * Try to find the mapping in the lookaside cache.
388 */
389 key_ok = make_oper_cache_key(pstate, &key, opname, ltypeId, rtypeId, location);
390
391 if (key_ok)
392 {
394 if (OidIsValid(operOid))
395 {
398 return (Operator) tup;
399 }
400 }
401
402 /*
403 * First try for an "exact" match.
404 */
406 if (!OidIsValid(operOid))
407 {
408 /*
409 * Otherwise, search for the most suitable candidate.
410 */
412
413 /* Get binary operators of given name */
415
416 /* No operators found? Then fail... */
417 if (clist != NULL)
418 {
419 /*
420 * Unspecified type for one of the arguments? then use the other
421 * (XXX this is probably dead code?)
422 */
423 Oid inputOids[2];
424
425 if (rtypeId == InvalidOid)
427 else if (ltypeId == InvalidOid)
429 inputOids[0] = ltypeId;
430 inputOids[1] = rtypeId;
432 }
433 }
434
435 if (OidIsValid(operOid))
437
439 {
440 if (key_ok)
442 }
443 else if (!noError)
444 op_error(pstate, opname, ltypeId, rtypeId,
445 fdresult, fgc_flags, location);
446
447 return (Operator) tup;
448}
static Oid binary_oper_exact(List *opname, Oid arg1, Oid arg2)
Definition parse_oper.c:266

References binary_oper_exact(), fb(), find_oper_cache_entry(), FUNCDETAIL_NOTFOUND, HeapTupleIsValid, InvalidOid, make_oper_cache_entry(), make_oper_cache_key(), ObjectIdGetDatum(), OidIsValid, op_error(), oper_select_candidate(), OpernameGetCandidates(), and SearchSysCache1().

Referenced by compatible_oper(), Do_MultiXactIdWait(), generate_operator_name(), LookupOperWithArgs(), make_op(), make_SAOP_expr(), make_scalar_array_op(), makeOperatorDependencies(), multi_sort_add_dimension(), MultiXactIdWait(), pushOperator(), tsquery_opr_selec(), tsqueryrecv(), and XactLockTableWait().

◆ oper_lookup_failure_details()

static int oper_lookup_failure_details ( int  fgc_flags,
bool  is_unary_op 
)
static

Definition at line 660 of file parse_oper.c.

661{
662 /*
663 * If not FGC_NAME_VISIBLE, we shouldn't raise the question of whether the
664 * arguments are wrong. If the operator name was not schema-qualified,
665 * it's helpful to distinguish between doesn't-exist-anywhere and
666 * not-in-search-path; but if it was, there's really nothing to add to the
667 * basic "operator does not exist" message.
668 *
669 * Note: we passed missing_ok = false to OpernameGetCandidates, so there's
670 * no need to consider FGC_SCHEMA_EXISTS here: we'd have already thrown an
671 * error if an explicitly-given schema doesn't exist.
672 */
674 {
676 return 0; /* schema-qualified name */
677 else if (!(fgc_flags & FGC_NAME_EXISTS))
678 return errdetail("There is no operator of that name.");
679 else
680 return errdetail("An operator of that name exists, but it is not in the search_path.");
681 }
682
683 /*
684 * Otherwise, the problem must be incorrect argument type(s).
685 */
686 if (is_unary_op)
687 {
688 (void) errdetail("No operator of that name accepts the given argument type.");
689 return errhint("You might need to add an explicit type cast.");
690 }
691 else
692 {
693 (void) errdetail("No operator of that name accepts the given argument types.");
694 return errhint("You might need to add explicit type casts.");
695 }
696}
#define FGC_NAME_EXISTS
Definition namespace.h:49
#define FGC_SCHEMA_GIVEN
Definition namespace.h:47
#define FGC_NAME_VISIBLE
Definition namespace.h:50

References errdetail(), errhint(), fb(), FGC_NAME_EXISTS, FGC_NAME_VISIBLE, and FGC_SCHEMA_GIVEN.

Referenced by op_error().

◆ oper_select_candidate()

static FuncDetailCode oper_select_candidate ( int  nargs,
Oid input_typeids,
FuncCandidateList  candidates,
Oid operOid 
)
static

Definition at line 317 of file parse_oper.c.

321{
322 int ncandidates;
323
324 /*
325 * Delete any candidates that cannot actually accept the given input
326 * types, whether directly or by coercion.
327 */
330
331 /* Done if no candidate or only one candidate survives */
332 if (ncandidates == 0)
333 {
335 return FUNCDETAIL_NOTFOUND;
336 }
337 if (ncandidates == 1)
338 {
339 *operOid = candidates->oid;
340 return FUNCDETAIL_NORMAL;
341 }
342
343 /*
344 * Use the same heuristics as for ambiguous functions to resolve the
345 * conflict.
346 */
348
349 if (candidates)
350 {
351 *operOid = candidates->oid;
352 return FUNCDETAIL_NORMAL;
353 }
354
356 return FUNCDETAIL_MULTIPLE; /* failed to select a best candidate */
357}
FuncCandidateList func_select_candidate(int nargs, Oid *input_typeids, FuncCandidateList candidates)
int func_match_argtypes(int nargs, Oid *input_typeids, FuncCandidateList raw_candidates, FuncCandidateList *candidates)
@ FUNCDETAIL_NORMAL
Definition parse_func.h:26

References fb(), func_match_argtypes(), func_select_candidate(), FUNCDETAIL_MULTIPLE, FUNCDETAIL_NORMAL, FUNCDETAIL_NOTFOUND, and InvalidOid.

Referenced by left_oper(), and oper().

◆ oprfuncid()

Oid oprfuncid ( Operator  op)

Definition at line 248 of file parse_oper.c.

249{
251
252 return pgopform->oprcode;
253}

References fb(), Form_pg_operator, and GETSTRUCT().

◆ oprid()

Variable Documentation

◆ OprCacheHash

HTAB* OprCacheHash = NULL
static