#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"
Oid leftTypeId, Oid rightTypeId,
bool isCommutator);
-static ObjectAddress makeOperatorDependencies(HeapTuple tuple);
-
/*
* Check whether a proposed operator name is legal
CatalogUpdateIndexes(pg_operator_desc, tup);
/* Add dependencies for the entry */
- makeOperatorDependencies(tup);
+ makeOperatorDependencies(tup, false);
heap_freetuple(tup);
{
Relation pg_operator_desc;
HeapTuple tup;
+ bool isUpdate;
bool nulls[Natts_pg_operator];
bool replaces[Natts_pg_operator];
Datum values[Natts_pg_operator];
negatorId;
bool selfCommutator = false;
NameData oname;
- TupleDesc tupDesc;
int i;
ObjectAddress address;
*/
if (operatorObjectId)
{
+ isUpdate = true;
+
tup = SearchSysCacheCopy1(OPEROID,
ObjectIdGetDatum(operatorObjectId));
if (!HeapTupleIsValid(tup))
}
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);
}
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);
}
/*
- * 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,
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))
#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"
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);
#define PG_OPERATOR_H
#include "catalog/genbki.h"
-#include "catalog/objectaddress.h"
-#include "nodes/pg_list.h"
/* ----------------
* pg_operator definition. cpp turns this into
DATA(insert OID = 3287 ( "#-" PGNSP PGUID b f f 3802 1009 3802 0 0 jsonb_delete_path - - ));
DESCR("delete path");
-/*
- * function prototypes
- */
-extern 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);
-
#endif /* PG_OPERATOR_H */
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * pg_operator_fn.h
+* prototypes for functions in catalog/pg_operator.c
+ *
+ *
+ * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/catalog/pg_operator_fn.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_OPERATOR_FN_H
+#define PG_OPERATOR_FN_H
+
+#include "catalog/objectaddress.h"
+#include "nodes/pg_list.h"
+
+extern 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);
+
+extern ObjectAddress makeOperatorDependencies(HeapTuple tuple, bool isUpdate);
+
+#endif /* PG_OPERATOR_FN_H */
-CREATE OR REPLACE FUNCTION alter_op_test_fn(boolean, boolean)
+CREATE FUNCTION alter_op_test_fn(boolean, boolean)
RETURNS boolean AS $$ SELECT NULL::BOOLEAN; $$ LANGUAGE sql IMMUTABLE;
+CREATE FUNCTION customcontsel(internal, oid, internal, integer)
+RETURNS float8 AS 'contsel' LANGUAGE internal STABLE STRICT;
CREATE OPERATOR === (
LEFTARG = boolean,
RIGHTARG = boolean,
PROCEDURE = alter_op_test_fn,
COMMUTATOR = ===,
NEGATOR = !==,
- RESTRICT = contsel,
+ RESTRICT = customcontsel,
JOIN = contjoinsel,
HASHES, MERGES
);
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+ ref | deptype
+-------------------------------------------------------+---------
+ function alter_op_test_fn(boolean,boolean) | n
+ function customcontsel(internal,oid,internal,integer) | n
+ schema public | n
+(3 rows)
+
--
-- Reset and set params
--
- | -
(1 row)
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+ ref | deptype
+--------------------------------------------+---------
+ function alter_op_test_fn(boolean,boolean) | n
+ schema public | n
+(2 rows)
+
ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = contsel);
ALTER OPERATOR === (boolean, boolean) SET (JOIN = contjoinsel);
SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
contsel | contjoinsel
(1 row)
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+ ref | deptype
+--------------------------------------------+---------
+ function alter_op_test_fn(boolean,boolean) | n
+ schema public | n
+(2 rows)
+
ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = NONE, JOIN = NONE);
SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
- | -
(1 row)
-ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = contsel, JOIN = contjoinsel);
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+ ref | deptype
+--------------------------------------------+---------
+ function alter_op_test_fn(boolean,boolean) | n
+ schema public | n
+(2 rows)
+
+ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = customcontsel, JOIN = contjoinsel);
SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
- oprrest | oprjoin
----------+-------------
- contsel | contjoinsel
+ oprrest | oprjoin
+---------------+-------------
+ customcontsel | contjoinsel
(1 row)
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+ ref | deptype
+-------------------------------------------------------+---------
+ function alter_op_test_fn(boolean,boolean) | n
+ function customcontsel(internal,oid,internal,integer) | n
+ schema public | n
+(3 rows)
+
--
-- Test invalid options.
--
RESET SESSION AUTHORIZATION;
DROP USER regtest_alter_user;
DROP OPERATOR === (boolean, boolean);
+DROP FUNCTION customcontsel(internal, oid, internal, integer);
+DROP FUNCTION alter_op_test_fn(boolean, boolean);
-CREATE OR REPLACE FUNCTION alter_op_test_fn(boolean, boolean)
+CREATE FUNCTION alter_op_test_fn(boolean, boolean)
RETURNS boolean AS $$ SELECT NULL::BOOLEAN; $$ LANGUAGE sql IMMUTABLE;
+CREATE FUNCTION customcontsel(internal, oid, internal, integer)
+RETURNS float8 AS 'contsel' LANGUAGE internal STABLE STRICT;
+
CREATE OPERATOR === (
LEFTARG = boolean,
RIGHTARG = boolean,
PROCEDURE = alter_op_test_fn,
COMMUTATOR = ===,
NEGATOR = !==,
- RESTRICT = contsel,
+ RESTRICT = customcontsel,
JOIN = contjoinsel,
HASHES, MERGES
);
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+
--
-- Reset and set params
--
SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+
ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = contsel);
ALTER OPERATOR === (boolean, boolean) SET (JOIN = contjoinsel);
SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+
ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = NONE, JOIN = NONE);
SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
-ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = contsel, JOIN = contjoinsel);
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+
+ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = customcontsel, JOIN = contjoinsel);
SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
+SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
+FROM pg_depend
+WHERE classid = 'pg_operator'::regclass AND
+ objid = '===(bool,bool)'::regoperator
+ORDER BY 1;
+
--
-- Test invalid options.
--
RESET SESSION AUTHORIZATION;
DROP USER regtest_alter_user;
DROP OPERATOR === (boolean, boolean);
+DROP FUNCTION customcontsel(internal, oid, internal, integer);
+DROP FUNCTION alter_op_test_fn(boolean, boolean);