2626#include "catalog/objectaccess.h"
2727#include "catalog/pg_namespace.h"
2828#include "catalog/pg_operator.h"
29+ #include "catalog/pg_operator_fn.h"
2930#include "catalog/pg_proc.h"
3031#include "catalog/pg_type.h"
3132#include "miscadmin.h"
@@ -61,8 +62,6 @@ static Oid get_other_operator(List *otherOp,
6162 Oid leftTypeId , Oid rightTypeId ,
6263 bool isCommutator );
6364
64- static ObjectAddress makeOperatorDependencies (HeapTuple tuple );
65-
6665
6766/*
6867 * Check whether a proposed operator name is legal
@@ -270,7 +269,7 @@ OperatorShellMake(const char *operatorName,
270269 CatalogUpdateIndexes (pg_operator_desc , tup );
271270
272271 /* Add dependencies for the entry */
273- makeOperatorDependencies (tup );
272+ makeOperatorDependencies (tup , false );
274273
275274 heap_freetuple (tup );
276275
@@ -340,6 +339,7 @@ OperatorCreate(const char *operatorName,
340339{
341340 Relation pg_operator_desc ;
342341 HeapTuple tup ;
342+ bool isUpdate ;
343343 bool nulls [Natts_pg_operator ];
344344 bool replaces [Natts_pg_operator ];
345345 Datum values [Natts_pg_operator ];
@@ -350,7 +350,6 @@ OperatorCreate(const char *operatorName,
350350 negatorId ;
351351 bool selfCommutator = false;
352352 NameData oname ;
353- TupleDesc tupDesc ;
354353 int i ;
355354 ObjectAddress address ;
356355
@@ -515,6 +514,8 @@ OperatorCreate(const char *operatorName,
515514 */
516515 if (operatorObjectId )
517516 {
517+ isUpdate = true;
518+
518519 tup = SearchSysCacheCopy1 (OPEROID ,
519520 ObjectIdGetDatum (operatorObjectId ));
520521 if (!HeapTupleIsValid (tup ))
@@ -531,8 +532,10 @@ OperatorCreate(const char *operatorName,
531532 }
532533 else
533534 {
534- tupDesc = pg_operator_desc -> rd_att ;
535- tup = heap_form_tuple (tupDesc , values , nulls );
535+ isUpdate = false;
536+
537+ tup = heap_form_tuple (RelationGetDescr (pg_operator_desc ),
538+ values , nulls );
536539
537540 operatorObjectId = simple_heap_insert (pg_operator_desc , tup );
538541 }
@@ -541,7 +544,7 @@ OperatorCreate(const char *operatorName,
541544 CatalogUpdateIndexes (pg_operator_desc , tup );
542545
543546 /* Add dependencies for the entry */
544- address = makeOperatorDependencies (tup );
547+ address = makeOperatorDependencies (tup , isUpdate );
545548
546549 /* Post creation hook for new operator */
547550 InvokeObjectPostCreateHook (OperatorRelationId , operatorObjectId , 0 );
@@ -759,14 +762,15 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
759762}
760763
761764/*
762- * Create dependencies for a new operator (either a freshly inserted
763- * complete operator, a new shell operator, or a just-updated shell).
765+ * Create dependencies for an operator (either a freshly inserted
766+ * complete operator, a new shell operator, a just-updated shell,
767+ * or an operator that's being modified by ALTER OPERATOR).
764768 *
765769 * NB: the OidIsValid tests in this routine are necessary, in case
766770 * the given operator is a shell.
767771 */
768- static ObjectAddress
769- makeOperatorDependencies (HeapTuple tuple )
772+ ObjectAddress
773+ makeOperatorDependencies (HeapTuple tuple , bool isUpdate )
770774{
771775 Form_pg_operator oper = (Form_pg_operator ) GETSTRUCT (tuple );
772776 ObjectAddress myself ,
@@ -777,11 +781,14 @@ makeOperatorDependencies(HeapTuple tuple)
777781 myself .objectSubId = 0 ;
778782
779783 /*
780- * In case we are updating a shell , delete any existing entries, except
784+ * If we are updating the operator , delete any existing entries, except
781785 * for extension membership which should remain the same.
782786 */
783- deleteDependencyRecordsFor (myself .classId , myself .objectId , true);
784- deleteSharedDependencyRecordsFor (myself .classId , myself .objectId , 0 );
787+ if (isUpdate )
788+ {
789+ deleteDependencyRecordsFor (myself .classId , myself .objectId , true);
790+ deleteSharedDependencyRecordsFor (myself .classId , myself .objectId , 0 );
791+ }
785792
786793 /* Dependency on namespace */
787794 if (OidIsValid (oper -> oprnamespace ))
0 commit comments