2012-09-27 22:21:11 +02:00
|
|
|
--
|
|
|
|
-- Test for ALTER some_object {RENAME TO, OWNER TO, SET SCHEMA}
|
|
|
|
--
|
|
|
|
-- Clean up in case a prior regression run failed
|
|
|
|
SET client_min_messages TO 'warning';
|
2018-03-15 19:00:31 +01:00
|
|
|
DROP ROLE IF EXISTS regress_alter_generic_user1;
|
|
|
|
DROP ROLE IF EXISTS regress_alter_generic_user2;
|
|
|
|
DROP ROLE IF EXISTS regress_alter_generic_user3;
|
2012-09-27 22:21:11 +02:00
|
|
|
RESET client_min_messages;
|
2018-03-15 19:00:31 +01:00
|
|
|
CREATE USER regress_alter_generic_user3;
|
|
|
|
CREATE USER regress_alter_generic_user2;
|
|
|
|
CREATE USER regress_alter_generic_user1 IN ROLE regress_alter_generic_user3;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE SCHEMA alt_nsp1;
|
|
|
|
CREATE SCHEMA alt_nsp2;
|
|
|
|
GRANT ALL ON SCHEMA alt_nsp1, alt_nsp2 TO public;
|
|
|
|
SET search_path = alt_nsp1, public;
|
|
|
|
--
|
|
|
|
-- Function and Aggregate
|
|
|
|
--
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE FUNCTION alt_func1(int) RETURNS int LANGUAGE sql
|
|
|
|
AS 'SELECT $1 + 1';
|
|
|
|
CREATE FUNCTION alt_func2(int) RETURNS int LANGUAGE sql
|
|
|
|
AS 'SELECT $1 - 1';
|
|
|
|
CREATE AGGREGATE alt_agg1 (
|
|
|
|
sfunc1 = int4pl, basetype = int4, stype1 = int4, initcond = 0
|
|
|
|
);
|
|
|
|
CREATE AGGREGATE alt_agg2 (
|
|
|
|
sfunc1 = int4mi, basetype = int4, stype1 = int4, initcond = 0
|
|
|
|
);
|
|
|
|
ALTER AGGREGATE alt_func1(int) RENAME TO alt_func3; -- failed (not aggregate)
|
|
|
|
ERROR: function alt_func1(integer) is not an aggregate
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER AGGREGATE alt_func1(int) OWNER TO regress_alter_generic_user3; -- failed (not aggregate)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: function alt_func1(integer) is not an aggregate
|
|
|
|
ALTER AGGREGATE alt_func1(int) SET SCHEMA alt_nsp2; -- failed (not aggregate)
|
|
|
|
ERROR: function alt_func1(integer) is not an aggregate
|
|
|
|
ALTER FUNCTION alt_func1(int) RENAME TO alt_func2; -- failed (name conflict)
|
|
|
|
ERROR: function alt_func2(integer) already exists in schema "alt_nsp1"
|
|
|
|
ALTER FUNCTION alt_func1(int) RENAME TO alt_func3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER FUNCTION alt_func2(int) OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER FUNCTION alt_func2(int) OWNER TO regress_alter_generic_user3; -- OK
|
2015-11-19 16:49:25 +01:00
|
|
|
ALTER FUNCTION alt_func2(int) SET SCHEMA alt_nsp1; -- OK, already there
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER FUNCTION alt_func2(int) SET SCHEMA alt_nsp2; -- OK
|
|
|
|
ALTER AGGREGATE alt_agg1(int) RENAME TO alt_agg2; -- failed (name conflict)
|
|
|
|
ERROR: function alt_agg2(integer) already exists in schema "alt_nsp1"
|
|
|
|
ALTER AGGREGATE alt_agg1(int) RENAME TO alt_agg3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER AGGREGATE alt_agg2(int) OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER AGGREGATE alt_agg2(int) OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER AGGREGATE alt_agg2(int) SET SCHEMA alt_nsp2; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user2;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE FUNCTION alt_func1(int) RETURNS int LANGUAGE sql
|
|
|
|
AS 'SELECT $1 + 2';
|
|
|
|
CREATE FUNCTION alt_func2(int) RETURNS int LANGUAGE sql
|
|
|
|
AS 'SELECT $1 - 2';
|
|
|
|
CREATE AGGREGATE alt_agg1 (
|
|
|
|
sfunc1 = int4pl, basetype = int4, stype1 = int4, initcond = 100
|
|
|
|
);
|
|
|
|
CREATE AGGREGATE alt_agg2 (
|
|
|
|
sfunc1 = int4mi, basetype = int4, stype1 = int4, initcond = -100
|
|
|
|
);
|
|
|
|
ALTER FUNCTION alt_func3(int) RENAME TO alt_func4; -- failed (not owner)
|
|
|
|
ERROR: must be owner of function alt_func3
|
|
|
|
ALTER FUNCTION alt_func1(int) RENAME TO alt_func4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER FUNCTION alt_func3(int) OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of function alt_func3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER FUNCTION alt_func2(int) OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER FUNCTION alt_func3(int) SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of function alt_func3
|
|
|
|
ALTER FUNCTION alt_func2(int) SET SCHEMA alt_nsp2; -- failed (name conflicts)
|
Rework order of checks in ALTER / SET SCHEMA
When attempting to move an object into the schema in which it already
was, for most objects classes we were correctly complaining about
exactly that ("object is already in schema"); but for some other object
classes, such as functions, we were instead complaining of a name
collision ("object already exists in schema"). The latter is wrong and
misleading, per complaint from Robert Haas in
CA+TgmoZ0+gNf7RDKRc3u5rHXffP=QjqPZKGxb4BsPz65k7qnHQ@mail.gmail.com
To fix, refactor the way these checks are done. As a bonus, the
resulting code is smaller and can also share some code with Rename
cases.
While at it, remove use of getObjectDescriptionOids() in error messages.
These are normally disallowed because of translatability considerations,
but this one had slipped through since 9.1. (Not sure that this is
worth backpatching, though, as it would create some untranslated
messages in back branches.)
This is loosely based on a patch by KaiGai Kohei, heavily reworked by
me.
2013-01-15 17:23:43 +01:00
|
|
|
ERROR: function alt_func2(integer) already exists in schema "alt_nsp2"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER AGGREGATE alt_agg3(int) RENAME TO alt_agg4; -- failed (not owner)
|
|
|
|
ERROR: must be owner of function alt_agg3
|
|
|
|
ALTER AGGREGATE alt_agg1(int) RENAME TO alt_agg4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER AGGREGATE alt_agg3(int) OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of function alt_agg3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER AGGREGATE alt_agg2(int) OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER AGGREGATE alt_agg3(int) SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of function alt_agg3
|
|
|
|
ALTER AGGREGATE alt_agg2(int) SET SCHEMA alt_nsp2; -- failed (name conflict)
|
Rework order of checks in ALTER / SET SCHEMA
When attempting to move an object into the schema in which it already
was, for most objects classes we were correctly complaining about
exactly that ("object is already in schema"); but for some other object
classes, such as functions, we were instead complaining of a name
collision ("object already exists in schema"). The latter is wrong and
misleading, per complaint from Robert Haas in
CA+TgmoZ0+gNf7RDKRc3u5rHXffP=QjqPZKGxb4BsPz65k7qnHQ@mail.gmail.com
To fix, refactor the way these checks are done. As a bonus, the
resulting code is smaller and can also share some code with Rename
cases.
While at it, remove use of getObjectDescriptionOids() in error messages.
These are normally disallowed because of translatability considerations,
but this one had slipped through since 9.1. (Not sure that this is
worth backpatching, though, as it would create some untranslated
messages in back branches.)
This is loosely based on a patch by KaiGai Kohei, heavily reworked by
me.
2013-01-15 17:23:43 +01:00
|
|
|
ERROR: function alt_agg2(integer) already exists in schema "alt_nsp2"
|
2012-09-27 22:21:11 +02:00
|
|
|
RESET SESSION AUTHORIZATION;
|
2018-03-02 14:57:38 +01:00
|
|
|
SELECT n.nspname, proname, prorettype::regtype, prokind, a.rolname
|
2012-09-27 22:21:11 +02:00
|
|
|
FROM pg_proc p, pg_namespace n, pg_authid a
|
|
|
|
WHERE p.pronamespace = n.oid AND p.proowner = a.oid
|
|
|
|
AND n.nspname IN ('alt_nsp1', 'alt_nsp2')
|
|
|
|
ORDER BY nspname, proname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | proname | prorettype | prokind | rolname
|
|
|
|
----------+-----------+------------+---------+-----------------------------
|
|
|
|
alt_nsp1 | alt_agg2 | integer | a | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_agg3 | integer | a | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_agg4 | integer | a | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_func2 | integer | f | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_func3 | integer | f | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_func4 | integer | f | regress_alter_generic_user2
|
|
|
|
alt_nsp2 | alt_agg2 | integer | a | regress_alter_generic_user3
|
|
|
|
alt_nsp2 | alt_func2 | integer | f | regress_alter_generic_user3
|
2012-09-27 22:21:11 +02:00
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
--
|
2012-10-01 15:42:03 +02:00
|
|
|
-- We would test collations here, but it's not possible because the error
|
|
|
|
-- messages tend to be nonportable.
|
2012-09-27 22:21:11 +02:00
|
|
|
--
|
|
|
|
--
|
|
|
|
-- Conversion
|
|
|
|
--
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE CONVERSION alt_conv1 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
|
|
|
|
CREATE CONVERSION alt_conv2 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
|
|
|
|
ALTER CONVERSION alt_conv1 RENAME TO alt_conv2; -- failed (name conflict)
|
|
|
|
ERROR: conversion "alt_conv2" already exists in schema "alt_nsp1"
|
|
|
|
ALTER CONVERSION alt_conv1 RENAME TO alt_conv3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER CONVERSION alt_conv2 OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER CONVERSION alt_conv2 OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER CONVERSION alt_conv2 SET SCHEMA alt_nsp2; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user2;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE CONVERSION alt_conv1 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
|
|
|
|
CREATE CONVERSION alt_conv2 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
|
|
|
|
ALTER CONVERSION alt_conv3 RENAME TO alt_conv4; -- failed (not owner)
|
|
|
|
ERROR: must be owner of conversion alt_conv3
|
|
|
|
ALTER CONVERSION alt_conv1 RENAME TO alt_conv4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER CONVERSION alt_conv3 OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of conversion alt_conv3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER CONVERSION alt_conv2 OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER CONVERSION alt_conv3 SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of conversion alt_conv3
|
|
|
|
ALTER CONVERSION alt_conv2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
Rework order of checks in ALTER / SET SCHEMA
When attempting to move an object into the schema in which it already
was, for most objects classes we were correctly complaining about
exactly that ("object is already in schema"); but for some other object
classes, such as functions, we were instead complaining of a name
collision ("object already exists in schema"). The latter is wrong and
misleading, per complaint from Robert Haas in
CA+TgmoZ0+gNf7RDKRc3u5rHXffP=QjqPZKGxb4BsPz65k7qnHQ@mail.gmail.com
To fix, refactor the way these checks are done. As a bonus, the
resulting code is smaller and can also share some code with Rename
cases.
While at it, remove use of getObjectDescriptionOids() in error messages.
These are normally disallowed because of translatability considerations,
but this one had slipped through since 9.1. (Not sure that this is
worth backpatching, though, as it would create some untranslated
messages in back branches.)
This is loosely based on a patch by KaiGai Kohei, heavily reworked by
me.
2013-01-15 17:23:43 +01:00
|
|
|
ERROR: conversion "alt_conv2" already exists in schema "alt_nsp2"
|
2012-09-27 22:21:11 +02:00
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
SELECT n.nspname, c.conname, a.rolname
|
|
|
|
FROM pg_conversion c, pg_namespace n, pg_authid a
|
|
|
|
WHERE c.connamespace = n.oid AND c.conowner = a.oid
|
|
|
|
AND n.nspname IN ('alt_nsp1', 'alt_nsp2')
|
|
|
|
ORDER BY nspname, conname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | conname | rolname
|
|
|
|
----------+-----------+-----------------------------
|
|
|
|
alt_nsp1 | alt_conv2 | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_conv3 | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_conv4 | regress_alter_generic_user2
|
|
|
|
alt_nsp2 | alt_conv2 | regress_alter_generic_user3
|
2012-09-27 22:21:11 +02:00
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Foreign Data Wrapper and Foreign Server
|
|
|
|
--
|
|
|
|
CREATE FOREIGN DATA WRAPPER alt_fdw1;
|
|
|
|
CREATE FOREIGN DATA WRAPPER alt_fdw2;
|
|
|
|
CREATE SERVER alt_fserv1 FOREIGN DATA WRAPPER alt_fdw1;
|
|
|
|
CREATE SERVER alt_fserv2 FOREIGN DATA WRAPPER alt_fdw2;
|
|
|
|
ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw2; -- failed (name conflict)
|
|
|
|
ERROR: foreign-data wrapper "alt_fdw2" already exists
|
|
|
|
ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw3; -- OK
|
|
|
|
ALTER SERVER alt_fserv1 RENAME TO alt_fserv2; -- failed (name conflict)
|
|
|
|
ERROR: server "alt_fserv2" already exists
|
|
|
|
ALTER SERVER alt_fserv1 RENAME TO alt_fserv3; -- OK
|
|
|
|
SELECT fdwname FROM pg_foreign_data_wrapper WHERE fdwname like 'alt_fdw%';
|
|
|
|
fdwname
|
|
|
|
----------
|
|
|
|
alt_fdw2
|
|
|
|
alt_fdw3
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
SELECT srvname FROM pg_foreign_server WHERE srvname like 'alt_fserv%';
|
|
|
|
srvname
|
|
|
|
------------
|
|
|
|
alt_fserv2
|
|
|
|
alt_fserv3
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Procedural Language
|
|
|
|
--
|
|
|
|
CREATE LANGUAGE alt_lang1 HANDLER plpgsql_call_handler;
|
|
|
|
CREATE LANGUAGE alt_lang2 HANDLER plpgsql_call_handler;
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER LANGUAGE alt_lang1 OWNER TO regress_alter_generic_user1; -- OK
|
|
|
|
ALTER LANGUAGE alt_lang2 OWNER TO regress_alter_generic_user2; -- OK
|
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER LANGUAGE alt_lang1 RENAME TO alt_lang2; -- failed (name conflict)
|
|
|
|
ERROR: language "alt_lang2" already exists
|
|
|
|
ALTER LANGUAGE alt_lang2 RENAME TO alt_lang3; -- failed (not owner)
|
|
|
|
ERROR: must be owner of language alt_lang2
|
|
|
|
ALTER LANGUAGE alt_lang1 RENAME TO alt_lang3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER LANGUAGE alt_lang2 OWNER TO regress_alter_generic_user3; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of language alt_lang2
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER LANGUAGE alt_lang3 OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER LANGUAGE alt_lang3 OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
SELECT lanname, a.rolname
|
|
|
|
FROM pg_language l, pg_authid a
|
|
|
|
WHERE l.lanowner = a.oid AND l.lanname like 'alt_lang%'
|
|
|
|
ORDER BY lanname;
|
2018-03-15 19:00:31 +01:00
|
|
|
lanname | rolname
|
|
|
|
-----------+-----------------------------
|
|
|
|
alt_lang2 | regress_alter_generic_user2
|
|
|
|
alt_lang3 | regress_alter_generic_user3
|
2012-09-27 22:21:11 +02:00
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Operator
|
|
|
|
--
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE OPERATOR @-@ ( leftarg = int4, rightarg = int4, procedure = int4mi );
|
|
|
|
CREATE OPERATOR @+@ ( leftarg = int4, rightarg = int4, procedure = int4pl );
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR @+@(int4, int4) OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER OPERATOR @+@(int4, int4) OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR @-@(int4, int4) SET SCHEMA alt_nsp2; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user2;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE OPERATOR @-@ ( leftarg = int4, rightarg = int4, procedure = int4mi );
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR @+@(int4, int4) OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of operator @+@
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR @-@(int4, int4) OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR @+@(int4, int4) SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of operator @+@
|
|
|
|
-- can't test this: the error message includes the raw oid of namespace
|
|
|
|
-- ALTER OPERATOR @-@(int4, int4) SET SCHEMA alt_nsp2; -- failed (name conflict)
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
SELECT n.nspname, oprname, a.rolname,
|
|
|
|
oprleft::regtype, oprright::regtype, oprcode::regproc
|
|
|
|
FROM pg_operator o, pg_namespace n, pg_authid a
|
|
|
|
WHERE o.oprnamespace = n.oid AND o.oprowner = a.oid
|
|
|
|
AND n.nspname IN ('alt_nsp1', 'alt_nsp2')
|
|
|
|
ORDER BY nspname, oprname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | oprname | rolname | oprleft | oprright | oprcode
|
|
|
|
----------+---------+-----------------------------+---------+----------+---------
|
|
|
|
alt_nsp1 | @+@ | regress_alter_generic_user3 | integer | integer | int4pl
|
|
|
|
alt_nsp1 | @-@ | regress_alter_generic_user2 | integer | integer | int4mi
|
|
|
|
alt_nsp2 | @-@ | regress_alter_generic_user1 | integer | integer | int4mi
|
2012-09-27 22:21:11 +02:00
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- OpFamily and OpClass
|
|
|
|
--
|
|
|
|
CREATE OPERATOR FAMILY alt_opf1 USING hash;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf2 USING hash;
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR FAMILY alt_opf1 USING hash OWNER TO regress_alter_generic_user1;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf2 USING hash OWNER TO regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE OPERATOR CLASS alt_opc1 FOR TYPE uuid USING hash AS STORAGE uuid;
|
|
|
|
CREATE OPERATOR CLASS alt_opc2 FOR TYPE uuid USING hash AS STORAGE uuid;
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR CLASS alt_opc1 USING hash OWNER TO regress_alter_generic_user1;
|
|
|
|
ALTER OPERATOR CLASS alt_opc2 USING hash OWNER TO regress_alter_generic_user1;
|
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf1 USING hash RENAME TO alt_opf2; -- failed (name conflict)
|
|
|
|
ERROR: operator family "alt_opf2" for access method "hash" already exists in schema "alt_nsp1"
|
|
|
|
ALTER OPERATOR FAMILY alt_opf1 USING hash RENAME TO alt_opf3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR FAMILY alt_opf2 USING hash OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER OPERATOR FAMILY alt_opf2 USING hash OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf2 USING hash SET SCHEMA alt_nsp2; -- OK
|
|
|
|
ALTER OPERATOR CLASS alt_opc1 USING hash RENAME TO alt_opc2; -- failed (name conflict)
|
|
|
|
ERROR: operator class "alt_opc2" for access method "hash" already exists in schema "alt_nsp1"
|
|
|
|
ALTER OPERATOR CLASS alt_opc1 USING hash RENAME TO alt_opc3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR CLASS alt_opc2 USING hash OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER OPERATOR CLASS alt_opc2 USING hash OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR CLASS alt_opc2 USING hash SET SCHEMA alt_nsp2; -- OK
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf1 USING hash;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf2 USING hash;
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR FAMILY alt_opf1 USING hash OWNER TO regress_alter_generic_user2;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf2 USING hash OWNER TO regress_alter_generic_user2;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE OPERATOR CLASS alt_opc1 FOR TYPE macaddr USING hash AS STORAGE macaddr;
|
|
|
|
CREATE OPERATOR CLASS alt_opc2 FOR TYPE macaddr USING hash AS STORAGE macaddr;
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR CLASS alt_opc1 USING hash OWNER TO regress_alter_generic_user2;
|
|
|
|
ALTER OPERATOR CLASS alt_opc2 USING hash OWNER TO regress_alter_generic_user2;
|
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user2;
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf3 USING hash RENAME TO alt_opf4; -- failed (not owner)
|
|
|
|
ERROR: must be owner of operator family alt_opf3
|
|
|
|
ALTER OPERATOR FAMILY alt_opf1 USING hash RENAME TO alt_opf4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR FAMILY alt_opf3 USING hash OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of operator family alt_opf3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR FAMILY alt_opf2 USING hash OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf3 USING hash SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of operator family alt_opf3
|
2013-01-21 16:06:41 +01:00
|
|
|
ALTER OPERATOR FAMILY alt_opf2 USING hash SET SCHEMA alt_nsp2; -- failed (name conflict)
|
|
|
|
ERROR: operator family "alt_opf2" for access method "hash" already exists in schema "alt_nsp2"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR CLASS alt_opc3 USING hash RENAME TO alt_opc4; -- failed (not owner)
|
|
|
|
ERROR: must be owner of operator class alt_opc3
|
|
|
|
ALTER OPERATOR CLASS alt_opc1 USING hash RENAME TO alt_opc4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR CLASS alt_opc3 USING hash OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of operator class alt_opc3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER OPERATOR CLASS alt_opc2 USING hash OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER OPERATOR CLASS alt_opc3 USING hash SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of operator class alt_opc3
|
2013-01-21 16:06:41 +01:00
|
|
|
ALTER OPERATOR CLASS alt_opc2 USING hash SET SCHEMA alt_nsp2; -- failed (name conflict)
|
|
|
|
ERROR: operator class "alt_opc2" for access method "hash" already exists in schema "alt_nsp2"
|
2012-09-27 22:21:11 +02:00
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
SELECT nspname, opfname, amname, rolname
|
|
|
|
FROM pg_opfamily o, pg_am m, pg_namespace n, pg_authid a
|
|
|
|
WHERE o.opfmethod = m.oid AND o.opfnamespace = n.oid AND o.opfowner = a.oid
|
|
|
|
AND n.nspname IN ('alt_nsp1', 'alt_nsp2')
|
|
|
|
AND NOT opfname LIKE 'alt_opc%'
|
|
|
|
ORDER BY nspname, opfname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | opfname | amname | rolname
|
|
|
|
----------+----------+--------+-----------------------------
|
|
|
|
alt_nsp1 | alt_opf2 | hash | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_opf3 | hash | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_opf4 | hash | regress_alter_generic_user2
|
|
|
|
alt_nsp2 | alt_opf2 | hash | regress_alter_generic_user3
|
2012-09-27 22:21:11 +02:00
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
SELECT nspname, opcname, amname, rolname
|
|
|
|
FROM pg_opclass o, pg_am m, pg_namespace n, pg_authid a
|
|
|
|
WHERE o.opcmethod = m.oid AND o.opcnamespace = n.oid AND o.opcowner = a.oid
|
|
|
|
AND n.nspname IN ('alt_nsp1', 'alt_nsp2')
|
|
|
|
ORDER BY nspname, opcname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | opcname | amname | rolname
|
|
|
|
----------+----------+--------+-----------------------------
|
|
|
|
alt_nsp1 | alt_opc2 | hash | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_opc3 | hash | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_opc4 | hash | regress_alter_generic_user2
|
|
|
|
alt_nsp2 | alt_opc2 | hash | regress_alter_generic_user3
|
2012-09-27 22:21:11 +02:00
|
|
|
(4 rows)
|
|
|
|
|
2013-07-23 14:53:21 +02:00
|
|
|
-- ALTER OPERATOR FAMILY ... ADD/DROP
|
|
|
|
-- Should work. Textbook case of CREATE / ALTER ADD / ALTER DROP / DROP
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf4 USING btree;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree ADD
|
|
|
|
-- int4 vs int2
|
|
|
|
OPERATOR 1 < (int4, int2) ,
|
|
|
|
OPERATOR 2 <= (int4, int2) ,
|
|
|
|
OPERATOR 3 = (int4, int2) ,
|
|
|
|
OPERATOR 4 >= (int4, int2) ,
|
|
|
|
OPERATOR 5 > (int4, int2) ,
|
|
|
|
FUNCTION 1 btint42cmp(int4, int2);
|
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree DROP
|
|
|
|
-- int4 vs int2
|
|
|
|
OPERATOR 1 (int4, int2) ,
|
|
|
|
OPERATOR 2 (int4, int2) ,
|
|
|
|
OPERATOR 3 (int4, int2) ,
|
|
|
|
OPERATOR 4 (int4, int2) ,
|
|
|
|
OPERATOR 5 (int4, int2) ,
|
|
|
|
FUNCTION 1 (int4, int2) ;
|
|
|
|
DROP OPERATOR FAMILY alt_opf4 USING btree;
|
|
|
|
ROLLBACK;
|
|
|
|
-- Should fail. Invalid values for ALTER OPERATOR FAMILY .. ADD / DROP
|
|
|
|
CREATE OPERATOR FAMILY alt_opf4 USING btree;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING invalid_index_method ADD OPERATOR 1 < (int4, int2); -- invalid indexing_method
|
|
|
|
ERROR: access method "invalid_index_method" does not exist
|
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree ADD OPERATOR 6 < (int4, int2); -- operator number should be between 1 and 5
|
|
|
|
ERROR: invalid operator number 6, must be between 1 and 5
|
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree ADD OPERATOR 0 < (int4, int2); -- operator number should be between 1 and 5
|
|
|
|
ERROR: invalid operator number 0, must be between 1 and 5
|
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree ADD OPERATOR 1 < ; -- operator without argument types
|
|
|
|
ERROR: operator argument types must be specified in ALTER OPERATOR FAMILY
|
Implement operator class parameters
PostgreSQL provides set of template index access methods, where opclasses have
much freedom in the semantics of indexing. These index AMs are GiST, GIN,
SP-GiST and BRIN. There opclasses define representation of keys, operations on
them and supported search strategies. So, it's natural that opclasses may be
faced some tradeoffs, which require user-side decision. This commit implements
opclass parameters allowing users to set some values, which tell opclass how to
index the particular dataset.
This commit doesn't introduce new storage in system catalog. Instead it uses
pg_attribute.attoptions, which is used for table column storage options but
unused for index attributes.
In order to evade changing signature of each opclass support function, we
implement unified way to pass options to opclass support functions. Options
are set to fn_expr as the constant bytea expression. It's possible due to the
fact that opclass support functions are executed outside of expressions, so
fn_expr is unused for them.
This commit comes with some examples of opclass options usage. We parametrize
signature length in GiST. That applies to multiple opclasses: tsvector_ops,
gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and
gist_hstore_ops. Also we parametrize maximum number of integer ranges for
gist__int_ops. However, the main future usage of this feature is expected
to be json, where users would be able to specify which way to index particular
json parts.
Catversion is bumped.
Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru
Author: Nikita Glukhov, revised by me
Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
2020-03-30 18:17:11 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree ADD FUNCTION 0 btint42cmp(int4, int2); -- invalid options parsing function
|
|
|
|
ERROR: invalid function number 0, must be between 1 and 5
|
2013-07-23 14:53:21 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree ADD FUNCTION 6 btint42cmp(int4, int2); -- function number should be between 1 and 5
|
Implement operator class parameters
PostgreSQL provides set of template index access methods, where opclasses have
much freedom in the semantics of indexing. These index AMs are GiST, GIN,
SP-GiST and BRIN. There opclasses define representation of keys, operations on
them and supported search strategies. So, it's natural that opclasses may be
faced some tradeoffs, which require user-side decision. This commit implements
opclass parameters allowing users to set some values, which tell opclass how to
index the particular dataset.
This commit doesn't introduce new storage in system catalog. Instead it uses
pg_attribute.attoptions, which is used for table column storage options but
unused for index attributes.
In order to evade changing signature of each opclass support function, we
implement unified way to pass options to opclass support functions. Options
are set to fn_expr as the constant bytea expression. It's possible due to the
fact that opclass support functions are executed outside of expressions, so
fn_expr is unused for them.
This commit comes with some examples of opclass options usage. We parametrize
signature length in GiST. That applies to multiple opclasses: tsvector_ops,
gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and
gist_hstore_ops. Also we parametrize maximum number of integer ranges for
gist__int_ops. However, the main future usage of this feature is expected
to be json, where users would be able to specify which way to index particular
json parts.
Catversion is bumped.
Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru
Author: Nikita Glukhov, revised by me
Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
2020-03-30 18:17:11 +02:00
|
|
|
ERROR: invalid function number 6, must be between 1 and 5
|
2013-07-23 14:53:21 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf4 USING btree ADD STORAGE invalid_storage; -- Ensure STORAGE is not a part of ALTER OPERATOR FAMILY
|
|
|
|
ERROR: STORAGE cannot be specified in ALTER OPERATOR FAMILY
|
|
|
|
DROP OPERATOR FAMILY alt_opf4 USING btree;
|
|
|
|
-- Should fail. Need to be SUPERUSER to do ALTER OPERATOR FAMILY .. ADD / DROP
|
|
|
|
BEGIN TRANSACTION;
|
2018-03-15 19:00:31 +01:00
|
|
|
CREATE ROLE regress_alter_generic_user5 NOSUPERUSER;
|
2013-07-23 14:53:21 +02:00
|
|
|
CREATE OPERATOR FAMILY alt_opf5 USING btree;
|
2018-03-15 19:00:31 +01:00
|
|
|
SET ROLE regress_alter_generic_user5;
|
2013-07-23 14:53:21 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf5 USING btree ADD OPERATOR 1 < (int4, int2), FUNCTION 1 btint42cmp(int4, int2);
|
|
|
|
ERROR: must be superuser to alter an operator family
|
|
|
|
RESET ROLE;
|
|
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
|
|
DROP OPERATOR FAMILY alt_opf5 USING btree;
|
|
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
|
|
ROLLBACK;
|
|
|
|
-- Should fail. Need rights to namespace for ALTER OPERATOR FAMILY .. ADD / DROP
|
|
|
|
BEGIN TRANSACTION;
|
2018-03-15 19:00:31 +01:00
|
|
|
CREATE ROLE regress_alter_generic_user6;
|
2013-07-23 14:53:21 +02:00
|
|
|
CREATE SCHEMA alt_nsp6;
|
2018-03-15 19:00:31 +01:00
|
|
|
REVOKE ALL ON SCHEMA alt_nsp6 FROM regress_alter_generic_user6;
|
2013-07-23 14:53:21 +02:00
|
|
|
CREATE OPERATOR FAMILY alt_nsp6.alt_opf6 USING btree;
|
2018-03-15 19:00:31 +01:00
|
|
|
SET ROLE regress_alter_generic_user6;
|
2013-07-23 14:53:21 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_nsp6.alt_opf6 USING btree ADD OPERATOR 1 < (int4, int2);
|
|
|
|
ERROR: permission denied for schema alt_nsp6
|
|
|
|
ROLLBACK;
|
|
|
|
-- Should fail. Only two arguments required for ALTER OPERATOR FAMILY ... DROP OPERATOR
|
|
|
|
CREATE OPERATOR FAMILY alt_opf7 USING btree;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf7 USING btree ADD OPERATOR 1 < (int4, int2);
|
|
|
|
ALTER OPERATOR FAMILY alt_opf7 USING btree DROP OPERATOR 1 (int4, int2, int8);
|
|
|
|
ERROR: one or two argument types must be specified
|
|
|
|
DROP OPERATOR FAMILY alt_opf7 USING btree;
|
|
|
|
-- Should work. During ALTER OPERATOR FAMILY ... DROP OPERATOR
|
|
|
|
-- when left type is the same as right type, a DROP with only one argument type should work
|
|
|
|
CREATE OPERATOR FAMILY alt_opf8 USING btree;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf8 USING btree ADD OPERATOR 1 < (int4, int4);
|
|
|
|
DROP OPERATOR FAMILY alt_opf8 USING btree;
|
|
|
|
-- Should work. Textbook case of ALTER OPERATOR FAMILY ... ADD OPERATOR with FOR ORDER BY
|
|
|
|
CREATE OPERATOR FAMILY alt_opf9 USING gist;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf9 USING gist ADD OPERATOR 1 < (int4, int4) FOR ORDER BY float_ops;
|
|
|
|
DROP OPERATOR FAMILY alt_opf9 USING gist;
|
|
|
|
-- Should fail. Ensure correct ordering methods in ALTER OPERATOR FAMILY ... ADD OPERATOR .. FOR ORDER BY
|
|
|
|
CREATE OPERATOR FAMILY alt_opf10 USING btree;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf10 USING btree ADD OPERATOR 1 < (int4, int4) FOR ORDER BY float_ops;
|
|
|
|
ERROR: access method "btree" does not support ordering operators
|
|
|
|
DROP OPERATOR FAMILY alt_opf10 USING btree;
|
|
|
|
-- Should work. Textbook case of ALTER OPERATOR FAMILY ... ADD OPERATOR with FOR ORDER BY
|
|
|
|
CREATE OPERATOR FAMILY alt_opf11 USING gist;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf11 USING gist ADD OPERATOR 1 < (int4, int4) FOR ORDER BY float_ops;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf11 USING gist DROP OPERATOR 1 (int4, int4);
|
|
|
|
DROP OPERATOR FAMILY alt_opf11 USING gist;
|
|
|
|
-- Should fail. btree comparison functions should return INTEGER in ALTER OPERATOR FAMILY ... ADD FUNCTION
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf12 USING btree;
|
|
|
|
CREATE FUNCTION fn_opf12 (int4, int2) RETURNS BIGINT AS 'SELECT NULL::BIGINT;' LANGUAGE SQL;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf12 USING btree ADD FUNCTION 1 fn_opf12(int4, int2);
|
2018-08-15 17:01:39 +02:00
|
|
|
ERROR: btree comparison functions must return integer
|
2013-07-23 14:53:21 +02:00
|
|
|
DROP OPERATOR FAMILY alt_opf12 USING btree;
|
|
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
|
|
ROLLBACK;
|
|
|
|
-- Should fail. hash comparison functions should return INTEGER in ALTER OPERATOR FAMILY ... ADD FUNCTION
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf13 USING hash;
|
|
|
|
CREATE FUNCTION fn_opf13 (int4) RETURNS BIGINT AS 'SELECT NULL::BIGINT;' LANGUAGE SQL;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf13 USING hash ADD FUNCTION 1 fn_opf13(int4);
|
2018-08-15 17:01:39 +02:00
|
|
|
ERROR: hash function 1 must return integer
|
2013-07-23 14:53:21 +02:00
|
|
|
DROP OPERATOR FAMILY alt_opf13 USING hash;
|
|
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
|
|
ROLLBACK;
|
|
|
|
-- Should fail. btree comparison functions should have two arguments in ALTER OPERATOR FAMILY ... ADD FUNCTION
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf14 USING btree;
|
|
|
|
CREATE FUNCTION fn_opf14 (int4) RETURNS BIGINT AS 'SELECT NULL::BIGINT;' LANGUAGE SQL;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf14 USING btree ADD FUNCTION 1 fn_opf14(int4);
|
2018-08-15 17:01:39 +02:00
|
|
|
ERROR: btree comparison functions must have two arguments
|
2013-07-23 14:53:21 +02:00
|
|
|
DROP OPERATOR FAMILY alt_opf14 USING btree;
|
|
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
|
|
ROLLBACK;
|
|
|
|
-- Should fail. hash comparison functions should have one argument in ALTER OPERATOR FAMILY ... ADD FUNCTION
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE OPERATOR FAMILY alt_opf15 USING hash;
|
|
|
|
CREATE FUNCTION fn_opf15 (int4, int2) RETURNS BIGINT AS 'SELECT NULL::BIGINT;' LANGUAGE SQL;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf15 USING hash ADD FUNCTION 1 fn_opf15(int4, int2);
|
2018-08-15 17:01:39 +02:00
|
|
|
ERROR: hash function 1 must have one argument
|
2013-07-23 14:53:21 +02:00
|
|
|
DROP OPERATOR FAMILY alt_opf15 USING hash;
|
|
|
|
ERROR: current transaction is aborted, commands ignored until end of transaction block
|
|
|
|
ROLLBACK;
|
2013-11-10 15:20:52 +01:00
|
|
|
-- Should fail. In gist throw an error when giving different data types for function argument
|
2013-07-23 14:53:21 +02:00
|
|
|
-- without defining left / right type in ALTER OPERATOR FAMILY ... ADD FUNCTION
|
|
|
|
CREATE OPERATOR FAMILY alt_opf16 USING gist;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf16 USING gist ADD FUNCTION 1 btint42cmp(int4, int2);
|
2018-08-15 17:01:39 +02:00
|
|
|
ERROR: associated data types must be specified for index support function
|
2013-07-23 14:53:21 +02:00
|
|
|
DROP OPERATOR FAMILY alt_opf16 USING gist;
|
|
|
|
-- Should fail. duplicate operator number / function number in ALTER OPERATOR FAMILY ... ADD FUNCTION
|
|
|
|
CREATE OPERATOR FAMILY alt_opf17 USING btree;
|
2015-07-05 19:14:38 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf17 USING btree ADD OPERATOR 1 < (int4, int4), OPERATOR 1 < (int4, int4); -- operator # appears twice in same statement
|
2013-07-23 14:53:21 +02:00
|
|
|
ERROR: operator number 1 for (integer,integer) appears more than once
|
|
|
|
ALTER OPERATOR FAMILY alt_opf17 USING btree ADD OPERATOR 1 < (int4, int4); -- operator 1 requested first-time
|
|
|
|
ALTER OPERATOR FAMILY alt_opf17 USING btree ADD OPERATOR 1 < (int4, int4); -- operator 1 requested again in separate statement
|
|
|
|
ERROR: operator 1(integer,integer) already exists in operator family "alt_opf17"
|
|
|
|
ALTER OPERATOR FAMILY alt_opf17 USING btree ADD
|
|
|
|
OPERATOR 1 < (int4, int2) ,
|
|
|
|
OPERATOR 2 <= (int4, int2) ,
|
|
|
|
OPERATOR 3 = (int4, int2) ,
|
|
|
|
OPERATOR 4 >= (int4, int2) ,
|
|
|
|
OPERATOR 5 > (int4, int2) ,
|
|
|
|
FUNCTION 1 btint42cmp(int4, int2) ,
|
|
|
|
FUNCTION 1 btint42cmp(int4, int2); -- procedure 1 appears twice in same statement
|
2018-08-15 17:01:39 +02:00
|
|
|
ERROR: function number 1 for (integer,smallint) appears more than once
|
2013-07-23 14:53:21 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf17 USING btree ADD
|
|
|
|
OPERATOR 1 < (int4, int2) ,
|
|
|
|
OPERATOR 2 <= (int4, int2) ,
|
|
|
|
OPERATOR 3 = (int4, int2) ,
|
|
|
|
OPERATOR 4 >= (int4, int2) ,
|
|
|
|
OPERATOR 5 > (int4, int2) ,
|
|
|
|
FUNCTION 1 btint42cmp(int4, int2); -- procedure 1 appears first time
|
|
|
|
ALTER OPERATOR FAMILY alt_opf17 USING btree ADD
|
|
|
|
OPERATOR 1 < (int4, int2) ,
|
|
|
|
OPERATOR 2 <= (int4, int2) ,
|
|
|
|
OPERATOR 3 = (int4, int2) ,
|
|
|
|
OPERATOR 4 >= (int4, int2) ,
|
|
|
|
OPERATOR 5 > (int4, int2) ,
|
|
|
|
FUNCTION 1 btint42cmp(int4, int2); -- procedure 1 requested again in separate statement
|
|
|
|
ERROR: operator 1(integer,smallint) already exists in operator family "alt_opf17"
|
|
|
|
DROP OPERATOR FAMILY alt_opf17 USING btree;
|
|
|
|
-- Should fail. Ensure that DROP requests for missing OPERATOR / FUNCTIONS
|
|
|
|
-- return appropriate message in ALTER OPERATOR FAMILY ... DROP OPERATOR / FUNCTION
|
|
|
|
CREATE OPERATOR FAMILY alt_opf18 USING btree;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf18 USING btree DROP OPERATOR 1 (int4, int4);
|
|
|
|
ERROR: operator 1(integer,integer) does not exist in operator family "alt_opf18"
|
|
|
|
ALTER OPERATOR FAMILY alt_opf18 USING btree ADD
|
|
|
|
OPERATOR 1 < (int4, int2) ,
|
|
|
|
OPERATOR 2 <= (int4, int2) ,
|
|
|
|
OPERATOR 3 = (int4, int2) ,
|
|
|
|
OPERATOR 4 >= (int4, int2) ,
|
|
|
|
OPERATOR 5 > (int4, int2) ,
|
|
|
|
FUNCTION 1 btint42cmp(int4, int2);
|
2020-02-26 20:28:25 +01:00
|
|
|
-- Should fail. Not allowed to have cross-type equalimage function.
|
|
|
|
ALTER OPERATOR FAMILY alt_opf18 USING btree
|
|
|
|
ADD FUNCTION 4 (int4, int2) btequalimage(oid);
|
|
|
|
ERROR: btree equal image functions must not be cross-type
|
2013-07-23 14:53:21 +02:00
|
|
|
ALTER OPERATOR FAMILY alt_opf18 USING btree DROP FUNCTION 2 (int4, int4);
|
|
|
|
ERROR: function 2(integer,integer) does not exist in operator family "alt_opf18"
|
|
|
|
DROP OPERATOR FAMILY alt_opf18 USING btree;
|
Implement operator class parameters
PostgreSQL provides set of template index access methods, where opclasses have
much freedom in the semantics of indexing. These index AMs are GiST, GIN,
SP-GiST and BRIN. There opclasses define representation of keys, operations on
them and supported search strategies. So, it's natural that opclasses may be
faced some tradeoffs, which require user-side decision. This commit implements
opclass parameters allowing users to set some values, which tell opclass how to
index the particular dataset.
This commit doesn't introduce new storage in system catalog. Instead it uses
pg_attribute.attoptions, which is used for table column storage options but
unused for index attributes.
In order to evade changing signature of each opclass support function, we
implement unified way to pass options to opclass support functions. Options
are set to fn_expr as the constant bytea expression. It's possible due to the
fact that opclass support functions are executed outside of expressions, so
fn_expr is unused for them.
This commit comes with some examples of opclass options usage. We parametrize
signature length in GiST. That applies to multiple opclasses: tsvector_ops,
gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and
gist_hstore_ops. Also we parametrize maximum number of integer ranges for
gist__int_ops. However, the main future usage of this feature is expected
to be json, where users would be able to specify which way to index particular
json parts.
Catversion is bumped.
Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru
Author: Nikita Glukhov, revised by me
Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
2020-03-30 18:17:11 +02:00
|
|
|
-- Should fail. Invalid opclass options function (#5) specifications.
|
|
|
|
CREATE OPERATOR FAMILY alt_opf19 USING btree;
|
|
|
|
ALTER OPERATOR FAMILY alt_opf19 USING btree ADD FUNCTION 5 test_opclass_options_func(internal, text[], bool);
|
|
|
|
ERROR: function test_opclass_options_func(internal, text[], boolean) does not exist
|
|
|
|
ALTER OPERATOR FAMILY alt_opf19 USING btree ADD FUNCTION 5 (int4) btint42cmp(int4, int2);
|
|
|
|
ERROR: invalid opclass options parsing function
|
|
|
|
HINT: opclass options parsing function must have signature '(internal) RETURNS void'
|
|
|
|
ALTER OPERATOR FAMILY alt_opf19 USING btree ADD FUNCTION 5 (int4, int2) btint42cmp(int4, int2);
|
|
|
|
ERROR: left and right associated data types for opclass options parsing functions must match
|
|
|
|
ALTER OPERATOR FAMILY alt_opf19 USING btree ADD FUNCTION 5 (int4) test_opclass_options_func(internal); -- Ok
|
|
|
|
ALTER OPERATOR FAMILY alt_opf19 USING btree DROP FUNCTION 5 (int4, int4);
|
|
|
|
DROP OPERATOR FAMILY alt_opf19 USING btree;
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
--
|
|
|
|
-- Statistics
|
|
|
|
--
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
CREATE TABLE alt_regress_1 (a INTEGER, b INTEGER);
|
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 19:59:23 +02:00
|
|
|
CREATE STATISTICS alt_stat1 ON a, b FROM alt_regress_1;
|
|
|
|
CREATE STATISTICS alt_stat2 ON a, b FROM alt_regress_1;
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
ALTER STATISTICS alt_stat1 RENAME TO alt_stat2; -- failed (name conflict)
|
2017-05-14 16:54:47 +02:00
|
|
|
ERROR: statistics object "alt_stat2" already exists in schema "alt_nsp1"
|
2020-01-02 14:40:18 +01:00
|
|
|
ALTER STATISTICS alt_stat1 RENAME TO alt_stat3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER STATISTICS alt_stat2 OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER STATISTICS alt_stat2 OWNER TO regress_alter_generic_user3; -- OK
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user2;
|
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 19:59:23 +02:00
|
|
|
CREATE TABLE alt_regress_2 (a INTEGER, b INTEGER);
|
|
|
|
CREATE STATISTICS alt_stat1 ON a, b FROM alt_regress_2;
|
|
|
|
CREATE STATISTICS alt_stat2 ON a, b FROM alt_regress_2;
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
ALTER STATISTICS alt_stat3 RENAME TO alt_stat4; -- failed (not owner)
|
2017-05-14 16:54:47 +02:00
|
|
|
ERROR: must be owner of statistics object alt_stat3
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
ALTER STATISTICS alt_stat1 RENAME TO alt_stat4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER STATISTICS alt_stat3 OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2017-05-14 16:54:47 +02:00
|
|
|
ERROR: must be owner of statistics object alt_stat3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER STATISTICS alt_stat2 OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
ALTER STATISTICS alt_stat3 SET SCHEMA alt_nsp2; -- failed (not owner)
|
2017-05-14 16:54:47 +02:00
|
|
|
ERROR: must be owner of statistics object alt_stat3
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
2017-05-14 16:54:47 +02:00
|
|
|
ERROR: statistics object "alt_stat2" already exists in schema "alt_nsp2"
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
RESET SESSION AUTHORIZATION;
|
2017-04-17 23:34:29 +02:00
|
|
|
SELECT nspname, stxname, rolname
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
FROM pg_statistic_ext s, pg_namespace n, pg_authid a
|
2017-04-17 23:34:29 +02:00
|
|
|
WHERE s.stxnamespace = n.oid AND s.stxowner = a.oid
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
|
2017-04-17 23:34:29 +02:00
|
|
|
ORDER BY nspname, stxname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | stxname | rolname
|
|
|
|
----------+-----------+-----------------------------
|
|
|
|
alt_nsp1 | alt_stat2 | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_stat3 | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_stat4 | regress_alter_generic_user2
|
|
|
|
alt_nsp2 | alt_stat2 | regress_alter_generic_user3
|
Implement multivariate n-distinct coefficients
Add support for explicitly declared statistic objects (CREATE
STATISTICS), allowing collection of statistics on more complex
combinations that individual table columns. Companion commands DROP
STATISTICS and ALTER STATISTICS ... OWNER TO / SET SCHEMA / RENAME are
added too. All this DDL has been designed so that more statistic types
can be added later on, such as multivariate most-common-values and
multivariate histograms between columns of a single table, leaving room
for permitting columns on multiple tables, too, as well as expressions.
This commit only adds support for collection of n-distinct coefficient
on user-specified sets of columns in a single table. This is useful to
estimate number of distinct groups in GROUP BY and DISTINCT clauses;
estimation errors there can cause over-allocation of memory in hashed
aggregates, for instance, so it's a worthwhile problem to solve. A new
special pseudo-type pg_ndistinct is used.
(num-distinct estimation was deemed sufficiently useful by itself that
this is worthwhile even if no further statistic types are added
immediately; so much so that another version of essentially the same
functionality was submitted by Kyotaro Horiguchi:
https://postgr.es/m/20150828.173334.114731693.horiguchi.kyotaro@lab.ntt.co.jp
though this commit does not use that code.)
Author: Tomas Vondra. Some code rework by Álvaro.
Reviewed-by: Dean Rasheed, David Rowley, Kyotaro Horiguchi, Jeff Janes,
Ideriha Takeshi
Discussion: https://postgr.es/m/543AFA15.4080608@fuzzy.cz
https://postgr.es/m/20170320190220.ixlaueanxegqd5gr@alvherre.pgsql
2017-03-24 18:06:10 +01:00
|
|
|
(4 rows)
|
|
|
|
|
2012-09-27 22:21:11 +02:00
|
|
|
--
|
|
|
|
-- Text Search Dictionary
|
|
|
|
--
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE TEXT SEARCH DICTIONARY alt_ts_dict1 (template=simple);
|
|
|
|
CREATE TEXT SEARCH DICTIONARY alt_ts_dict2 (template=simple);
|
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict2; -- failed (name conflict)
|
2013-01-21 16:06:41 +01:00
|
|
|
ERROR: text search dictionary "alt_ts_dict2" already exists in schema "alt_nsp1"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 SET SCHEMA alt_nsp2; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user2;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE TEXT SEARCH DICTIONARY alt_ts_dict1 (template=simple);
|
|
|
|
CREATE TEXT SEARCH DICTIONARY alt_ts_dict2 (template=simple);
|
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict3 RENAME TO alt_ts_dict4; -- failed (not owner)
|
|
|
|
ERROR: must be owner of text search dictionary alt_ts_dict3
|
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict3 OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of text search dictionary alt_ts_dict3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict3 SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of text search dictionary alt_ts_dict3
|
|
|
|
ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
Rework order of checks in ALTER / SET SCHEMA
When attempting to move an object into the schema in which it already
was, for most objects classes we were correctly complaining about
exactly that ("object is already in schema"); but for some other object
classes, such as functions, we were instead complaining of a name
collision ("object already exists in schema"). The latter is wrong and
misleading, per complaint from Robert Haas in
CA+TgmoZ0+gNf7RDKRc3u5rHXffP=QjqPZKGxb4BsPz65k7qnHQ@mail.gmail.com
To fix, refactor the way these checks are done. As a bonus, the
resulting code is smaller and can also share some code with Rename
cases.
While at it, remove use of getObjectDescriptionOids() in error messages.
These are normally disallowed because of translatability considerations,
but this one had slipped through since 9.1. (Not sure that this is
worth backpatching, though, as it would create some untranslated
messages in back branches.)
This is loosely based on a patch by KaiGai Kohei, heavily reworked by
me.
2013-01-15 17:23:43 +01:00
|
|
|
ERROR: text search dictionary "alt_ts_dict2" already exists in schema "alt_nsp2"
|
2012-09-27 22:21:11 +02:00
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
SELECT nspname, dictname, rolname
|
|
|
|
FROM pg_ts_dict t, pg_namespace n, pg_authid a
|
|
|
|
WHERE t.dictnamespace = n.oid AND t.dictowner = a.oid
|
|
|
|
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
|
|
|
|
ORDER BY nspname, dictname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | dictname | rolname
|
|
|
|
----------+--------------+-----------------------------
|
|
|
|
alt_nsp1 | alt_ts_dict2 | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_ts_dict3 | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_ts_dict4 | regress_alter_generic_user2
|
|
|
|
alt_nsp2 | alt_ts_dict2 | regress_alter_generic_user3
|
2012-09-27 22:21:11 +02:00
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Text Search Configuration
|
|
|
|
--
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user1;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE TEXT SEARCH CONFIGURATION alt_ts_conf1 (copy=english);
|
|
|
|
CREATE TEXT SEARCH CONFIGURATION alt_ts_conf2 (copy=english);
|
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf2; -- failed (name conflict)
|
2013-01-21 16:06:41 +01:00
|
|
|
ERROR: text search configuration "alt_ts_conf2" already exists in schema "alt_nsp1"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf3; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regress_alter_generic_user2; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user2"
|
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regress_alter_generic_user3; -- OK
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 SET SCHEMA alt_nsp2; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
SET SESSION AUTHORIZATION regress_alter_generic_user2;
|
2012-09-27 22:21:11 +02:00
|
|
|
CREATE TEXT SEARCH CONFIGURATION alt_ts_conf1 (copy=english);
|
|
|
|
CREATE TEXT SEARCH CONFIGURATION alt_ts_conf2 (copy=english);
|
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf3 RENAME TO alt_ts_conf4; -- failed (not owner)
|
|
|
|
ERROR: must be owner of text search configuration alt_ts_conf3
|
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf4; -- OK
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf3 OWNER TO regress_alter_generic_user2; -- failed (not owner)
|
2012-09-27 22:21:11 +02:00
|
|
|
ERROR: must be owner of text search configuration alt_ts_conf3
|
2018-03-15 19:00:31 +01:00
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regress_alter_generic_user3; -- failed (no role membership)
|
|
|
|
ERROR: must be member of role "regress_alter_generic_user3"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf3 SET SCHEMA alt_nsp2; -- failed (not owner)
|
|
|
|
ERROR: must be owner of text search configuration alt_ts_conf3
|
|
|
|
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
Rework order of checks in ALTER / SET SCHEMA
When attempting to move an object into the schema in which it already
was, for most objects classes we were correctly complaining about
exactly that ("object is already in schema"); but for some other object
classes, such as functions, we were instead complaining of a name
collision ("object already exists in schema"). The latter is wrong and
misleading, per complaint from Robert Haas in
CA+TgmoZ0+gNf7RDKRc3u5rHXffP=QjqPZKGxb4BsPz65k7qnHQ@mail.gmail.com
To fix, refactor the way these checks are done. As a bonus, the
resulting code is smaller and can also share some code with Rename
cases.
While at it, remove use of getObjectDescriptionOids() in error messages.
These are normally disallowed because of translatability considerations,
but this one had slipped through since 9.1. (Not sure that this is
worth backpatching, though, as it would create some untranslated
messages in back branches.)
This is loosely based on a patch by KaiGai Kohei, heavily reworked by
me.
2013-01-15 17:23:43 +01:00
|
|
|
ERROR: text search configuration "alt_ts_conf2" already exists in schema "alt_nsp2"
|
2012-09-27 22:21:11 +02:00
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
SELECT nspname, cfgname, rolname
|
|
|
|
FROM pg_ts_config t, pg_namespace n, pg_authid a
|
|
|
|
WHERE t.cfgnamespace = n.oid AND t.cfgowner = a.oid
|
|
|
|
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
|
|
|
|
ORDER BY nspname, cfgname;
|
2018-03-15 19:00:31 +01:00
|
|
|
nspname | cfgname | rolname
|
|
|
|
----------+--------------+-----------------------------
|
|
|
|
alt_nsp1 | alt_ts_conf2 | regress_alter_generic_user2
|
|
|
|
alt_nsp1 | alt_ts_conf3 | regress_alter_generic_user1
|
|
|
|
alt_nsp1 | alt_ts_conf4 | regress_alter_generic_user2
|
|
|
|
alt_nsp2 | alt_ts_conf2 | regress_alter_generic_user3
|
2012-09-27 22:21:11 +02:00
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Text Search Template
|
|
|
|
--
|
|
|
|
CREATE TEXT SEARCH TEMPLATE alt_ts_temp1 (lexize=dsimple_lexize);
|
|
|
|
CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
|
|
|
|
ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp2; -- failed (name conflict)
|
2013-01-21 16:06:41 +01:00
|
|
|
ERROR: text search template "alt_ts_temp2" already exists in schema "alt_nsp1"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp3; -- OK
|
|
|
|
ALTER TEXT SEARCH TEMPLATE alt_ts_temp2 SET SCHEMA alt_nsp2; -- OK
|
|
|
|
CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
|
|
|
|
ALTER TEXT SEARCH TEMPLATE alt_ts_temp2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
Rework order of checks in ALTER / SET SCHEMA
When attempting to move an object into the schema in which it already
was, for most objects classes we were correctly complaining about
exactly that ("object is already in schema"); but for some other object
classes, such as functions, we were instead complaining of a name
collision ("object already exists in schema"). The latter is wrong and
misleading, per complaint from Robert Haas in
CA+TgmoZ0+gNf7RDKRc3u5rHXffP=QjqPZKGxb4BsPz65k7qnHQ@mail.gmail.com
To fix, refactor the way these checks are done. As a bonus, the
resulting code is smaller and can also share some code with Rename
cases.
While at it, remove use of getObjectDescriptionOids() in error messages.
These are normally disallowed because of translatability considerations,
but this one had slipped through since 9.1. (Not sure that this is
worth backpatching, though, as it would create some untranslated
messages in back branches.)
This is loosely based on a patch by KaiGai Kohei, heavily reworked by
me.
2013-01-15 17:23:43 +01:00
|
|
|
ERROR: text search template "alt_ts_temp2" already exists in schema "alt_nsp2"
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
-- invalid: non-lowercase quoted identifiers
|
|
|
|
CREATE TEXT SEARCH TEMPLATE tstemp_case ("Init" = init_function);
|
|
|
|
ERROR: text search template parameter "Init" not recognized
|
2012-09-27 22:21:11 +02:00
|
|
|
SELECT nspname, tmplname
|
|
|
|
FROM pg_ts_template t, pg_namespace n
|
|
|
|
WHERE t.tmplnamespace = n.oid AND nspname like 'alt_nsp%'
|
|
|
|
ORDER BY nspname, tmplname;
|
|
|
|
nspname | tmplname
|
|
|
|
----------+--------------
|
|
|
|
alt_nsp1 | alt_ts_temp2
|
|
|
|
alt_nsp1 | alt_ts_temp3
|
|
|
|
alt_nsp2 | alt_ts_temp2
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Text Search Parser
|
|
|
|
--
|
|
|
|
CREATE TEXT SEARCH PARSER alt_ts_prs1
|
|
|
|
(start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
|
|
|
|
CREATE TEXT SEARCH PARSER alt_ts_prs2
|
|
|
|
(start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
|
|
|
|
ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs2; -- failed (name conflict)
|
2013-01-21 16:06:41 +01:00
|
|
|
ERROR: text search parser "alt_ts_prs2" already exists in schema "alt_nsp1"
|
2012-09-27 22:21:11 +02:00
|
|
|
ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs3; -- OK
|
|
|
|
ALTER TEXT SEARCH PARSER alt_ts_prs2 SET SCHEMA alt_nsp2; -- OK
|
|
|
|
CREATE TEXT SEARCH PARSER alt_ts_prs2
|
|
|
|
(start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
|
|
|
|
ALTER TEXT SEARCH PARSER alt_ts_prs2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
Rework order of checks in ALTER / SET SCHEMA
When attempting to move an object into the schema in which it already
was, for most objects classes we were correctly complaining about
exactly that ("object is already in schema"); but for some other object
classes, such as functions, we were instead complaining of a name
collision ("object already exists in schema"). The latter is wrong and
misleading, per complaint from Robert Haas in
CA+TgmoZ0+gNf7RDKRc3u5rHXffP=QjqPZKGxb4BsPz65k7qnHQ@mail.gmail.com
To fix, refactor the way these checks are done. As a bonus, the
resulting code is smaller and can also share some code with Rename
cases.
While at it, remove use of getObjectDescriptionOids() in error messages.
These are normally disallowed because of translatability considerations,
but this one had slipped through since 9.1. (Not sure that this is
worth backpatching, though, as it would create some untranslated
messages in back branches.)
This is loosely based on a patch by KaiGai Kohei, heavily reworked by
me.
2013-01-15 17:23:43 +01:00
|
|
|
ERROR: text search parser "alt_ts_prs2" already exists in schema "alt_nsp2"
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
-- invalid: non-lowercase quoted identifiers
|
|
|
|
CREATE TEXT SEARCH PARSER tspars_case ("Start" = start_function);
|
|
|
|
ERROR: text search parser parameter "Start" not recognized
|
2012-09-27 22:21:11 +02:00
|
|
|
SELECT nspname, prsname
|
|
|
|
FROM pg_ts_parser t, pg_namespace n
|
|
|
|
WHERE t.prsnamespace = n.oid AND nspname like 'alt_nsp%'
|
|
|
|
ORDER BY nspname, prsname;
|
|
|
|
nspname | prsname
|
|
|
|
----------+-------------
|
|
|
|
alt_nsp1 | alt_ts_prs2
|
|
|
|
alt_nsp1 | alt_ts_prs3
|
|
|
|
alt_nsp2 | alt_ts_prs2
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
---
|
|
|
|
--- Cleanup resources
|
|
|
|
---
|
|
|
|
DROP FOREIGN DATA WRAPPER alt_fdw2 CASCADE;
|
2017-08-01 22:49:23 +02:00
|
|
|
NOTICE: drop cascades to server alt_fserv2
|
2012-09-27 22:21:11 +02:00
|
|
|
DROP FOREIGN DATA WRAPPER alt_fdw3 CASCADE;
|
2017-08-01 22:49:23 +02:00
|
|
|
NOTICE: drop cascades to server alt_fserv3
|
2012-09-27 22:21:11 +02:00
|
|
|
DROP LANGUAGE alt_lang2 CASCADE;
|
|
|
|
DROP LANGUAGE alt_lang3 CASCADE;
|
|
|
|
DROP SCHEMA alt_nsp1 CASCADE;
|
2017-08-01 22:49:23 +02:00
|
|
|
NOTICE: drop cascades to 28 other objects
|
2019-03-25 00:15:37 +01:00
|
|
|
DETAIL: drop cascades to function alt_func3(integer)
|
|
|
|
drop cascades to function alt_agg3(integer)
|
|
|
|
drop cascades to function alt_func4(integer)
|
|
|
|
drop cascades to function alt_func2(integer)
|
|
|
|
drop cascades to function alt_agg4(integer)
|
|
|
|
drop cascades to function alt_agg2(integer)
|
|
|
|
drop cascades to conversion alt_conv3
|
|
|
|
drop cascades to conversion alt_conv4
|
|
|
|
drop cascades to conversion alt_conv2
|
|
|
|
drop cascades to operator @+@(integer,integer)
|
|
|
|
drop cascades to operator @-@(integer,integer)
|
|
|
|
drop cascades to operator family alt_opf3 for access method hash
|
|
|
|
drop cascades to operator family alt_opc1 for access method hash
|
|
|
|
drop cascades to operator family alt_opc2 for access method hash
|
|
|
|
drop cascades to operator family alt_opf4 for access method hash
|
|
|
|
drop cascades to operator family alt_opf2 for access method hash
|
|
|
|
drop cascades to table alt_regress_1
|
|
|
|
drop cascades to table alt_regress_2
|
|
|
|
drop cascades to text search dictionary alt_ts_dict3
|
|
|
|
drop cascades to text search dictionary alt_ts_dict4
|
|
|
|
drop cascades to text search dictionary alt_ts_dict2
|
|
|
|
drop cascades to text search configuration alt_ts_conf3
|
|
|
|
drop cascades to text search configuration alt_ts_conf4
|
|
|
|
drop cascades to text search configuration alt_ts_conf2
|
|
|
|
drop cascades to text search template alt_ts_temp3
|
|
|
|
drop cascades to text search template alt_ts_temp2
|
|
|
|
drop cascades to text search parser alt_ts_prs3
|
|
|
|
drop cascades to text search parser alt_ts_prs2
|
2012-09-27 22:21:11 +02:00
|
|
|
DROP SCHEMA alt_nsp2 CASCADE;
|
2017-08-01 22:49:23 +02:00
|
|
|
NOTICE: drop cascades to 9 other objects
|
2019-03-25 00:15:37 +01:00
|
|
|
DETAIL: drop cascades to function alt_nsp2.alt_func2(integer)
|
|
|
|
drop cascades to function alt_nsp2.alt_agg2(integer)
|
|
|
|
drop cascades to conversion alt_nsp2.alt_conv2
|
|
|
|
drop cascades to operator alt_nsp2.@-@(integer,integer)
|
|
|
|
drop cascades to operator family alt_nsp2.alt_opf2 for access method hash
|
|
|
|
drop cascades to text search dictionary alt_nsp2.alt_ts_dict2
|
|
|
|
drop cascades to text search configuration alt_nsp2.alt_ts_conf2
|
|
|
|
drop cascades to text search template alt_nsp2.alt_ts_temp2
|
|
|
|
drop cascades to text search parser alt_nsp2.alt_ts_prs2
|
2018-03-15 19:00:31 +01:00
|
|
|
DROP USER regress_alter_generic_user1;
|
|
|
|
DROP USER regress_alter_generic_user2;
|
|
|
|
DROP USER regress_alter_generic_user3;
|