From: Tom Lane Date: Fri, 10 Mar 2017 18:15:47 +0000 (-0500) Subject: Change the relkind for partitioned tables from 'P' to 'p'. X-Git-Tag: REL_10_BETA1~689 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b358b42f8eb6156a82ac9a41fc4e8335c8dc37a;p=postgresql Change the relkind for partitioned tables from 'P' to 'p'. Seven of the eight other relkind codes are lower-case, so it wasn't consistent for this one to be upper-case. Fix it while we still can. Historical notes: the reason for the lone exception, i.e. sequences being 'S', is that 's' was once used for "special" relations. Also, at one time the partitioned-tables patch used both 'P' and 'p', but that got changed, leaving only a surprising choice behind. This also fixes a couple little bits of technical debt, such as type_sanity.sql not knowing that 'm' is a legal value for relkind. Discussion: https://postgr.es/m/27899.1488909319@sss.pgh.pa.us --- diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 28cdabe6fe..2c2da2ad8a 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1758,12 +1758,15 @@ char - r = ordinary table, P = partitioned table, - i = index - S = sequence, v = view, + r = ordinary table, + i = index, + S = sequence, + t = TOAST table, + v = view, m = materialized view, - c = composite type, t = TOAST table, - f = foreign table + c = composite type, + f = foreign table, + p = partitioned table diff --git a/src/backend/catalog/information_schema.sql b/src/backend/catalog/information_schema.sql index 51795cd6de..fa2a88fc5c 100644 --- a/src/backend/catalog/information_schema.sql +++ b/src/backend/catalog/information_schema.sql @@ -365,7 +365,7 @@ CREATE VIEW attributes AS ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default') WHERE a.attnum > 0 AND NOT a.attisdropped - AND c.relkind in ('c') + AND c.relkind IN ('c') AND (pg_has_role(c.relowner, 'USAGE') OR has_type_privilege(c.reltype, 'USAGE')); @@ -453,7 +453,7 @@ CREATE VIEW check_constraints AS AND a.attnum > 0 AND NOT a.attisdropped AND a.attnotnull - AND r.relkind IN ('r', 'P') + AND r.relkind IN ('r', 'p') AND pg_has_role(r.relowner, 'USAGE'); GRANT SELECT ON check_constraints TO PUBLIC; @@ -525,7 +525,7 @@ CREATE VIEW column_domain_usage AS AND a.attrelid = c.oid AND a.atttypid = t.oid AND t.typtype = 'd' - AND c.relkind IN ('r', 'v', 'f', 'P') + AND c.relkind IN ('r', 'v', 'f', 'p') AND a.attnum > 0 AND NOT a.attisdropped AND pg_has_role(t.typowner, 'USAGE'); @@ -564,7 +564,7 @@ CREATE VIEW column_privileges AS pr_c.relowner FROM (SELECT oid, relname, relnamespace, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).* FROM pg_class - WHERE relkind IN ('r', 'v', 'f', 'P') + WHERE relkind IN ('r', 'v', 'f', 'p') ) pr_c (oid, relname, relnamespace, relowner, grantor, grantee, prtype, grantable), pg_attribute a WHERE a.attrelid = pr_c.oid @@ -586,7 +586,7 @@ CREATE VIEW column_privileges AS ) pr_a (attrelid, attname, grantor, grantee, prtype, grantable), pg_class c WHERE pr_a.attrelid = c.oid - AND relkind IN ('r', 'v', 'f', 'P') + AND relkind IN ('r', 'v', 'f', 'p') ) x, pg_namespace nc, pg_authid u_grantor, @@ -629,7 +629,8 @@ CREATE VIEW column_udt_usage AS WHERE a.attrelid = c.oid AND a.atttypid = t.oid AND nc.oid = c.relnamespace - AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'P') + AND a.attnum > 0 AND NOT a.attisdropped + AND c.relkind in ('r', 'v', 'f', 'p') AND pg_has_role(coalesce(bt.typowner, t.typowner), 'USAGE'); GRANT SELECT ON column_udt_usage TO PUBLIC; @@ -738,7 +739,7 @@ CREATE VIEW columns AS CAST('NEVER' AS character_data) AS is_generated, CAST(null AS character_data) AS generation_expression, - CAST(CASE WHEN c.relkind IN ('r', 'P') OR + CAST(CASE WHEN c.relkind IN ('r', 'p') OR (c.relkind IN ('v', 'f') AND pg_column_is_updatable(c.oid, a.attnum, false)) THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_updatable @@ -753,7 +754,8 @@ CREATE VIEW columns AS WHERE (NOT pg_is_other_temp_schema(nc.oid)) - AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'P') + AND a.attnum > 0 AND NOT a.attisdropped + AND c.relkind IN ('r', 'v', 'f', 'p') AND (pg_has_role(c.relowner, 'USAGE') OR has_column_privilege(c.oid, a.attnum, @@ -789,7 +791,7 @@ CREATE VIEW constraint_column_usage AS AND d.objid = c.oid AND c.connamespace = nc.oid AND c.contype = 'c' - AND r.relkind IN ('r', 'P') + AND r.relkind IN ('r', 'p') AND NOT a.attisdropped UNION ALL @@ -805,7 +807,7 @@ CREATE VIEW constraint_column_usage AS AND a.attnum = ANY (CASE c.contype WHEN 'f' THEN c.confkey ELSE c.conkey END) AND NOT a.attisdropped AND c.contype IN ('p', 'u', 'f') - AND r.relkind IN ('r', 'P') + AND r.relkind IN ('r', 'p') ) AS x (tblschema, tblname, tblowner, colname, cstrschema, cstrname) @@ -841,7 +843,7 @@ CREATE VIEW constraint_table_usage AS WHERE c.connamespace = nc.oid AND r.relnamespace = nr.oid AND ( (c.contype = 'f' AND c.confrelid = r.oid) OR (c.contype IN ('p', 'u') AND c.conrelid = r.oid) ) - AND r.relkind IN ('r', 'P') + AND r.relkind IN ('r', 'p') AND pg_has_role(r.relowner, 'USAGE'); GRANT SELECT ON constraint_table_usage TO PUBLIC; @@ -1058,7 +1060,7 @@ CREATE VIEW key_column_usage AS AND r.oid = c.conrelid AND nc.oid = c.connamespace AND c.contype IN ('p', 'u', 'f') - AND r.relkind IN ('r', 'P') + AND r.relkind IN ('r', 'p') AND (NOT pg_is_other_temp_schema(nr.oid)) ) AS ss WHERE ss.roid = a.attrelid AND a.attnum = (ss.x).x @@ -1774,7 +1776,7 @@ CREATE VIEW table_constraints AS WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace AND c.conrelid = r.oid AND c.contype NOT IN ('t', 'x') -- ignore nonstandard constraints - AND r.relkind IN ('r', 'P') + AND r.relkind IN ('r', 'p') AND (NOT pg_is_other_temp_schema(nr.oid)) AND (pg_has_role(r.relowner, 'USAGE') -- SELECT privilege omitted, per SQL standard @@ -1804,7 +1806,7 @@ CREATE VIEW table_constraints AS AND a.attnotnull AND a.attnum > 0 AND NOT a.attisdropped - AND r.relkind IN ('r', 'P') + AND r.relkind IN ('r', 'p') AND (NOT pg_is_other_temp_schema(nr.oid)) AND (pg_has_role(r.relowner, 'USAGE') -- SELECT privilege omitted, per SQL standard @@ -1854,7 +1856,7 @@ CREATE VIEW table_privileges AS ) AS grantee (oid, rolname) WHERE c.relnamespace = nc.oid - AND c.relkind IN ('r', 'v', 'P') + AND c.relkind IN ('r', 'v', 'p') AND c.grantee = grantee.oid AND c.grantor = u_grantor.oid AND c.prtype IN ('INSERT', 'SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER') @@ -1898,7 +1900,7 @@ CREATE VIEW tables AS CAST( CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY' - WHEN c.relkind IN ('r', 'P') THEN 'BASE TABLE' + WHEN c.relkind IN ('r', 'p') THEN 'BASE TABLE' WHEN c.relkind = 'v' THEN 'VIEW' WHEN c.relkind = 'f' THEN 'FOREIGN TABLE' ELSE null END @@ -1911,7 +1913,7 @@ CREATE VIEW tables AS CAST(nt.nspname AS sql_identifier) AS user_defined_type_schema, CAST(t.typname AS sql_identifier) AS user_defined_type_name, - CAST(CASE WHEN c.relkind IN ('r', 'P') OR + CAST(CASE WHEN c.relkind IN ('r', 'p') OR (c.relkind IN ('v', 'f') AND -- 1 << CMD_INSERT pg_relation_is_updatable(c.oid, false) & 8 = 8) @@ -1923,7 +1925,7 @@ CREATE VIEW tables AS FROM pg_namespace nc JOIN pg_class c ON (nc.oid = c.relnamespace) LEFT JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON (c.reloftype = t.oid) - WHERE c.relkind IN ('r', 'v', 'f', 'P') + WHERE c.relkind IN ('r', 'v', 'f', 'p') AND (NOT pg_is_other_temp_schema(nc.oid)) AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER') @@ -2442,7 +2444,7 @@ CREATE VIEW view_column_usage AS AND dt.refclassid = 'pg_catalog.pg_class'::regclass AND dt.refobjid = t.oid AND t.relnamespace = nt.oid - AND t.relkind IN ('r', 'v', 'f', 'P') + AND t.relkind IN ('r', 'v', 'f', 'p') AND t.oid = a.attrelid AND dt.refobjsubid = a.attnum AND pg_has_role(t.relowner, 'USAGE'); @@ -2520,7 +2522,7 @@ CREATE VIEW view_table_usage AS AND dt.refclassid = 'pg_catalog.pg_class'::regclass AND dt.refobjid = t.oid AND t.relnamespace = nt.oid - AND t.relkind IN ('r', 'v', 'f', 'P') + AND t.relkind IN ('r', 'v', 'f', 'p') AND pg_has_role(t.relowner, 'USAGE'); GRANT SELECT ON view_table_usage TO PUBLIC; @@ -2673,7 +2675,7 @@ CREATE VIEW element_types AS a.attnum, a.atttypid, a.attcollation FROM pg_class c, pg_attribute a WHERE c.oid = a.attrelid - AND c.relkind IN ('r', 'v', 'f', 'c', 'P') + AND c.relkind IN ('r', 'v', 'f', 'c', 'p') AND attnum > 0 AND NOT attisdropped UNION ALL diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index ba980de86b..0bce20914e 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -136,7 +136,7 @@ CREATE VIEW pg_tables AS C.relrowsecurity AS rowsecurity FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) - WHERE C.relkind IN ('r', 'P'); + WHERE C.relkind IN ('r', 'p'); CREATE VIEW pg_matviews AS SELECT @@ -294,7 +294,7 @@ CREATE VIEW pg_prepared_statements AS CREATE VIEW pg_seclabels AS SELECT l.objoid, l.classoid, l.objsubid, - CASE WHEN rel.relkind IN ('r', 'P') THEN 'table'::text + CASE WHEN rel.relkind IN ('r', 'p') THEN 'table'::text WHEN rel.relkind = 'v' THEN 'view'::text WHEN rel.relkind = 'm' THEN 'materialized view'::text WHEN rel.relkind = 'S' THEN 'sequence'::text diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 4c05b30068..9f5e302061 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201703081 +#define CATALOG_VERSION_NO 201703101 #endif diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 3f96611f74..d1d493ee05 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -162,10 +162,10 @@ DESCR(""); #define RELKIND_SEQUENCE 'S' /* sequence object */ #define RELKIND_TOASTVALUE 't' /* for out-of-line values */ #define RELKIND_VIEW 'v' /* view */ +#define RELKIND_MATVIEW 'm' /* materialized view */ #define RELKIND_COMPOSITE_TYPE 'c' /* composite type */ #define RELKIND_FOREIGN_TABLE 'f' /* foreign table */ -#define RELKIND_MATVIEW 'm' /* materialized view */ -#define RELKIND_PARTITIONED_TABLE 'P' /* partitioned table */ +#define RELKIND_PARTITIONED_TABLE 'p' /* partitioned table */ #define RELPERSISTENCE_PERMANENT 'p' /* regular table */ #define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */ @@ -178,9 +178,10 @@ DESCR(""); /* all columns are logged as replica identity */ #define REPLICA_IDENTITY_FULL 'f' /* - * an explicitly chosen candidate key's columns are used as identity; - * will still be set if the index has been dropped, in that case it - * has the same meaning as 'd' + * an explicitly chosen candidate key's columns are used as replica identity. + * Note this will still be set if the index has been dropped; in that case it + * has the same meaning as 'd'. */ #define REPLICA_IDENTITY_INDEX 'i' + #endif /* PG_CLASS_H */ diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index c07a474b3d..6f8645ddbd 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -404,7 +404,7 @@ CREATE TABLE partitioned ( SELECT relkind FROM pg_class WHERE relname = 'partitioned'; relkind --------- - P + p (1 row) -- check that range partition key columns are marked NOT NULL diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index c661f1d962..bd13ae6010 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1481,7 +1481,7 @@ pg_seclabels| SELECT l.objoid, l.classoid, l.objsubid, CASE - WHEN (rel.relkind = ANY (ARRAY['r'::"char", 'P'::"char"])) THEN 'table'::text + WHEN (rel.relkind = ANY (ARRAY['r'::"char", 'p'::"char"])) THEN 'table'::text WHEN (rel.relkind = 'v'::"char") THEN 'view'::text WHEN (rel.relkind = 'm'::"char") THEN 'materialized view'::text WHEN (rel.relkind = 'S'::"char") THEN 'sequence'::text @@ -2171,7 +2171,7 @@ pg_tables| SELECT n.nspname AS schemaname, FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace))) - WHERE (c.relkind = ANY (ARRAY['r'::"char", 'P'::"char"])); + WHERE (c.relkind = ANY (ARRAY['r'::"char", 'p'::"char"])); pg_timezone_abbrevs| SELECT pg_timezone_abbrevs.abbrev, pg_timezone_abbrevs.utc_offset, pg_timezone_abbrevs.is_dst diff --git a/src/test/regress/expected/sanity_check.out b/src/test/regress/expected/sanity_check.out index bdbb39180f..b5eff55e9b 100644 --- a/src/test/regress/expected/sanity_check.out +++ b/src/test/regress/expected/sanity_check.out @@ -9,7 +9,7 @@ VACUUM; \a\t SELECT relname, relhasindex FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace - WHERE relkind IN ('r', 'P') AND (nspname ~ '^pg_temp_') IS NOT TRUE + WHERE relkind IN ('r', 'p') AND (nspname ~ '^pg_temp_') IS NOT TRUE ORDER BY relname; a|f a_star|f diff --git a/src/test/regress/expected/type_sanity.out b/src/test/regress/expected/type_sanity.out index 312d290e73..8d75bbfab3 100644 --- a/src/test/regress/expected/type_sanity.out +++ b/src/test/regress/expected/type_sanity.out @@ -464,7 +464,7 @@ ORDER BY 1; -- Look for illegal values in pg_class fields SELECT p1.oid, p1.relname FROM pg_class as p1 -WHERE relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f') OR +WHERE relkind NOT IN ('r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p') OR relpersistence NOT IN ('p', 'u', 't') OR relreplident NOT IN ('d', 'n', 'f', 'i'); oid | relname diff --git a/src/test/regress/sql/sanity_check.sql b/src/test/regress/sql/sanity_check.sql index fa3a90ff11..04aee457dd 100644 --- a/src/test/regress/sql/sanity_check.sql +++ b/src/test/regress/sql/sanity_check.sql @@ -12,7 +12,7 @@ VACUUM; SELECT relname, relhasindex FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace - WHERE relkind IN ('r', 'P') AND (nspname ~ '^pg_temp_') IS NOT TRUE + WHERE relkind IN ('r', 'p') AND (nspname ~ '^pg_temp_') IS NOT TRUE ORDER BY relname; -- restore normal output mode diff --git a/src/test/regress/sql/type_sanity.sql b/src/test/regress/sql/type_sanity.sql index 0282f84d2e..0a31249f5d 100644 --- a/src/test/regress/sql/type_sanity.sql +++ b/src/test/regress/sql/type_sanity.sql @@ -339,7 +339,7 @@ ORDER BY 1; SELECT p1.oid, p1.relname FROM pg_class as p1 -WHERE relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f') OR +WHERE relkind NOT IN ('r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p') OR relpersistence NOT IN ('p', 'u', 't') OR relreplident NOT IN ('d', 'n', 'f', 'i');