Commit 2cf8c7aa authored by Tom Lane's avatar Tom Lane

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
parent 1466bcfa
This diff is collapsed.
...@@ -8,7 +8,7 @@ ERROR: random() is not a procedure ...@@ -8,7 +8,7 @@ ERROR: random() is not a procedure
LINE 1: CALL random(); LINE 1: CALL random();
^ ^
HINT: To call a function, use SELECT. HINT: To call a function, use SELECT.
CREATE FUNCTION testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$; CREATE FUNCTION cp_testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$;
CREATE TABLE cp_test (a int, b text); CREATE TABLE cp_test (a int, b text);
CREATE PROCEDURE ptest1(x text) CREATE PROCEDURE ptest1(x text)
LANGUAGE SQL LANGUAGE SQL
...@@ -118,14 +118,14 @@ LINE 1: ALTER PROCEDURE ptest1(text) STRICT; ...@@ -118,14 +118,14 @@ LINE 1: ALTER PROCEDURE ptest1(text) STRICT;
^ ^
ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function
ERROR: ptest1(text) is not a function ERROR: ptest1(text) is not a function
ALTER PROCEDURE testfunc1(int) VOLATILE; -- error: not a procedure ALTER PROCEDURE cp_testfunc1(int) VOLATILE; -- error: not a procedure
ERROR: testfunc1(integer) is not a procedure ERROR: cp_testfunc1(integer) is not a procedure
ALTER PROCEDURE nonexistent() VOLATILE; ALTER PROCEDURE nonexistent() VOLATILE;
ERROR: procedure nonexistent() does not exist ERROR: procedure nonexistent() does not exist
DROP FUNCTION ptest1(text); -- error: not a function DROP FUNCTION ptest1(text); -- error: not a function
ERROR: ptest1(text) is not a function ERROR: ptest1(text) is not a function
DROP PROCEDURE testfunc1(int); -- error: not a procedure DROP PROCEDURE cp_testfunc1(int); -- error: not a procedure
ERROR: testfunc1(integer) is not a procedure ERROR: cp_testfunc1(integer) is not a procedure
DROP PROCEDURE nonexistent(); DROP PROCEDURE nonexistent();
ERROR: procedure nonexistent() does not exist ERROR: procedure nonexistent() does not exist
-- privileges -- privileges
...@@ -141,11 +141,11 @@ SET ROLE regress_cp_user1; ...@@ -141,11 +141,11 @@ SET ROLE regress_cp_user1;
CALL ptest1('a'); -- ok CALL ptest1('a'); -- ok
RESET ROLE; RESET ROLE;
-- ROUTINE syntax -- ROUTINE syntax
ALTER ROUTINE testfunc1(int) RENAME TO testfunc1a; ALTER ROUTINE cp_testfunc1(int) RENAME TO cp_testfunc1a;
ALTER ROUTINE testfunc1a RENAME TO testfunc1; ALTER ROUTINE cp_testfunc1a RENAME TO cp_testfunc1;
ALTER ROUTINE ptest1(text) RENAME TO ptest1a; ALTER ROUTINE ptest1(text) RENAME TO ptest1a;
ALTER ROUTINE ptest1a RENAME TO ptest1; ALTER ROUTINE ptest1a RENAME TO ptest1;
DROP ROUTINE testfunc1(int); DROP ROUTINE cp_testfunc1(int);
-- cleanup -- cleanup
DROP PROCEDURE ptest1; DROP PROCEDURE ptest1;
DROP PROCEDURE ptest2; DROP PROCEDURE ptest2;
......
This diff is collapsed.
This diff is collapsed.
...@@ -254,27 +254,27 @@ NOTICE: 3 ...@@ -254,27 +254,27 @@ NOTICE: 3
-- Check that addition or removal of any partition is correctly dealt with by -- Check that addition or removal of any partition is correctly dealt with by
-- default partition table when it is being used in prepared statement. -- default partition table when it is being used in prepared statement.
create table list_parted (a int) partition by list(a); create table pc_list_parted (a int) partition by list(a);
create table list_part_null partition of list_parted for values in (null); create table pc_list_part_null partition of pc_list_parted for values in (null);
create table list_part_1 partition of list_parted for values in (1); create table pc_list_part_1 partition of pc_list_parted for values in (1);
create table list_part_def partition of list_parted default; create table pc_list_part_def partition of pc_list_parted default;
prepare pstmt_def_insert (int) as insert into list_part_def values($1); prepare pstmt_def_insert (int) as insert into pc_list_part_def values($1);
-- should fail -- should fail
execute pstmt_def_insert(null); execute pstmt_def_insert(null);
ERROR: new row for relation "list_part_def" violates partition constraint ERROR: new row for relation "pc_list_part_def" violates partition constraint
DETAIL: Failing row contains (null). DETAIL: Failing row contains (null).
execute pstmt_def_insert(1); execute pstmt_def_insert(1);
ERROR: new row for relation "list_part_def" violates partition constraint ERROR: new row for relation "pc_list_part_def" violates partition constraint
DETAIL: Failing row contains (1). DETAIL: Failing row contains (1).
create table list_part_2 partition of list_parted for values in (2); create table pc_list_part_2 partition of pc_list_parted for values in (2);
execute pstmt_def_insert(2); execute pstmt_def_insert(2);
ERROR: new row for relation "list_part_def" violates partition constraint ERROR: new row for relation "pc_list_part_def" violates partition constraint
DETAIL: Failing row contains (2). DETAIL: Failing row contains (2).
alter table list_parted detach partition list_part_null; alter table pc_list_parted detach partition pc_list_part_null;
-- should be ok -- should be ok
execute pstmt_def_insert(null); execute pstmt_def_insert(null);
drop table list_part_1; drop table pc_list_part_1;
-- should be ok -- should be ok
execute pstmt_def_insert(1); execute pstmt_def_insert(1);
drop table list_parted, list_part_null; drop table pc_list_parted, pc_list_part_null;
deallocate pstmt_def_insert; deallocate pstmt_def_insert;
This diff is collapsed.
...@@ -1303,31 +1303,31 @@ ERROR: cannot change name of input parameter "c" ...@@ -1303,31 +1303,31 @@ ERROR: cannot change name of input parameter "c"
HINT: Use DROP FUNCTION dfunc(character varying,numeric) first. HINT: Use DROP FUNCTION dfunc(character varying,numeric) first.
drop function dfunc(varchar, numeric); drop function dfunc(varchar, numeric);
--fail, named parameters are not unique --fail, named parameters are not unique
create function testfoo(a int, a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
create function testfoo(int, out a int, out a int) returns int as $$ select 1;$$ language sql; create function testpolym(int, out a int, out a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
create function testfoo(out a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(out a int, inout a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
create function testfoo(a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, inout a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
-- valid -- valid
create function testfoo(a int, out a int) returns int as $$ select $1;$$ language sql; create function testpolym(a int, out a int) returns int as $$ select $1;$$ language sql;
select testfoo(37); select testpolym(37);
testfoo testpolym
--------- -----------
37 37
(1 row) (1 row)
drop function testfoo(int); drop function testpolym(int);
create function testfoo(a int) returns table(a int) as $$ select $1;$$ language sql; create function testpolym(a int) returns table(a int) as $$ select $1;$$ language sql;
select * from testfoo(37); select * from testpolym(37);
a a
---- ----
37 37
(1 row) (1 row)
drop function testfoo(int); drop function testpolym(int);
-- test polymorphic params and defaults -- test polymorphic params and defaults
create function dfunc(a anyelement, b anyelement = null, flag bool = true) create function dfunc(a anyelement, b anyelement = null, flag bool = true)
returns anyelement as $$ returns anyelement as $$
......
This diff is collapsed.
This diff is collapsed.
...@@ -1175,47 +1175,47 @@ SELECT count(*) FROM shoe; ...@@ -1175,47 +1175,47 @@ SELECT count(*) FROM shoe;
-- --
-- Simple test of qualified ON INSERT ... this did not work in 7.0 ... -- Simple test of qualified ON INSERT ... this did not work in 7.0 ...
-- --
create table foo (f1 int); create table rules_foo (f1 int);
create table foo2 (f1 int); create table rules_foo2 (f1 int);
create rule foorule as on insert to foo where f1 < 100 create rule rules_foorule as on insert to rules_foo where f1 < 100
do instead nothing; do instead nothing;
insert into foo values(1); insert into rules_foo values(1);
insert into foo values(1001); insert into rules_foo values(1001);
select * from foo; select * from rules_foo;
f1 f1
------ ------
1001 1001
(1 row) (1 row)
drop rule foorule on foo; drop rule rules_foorule on rules_foo;
-- this should fail because f1 is not exposed for unqualified reference: -- this should fail because f1 is not exposed for unqualified reference:
create rule foorule as on insert to foo where f1 < 100 create rule rules_foorule as on insert to rules_foo where f1 < 100
do instead insert into foo2 values (f1); do instead insert into rules_foo2 values (f1);
ERROR: column "f1" does not exist ERROR: column "f1" does not exist
LINE 2: do instead insert into foo2 values (f1); LINE 2: do instead insert into rules_foo2 values (f1);
^ ^
HINT: There is a column named "f1" in table "old", but it cannot be referenced from this part of the query. HINT: There is a column named "f1" in table "old", but it cannot be referenced from this part of the query.
-- this is the correct way: -- this is the correct way:
create rule foorule as on insert to foo where f1 < 100 create rule rules_foorule as on insert to rules_foo where f1 < 100
do instead insert into foo2 values (new.f1); do instead insert into rules_foo2 values (new.f1);
insert into foo values(2); insert into rules_foo values(2);
insert into foo values(100); insert into rules_foo values(100);
select * from foo; select * from rules_foo;
f1 f1
------ ------
1001 1001
100 100
(2 rows) (2 rows)
select * from foo2; select * from rules_foo2;
f1 f1
---- ----
2 2
(1 row) (1 row)
drop rule foorule on foo; drop rule rules_foorule on rules_foo;
drop table foo; drop table rules_foo;
drop table foo2; drop table rules_foo2;
-- --
-- Test rules containing INSERT ... SELECT, which is a very ugly special -- Test rules containing INSERT ... SELECT, which is a very ugly special
-- case as of 7.1. Example is based on bug report from Joel Burton. -- case as of 7.1. Example is based on bug report from Joel Burton.
...@@ -2535,50 +2535,50 @@ DETAIL: Key (id3a, id3b)=(1, 13) is not present in table "rule_and_refint_t1". ...@@ -2535,50 +2535,50 @@ DETAIL: Key (id3a, id3b)=(1, 13) is not present in table "rule_and_refint_t1".
-- --
-- disallow dropping a view's rule (bug #5072) -- disallow dropping a view's rule (bug #5072)
-- --
create view fooview as select 'foo'::text; create view rules_fooview as select 'rules_foo'::text;
drop rule "_RETURN" on fooview; drop rule "_RETURN" on rules_fooview;
ERROR: cannot drop rule _RETURN on view fooview because view fooview requires it ERROR: cannot drop rule _RETURN on view rules_fooview because view rules_fooview requires it
HINT: You can drop view fooview instead. HINT: You can drop view rules_fooview instead.
drop view fooview; drop view rules_fooview;
-- --
-- test conversion of table to view (needed to load some pg_dump files) -- test conversion of table to view (needed to load some pg_dump files)
-- --
create table fooview (x int, y text); create table rules_fooview (x int, y text);
select xmin, * from fooview; select xmin, * from rules_fooview;
xmin | x | y xmin | x | y
------+---+--- ------+---+---
(0 rows) (0 rows)
create rule "_RETURN" as on select to fooview do instead create rule "_RETURN" as on select to rules_fooview do instead
select 1 as x, 'aaa'::text as y; select 1 as x, 'aaa'::text as y;
select * from fooview; select * from rules_fooview;
x | y x | y
---+----- ---+-----
1 | aaa 1 | aaa
(1 row) (1 row)
select xmin, * from fooview; -- fail, views don't have such a column select xmin, * from rules_fooview; -- fail, views don't have such a column
ERROR: column "xmin" does not exist ERROR: column "xmin" does not exist
LINE 1: select xmin, * from fooview; LINE 1: select xmin, * from rules_fooview;
^ ^
select reltoastrelid, relkind, relfrozenxid select reltoastrelid, relkind, relfrozenxid
from pg_class where oid = 'fooview'::regclass; from pg_class where oid = 'rules_fooview'::regclass;
reltoastrelid | relkind | relfrozenxid reltoastrelid | relkind | relfrozenxid
---------------+---------+-------------- ---------------+---------+--------------
0 | v | 0 0 | v | 0
(1 row) (1 row)
drop view fooview; drop view rules_fooview;
-- trying to convert a partitioned table to view is not allowed -- trying to convert a partitioned table to view is not allowed
create table fooview (x int, y text) partition by list (x); create table rules_fooview (x int, y text) partition by list (x);
create rule "_RETURN" as on select to fooview do instead create rule "_RETURN" as on select to rules_fooview do instead
select 1 as x, 'aaa'::text as y; select 1 as x, 'aaa'::text as y;
ERROR: cannot convert partitioned table "fooview" to a view ERROR: cannot convert partitioned table "rules_fooview" to a view
-- nor can one convert a partition to view -- nor can one convert a partition to view
create table fooview_part partition of fooview for values in (1); create table rules_fooview_part partition of rules_fooview for values in (1);
create rule "_RETURN" as on select to fooview_part do instead create rule "_RETURN" as on select to rules_fooview_part do instead
select 1 as x, 'aaa'::text as y; select 1 as x, 'aaa'::text as y;
ERROR: cannot convert partition "fooview_part" to a view ERROR: cannot convert partition "rules_fooview_part" to a view
-- --
-- check for planner problems with complex inherited UPDATES -- check for planner problems with complex inherited UPDATES
-- --
...@@ -3229,12 +3229,12 @@ SELECT pg_get_partkeydef(0); ...@@ -3229,12 +3229,12 @@ SELECT pg_get_partkeydef(0);
(1 row) (1 row)
-- test rename for a rule defined on a partitioned table -- test rename for a rule defined on a partitioned table
CREATE TABLE parted_table (a int) PARTITION BY LIST (a); CREATE TABLE rules_parted_table (a int) PARTITION BY LIST (a);
CREATE TABLE parted_table_1 PARTITION OF parted_table FOR VALUES IN (1); CREATE TABLE rules_parted_table_1 PARTITION OF rules_parted_table FOR VALUES IN (1);
CREATE RULE parted_table_insert AS ON INSERT to parted_table CREATE RULE rules_parted_table_insert AS ON INSERT to rules_parted_table
DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*); DO INSTEAD INSERT INTO rules_parted_table_1 VALUES (NEW.*);
ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect; ALTER RULE rules_parted_table_insert ON rules_parted_table RENAME TO rules_parted_table_insert_redirect;
DROP TABLE parted_table; DROP TABLE rules_parted_table;
-- --
-- Test enabling/disabling -- Test enabling/disabling
-- --
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
-- SELECT_INTO -- SELECT_INTO
-- --
SELECT * SELECT *
INTO TABLE tmp1 INTO TABLE sitmp1
FROM onek FROM onek
WHERE onek.unique1 < 2; WHERE onek.unique1 < 2;
DROP TABLE tmp1; DROP TABLE sitmp1;
SELECT * SELECT *
INTO TABLE tmp1 INTO TABLE sitmp1
FROM onek2 FROM onek2
WHERE onek2.unique1 < 2; WHERE onek2.unique1 < 2;
DROP TABLE tmp1; DROP TABLE sitmp1;
-- --
-- SELECT INTO and INSERT permission, if owner is not allowed to insert. -- SELECT INTO and INSERT permission, if owner is not allowed to insert.
-- --
......
-- --
-- PARALLEL -- PARALLEL
-- --
create or replace function parallel_restricted(int) returns int as create function sp_parallel_restricted(int) returns int as
$$begin return $1; end$$ language plpgsql parallel restricted; $$begin return $1; end$$ language plpgsql parallel restricted;
-- Serializable isolation would disable parallel query, so explicitly use an -- Serializable isolation would disable parallel query, so explicitly use an
-- arbitrary other level. -- arbitrary other level.
...@@ -122,12 +122,12 @@ select round(avg(aa)), sum(aa) from a_star a4; ...@@ -122,12 +122,12 @@ select round(avg(aa)), sum(aa) from a_star a4;
reset enable_parallel_append; reset enable_parallel_append;
-- Parallel Append that runs serially -- Parallel Append that runs serially
create or replace function foobar() returns setof text as create function sp_test_func() returns setof text as
$$ select 'foo'::varchar union all select 'bar'::varchar $$ $$ select 'foo'::varchar union all select 'bar'::varchar $$
language sql stable; language sql stable;
select foobar() order by 1; select sp_test_func() order by 1;
foobar sp_test_func
-------- --------------
bar bar
foo foo
(2 rows) (2 rows)
...@@ -178,15 +178,15 @@ reset parallel_leader_participation; ...@@ -178,15 +178,15 @@ reset parallel_leader_participation;
-- test that parallel_restricted function doesn't run in worker -- test that parallel_restricted function doesn't run in worker
alter table tenk1 set (parallel_workers = 4); alter table tenk1 set (parallel_workers = 4);
explain (verbose, costs off) explain (verbose, costs off)
select parallel_restricted(unique1) from tenk1 select sp_parallel_restricted(unique1) from tenk1
where stringu1 = 'GRAAAA' order by 1; where stringu1 = 'GRAAAA' order by 1;
QUERY PLAN QUERY PLAN
--------------------------------------------------------- ---------------------------------------------------------
Sort Sort
Output: (parallel_restricted(unique1)) Output: (sp_parallel_restricted(unique1))
Sort Key: (parallel_restricted(tenk1.unique1)) Sort Key: (sp_parallel_restricted(tenk1.unique1))
-> Gather -> Gather
Output: parallel_restricted(unique1) Output: sp_parallel_restricted(unique1)
Workers Planned: 4 Workers Planned: 4
-> Parallel Seq Scan on public.tenk1 -> Parallel Seq Scan on public.tenk1
Output: unique1 Output: unique1
...@@ -231,12 +231,12 @@ explain (costs off) ...@@ -231,12 +231,12 @@ explain (costs off)
-- test that parallel plan for aggregates is not selected when -- test that parallel plan for aggregates is not selected when
-- target list contains parallel restricted clause. -- target list contains parallel restricted clause.
explain (costs off) explain (costs off)
select sum(parallel_restricted(unique1)) from tenk1 select sum(sp_parallel_restricted(unique1)) from tenk1
group by(parallel_restricted(unique1)); group by(sp_parallel_restricted(unique1));
QUERY PLAN QUERY PLAN
------------------------------------------------------------------- -------------------------------------------------------------------
HashAggregate HashAggregate
Group Key: parallel_restricted(unique1) Group Key: sp_parallel_restricted(unique1)
-> Gather -> Gather
Workers Planned: 4 Workers Planned: 4
-> Parallel Index Only Scan using tenk1_unique1 on tenk1 -> Parallel Index Only Scan using tenk1_unique1 on tenk1
...@@ -609,21 +609,21 @@ select count(*) from tenk1 group by twenty; ...@@ -609,21 +609,21 @@ select count(*) from tenk1 group by twenty;
(20 rows) (20 rows)
--test expressions in targetlist are pushed down for gather merge --test expressions in targetlist are pushed down for gather merge
create or replace function simple_func(var1 integer) returns integer create function sp_simple_func(var1 integer) returns integer
as $$ as $$
begin begin
return var1 + 10; return var1 + 10;
end; end;
$$ language plpgsql PARALLEL SAFE; $$ language plpgsql PARALLEL SAFE;
explain (costs off, verbose) explain (costs off, verbose)
select ten, simple_func(ten) from tenk1 where ten < 100 order by ten; select ten, sp_simple_func(ten) from tenk1 where ten < 100 order by ten;
QUERY PLAN QUERY PLAN
----------------------------------------------------- -----------------------------------------------------
Gather Merge Gather Merge
Output: ten, (simple_func(ten)) Output: ten, (sp_simple_func(ten))
Workers Planned: 4 Workers Planned: 4
-> Result -> Result
Output: ten, simple_func(ten) Output: ten, sp_simple_func(ten)
-> Sort -> Sort
Output: ten Output: ten
Sort Key: tenk1.ten Sort Key: tenk1.ten
...@@ -632,7 +632,7 @@ explain (costs off, verbose) ...@@ -632,7 +632,7 @@ explain (costs off, verbose)
Filter: (tenk1.ten < 100) Filter: (tenk1.ten < 100)
(11 rows) (11 rows)
drop function simple_func(integer); drop function sp_simple_func(integer);
-- test gather merge with parallel leader participation disabled -- test gather merge with parallel leader participation disabled
set parallel_leader_participation = off; set parallel_leader_participation = off;
explain (costs off) explain (costs off)
...@@ -827,7 +827,7 @@ explain (costs off) ...@@ -827,7 +827,7 @@ explain (costs off)
ROLLBACK TO SAVEPOINT settings; ROLLBACK TO SAVEPOINT settings;
-- exercise record typmod remapping between backends -- exercise record typmod remapping between backends
CREATE OR REPLACE FUNCTION make_record(n int) CREATE FUNCTION make_record(n int)
RETURNS RECORD LANGUAGE plpgsql PARALLEL SAFE AS RETURNS RECORD LANGUAGE plpgsql PARALLEL SAFE AS
$$ $$
BEGIN BEGIN
......
...@@ -146,69 +146,69 @@ COMMIT; ...@@ -146,69 +146,69 @@ COMMIT;
-- Subtransactions, basic tests -- Subtransactions, basic tests
-- create & drop tables -- create & drop tables
SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE; SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE;
CREATE TABLE foobar (a int); CREATE TABLE trans_foobar (a int);
BEGIN; BEGIN;
CREATE TABLE foo (a int); CREATE TABLE trans_foo (a int);
SAVEPOINT one; SAVEPOINT one;
DROP TABLE foo; DROP TABLE trans_foo;
CREATE TABLE bar (a int); CREATE TABLE trans_bar (a int);
ROLLBACK TO SAVEPOINT one; ROLLBACK TO SAVEPOINT one;
RELEASE SAVEPOINT one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
CREATE TABLE baz (a int); CREATE TABLE trans_baz (a int);
RELEASE SAVEPOINT two; RELEASE SAVEPOINT two;
drop TABLE foobar; drop TABLE trans_foobar;
CREATE TABLE barbaz (a int); CREATE TABLE trans_barbaz (a int);
COMMIT; COMMIT;
-- should exist: barbaz, baz, foo -- should exist: trans_barbaz, trans_baz, trans_foo
SELECT * FROM foo; -- should be empty SELECT * FROM trans_foo; -- should be empty
a a
--- ---
(0 rows) (0 rows)
SELECT * FROM bar; -- shouldn't exist SELECT * FROM trans_bar; -- shouldn't exist
ERROR: relation "bar" does not exist ERROR: relation "trans_bar" does not exist
LINE 1: SELECT * FROM bar; LINE 1: SELECT * FROM trans_bar;
^ ^
SELECT * FROM barbaz; -- should be empty SELECT * FROM trans_barbaz; -- should be empty
a a
--- ---
(0 rows) (0 rows)
SELECT * FROM baz; -- should be empty SELECT * FROM trans_baz; -- should be empty
a a
--- ---
(0 rows) (0 rows)
-- inserts -- inserts
BEGIN; BEGIN;
INSERT INTO foo VALUES (1); INSERT INTO trans_foo VALUES (1);
SAVEPOINT one; SAVEPOINT one;
INSERT into bar VALUES (1); INSERT into trans_bar VALUES (1);
ERROR: relation "bar" does not exist ERROR: relation "trans_bar" does not exist
LINE 1: INSERT into bar VALUES (1); LINE 1: INSERT into trans_bar VALUES (1);
^ ^
ROLLBACK TO one; ROLLBACK TO one;
RELEASE SAVEPOINT one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
INSERT into barbaz VALUES (1); INSERT into trans_barbaz VALUES (1);
RELEASE two; RELEASE two;
SAVEPOINT three; SAVEPOINT three;
SAVEPOINT four; SAVEPOINT four;
INSERT INTO foo VALUES (2); INSERT INTO trans_foo VALUES (2);
RELEASE SAVEPOINT four; RELEASE SAVEPOINT four;
ROLLBACK TO SAVEPOINT three; ROLLBACK TO SAVEPOINT three;
RELEASE SAVEPOINT three; RELEASE SAVEPOINT three;
INSERT INTO foo VALUES (3); INSERT INTO trans_foo VALUES (3);
COMMIT; COMMIT;
SELECT * FROM foo; -- should have 1 and 3 SELECT * FROM trans_foo; -- should have 1 and 3
a a
--- ---
1 1
3 3
(2 rows) (2 rows)
SELECT * FROM barbaz; -- should have 1 SELECT * FROM trans_barbaz; -- should have 1
a a
--- ---
1 1
...@@ -217,9 +217,9 @@ SELECT * FROM barbaz; -- should have 1 ...@@ -217,9 +217,9 @@ SELECT * FROM barbaz; -- should have 1
-- test whole-tree commit -- test whole-tree commit
BEGIN; BEGIN;
SAVEPOINT one; SAVEPOINT one;
SELECT foo; SELECT trans_foo;
ERROR: column "foo" does not exist ERROR: column "trans_foo" does not exist
LINE 1: SELECT foo; LINE 1: SELECT trans_foo;
^ ^
ROLLBACK TO SAVEPOINT one; ROLLBACK TO SAVEPOINT one;
RELEASE SAVEPOINT one; RELEASE SAVEPOINT one;
...@@ -266,9 +266,9 @@ BEGIN; ...@@ -266,9 +266,9 @@ BEGIN;
INSERT INTO savepoints VALUES (4); INSERT INTO savepoints VALUES (4);
SAVEPOINT one; SAVEPOINT one;
INSERT INTO savepoints VALUES (5); INSERT INTO savepoints VALUES (5);
SELECT foo; SELECT trans_foo;
ERROR: column "foo" does not exist ERROR: column "trans_foo" does not exist
LINE 1: SELECT foo; LINE 1: SELECT trans_foo;
^ ^
COMMIT; COMMIT;
SELECT * FROM savepoints; SELECT * FROM savepoints;
...@@ -549,9 +549,9 @@ DETAIL: Key (a)=(1) already exists. ...@@ -549,9 +549,9 @@ DETAIL: Key (a)=(1) already exists.
ERROR: duplicate key value violates unique constraint "koju_a_key" ERROR: duplicate key value violates unique constraint "koju_a_key"
DETAIL: Key (a)=(1) already exists. DETAIL: Key (a)=(1) already exists.
ROLLBACK; ROLLBACK;
DROP TABLE foo; DROP TABLE trans_foo;
DROP TABLE baz; DROP TABLE trans_baz;
DROP TABLE barbaz; DROP TABLE trans_barbaz;
-- test case for problems with revalidating an open relation during abort -- test case for problems with revalidating an open relation during abort
create function inverse(int) returns float8 as create function inverse(int) returns float8 as
$$ $$
......
...@@ -23,8 +23,8 @@ CREATE VIEW rw_view15 AS SELECT a, upper(b) FROM base_tbl; -- Expression/functio ...@@ -23,8 +23,8 @@ CREATE VIEW rw_view15 AS SELECT a, upper(b) FROM base_tbl; -- Expression/functio
CREATE VIEW rw_view16 AS SELECT a, b, a AS aa FROM base_tbl; -- Repeated column may be part of an updatable view CREATE VIEW rw_view16 AS SELECT a, b, a AS aa FROM base_tbl; -- Repeated column may be part of an updatable view
CREATE VIEW ro_view17 AS SELECT * FROM ro_view1; -- Base relation not updatable CREATE VIEW ro_view17 AS SELECT * FROM ro_view1; -- Base relation not updatable
CREATE VIEW ro_view18 AS SELECT * FROM (VALUES(1)) AS tmp(a); -- VALUES in rangetable CREATE VIEW ro_view18 AS SELECT * FROM (VALUES(1)) AS tmp(a); -- VALUES in rangetable
CREATE SEQUENCE seq; CREATE SEQUENCE uv_seq;
CREATE VIEW ro_view19 AS SELECT * FROM seq; -- View based on a sequence CREATE VIEW ro_view19 AS SELECT * FROM uv_seq; -- View based on a sequence
CREATE VIEW ro_view20 AS SELECT a, b, generate_series(1, a) g FROM base_tbl; -- SRF in targetlist not supported CREATE VIEW ro_view20 AS SELECT a, b, generate_series(1, a) g FROM base_tbl; -- SRF in targetlist not supported
SELECT table_name, is_insertable_into SELECT table_name, is_insertable_into
FROM information_schema.tables FROM information_schema.tables
...@@ -347,7 +347,7 @@ drop cascades to view ro_view20 ...@@ -347,7 +347,7 @@ drop cascades to view ro_view20
drop cascades to view ro_view4 drop cascades to view ro_view4
drop cascades to view rw_view14 drop cascades to view rw_view14
DROP VIEW ro_view10, ro_view12, ro_view18; DROP VIEW ro_view10, ro_view12, ro_view18;
DROP SEQUENCE seq CASCADE; DROP SEQUENCE uv_seq CASCADE;
NOTICE: drop cascades to view ro_view19 NOTICE: drop cascades to view ro_view19
-- simple updatable view -- simple updatable view
CREATE TABLE base_tbl (a int PRIMARY KEY, b text DEFAULT 'Unspecified'); CREATE TABLE base_tbl (a int PRIMARY KEY, b text DEFAULT 'Unspecified');
...@@ -2368,66 +2368,66 @@ DETAIL: Failing row contains (-1, invalid). ...@@ -2368,66 +2368,66 @@ DETAIL: Failing row contains (-1, invalid).
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; DROP TABLE t1;
-- check that an auto-updatable view on a partitioned table works correctly -- check that an auto-updatable view on a partitioned table works correctly
create table pt (a int, b int, v varchar) partition by range (a, b); create table uv_pt (a int, b int, v varchar) partition by range (a, b);
create table pt1 (b int not null, v varchar, a int not null) partition by range (b); create table uv_pt1 (b int not null, v varchar, a int not null) partition by range (b);
create table pt11 (like pt1); create table uv_pt11 (like uv_pt1);
alter table pt11 drop a; alter table uv_pt11 drop a;
alter table pt11 add a int; alter table uv_pt11 add a int;
alter table pt11 drop a; alter table uv_pt11 drop a;
alter table pt11 add a int not null; alter table uv_pt11 add a int not null;
alter table pt1 attach partition pt11 for values from (2) to (5); alter table uv_pt1 attach partition uv_pt11 for values from (2) to (5);
alter table pt attach partition pt1 for values from (1, 2) to (1, 10); alter table uv_pt attach partition uv_pt1 for values from (1, 2) to (1, 10);
create view ptv as select * from pt; create view uv_ptv as select * from uv_pt;
select events & 4 != 0 AS upd, select events & 4 != 0 AS upd,
events & 8 != 0 AS ins, events & 8 != 0 AS ins,
events & 16 != 0 AS del events & 16 != 0 AS del
from pg_catalog.pg_relation_is_updatable('pt'::regclass, false) t(events); from pg_catalog.pg_relation_is_updatable('uv_pt'::regclass, false) t(events);
upd | ins | del upd | ins | del
-----+-----+----- -----+-----+-----
t | t | t t | t | t
(1 row) (1 row)
select pg_catalog.pg_column_is_updatable('pt'::regclass, 1::smallint, false); select pg_catalog.pg_column_is_updatable('uv_pt'::regclass, 1::smallint, false);
pg_column_is_updatable pg_column_is_updatable
------------------------ ------------------------
t t
(1 row) (1 row)
select pg_catalog.pg_column_is_updatable('pt'::regclass, 2::smallint, false); select pg_catalog.pg_column_is_updatable('uv_pt'::regclass, 2::smallint, false);
pg_column_is_updatable pg_column_is_updatable
------------------------ ------------------------
t t
(1 row) (1 row)
select table_name, is_updatable, is_insertable_into select table_name, is_updatable, is_insertable_into
from information_schema.views where table_name = 'ptv'; from information_schema.views where table_name = 'uv_ptv';
table_name | is_updatable | is_insertable_into table_name | is_updatable | is_insertable_into
------------+--------------+-------------------- ------------+--------------+--------------------
ptv | YES | YES uv_ptv | YES | YES
(1 row) (1 row)
select table_name, column_name, is_updatable select table_name, column_name, is_updatable
from information_schema.columns where table_name = 'ptv' order by column_name; from information_schema.columns where table_name = 'uv_ptv' order by column_name;
table_name | column_name | is_updatable table_name | column_name | is_updatable
------------+-------------+-------------- ------------+-------------+--------------
ptv | a | YES uv_ptv | a | YES
ptv | b | YES uv_ptv | b | YES
ptv | v | YES uv_ptv | v | YES
(3 rows) (3 rows)
insert into ptv values (1, 2); insert into uv_ptv values (1, 2);
select tableoid::regclass, * from pt; select tableoid::regclass, * from uv_pt;
tableoid | a | b | v tableoid | a | b | v
----------+---+---+--- ----------+---+---+---
pt11 | 1 | 2 | uv_pt11 | 1 | 2 |
(1 row) (1 row)
create view ptv_wco as select * from pt where a = 0 with check option; create view uv_ptv_wco as select * from uv_pt where a = 0 with check option;
insert into ptv_wco values (1, 2); insert into uv_ptv_wco values (1, 2);
ERROR: new row violates check option for view "ptv_wco" ERROR: new row violates check option for view "uv_ptv_wco"
DETAIL: Failing row contains (1, 2, null). DETAIL: Failing row contains (1, 2, null).
drop view ptv, ptv_wco; drop view uv_ptv, uv_ptv_wco;
drop table pt, pt1, pt11; drop table uv_pt, uv_pt1, uv_pt11;
-- check that wholerow vars appearing in WITH CHECK OPTION constraint expressions -- check that wholerow vars appearing in WITH CHECK OPTION constraint expressions
-- work fine with partitioned tables -- work fine with partitioned tables
create table wcowrtest (a int) partition by list (a); create table wcowrtest (a int) partition by list (a);
......
...@@ -1819,12 +1819,12 @@ SELECT * FROM y; ...@@ -1819,12 +1819,12 @@ SELECT * FROM y;
(22 rows) (22 rows)
-- data-modifying WITH containing INSERT...ON CONFLICT DO UPDATE -- data-modifying WITH containing INSERT...ON CONFLICT DO UPDATE
CREATE TABLE z AS SELECT i AS k, (i || ' v')::text v FROM generate_series(1, 16, 3) i; CREATE TABLE withz AS SELECT i AS k, (i || ' v')::text v FROM generate_series(1, 16, 3) i;
ALTER TABLE z ADD UNIQUE (k); ALTER TABLE withz ADD UNIQUE (k);
WITH t AS ( WITH t AS (
INSERT INTO z SELECT i, 'insert' INSERT INTO withz SELECT i, 'insert'
FROM generate_series(0, 16) i FROM generate_series(0, 16) i
ON CONFLICT (k) DO UPDATE SET v = z.v || ', now update' ON CONFLICT (k) DO UPDATE SET v = withz.v || ', now update'
RETURNING * RETURNING *
) )
SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k; SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k;
...@@ -1836,8 +1836,8 @@ SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k; ...@@ -1836,8 +1836,8 @@ SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k;
-- Test EXCLUDED.* reference within CTE -- Test EXCLUDED.* reference within CTE
WITH aa AS ( WITH aa AS (
INSERT INTO z VALUES(1, 5) ON CONFLICT (k) DO UPDATE SET v = EXCLUDED.v INSERT INTO withz VALUES(1, 5) ON CONFLICT (k) DO UPDATE SET v = EXCLUDED.v
WHERE z.k != EXCLUDED.k WHERE withz.k != EXCLUDED.k
RETURNING * RETURNING *
) )
SELECT * FROM aa; SELECT * FROM aa;
...@@ -1846,7 +1846,7 @@ SELECT * FROM aa; ...@@ -1846,7 +1846,7 @@ SELECT * FROM aa;
(0 rows) (0 rows)
-- New query/snapshot demonstrates side-effects of previous query. -- New query/snapshot demonstrates side-effects of previous query.
SELECT * FROM z ORDER BY k; SELECT * FROM withz ORDER BY k;
k | v k | v
----+------------------ ----+------------------
0 | insert 0 | insert
...@@ -1873,19 +1873,19 @@ SELECT * FROM z ORDER BY k; ...@@ -1873,19 +1873,19 @@ SELECT * FROM z ORDER BY k;
-- reference outside values -- reference outside values
-- --
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1);
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = ' update' WHERE z.k = (SELECT a FROM aa); ON CONFLICT (k) DO UPDATE SET v = ' update' WHERE withz.k = (SELECT a FROM aa);
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1);
WITH aa AS (SELECT 'a' a, 'b' b UNION ALL SELECT 'a' a, 'b' b) WITH aa AS (SELECT 'a' a, 'b' b UNION ALL SELECT 'a' a, 'b' b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 'a' LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 'a' LIMIT 1);
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, (SELECT b || ' insert' FROM aa WHERE a = 1 )) INSERT INTO withz VALUES(1, (SELECT b || ' insert' FROM aa WHERE a = 1 ))
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1);
-- Update a row more than once, in different parts of a wCTE. That is -- Update a row more than once, in different parts of a wCTE. That is
-- an allowed, presumably very rare, edge case, but since it was -- an allowed, presumably very rare, edge case, but since it was
...@@ -1893,17 +1893,17 @@ ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIM ...@@ -1893,17 +1893,17 @@ ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIM
WITH simpletup AS ( WITH simpletup AS (
SELECT 2 k, 'Green' v), SELECT 2 k, 'Green' v),
upsert_cte AS ( upsert_cte AS (
INSERT INTO z VALUES(2, 'Blue') ON CONFLICT (k) DO INSERT INTO withz VALUES(2, 'Blue') ON CONFLICT (k) DO
UPDATE SET (k, v) = (SELECT k, v FROM simpletup WHERE simpletup.k = z.k) UPDATE SET (k, v) = (SELECT k, v FROM simpletup WHERE simpletup.k = withz.k)
RETURNING k, v) RETURNING k, v)
INSERT INTO z VALUES(2, 'Red') ON CONFLICT (k) DO INSERT INTO withz VALUES(2, 'Red') ON CONFLICT (k) DO
UPDATE SET (k, v) = (SELECT k, v FROM upsert_cte WHERE upsert_cte.k = z.k) UPDATE SET (k, v) = (SELECT k, v FROM upsert_cte WHERE upsert_cte.k = withz.k)
RETURNING k, v; RETURNING k, v;
k | v k | v
---+--- ---+---
(0 rows) (0 rows)
DROP TABLE z; DROP TABLE withz;
-- check that run to completion happens in proper ordering -- check that run to completion happens in proper ordering
TRUNCATE TABLE y; TRUNCATE TABLE y;
INSERT INTO y SELECT generate_series(1, 3); INSERT INTO y SELECT generate_series(1, 3);
...@@ -2280,7 +2280,7 @@ LINE 1: WITH test AS (SELECT 42) INSERT INTO test VALUES (1); ...@@ -2280,7 +2280,7 @@ LINE 1: WITH test AS (SELECT 42) INSERT INTO test VALUES (1);
-- check response to attempt to modify table with same name as a CTE (perhaps -- check response to attempt to modify table with same name as a CTE (perhaps
-- surprisingly it works, because CTEs don't hide tables from data-modifying -- surprisingly it works, because CTEs don't hide tables from data-modifying
-- statements) -- statements)
create table test (i int); create temp table test (i int);
with test as (select 42) insert into test select * from test; with test as (select 42) insert into test select * from test;
select * from test; select * from test;
i i
......
This diff is collapsed.
CALL nonexistent(); -- error CALL nonexistent(); -- error
CALL random(); -- error CALL random(); -- error
CREATE FUNCTION testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$; CREATE FUNCTION cp_testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$;
CREATE TABLE cp_test (a int, b text); CREATE TABLE cp_test (a int, b text);
...@@ -76,11 +76,11 @@ CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES ...@@ -76,11 +76,11 @@ CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES
ALTER PROCEDURE ptest1(text) STRICT; ALTER PROCEDURE ptest1(text) STRICT;
ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function
ALTER PROCEDURE testfunc1(int) VOLATILE; -- error: not a procedure ALTER PROCEDURE cp_testfunc1(int) VOLATILE; -- error: not a procedure
ALTER PROCEDURE nonexistent() VOLATILE; ALTER PROCEDURE nonexistent() VOLATILE;
DROP FUNCTION ptest1(text); -- error: not a function DROP FUNCTION ptest1(text); -- error: not a function
DROP PROCEDURE testfunc1(int); -- error: not a procedure DROP PROCEDURE cp_testfunc1(int); -- error: not a procedure
DROP PROCEDURE nonexistent(); DROP PROCEDURE nonexistent();
...@@ -100,13 +100,13 @@ RESET ROLE; ...@@ -100,13 +100,13 @@ RESET ROLE;
-- ROUTINE syntax -- ROUTINE syntax
ALTER ROUTINE testfunc1(int) RENAME TO testfunc1a; ALTER ROUTINE cp_testfunc1(int) RENAME TO cp_testfunc1a;
ALTER ROUTINE testfunc1a RENAME TO testfunc1; ALTER ROUTINE cp_testfunc1a RENAME TO cp_testfunc1;
ALTER ROUTINE ptest1(text) RENAME TO ptest1a; ALTER ROUTINE ptest1(text) RENAME TO ptest1a;
ALTER ROUTINE ptest1a RENAME TO ptest1; ALTER ROUTINE ptest1a RENAME TO ptest1;
DROP ROUTINE testfunc1(int); DROP ROUTINE cp_testfunc1(int);
-- cleanup -- cleanup
......
This diff is collapsed.
CREATE TABLE toasttest(descr text, cnt int DEFAULT 0, f1 text, f2 text); CREATE TABLE indtoasttest(descr text, cnt int DEFAULT 0, f1 text, f2 text);
INSERT INTO toasttest(descr, f1, f2) VALUES('two-compressed', repeat('1234567890',1000), repeat('1234567890',1000)); INSERT INTO indtoasttest(descr, f1, f2) VALUES('two-compressed', repeat('1234567890',1000), repeat('1234567890',1000));
INSERT INTO toasttest(descr, f1, f2) VALUES('two-toasted', repeat('1234567890',30000), repeat('1234567890',50000)); INSERT INTO indtoasttest(descr, f1, f2) VALUES('two-toasted', repeat('1234567890',30000), repeat('1234567890',50000));
INSERT INTO toasttest(descr, f1, f2) VALUES('one-compressed,one-null', NULL, repeat('1234567890',1000)); INSERT INTO indtoasttest(descr, f1, f2) VALUES('one-compressed,one-null', NULL, repeat('1234567890',1000));
INSERT INTO toasttest(descr, f1, f2) VALUES('one-toasted,one-null', NULL, repeat('1234567890',50000)); INSERT INTO indtoasttest(descr, f1, f2) VALUES('one-toasted,one-null', NULL, repeat('1234567890',50000));
-- check whether indirect tuples works on the most basic level -- check whether indirect tuples works on the most basic level
SELECT descr, substring(make_tuple_indirect(toasttest)::text, 1, 200) FROM toasttest; SELECT descr, substring(make_tuple_indirect(indtoasttest)::text, 1, 200) FROM indtoasttest;
-- modification without changing varlenas -- modification without changing varlenas
UPDATE toasttest SET cnt = cnt +1 RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1 RETURNING substring(indtoasttest::text, 1, 200);
-- modification without modifying assigned value -- modification without modifying assigned value
UPDATE toasttest SET cnt = cnt +1, f1 = f1 RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1, f1 = f1 RETURNING substring(indtoasttest::text, 1, 200);
-- modification modifying, but effectively not changing -- modification modifying, but effectively not changing
UPDATE toasttest SET cnt = cnt +1, f1 = f1||'' RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1, f1 = f1||'' RETURNING substring(indtoasttest::text, 1, 200);
UPDATE toasttest SET cnt = cnt +1, f1 = '-'||f1||'-' RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1, f1 = '-'||f1||'-' RETURNING substring(indtoasttest::text, 1, 200);
SELECT substring(toasttest::text, 1, 200) FROM toasttest; SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
-- check we didn't screw with main/toast tuple visibility -- check we didn't screw with main/toast tuple visibility
VACUUM FREEZE toasttest; VACUUM FREEZE indtoasttest;
SELECT substring(toasttest::text, 1, 200) FROM toasttest; SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
-- now create a trigger that forces all Datums to be indirect ones -- now create a trigger that forces all Datums to be indirect ones
CREATE FUNCTION update_using_indirect() CREATE FUNCTION update_using_indirect()
...@@ -33,29 +33,29 @@ BEGIN ...@@ -33,29 +33,29 @@ BEGIN
RETURN NEW; RETURN NEW;
END$$; END$$;
CREATE TRIGGER toasttest_update_indirect CREATE TRIGGER indtoasttest_update_indirect
BEFORE INSERT OR UPDATE BEFORE INSERT OR UPDATE
ON toasttest ON indtoasttest
FOR EACH ROW FOR EACH ROW
EXECUTE PROCEDURE update_using_indirect(); EXECUTE PROCEDURE update_using_indirect();
-- modification without changing varlenas -- modification without changing varlenas
UPDATE toasttest SET cnt = cnt +1 RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1 RETURNING substring(indtoasttest::text, 1, 200);
-- modification without modifying assigned value -- modification without modifying assigned value
UPDATE toasttest SET cnt = cnt +1, f1 = f1 RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1, f1 = f1 RETURNING substring(indtoasttest::text, 1, 200);
-- modification modifying, but effectively not changing -- modification modifying, but effectively not changing
UPDATE toasttest SET cnt = cnt +1, f1 = f1||'' RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1, f1 = f1||'' RETURNING substring(indtoasttest::text, 1, 200);
UPDATE toasttest SET cnt = cnt +1, f1 = '-'||f1||'-' RETURNING substring(toasttest::text, 1, 200); UPDATE indtoasttest SET cnt = cnt +1, f1 = '-'||f1||'-' RETURNING substring(indtoasttest::text, 1, 200);
INSERT INTO toasttest(descr, f1, f2) VALUES('one-toasted,one-null, via indirect', repeat('1234567890',30000), NULL); INSERT INTO indtoasttest(descr, f1, f2) VALUES('one-toasted,one-null, via indirect', repeat('1234567890',30000), NULL);
SELECT substring(toasttest::text, 1, 200) FROM toasttest; SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
-- check we didn't screw with main/toast tuple visibility -- check we didn't screw with main/toast tuple visibility
VACUUM FREEZE toasttest; VACUUM FREEZE indtoasttest;
SELECT substring(toasttest::text, 1, 200) FROM toasttest; SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;
DROP TABLE toasttest; DROP TABLE indtoasttest;
DROP FUNCTION update_using_indirect(); DROP FUNCTION update_using_indirect();
...@@ -1792,25 +1792,25 @@ delete from xx1 using lateral (select * from int4_tbl where f1 = x1) ss; ...@@ -1792,25 +1792,25 @@ delete from xx1 using lateral (select * from int4_tbl where f1 = x1) ss;
-- test LATERAL reference propagation down a multi-level inheritance hierarchy -- test LATERAL reference propagation down a multi-level inheritance hierarchy
-- produced for a multi-level partitioned table hierarchy. -- produced for a multi-level partitioned table hierarchy.
-- --
create table pt1 (a int, b int, c varchar) partition by range(a); create table join_pt1 (a int, b int, c varchar) partition by range(a);
create table pt1p1 partition of pt1 for values from (0) to (100) partition by range(b); create table join_pt1p1 partition of join_pt1 for values from (0) to (100) partition by range(b);
create table pt1p2 partition of pt1 for values from (100) to (200); create table join_pt1p2 partition of join_pt1 for values from (100) to (200);
create table pt1p1p1 partition of pt1p1 for values from (0) to (100); create table join_pt1p1p1 partition of join_pt1p1 for values from (0) to (100);
insert into pt1 values (1, 1, 'x'), (101, 101, 'y'); insert into join_pt1 values (1, 1, 'x'), (101, 101, 'y');
create table ut1 (a int, b int, c varchar); create table join_ut1 (a int, b int, c varchar);
insert into ut1 values (101, 101, 'y'), (2, 2, 'z'); insert into join_ut1 values (101, 101, 'y'), (2, 2, 'z');
explain (verbose, costs off) explain (verbose, costs off)
select t1.b, ss.phv from ut1 t1 left join lateral select t1.b, ss.phv from join_ut1 t1 left join lateral
(select t2.a as t2a, t3.a t3a, least(t1.a, t2.a, t3.a) phv (select t2.a as t2a, t3.a t3a, least(t1.a, t2.a, t3.a) phv
from pt1 t2 join ut1 t3 on t2.a = t3.b) ss from join_pt1 t2 join join_ut1 t3 on t2.a = t3.b) ss
on t1.a = ss.t2a order by t1.a; on t1.a = ss.t2a order by t1.a;
select t1.b, ss.phv from ut1 t1 left join lateral select t1.b, ss.phv from join_ut1 t1 left join lateral
(select t2.a as t2a, t3.a t3a, least(t1.a, t2.a, t3.a) phv (select t2.a as t2a, t3.a t3a, least(t1.a, t2.a, t3.a) phv
from pt1 t2 join ut1 t3 on t2.a = t3.b) ss from join_pt1 t2 join join_ut1 t3 on t2.a = t3.b) ss
on t1.a = ss.t2a order by t1.a; on t1.a = ss.t2a order by t1.a;
drop table pt1; drop table join_pt1;
drop table ut1; drop table join_ut1;
-- --
-- test that foreign key join estimation performs sanely for outer joins -- test that foreign key join estimation performs sanely for outer joins
-- --
...@@ -2281,10 +2281,10 @@ rollback to settings; ...@@ -2281,10 +2281,10 @@ rollback to settings;
-- Exercise rescans. We'll turn off parallel_leader_participation so -- Exercise rescans. We'll turn off parallel_leader_participation so
-- that we can check that instrumentation comes back correctly. -- that we can check that instrumentation comes back correctly.
create table foo as select generate_series(1, 3) as id, 'xxxxx'::text as t; create table join_foo as select generate_series(1, 3) as id, 'xxxxx'::text as t;
alter table foo set (parallel_workers = 0); alter table join_foo set (parallel_workers = 0);
create table bar as select generate_series(1, 10000) as id, 'xxxxx'::text as t; create table join_bar as select generate_series(1, 10000) as id, 'xxxxx'::text as t;
alter table bar set (parallel_workers = 2); alter table join_bar set (parallel_workers = 2);
-- multi-batch with rescan, parallel-oblivious -- multi-batch with rescan, parallel-oblivious
savepoint settings; savepoint settings;
...@@ -2298,18 +2298,18 @@ set enable_material = off; ...@@ -2298,18 +2298,18 @@ set enable_material = off;
set enable_mergejoin = off; set enable_mergejoin = off;
set work_mem = '64kB'; set work_mem = '64kB';
explain (costs off) explain (costs off)
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select final > 1 as multibatch select final > 1 as multibatch
from hash_join_batches( from hash_join_batches(
$$ $$
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
$$); $$);
rollback to settings; rollback to settings;
...@@ -2325,18 +2325,18 @@ set enable_material = off; ...@@ -2325,18 +2325,18 @@ set enable_material = off;
set enable_mergejoin = off; set enable_mergejoin = off;
set work_mem = '4MB'; set work_mem = '4MB';
explain (costs off) explain (costs off)
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select final > 1 as multibatch select final > 1 as multibatch
from hash_join_batches( from hash_join_batches(
$$ $$
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
$$); $$);
rollback to settings; rollback to settings;
...@@ -2352,18 +2352,18 @@ set enable_material = off; ...@@ -2352,18 +2352,18 @@ set enable_material = off;
set enable_mergejoin = off; set enable_mergejoin = off;
set work_mem = '64kB'; set work_mem = '64kB';
explain (costs off) explain (costs off)
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select final > 1 as multibatch select final > 1 as multibatch
from hash_join_batches( from hash_join_batches(
$$ $$
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
$$); $$);
rollback to settings; rollback to settings;
...@@ -2379,18 +2379,18 @@ set enable_material = off; ...@@ -2379,18 +2379,18 @@ set enable_material = off;
set enable_mergejoin = off; set enable_mergejoin = off;
set work_mem = '4MB'; set work_mem = '4MB';
explain (costs off) explain (costs off)
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
select final > 1 as multibatch select final > 1 as multibatch
from hash_join_batches( from hash_join_batches(
$$ $$
select count(*) from foo select count(*) from join_foo
left join (select b1.id, b1.t from bar b1 join bar b2 using (id)) ss left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss
on foo.id < ss.id + 1 and foo.id > ss.id - 1; on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1;
$$); $$);
rollback to settings; rollback to settings;
......
This diff is collapsed.
This diff is collapsed.
...@@ -734,18 +734,18 @@ $$ language sql; ...@@ -734,18 +734,18 @@ $$ language sql;
drop function dfunc(varchar, numeric); drop function dfunc(varchar, numeric);
--fail, named parameters are not unique --fail, named parameters are not unique
create function testfoo(a int, a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, a int) returns int as $$ select 1;$$ language sql;
create function testfoo(int, out a int, out a int) returns int as $$ select 1;$$ language sql; create function testpolym(int, out a int, out a int) returns int as $$ select 1;$$ language sql;
create function testfoo(out a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(out a int, inout a int) returns int as $$ select 1;$$ language sql;
create function testfoo(a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, inout a int) returns int as $$ select 1;$$ language sql;
-- valid -- valid
create function testfoo(a int, out a int) returns int as $$ select $1;$$ language sql; create function testpolym(a int, out a int) returns int as $$ select $1;$$ language sql;
select testfoo(37); select testpolym(37);
drop function testfoo(int); drop function testpolym(int);
create function testfoo(a int) returns table(a int) as $$ select $1;$$ language sql; create function testpolym(a int) returns table(a int) as $$ select $1;$$ language sql;
select * from testfoo(37); select * from testpolym(37);
drop function testfoo(int); drop function testpolym(int);
-- test polymorphic params and defaults -- test polymorphic params and defaults
create function dfunc(a anyelement, b anyelement = null, flag bool = true) create function dfunc(a anyelement, b anyelement = null, flag bool = true)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment