72 bool canMerge =
false;
103 foreach(pl, parameters)
107 if (strcmp(defel->
defname,
"leftarg") == 0)
110 if (typeName1->
setof)
112 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
113 errmsg(
"SETOF type not allowed for operator argument")));
115 else if (strcmp(defel->
defname,
"rightarg") == 0)
118 if (typeName2->
setof)
120 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
121 errmsg(
"SETOF type not allowed for operator argument")));
124 else if (strcmp(defel->
defname,
"function") == 0)
126 else if (strcmp(defel->
defname,
"procedure") == 0)
128 else if (strcmp(defel->
defname,
"commutator") == 0)
130 else if (strcmp(defel->
defname,
"negator") == 0)
132 else if (strcmp(defel->
defname,
"restrict") == 0)
134 else if (strcmp(defel->
defname,
"join") == 0)
136 else if (strcmp(defel->
defname,
"hashes") == 0)
138 else if (strcmp(defel->
defname,
"merges") == 0)
141 else if (strcmp(defel->
defname,
"sort1") == 0)
143 else if (strcmp(defel->
defname,
"sort2") == 0)
145 else if (strcmp(defel->
defname,
"ltcmp") == 0)
147 else if (strcmp(defel->
defname,
"gtcmp") == 0)
153 (
errcode(ERRCODE_SYNTAX_ERROR),
154 errmsg(
"operator attribute \"%s\" not recognized",
162 if (functionName ==
NIL)
164 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
165 errmsg(
"operator function must be specified")));
182 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
183 errmsg(
"operator argument types must be specified")));
186 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
187 errmsg(
"operator right argument type must be specified"),
188 errdetail(
"Postfix operators are not supported.")));
281 typeId[0] = INTERNALOID;
283 typeId[2] = INTERNALOID;
286 restrictionOid =
LookupFuncName(restrictionName, 4, typeId,
false);
291 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
292 errmsg(
"restriction estimator function %s must return type %s",
301 return restrictionOid;
317 typeId[0] = INTERNALOID;
319 typeId[2] = INTERNALOID;
321 typeId[4] = INTERNALOID;
334 (
errcode(ERRCODE_AMBIGUOUS_FUNCTION),
335 errmsg(
"join estimator function %s has multiple matches",
349 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
350 errmsg(
"join estimator function %s must return type %s",
376 elog(
ERROR,
"cache lookup failed for operator %u", operOid);
387 OperatorUpd(operOid, op->oprcom, op->oprnegate,
true);
388 if (operOid == op->oprcom || operOid == op->oprnegate)
393 elog(
ERROR,
"cache lookup failed for operator %u", operOid);
421 bool nulls[Natts_pg_operator];
422 bool replaces[Natts_pg_operator];
424 bool updateRestriction =
false;
427 bool updateJoin =
false;
435 elog(
ERROR,
"cache lookup failed for operator %u", oprId);
439 foreach(pl,
stmt->options)
444 if (defel->
arg == NULL)
449 if (strcmp(defel->
defname,
"restrict") == 0)
451 restrictionName = param;
452 updateRestriction =
true;
454 else if (strcmp(defel->
defname,
"join") == 0)
464 else if (strcmp(defel->
defname,
"leftarg") == 0 ||
465 strcmp(defel->
defname,
"rightarg") == 0 ||
466 strcmp(defel->
defname,
"function") == 0 ||
467 strcmp(defel->
defname,
"procedure") == 0 ||
468 strcmp(defel->
defname,
"commutator") == 0 ||
469 strcmp(defel->
defname,
"negator") == 0 ||
470 strcmp(defel->
defname,
"hashes") == 0 ||
471 strcmp(defel->
defname,
"merges") == 0)
474 (
errcode(ERRCODE_SYNTAX_ERROR),
475 errmsg(
"operator attribute \"%s\" cannot be changed",
480 (
errcode(ERRCODE_SYNTAX_ERROR),
481 errmsg(
"operator attribute \"%s\" not recognized",
508 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
509 errmsg(
"only binary operators can have join selectivity")));
512 if (oprForm->oprresult != BOOLOID)
516 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
517 errmsg(
"only boolean operators can have restriction selectivity")));
520 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
521 errmsg(
"only boolean operators can have join selectivity")));
525 for (
i = 0;
i < Natts_pg_operator; ++
i)
531 if (updateRestriction)
533 replaces[Anum_pg_operator_oprrest - 1] =
true;
534 values[Anum_pg_operator_oprrest - 1] = restrictionOid;
538 replaces[Anum_pg_operator_oprjoin - 1] =
true;
539 values[Anum_pg_operator_oprjoin - 1] = joinOid;
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
static Datum values[MAXATTR]
#define OidIsValid(objectId)
elog(ERROR, "%s: %s", p2, msg)
bool defGetBoolean(DefElem *def)
List * defGetQualifiedName(DefElem *def)
TypeName * defGetTypeName(DefElem *def)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
#define HeapTupleIsValid(tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
char * get_namespace_name(Oid nspid)
Oid get_func_rettype(Oid funcid)
Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p)
char * NameListToString(List *names)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
void RemoveOperatorById(Oid operOid)
static Oid ValidateJoinEstimator(List *joinName)
ObjectAddress DefineOperator(List *names, List *parameters)
static Oid ValidateRestrictionEstimator(List *restrictionName)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
ObjectAddress OperatorCreate(const char *operatorName, Oid operatorNamespace, Oid leftTypeId, Oid rightTypeId, Oid procedureId, List *commutatorName, List *negatorName, Oid restrictionId, Oid joinId, bool canMerge, bool canHash)
ObjectAddress makeOperatorDependencies(HeapTuple tuple, bool makeExtensionDep, bool isUpdate)
void OperatorUpd(Oid baseId, Oid commId, Oid negId, bool isDelete)
FormData_pg_operator * Form_pg_operator
static Datum ObjectIdGetDatum(Oid X)
#define RelationGetDescr(relation)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define SearchSysCacheCopy1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)