2014-12-23 13:31:29 -05:00
|
|
|
--
|
|
|
|
|
-- Test for pg_get_object_address
|
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
-- Clean up in case a prior regression run failed
|
|
|
|
|
SET client_min_messages TO 'warning';
|
2016-07-17 18:42:31 -04:00
|
|
|
DROP ROLE IF EXISTS regress_addr_user;
|
|
|
|
|
RESET client_min_messages;
|
2014-12-23 13:31:29 -05:00
|
|
|
|
2016-07-17 18:42:31 -04:00
|
|
|
CREATE USER regress_addr_user;
|
2014-12-23 13:31:29 -05:00
|
|
|
|
|
|
|
|
-- Test generic object addressing/identification functions
|
|
|
|
|
CREATE SCHEMA addr_nsp;
|
|
|
|
|
SET search_path TO 'addr_nsp';
|
|
|
|
|
CREATE FOREIGN DATA WRAPPER addr_fdw;
|
|
|
|
|
CREATE SERVER addr_fserv FOREIGN DATA WRAPPER addr_fdw;
|
|
|
|
|
CREATE TEXT SEARCH DICTIONARY addr_ts_dict (template=simple);
|
|
|
|
|
CREATE TEXT SEARCH CONFIGURATION addr_ts_conf (copy=english);
|
|
|
|
|
CREATE TEXT SEARCH TEMPLATE addr_ts_temp (lexize=dsimple_lexize);
|
|
|
|
|
CREATE TEXT SEARCH PARSER addr_ts_prs
|
|
|
|
|
(start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
|
|
|
|
|
CREATE TABLE addr_nsp.gentable (
|
|
|
|
|
a serial primary key CONSTRAINT a_chk CHECK (a > 0),
|
|
|
|
|
b text DEFAULT 'hello');
|
2018-06-26 11:28:41 -04:00
|
|
|
CREATE TABLE addr_nsp.parttable (
|
|
|
|
|
a int PRIMARY KEY
|
|
|
|
|
) PARTITION BY RANGE (a);
|
2014-12-23 13:31:29 -05:00
|
|
|
CREATE VIEW addr_nsp.genview AS SELECT * from addr_nsp.gentable;
|
|
|
|
|
CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;
|
|
|
|
|
CREATE TYPE addr_nsp.gencomptype AS (a int);
|
|
|
|
|
CREATE TYPE addr_nsp.genenum AS ENUM ('one', 'two');
|
|
|
|
|
CREATE FOREIGN TABLE addr_nsp.genftable (a int) SERVER addr_fserv;
|
|
|
|
|
CREATE AGGREGATE addr_nsp.genaggr(int4) (sfunc = int4pl, stype = int4);
|
|
|
|
|
CREATE DOMAIN addr_nsp.gendomain AS int4 CONSTRAINT domconstr CHECK (value > 0);
|
|
|
|
|
CREATE FUNCTION addr_nsp.trig() RETURNS TRIGGER LANGUAGE plpgsql AS $$ BEGIN END; $$;
|
|
|
|
|
CREATE TRIGGER t BEFORE INSERT ON addr_nsp.gentable FOR EACH ROW EXECUTE PROCEDURE addr_nsp.trig();
|
|
|
|
|
CREATE POLICY genpol ON addr_nsp.gentable;
|
2017-11-30 08:46:13 -05:00
|
|
|
CREATE PROCEDURE addr_nsp.proc(int4) LANGUAGE SQL AS $$ $$;
|
2015-03-11 16:01:13 -04:00
|
|
|
CREATE SERVER "integer" FOREIGN DATA WRAPPER addr_fdw;
|
2016-07-17 18:42:31 -04:00
|
|
|
CREATE USER MAPPING FOR regress_addr_user SERVER "integer";
|
|
|
|
|
ALTER DEFAULT PRIVILEGES FOR ROLE regress_addr_user IN SCHEMA public GRANT ALL ON TABLES TO regress_addr_user;
|
|
|
|
|
ALTER DEFAULT PRIVILEGES FOR ROLE regress_addr_user REVOKE DELETE ON TABLES FROM regress_addr_user;
|
2019-02-09 21:02:06 -05:00
|
|
|
-- this transform would be quite unsafe to leave lying around,
|
|
|
|
|
-- except that the SQL language pays no attention to transforms:
|
2015-06-21 15:08:49 -04:00
|
|
|
CREATE TRANSFORM FOR int LANGUAGE SQL (
|
2019-02-09 21:02:06 -05:00
|
|
|
FROM SQL WITH FUNCTION prsd_lextype(internal),
|
2015-06-21 15:08:49 -04:00
|
|
|
TO SQL WITH FUNCTION int4recv(internal));
|
2019-07-12 18:35:34 -04:00
|
|
|
-- suppress warning that depends on wal_level
|
|
|
|
|
SET client_min_messages = 'ERROR';
|
2017-01-26 13:10:22 -05:00
|
|
|
CREATE PUBLICATION addr_pub FOR TABLE addr_nsp.gentable;
|
2019-07-12 18:35:34 -04:00
|
|
|
RESET client_min_messages;
|
Fix regression tests to use only global names beginning with "regress_".
In commit 18555b132 we tentatively established a rule that regression
tests should use names containing "regression" for databases, and names
starting with "regress_" for all other globally-visible object names, so
as to circumscribe the side-effects that "make installcheck" could have on
an existing installation. However, no enforcement mechanism was created,
so it's unsurprising that some new violations have crept in since then.
In fact, a whole new *category* of violations has crept in, to wit we now
also have globally-visible subscription and replication origin names, and
"make installcheck" could very easily clobber user-created objects of
those types. So it's past time to do something about this.
This commit sanitizes the tests enough that they will pass (i.e. not
generate any visible warnings) with the enforcement mechanism I'll add
in the next commit. There are some TAP tests that still trigger the
warnings, but the warnings do not cause test failure. Since these tests
do not actually run against a pre-existing installation, there's no need
to worry whether they could conflict with user-created objects.
The problem with rolenames.sql testing special role names like "user"
is still there, and is dealt with only very cosmetically in this patch
(by hiding the warnings :-(). What we actually need to do to be safe is
to take that test script out of "make installcheck" altogether, but that
seems like material for a separate patch.
Discussion: https://postgr.es/m/16638.1468620817@sss.pgh.pa.us
2019-06-29 11:09:03 -04:00
|
|
|
CREATE SUBSCRIPTION regress_addr_sub CONNECTION '' PUBLICATION bar WITH (connect = false, slot_name = NONE);
|
Change CREATE STATISTICS syntax
Previously, we had the WITH clause in the middle of the command, where
you'd specify both generic options as well as statistic types. Few
people liked this, so this commit changes it to remove the WITH keyword
from that clause and makes it accept statistic types only. (We
currently don't have any generic options, but if we invent in the
future, we will gain a new WITH clause, probably at the end of the
command).
Also, the column list is now specified without parens, which makes the
whole command look more similar to a SELECT command. This change will
let us expand the command to supporting expressions (not just columns
names) as well as multiple tables and their join conditions.
Tom added lots of code comments and fixed some parts of the CREATE
STATISTICS reference page, too; more changes in this area are
forthcoming. He also fixed a potential problem in the alter_generic
regression test, reducing verbosity on a cascaded drop to avoid
dependency on message ordering, as we do in other tests.
Tom also closed a security bug: we documented that table ownership was
required in order to create a statistics object on it, but didn't
actually implement it.
Implement tab-completion for statistics objects. This can stand some
more improvement.
Authors: Alvaro Herrera, with lots of cleanup by Tom Lane
Discussion: https://postgr.es/m/20170420212426.ltvgyhnefvhixm6i@alvherre.pgsql
2017-05-12 13:59:23 -04:00
|
|
|
CREATE STATISTICS addr_nsp.gentable_stat ON a, b FROM addr_nsp.gentable;
|
2014-12-23 13:31:29 -05:00
|
|
|
|
|
|
|
|
-- test some error cases
|
|
|
|
|
SELECT pg_get_object_address('stone', '{}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('table', '{}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('table', '{NULL}', '{}');
|
|
|
|
|
|
|
|
|
|
-- unrecognized object types
|
|
|
|
|
DO $$
|
|
|
|
|
DECLARE
|
|
|
|
|
objtype text;
|
|
|
|
|
BEGIN
|
|
|
|
|
FOR objtype IN VALUES ('toast table'), ('index column'), ('sequence column'),
|
2015-03-16 11:06:34 -04:00
|
|
|
('toast table column'), ('view column'), ('materialized view column')
|
2014-12-23 13:31:29 -05:00
|
|
|
LOOP
|
|
|
|
|
BEGIN
|
|
|
|
|
PERFORM pg_get_object_address(objtype, '{one}', '{}');
|
|
|
|
|
EXCEPTION WHEN invalid_parameter_value THEN
|
|
|
|
|
RAISE WARNING 'error for %: %', objtype, sqlerrm;
|
|
|
|
|
END;
|
|
|
|
|
END LOOP;
|
|
|
|
|
END;
|
|
|
|
|
$$;
|
|
|
|
|
|
2017-03-16 11:51:08 -04:00
|
|
|
-- miscellaneous other errors
|
|
|
|
|
select * from pg_get_object_address('operator of access method', '{btree,integer_ops,1}', '{int4,bool}');
|
|
|
|
|
select * from pg_get_object_address('operator of access method', '{btree,integer_ops,99}', '{int4,int4}');
|
|
|
|
|
select * from pg_get_object_address('function of access method', '{btree,integer_ops,1}', '{int4,bool}');
|
|
|
|
|
select * from pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}');
|
|
|
|
|
|
2014-12-23 13:31:29 -05:00
|
|
|
DO $$
|
|
|
|
|
DECLARE
|
|
|
|
|
objtype text;
|
|
|
|
|
names text[];
|
|
|
|
|
args text[];
|
|
|
|
|
BEGIN
|
|
|
|
|
FOR objtype IN VALUES
|
|
|
|
|
('table'), ('index'), ('sequence'), ('view'),
|
|
|
|
|
('materialized view'), ('foreign table'),
|
|
|
|
|
('table column'), ('foreign table column'),
|
2017-11-30 08:46:13 -05:00
|
|
|
('aggregate'), ('function'), ('procedure'), ('type'), ('cast'),
|
2014-12-23 13:31:29 -05:00
|
|
|
('table constraint'), ('domain constraint'), ('conversion'), ('default value'),
|
|
|
|
|
('operator'), ('operator class'), ('operator family'), ('rule'), ('trigger'),
|
|
|
|
|
('text search parser'), ('text search dictionary'),
|
|
|
|
|
('text search template'), ('text search configuration'),
|
2015-06-21 15:08:49 -04:00
|
|
|
('policy'), ('user mapping'), ('default acl'), ('transform'),
|
2017-01-26 13:10:22 -05:00
|
|
|
('operator of access method'), ('function of access method'),
|
|
|
|
|
('publication relation')
|
2014-12-23 13:31:29 -05:00
|
|
|
LOOP
|
|
|
|
|
FOR names IN VALUES ('{eins}'), ('{addr_nsp, zwei}'), ('{eins, zwei, drei}')
|
|
|
|
|
LOOP
|
|
|
|
|
FOR args IN VALUES ('{}'), ('{integer}')
|
|
|
|
|
LOOP
|
|
|
|
|
BEGIN
|
|
|
|
|
PERFORM pg_get_object_address(objtype, names, args);
|
|
|
|
|
EXCEPTION WHEN OTHERS THEN
|
|
|
|
|
RAISE WARNING 'error for %,%,%: %', objtype, names, args, sqlerrm;
|
|
|
|
|
END;
|
|
|
|
|
END LOOP;
|
|
|
|
|
END LOOP;
|
|
|
|
|
END LOOP;
|
|
|
|
|
END;
|
|
|
|
|
$$;
|
|
|
|
|
|
|
|
|
|
-- these object types cannot be qualified names
|
|
|
|
|
SELECT pg_get_object_address('language', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('language', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('large object', '{123}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('large object', '{123,456}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('large object', '{blargh}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('schema', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('schema', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('role', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('role', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('database', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('database', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('tablespace', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('tablespace', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('foreign-data wrapper', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('foreign-data wrapper', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('server', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('server', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('extension', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('extension', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('event trigger', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('event trigger', '{one,two}', '{}');
|
2016-03-23 22:01:35 -04:00
|
|
|
SELECT pg_get_object_address('access method', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('access method', '{one,two}', '{}');
|
2017-01-26 13:10:22 -05:00
|
|
|
SELECT pg_get_object_address('publication', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('publication', '{one,two}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('subscription', '{one}', '{}');
|
|
|
|
|
SELECT pg_get_object_address('subscription', '{one,two}', '{}');
|
2014-12-23 13:31:29 -05:00
|
|
|
|
|
|
|
|
-- test successful cases
|
|
|
|
|
WITH objects (type, name, args) AS (VALUES
|
|
|
|
|
('table', '{addr_nsp, gentable}'::text[], '{}'::text[]),
|
2018-06-26 11:28:41 -04:00
|
|
|
('table', '{addr_nsp, parttable}'::text[], '{}'::text[]),
|
2014-12-23 13:31:29 -05:00
|
|
|
('index', '{addr_nsp, gentable_pkey}', '{}'),
|
2018-06-26 11:28:41 -04:00
|
|
|
('index', '{addr_nsp, parttable_pkey}', '{}'),
|
2014-12-23 13:31:29 -05:00
|
|
|
('sequence', '{addr_nsp, gentable_a_seq}', '{}'),
|
|
|
|
|
-- toast table
|
|
|
|
|
('view', '{addr_nsp, genview}', '{}'),
|
|
|
|
|
('materialized view', '{addr_nsp, genmatview}', '{}'),
|
|
|
|
|
('foreign table', '{addr_nsp, genftable}', '{}'),
|
|
|
|
|
('table column', '{addr_nsp, gentable, b}', '{}'),
|
|
|
|
|
('foreign table column', '{addr_nsp, genftable, a}', '{}'),
|
|
|
|
|
('aggregate', '{addr_nsp, genaggr}', '{int4}'),
|
|
|
|
|
('function', '{pg_catalog, pg_identify_object}', '{pg_catalog.oid, pg_catalog.oid, int4}'),
|
2017-11-30 08:46:13 -05:00
|
|
|
('procedure', '{addr_nsp, proc}', '{int4}'),
|
2014-12-23 13:31:29 -05:00
|
|
|
('type', '{pg_catalog._int4}', '{}'),
|
|
|
|
|
('type', '{addr_nsp.gendomain}', '{}'),
|
|
|
|
|
('type', '{addr_nsp.gencomptype}', '{}'),
|
|
|
|
|
('type', '{addr_nsp.genenum}', '{}'),
|
|
|
|
|
('cast', '{int8}', '{int4}'),
|
|
|
|
|
('collation', '{default}', '{}'),
|
|
|
|
|
('table constraint', '{addr_nsp, gentable, a_chk}', '{}'),
|
2014-12-30 11:57:23 -05:00
|
|
|
('domain constraint', '{addr_nsp.gendomain}', '{domconstr}'),
|
2019-07-05 14:17:27 -04:00
|
|
|
('conversion', '{pg_catalog, koi8_r_to_mic}', '{}'),
|
2014-12-23 13:31:29 -05:00
|
|
|
('default value', '{addr_nsp, gentable, b}', '{}'),
|
|
|
|
|
('language', '{plpgsql}', '{}'),
|
|
|
|
|
-- large object
|
|
|
|
|
('operator', '{+}', '{int4, int4}'),
|
2015-03-16 11:06:34 -04:00
|
|
|
('operator class', '{btree, int4_ops}', '{}'),
|
|
|
|
|
('operator family', '{btree, integer_ops}', '{}'),
|
|
|
|
|
('operator of access method', '{btree,integer_ops,1}', '{integer,integer}'),
|
|
|
|
|
('function of access method', '{btree,integer_ops,2}', '{integer,integer}'),
|
2014-12-23 13:31:29 -05:00
|
|
|
('rule', '{addr_nsp, genview, _RETURN}', '{}'),
|
|
|
|
|
('trigger', '{addr_nsp, gentable, t}', '{}'),
|
|
|
|
|
('schema', '{addr_nsp}', '{}'),
|
|
|
|
|
('text search parser', '{addr_ts_prs}', '{}'),
|
|
|
|
|
('text search dictionary', '{addr_ts_dict}', '{}'),
|
|
|
|
|
('text search template', '{addr_ts_temp}', '{}'),
|
|
|
|
|
('text search configuration', '{addr_ts_conf}', '{}'),
|
2016-07-17 18:42:31 -04:00
|
|
|
('role', '{regress_addr_user}', '{}'),
|
2014-12-23 13:31:29 -05:00
|
|
|
-- database
|
|
|
|
|
-- tablespace
|
|
|
|
|
('foreign-data wrapper', '{addr_fdw}', '{}'),
|
|
|
|
|
('server', '{addr_fserv}', '{}'),
|
2016-07-17 18:42:31 -04:00
|
|
|
('user mapping', '{regress_addr_user}', '{integer}'),
|
|
|
|
|
('default acl', '{regress_addr_user,public}', '{r}'),
|
|
|
|
|
('default acl', '{regress_addr_user}', '{r}'),
|
2014-12-23 13:31:29 -05:00
|
|
|
-- extension
|
2014-12-26 12:18:09 -05:00
|
|
|
-- event trigger
|
2015-06-21 15:08:49 -04:00
|
|
|
('policy', '{addr_nsp, gentable, genpol}', '{}'),
|
2016-03-23 22:01:35 -04:00
|
|
|
('transform', '{int}', '{sql}'),
|
2017-01-26 13:10:22 -05:00
|
|
|
('access method', '{btree}', '{}'),
|
|
|
|
|
('publication', '{addr_pub}', '{}'),
|
|
|
|
|
('publication relation', '{addr_nsp, gentable}', '{addr_pub}'),
|
Fix regression tests to use only global names beginning with "regress_".
In commit 18555b132 we tentatively established a rule that regression
tests should use names containing "regression" for databases, and names
starting with "regress_" for all other globally-visible object names, so
as to circumscribe the side-effects that "make installcheck" could have on
an existing installation. However, no enforcement mechanism was created,
so it's unsurprising that some new violations have crept in since then.
In fact, a whole new *category* of violations has crept in, to wit we now
also have globally-visible subscription and replication origin names, and
"make installcheck" could very easily clobber user-created objects of
those types. So it's past time to do something about this.
This commit sanitizes the tests enough that they will pass (i.e. not
generate any visible warnings) with the enforcement mechanism I'll add
in the next commit. There are some TAP tests that still trigger the
warnings, but the warnings do not cause test failure. Since these tests
do not actually run against a pre-existing installation, there's no need
to worry whether they could conflict with user-created objects.
The problem with rolenames.sql testing special role names like "user"
is still there, and is dealt with only very cosmetically in this patch
(by hiding the warnings :-(). What we actually need to do to be safe is
to take that test script out of "make installcheck" altogether, but that
seems like material for a separate patch.
Discussion: https://postgr.es/m/16638.1468620817@sss.pgh.pa.us
2019-06-29 11:09:03 -04:00
|
|
|
('subscription', '{regress_addr_sub}', '{}'),
|
2017-05-14 10:54:47 -04:00
|
|
|
('statistics object', '{addr_nsp, gentable_stat}', '{}')
|
2014-12-23 13:31:29 -05:00
|
|
|
)
|
2017-03-01 12:22:33 -05:00
|
|
|
SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*,
|
2014-12-30 13:41:50 -05:00
|
|
|
-- test roundtrip through pg_identify_object_as_address
|
2017-03-01 12:22:33 -05:00
|
|
|
ROW(pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)) =
|
|
|
|
|
ROW(pg_identify_object(addr2.classid, addr2.objid, addr2.objsubid))
|
2014-12-30 13:41:50 -05:00
|
|
|
FROM objects, pg_get_object_address(type, name, args) addr1,
|
2017-03-01 12:22:33 -05:00
|
|
|
pg_identify_object_as_address(classid, objid, objsubid) ioa(typ,nms,args),
|
2014-12-30 13:41:50 -05:00
|
|
|
pg_get_object_address(typ, nms, ioa.args) as addr2
|
2017-03-01 12:22:33 -05:00
|
|
|
ORDER BY addr1.classid, addr1.objid, addr1.objsubid;
|
2014-12-23 13:31:29 -05:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
--- Cleanup resources
|
|
|
|
|
---
|
|
|
|
|
DROP FOREIGN DATA WRAPPER addr_fdw CASCADE;
|
2017-01-26 13:10:22 -05:00
|
|
|
DROP PUBLICATION addr_pub;
|
Fix regression tests to use only global names beginning with "regress_".
In commit 18555b132 we tentatively established a rule that regression
tests should use names containing "regression" for databases, and names
starting with "regress_" for all other globally-visible object names, so
as to circumscribe the side-effects that "make installcheck" could have on
an existing installation. However, no enforcement mechanism was created,
so it's unsurprising that some new violations have crept in since then.
In fact, a whole new *category* of violations has crept in, to wit we now
also have globally-visible subscription and replication origin names, and
"make installcheck" could very easily clobber user-created objects of
those types. So it's past time to do something about this.
This commit sanitizes the tests enough that they will pass (i.e. not
generate any visible warnings) with the enforcement mechanism I'll add
in the next commit. There are some TAP tests that still trigger the
warnings, but the warnings do not cause test failure. Since these tests
do not actually run against a pre-existing installation, there's no need
to worry whether they could conflict with user-created objects.
The problem with rolenames.sql testing special role names like "user"
is still there, and is dealt with only very cosmetically in this patch
(by hiding the warnings :-(). What we actually need to do to be safe is
to take that test script out of "make installcheck" altogether, but that
seems like material for a separate patch.
Discussion: https://postgr.es/m/16638.1468620817@sss.pgh.pa.us
2019-06-29 11:09:03 -04:00
|
|
|
DROP SUBSCRIPTION regress_addr_sub;
|
2014-12-23 13:31:29 -05:00
|
|
|
|
|
|
|
|
DROP SCHEMA addr_nsp CASCADE;
|
|
|
|
|
|
2016-07-17 18:42:31 -04:00
|
|
|
DROP OWNED BY regress_addr_user;
|
|
|
|
|
DROP USER regress_addr_user;
|