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",
387 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
388 errmsg(
"operator does not exist: %s",
395 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
396 errmsg(
"operator is only a shell: %s",
423 elog(
ERROR,
"cache lookup failed for operator %u", operOid);
434 OperatorUpd(operOid, op->oprcom, op->oprnegate,
true);
435 if (operOid == op->oprcom || operOid == op->oprnegate)
440 elog(
ERROR,
"cache lookup failed for operator %u", operOid);
472 bool nulls[Natts_pg_operator];
473 bool replaces[Natts_pg_operator];
475 bool updateRestriction =
false;
478 bool updateJoin =
false;
484 bool canMerge =
false;
485 bool updateMerges =
false;
486 bool canHash =
false;
487 bool updateHashes =
false;
494 elog(
ERROR,
"cache lookup failed for operator %u", oprId);
498 foreach(pl,
stmt->options)
503 if (defel->
arg == NULL)
508 if (strcmp(defel->
defname,
"restrict") == 0)
510 restrictionName = param;
511 updateRestriction =
true;
513 else if (strcmp(defel->
defname,
"join") == 0)
518 else if (strcmp(defel->
defname,
"commutator") == 0)
522 else if (strcmp(defel->
defname,
"negator") == 0)
526 else if (strcmp(defel->
defname,
"merges") == 0)
531 else if (strcmp(defel->
defname,
"hashes") == 0)
541 else if (strcmp(defel->
defname,
"leftarg") == 0 ||
542 strcmp(defel->
defname,
"rightarg") == 0 ||
543 strcmp(defel->
defname,
"function") == 0 ||
544 strcmp(defel->
defname,
"procedure") == 0)
547 (
errcode(ERRCODE_SYNTAX_ERROR),
548 errmsg(
"operator attribute \"%s\" cannot be changed",
553 (
errcode(ERRCODE_SYNTAX_ERROR),
554 errmsg(
"operator attribute \"%s\" not recognized",
597 if (negatorOid == oprForm->oid)
599 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
600 errmsg(
"operator cannot be its own negator")));
612 commutatorOid != oprForm->oprcom)
614 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
615 errmsg(
"operator attribute \"%s\" cannot be changed if it has already been set",
619 negatorOid != oprForm->oprnegate)
621 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
622 errmsg(
"operator attribute \"%s\" cannot be changed if it has already been set",
625 if (updateMerges && oprForm->oprcanmerge && !canMerge)
627 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
628 errmsg(
"operator attribute \"%s\" cannot be changed if it has already been set",
631 if (updateHashes && oprForm->oprcanhash && !canHash)
633 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
634 errmsg(
"operator attribute \"%s\" cannot be changed if it has already been set",
649 for (
i = 0;
i < Natts_pg_operator; ++
i)
655 if (updateRestriction)
657 replaces[Anum_pg_operator_oprrest - 1] =
true;
662 replaces[Anum_pg_operator_oprjoin - 1] =
true;
667 replaces[Anum_pg_operator_oprcom - 1] =
true;
672 replaces[Anum_pg_operator_oprnegate - 1] =
true;
677 replaces[Anum_pg_operator_oprcanmerge - 1] =
true;
682 replaces[Anum_pg_operator_oprcanhash - 1] =
true;
694 OperatorUpd(oprId, commutatorOid, negatorOid,
false);
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)
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, const Datum *replValues, const bool *replIsnull, const 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(const List *names, char **objname_p)
char * NameListToString(const List *names)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
void RemoveOperatorById(Oid operOid)
static Oid ValidateJoinEstimator(List *joinName)
static Oid ValidateOperatorReference(List *name, Oid leftTypeId, Oid rightTypeId)
ObjectAddress DefineOperator(List *names, List *parameters)
static Oid ValidateRestrictionEstimator(List *restrictionName)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
const char * op_signature_string(List *op, Oid arg1, Oid arg2)
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)
void OperatorValidateParams(Oid leftTypeId, Oid rightTypeId, Oid operResultType, bool hasCommutator, bool hasNegator, bool hasRestrictionSelectivity, bool hasJoinSelectivity, bool canMerge, bool canHash)
Oid OperatorLookup(List *operatorName, Oid leftObjectId, Oid rightObjectId, bool *defined)
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 BoolGetDatum(bool X)
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)