summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2015-12-31 22:37:31 +0000
committerTom Lane2015-12-31 22:37:31 +0000
commit0dab5ef39b3d9d86e45bbbb2f6ea60b4f5517d9a (patch)
treed9b7a923d9d00270142b0209f621e433b61e4133 /src/test
parente5d06f2b12a7c75f2b0c7fd2055a14efaa2b59ec (diff)
Fix ALTER OPERATOR to update dependencies properly.
Fix an oversight in commit 321eed5f0f7563a0: 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.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/alter_operator.out73
-rw-r--r--src/test/regress/sql/alter_operator.sql41
2 files changed, 105 insertions, 9 deletions
diff --git a/src/test/regress/expected/alter_operator.out b/src/test/regress/expected/alter_operator.out
index ce8366a1397..449ed53f8bb 100644
--- a/src/test/regress/expected/alter_operator.out
+++ b/src/test/regress/expected/alter_operator.out
@@ -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);
diff --git a/src/test/regress/sql/alter_operator.sql b/src/test/regress/sql/alter_operator.sql
index a7e1988682f..dfabec61752 100644
--- a/src/test/regress/sql/alter_operator.sql
+++ b/src/test/regress/sql/alter_operator.sql
@@ -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);