mirror of
https://github.com/postgres/postgres.git
synced 2025-12-04 12:02:48 +03:00
Fix ALTER OPERATOR to update dependencies properly.
Fix an oversight in commit 321eed5f0f: replacing an operator's
selectivity functions needs to result in a corresponding update in
pg_depend. We have a function that can handle that, but it was not
called by AlterOperator().
To fix this without enlarging pg_operator.h's #include list beyond
what clients can safely include, split off the function definitions
into a new file pg_operator_fn.h, similarly to what we've done for
some other catalog header files. It's not entirely clear whether
any client-side code needs to include pg_operator.h, but it seems
prudent to assume that there is some such code somewhere.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "catalog/objectaccess.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_operator_fn.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "miscadmin.h"
|
||||
@@ -61,8 +62,6 @@ static Oid get_other_operator(List *otherOp,
|
||||
Oid leftTypeId, Oid rightTypeId,
|
||||
bool isCommutator);
|
||||
|
||||
static ObjectAddress makeOperatorDependencies(HeapTuple tuple);
|
||||
|
||||
|
||||
/*
|
||||
* Check whether a proposed operator name is legal
|
||||
@@ -270,7 +269,7 @@ OperatorShellMake(const char *operatorName,
|
||||
CatalogUpdateIndexes(pg_operator_desc, tup);
|
||||
|
||||
/* Add dependencies for the entry */
|
||||
makeOperatorDependencies(tup);
|
||||
makeOperatorDependencies(tup, false);
|
||||
|
||||
heap_freetuple(tup);
|
||||
|
||||
@@ -340,6 +339,7 @@ OperatorCreate(const char *operatorName,
|
||||
{
|
||||
Relation pg_operator_desc;
|
||||
HeapTuple tup;
|
||||
bool isUpdate;
|
||||
bool nulls[Natts_pg_operator];
|
||||
bool replaces[Natts_pg_operator];
|
||||
Datum values[Natts_pg_operator];
|
||||
@@ -350,7 +350,6 @@ OperatorCreate(const char *operatorName,
|
||||
negatorId;
|
||||
bool selfCommutator = false;
|
||||
NameData oname;
|
||||
TupleDesc tupDesc;
|
||||
int i;
|
||||
ObjectAddress address;
|
||||
|
||||
@@ -515,6 +514,8 @@ OperatorCreate(const char *operatorName,
|
||||
*/
|
||||
if (operatorObjectId)
|
||||
{
|
||||
isUpdate = true;
|
||||
|
||||
tup = SearchSysCacheCopy1(OPEROID,
|
||||
ObjectIdGetDatum(operatorObjectId));
|
||||
if (!HeapTupleIsValid(tup))
|
||||
@@ -531,8 +532,10 @@ OperatorCreate(const char *operatorName,
|
||||
}
|
||||
else
|
||||
{
|
||||
tupDesc = pg_operator_desc->rd_att;
|
||||
tup = heap_form_tuple(tupDesc, values, nulls);
|
||||
isUpdate = false;
|
||||
|
||||
tup = heap_form_tuple(RelationGetDescr(pg_operator_desc),
|
||||
values, nulls);
|
||||
|
||||
operatorObjectId = simple_heap_insert(pg_operator_desc, tup);
|
||||
}
|
||||
@@ -541,7 +544,7 @@ OperatorCreate(const char *operatorName,
|
||||
CatalogUpdateIndexes(pg_operator_desc, tup);
|
||||
|
||||
/* Add dependencies for the entry */
|
||||
address = makeOperatorDependencies(tup);
|
||||
address = makeOperatorDependencies(tup, isUpdate);
|
||||
|
||||
/* Post creation hook for new operator */
|
||||
InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);
|
||||
@@ -759,14 +762,15 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
|
||||
}
|
||||
|
||||
/*
|
||||
* Create dependencies for a new operator (either a freshly inserted
|
||||
* complete operator, a new shell operator, or a just-updated shell).
|
||||
* Create dependencies for an operator (either a freshly inserted
|
||||
* complete operator, a new shell operator, a just-updated shell,
|
||||
* or an operator that's being modified by ALTER OPERATOR).
|
||||
*
|
||||
* NB: the OidIsValid tests in this routine are necessary, in case
|
||||
* the given operator is a shell.
|
||||
*/
|
||||
static ObjectAddress
|
||||
makeOperatorDependencies(HeapTuple tuple)
|
||||
ObjectAddress
|
||||
makeOperatorDependencies(HeapTuple tuple, bool isUpdate)
|
||||
{
|
||||
Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple);
|
||||
ObjectAddress myself,
|
||||
@@ -777,11 +781,14 @@ makeOperatorDependencies(HeapTuple tuple)
|
||||
myself.objectSubId = 0;
|
||||
|
||||
/*
|
||||
* In case we are updating a shell, delete any existing entries, except
|
||||
* If we are updating the operator, delete any existing entries, except
|
||||
* for extension membership which should remain the same.
|
||||
*/
|
||||
deleteDependencyRecordsFor(myself.classId, myself.objectId, true);
|
||||
deleteSharedDependencyRecordsFor(myself.classId, myself.objectId, 0);
|
||||
if (isUpdate)
|
||||
{
|
||||
deleteDependencyRecordsFor(myself.classId, myself.objectId, true);
|
||||
deleteSharedDependencyRecordsFor(myself.classId, myself.objectId, 0);
|
||||
}
|
||||
|
||||
/* Dependency on namespace */
|
||||
if (OidIsValid(oper->oprnamespace))
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/objectaccess.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_operator_fn.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/alter.h"
|
||||
#include "commands/defrem.h"
|
||||
@@ -500,9 +501,9 @@ AlterOperator(AlterOperatorStmt *stmt)
|
||||
simple_heap_update(catalog, &tup->t_self, tup);
|
||||
CatalogUpdateIndexes(catalog, tup);
|
||||
|
||||
InvokeObjectPostAlterHook(OperatorRelationId, oprId, 0);
|
||||
address = makeOperatorDependencies(tup, true);
|
||||
|
||||
ObjectAddressSet(address, OperatorRelationId, oprId);
|
||||
InvokeObjectPostAlterHook(OperatorRelationId, oprId, 0);
|
||||
|
||||
heap_close(catalog, NoLock);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user