26
26
#include "catalog/objectaccess.h"
27
27
#include "catalog/pg_namespace.h"
28
28
#include "catalog/pg_operator.h"
29
+ #include "catalog/pg_operator_fn.h"
29
30
#include "catalog/pg_proc.h"
30
31
#include "catalog/pg_type.h"
31
32
#include "miscadmin.h"
@@ -61,8 +62,6 @@ static Oid get_other_operator(List *otherOp,
61
62
Oid leftTypeId , Oid rightTypeId ,
62
63
bool isCommutator );
63
64
64
- static ObjectAddress makeOperatorDependencies (HeapTuple tuple );
65
-
66
65
67
66
/*
68
67
* Check whether a proposed operator name is legal
@@ -270,7 +269,7 @@ OperatorShellMake(const char *operatorName,
270
269
CatalogUpdateIndexes (pg_operator_desc , tup );
271
270
272
271
/* Add dependencies for the entry */
273
- makeOperatorDependencies (tup );
272
+ makeOperatorDependencies (tup , false );
274
273
275
274
heap_freetuple (tup );
276
275
@@ -340,6 +339,7 @@ OperatorCreate(const char *operatorName,
340
339
{
341
340
Relation pg_operator_desc ;
342
341
HeapTuple tup ;
342
+ bool isUpdate ;
343
343
bool nulls [Natts_pg_operator ];
344
344
bool replaces [Natts_pg_operator ];
345
345
Datum values [Natts_pg_operator ];
@@ -350,7 +350,6 @@ OperatorCreate(const char *operatorName,
350
350
negatorId ;
351
351
bool selfCommutator = false;
352
352
NameData oname ;
353
- TupleDesc tupDesc ;
354
353
int i ;
355
354
ObjectAddress address ;
356
355
@@ -515,6 +514,8 @@ OperatorCreate(const char *operatorName,
515
514
*/
516
515
if (operatorObjectId )
517
516
{
517
+ isUpdate = true;
518
+
518
519
tup = SearchSysCacheCopy1 (OPEROID ,
519
520
ObjectIdGetDatum (operatorObjectId ));
520
521
if (!HeapTupleIsValid (tup ))
@@ -531,8 +532,10 @@ OperatorCreate(const char *operatorName,
531
532
}
532
533
else
533
534
{
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 );
536
539
537
540
operatorObjectId = simple_heap_insert (pg_operator_desc , tup );
538
541
}
@@ -541,7 +544,7 @@ OperatorCreate(const char *operatorName,
541
544
CatalogUpdateIndexes (pg_operator_desc , tup );
542
545
543
546
/* Add dependencies for the entry */
544
- address = makeOperatorDependencies (tup );
547
+ address = makeOperatorDependencies (tup , isUpdate );
545
548
546
549
/* Post creation hook for new operator */
547
550
InvokeObjectPostCreateHook (OperatorRelationId , operatorObjectId , 0 );
@@ -759,14 +762,15 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
759
762
}
760
763
761
764
/*
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).
764
768
*
765
769
* NB: the OidIsValid tests in this routine are necessary, in case
766
770
* the given operator is a shell.
767
771
*/
768
- static ObjectAddress
769
- makeOperatorDependencies (HeapTuple tuple )
772
+ ObjectAddress
773
+ makeOperatorDependencies (HeapTuple tuple , bool isUpdate )
770
774
{
771
775
Form_pg_operator oper = (Form_pg_operator ) GETSTRUCT (tuple );
772
776
ObjectAddress myself ,
@@ -777,11 +781,14 @@ makeOperatorDependencies(HeapTuple tuple)
777
781
myself .objectSubId = 0 ;
778
782
779
783
/*
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
781
785
* for extension membership which should remain the same.
782
786
*/
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
+ }
785
792
786
793
/* Dependency on namespace */
787
794
if (OidIsValid (oper -> oprnamespace ))
0 commit comments