2017-11-30 14:46:13 +01:00
|
|
|
CALL nonexistent(); -- error
|
|
|
|
CALL random(); -- error
|
|
|
|
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
CREATE FUNCTION cp_testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$;
|
2017-11-30 14:46:13 +01:00
|
|
|
|
|
|
|
CREATE TABLE cp_test (a int, b text);
|
|
|
|
|
|
|
|
CREATE PROCEDURE ptest1(x text)
|
|
|
|
LANGUAGE SQL
|
|
|
|
AS $$
|
|
|
|
INSERT INTO cp_test VALUES (1, x);
|
|
|
|
$$;
|
|
|
|
|
|
|
|
SELECT ptest1('x'); -- error
|
|
|
|
CALL ptest1('a'); -- ok
|
Avoid premature free of pass-by-reference CALL arguments.
Prematurely freeing the EState used to evaluate CALL arguments led, in some
cases, to passing dangling pointers to the procedure. This was masked in
trivial cases because the argument pointers would point to Const nodes in
the original expression tree, and in some other cases because the result
value would end up in the standalone ExprContext rather than in memory
belonging to the EState --- but that wasn't exactly high quality
programming either, because the standalone ExprContext was never
explicitly freed, breaking assorted API contracts.
In addition, using a separate EState for each argument was just silly.
So let's use just one EState, and one ExprContext, and make the latter
belong to the former rather than be standalone, and clean up the EState
(and hence the ExprContext) post-call.
While at it, improve the function's commentary a bit.
Discussion: https://postgr.es/m/29173.1518282748@sss.pgh.pa.us
2018-02-10 19:37:12 +01:00
|
|
|
CALL ptest1('xy' || 'zzy'); -- ok, constant-folded arg
|
|
|
|
CALL ptest1(substring(random()::text, 1, 1)); -- ok, volatile arg
|
2017-11-30 14:46:13 +01:00
|
|
|
|
|
|
|
\df ptest1
|
2018-02-13 16:34:04 +01:00
|
|
|
SELECT pg_get_functiondef('ptest1'::regproc);
|
2017-11-30 14:46:13 +01:00
|
|
|
|
Avoid premature free of pass-by-reference CALL arguments.
Prematurely freeing the EState used to evaluate CALL arguments led, in some
cases, to passing dangling pointers to the procedure. This was masked in
trivial cases because the argument pointers would point to Const nodes in
the original expression tree, and in some other cases because the result
value would end up in the standalone ExprContext rather than in memory
belonging to the EState --- but that wasn't exactly high quality
programming either, because the standalone ExprContext was never
explicitly freed, breaking assorted API contracts.
In addition, using a separate EState for each argument was just silly.
So let's use just one EState, and one ExprContext, and make the latter
belong to the former rather than be standalone, and clean up the EState
(and hence the ExprContext) post-call.
While at it, improve the function's commentary a bit.
Discussion: https://postgr.es/m/29173.1518282748@sss.pgh.pa.us
2018-02-10 19:37:12 +01:00
|
|
|
SELECT * FROM cp_test ORDER BY b COLLATE "C";
|
2017-11-30 14:46:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE ptest2()
|
|
|
|
LANGUAGE SQL
|
|
|
|
AS $$
|
|
|
|
SELECT 5;
|
|
|
|
$$;
|
|
|
|
|
|
|
|
CALL ptest2();
|
|
|
|
|
|
|
|
|
2018-02-21 00:03:31 +01:00
|
|
|
-- nested CALL
|
|
|
|
TRUNCATE cp_test;
|
|
|
|
|
|
|
|
CREATE PROCEDURE ptest3(y text)
|
|
|
|
LANGUAGE SQL
|
|
|
|
AS $$
|
|
|
|
CALL ptest1(y);
|
|
|
|
CALL ptest1($1);
|
|
|
|
$$;
|
|
|
|
|
|
|
|
CALL ptest3('b');
|
|
|
|
|
|
|
|
SELECT * FROM cp_test;
|
|
|
|
|
|
|
|
|
2018-03-14 16:47:21 +01:00
|
|
|
-- output arguments
|
|
|
|
|
|
|
|
CREATE PROCEDURE ptest4a(INOUT a int, INOUT b int)
|
|
|
|
LANGUAGE SQL
|
|
|
|
AS $$
|
|
|
|
SELECT 1, 2;
|
|
|
|
$$;
|
|
|
|
|
|
|
|
CALL ptest4a(NULL, NULL);
|
|
|
|
|
|
|
|
CREATE PROCEDURE ptest4b(INOUT b int, INOUT a int)
|
|
|
|
LANGUAGE SQL
|
|
|
|
AS $$
|
|
|
|
CALL ptest4a(a, b); -- error, not supported
|
|
|
|
$$;
|
|
|
|
|
|
|
|
DROP PROCEDURE ptest4a;
|
|
|
|
|
|
|
|
|
2017-11-30 14:46:13 +01:00
|
|
|
-- various error cases
|
|
|
|
|
2017-12-13 16:37:48 +01:00
|
|
|
CALL version(); -- error: not a procedure
|
|
|
|
CALL sum(1); -- error: not a procedure
|
|
|
|
|
2017-11-30 14:46:13 +01:00
|
|
|
CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT INTO cp_test VALUES (1, 'a') $$;
|
|
|
|
CREATE PROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERT INTO cp_test VALUES (1, 'a') $$;
|
|
|
|
CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES (1, 'a') $$;
|
|
|
|
|
|
|
|
ALTER PROCEDURE ptest1(text) STRICT;
|
|
|
|
ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
ALTER PROCEDURE cp_testfunc1(int) VOLATILE; -- error: not a procedure
|
2017-11-30 14:46:13 +01:00
|
|
|
ALTER PROCEDURE nonexistent() VOLATILE;
|
|
|
|
|
|
|
|
DROP FUNCTION ptest1(text); -- error: not a function
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
DROP PROCEDURE cp_testfunc1(int); -- error: not a procedure
|
2017-11-30 14:46:13 +01:00
|
|
|
DROP PROCEDURE nonexistent();
|
|
|
|
|
|
|
|
|
|
|
|
-- privileges
|
|
|
|
|
2018-03-15 19:00:31 +01:00
|
|
|
CREATE USER regress_cp_user1;
|
|
|
|
GRANT INSERT ON cp_test TO regress_cp_user1;
|
2017-11-30 14:46:13 +01:00
|
|
|
REVOKE EXECUTE ON PROCEDURE ptest1(text) FROM PUBLIC;
|
2018-03-15 19:00:31 +01:00
|
|
|
SET ROLE regress_cp_user1;
|
2017-11-30 14:46:13 +01:00
|
|
|
CALL ptest1('a'); -- error
|
|
|
|
RESET ROLE;
|
2018-03-15 19:00:31 +01:00
|
|
|
GRANT EXECUTE ON PROCEDURE ptest1(text) TO regress_cp_user1;
|
|
|
|
SET ROLE regress_cp_user1;
|
2017-11-30 14:46:13 +01:00
|
|
|
CALL ptest1('a'); -- ok
|
|
|
|
RESET ROLE;
|
|
|
|
|
|
|
|
|
|
|
|
-- ROUTINE syntax
|
|
|
|
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
ALTER ROUTINE cp_testfunc1(int) RENAME TO cp_testfunc1a;
|
|
|
|
ALTER ROUTINE cp_testfunc1a RENAME TO cp_testfunc1;
|
2017-11-30 14:46:13 +01:00
|
|
|
|
|
|
|
ALTER ROUTINE ptest1(text) RENAME TO ptest1a;
|
|
|
|
ALTER ROUTINE ptest1a RENAME TO ptest1;
|
|
|
|
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
DROP ROUTINE cp_testfunc1(int);
|
2017-11-30 14:46:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- cleanup
|
|
|
|
|
|
|
|
DROP PROCEDURE ptest1;
|
|
|
|
DROP PROCEDURE ptest2;
|
|
|
|
|
|
|
|
DROP TABLE cp_test;
|
|
|
|
|
2018-03-15 19:00:31 +01:00
|
|
|
DROP USER regress_cp_user1;
|