mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +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:
@ -1,15 +1,29 @@
|
||||
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
|
||||
--
|
||||
@ -22,6 +36,17 @@ SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
|
||||
- | -
|
||||
(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 = '==='
|
||||
@ -31,6 +56,17 @@ 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;
|
||||
@ -39,14 +75,37 @@ SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
|
||||
- | -
|
||||
(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.
|
||||
--
|
||||
@ -73,3 +132,5 @@ ERROR: must be owner of operator ===
|
||||
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);
|
||||
|
@ -1,17 +1,26 @@
|
||||
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
|
||||
--
|
||||
@ -22,22 +31,46 @@ ALTER OPERATOR === (boolean, boolean) SET (JOIN = NONE);
|
||||
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.
|
||||
--
|
||||
@ -60,3 +93,5 @@ ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = NONE);
|
||||
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);
|
||||
|
Reference in New Issue
Block a user