Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b358b4

Browse files
committed
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/[email protected]
1 parent a83e4b4 commit 8b358b4

File tree

11 files changed

+47
-41
lines changed

11 files changed

+47
-41
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,12 +1758,15 @@
17581758
<entry><type>char</type></entry>
17591759
<entry></entry>
17601760
<entry>
1761-
<literal>r</> = ordinary table, <literal>P</> = partitioned table,
1762-
<literal>i</> = index
1763-
<literal>S</> = sequence, <literal>v</> = view,
1761+
<literal>r</> = ordinary table,
1762+
<literal>i</> = index,
1763+
<literal>S</> = sequence,
1764+
<literal>t</> = TOAST table,
1765+
<literal>v</> = view,
17641766
<literal>m</> = materialized view,
1765-
<literal>c</> = composite type, <literal>t</> = TOAST table,
1766-
<literal>f</> = foreign table
1767+
<literal>c</> = composite type,
1768+
<literal>f</> = foreign table,
1769+
<literal>p</> = partitioned table
17671770
</entry>
17681771
</row>
17691772

src/backend/catalog/information_schema.sql

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ CREATE VIEW attributes AS
365365
ON a.attcollation = co.oid AND (nco.nspname, co.collname) <> ('pg_catalog', 'default')
366366

367367
WHERE a.attnum > 0 AND NOT a.attisdropped
368-
AND c.relkind in ('c')
368+
AND c.relkind IN ('c')
369369
AND (pg_has_role(c.relowner, 'USAGE')
370370
OR has_type_privilege(c.reltype, 'USAGE'));
371371

@@ -453,7 +453,7 @@ CREATE VIEW check_constraints AS
453453
AND a.attnum > 0
454454
AND NOT a.attisdropped
455455
AND a.attnotnull
456-
AND r.relkind IN ('r', 'P')
456+
AND r.relkind IN ('r', 'p')
457457
AND pg_has_role(r.relowner, 'USAGE');
458458

459459
GRANT SELECT ON check_constraints TO PUBLIC;
@@ -525,7 +525,7 @@ CREATE VIEW column_domain_usage AS
525525
AND a.attrelid = c.oid
526526
AND a.atttypid = t.oid
527527
AND t.typtype = 'd'
528-
AND c.relkind IN ('r', 'v', 'f', 'P')
528+
AND c.relkind IN ('r', 'v', 'f', 'p')
529529
AND a.attnum > 0
530530
AND NOT a.attisdropped
531531
AND pg_has_role(t.typowner, 'USAGE');
@@ -564,7 +564,7 @@ CREATE VIEW column_privileges AS
564564
pr_c.relowner
565565
FROM (SELECT oid, relname, relnamespace, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).*
566566
FROM pg_class
567-
WHERE relkind IN ('r', 'v', 'f', 'P')
567+
WHERE relkind IN ('r', 'v', 'f', 'p')
568568
) pr_c (oid, relname, relnamespace, relowner, grantor, grantee, prtype, grantable),
569569
pg_attribute a
570570
WHERE a.attrelid = pr_c.oid
@@ -586,7 +586,7 @@ CREATE VIEW column_privileges AS
586586
) pr_a (attrelid, attname, grantor, grantee, prtype, grantable),
587587
pg_class c
588588
WHERE pr_a.attrelid = c.oid
589-
AND relkind IN ('r', 'v', 'f', 'P')
589+
AND relkind IN ('r', 'v', 'f', 'p')
590590
) x,
591591
pg_namespace nc,
592592
pg_authid u_grantor,
@@ -629,7 +629,8 @@ CREATE VIEW column_udt_usage AS
629629
WHERE a.attrelid = c.oid
630630
AND a.atttypid = t.oid
631631
AND nc.oid = c.relnamespace
632-
AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'P')
632+
AND a.attnum > 0 AND NOT a.attisdropped
633+
AND c.relkind in ('r', 'v', 'f', 'p')
633634
AND pg_has_role(coalesce(bt.typowner, t.typowner), 'USAGE');
634635

635636
GRANT SELECT ON column_udt_usage TO PUBLIC;
@@ -738,7 +739,7 @@ CREATE VIEW columns AS
738739
CAST('NEVER' AS character_data) AS is_generated,
739740
CAST(null AS character_data) AS generation_expression,
740741

741-
CAST(CASE WHEN c.relkind IN ('r', 'P') OR
742+
CAST(CASE WHEN c.relkind IN ('r', 'p') OR
742743
(c.relkind IN ('v', 'f') AND
743744
pg_column_is_updatable(c.oid, a.attnum, false))
744745
THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_updatable
@@ -753,7 +754,8 @@ CREATE VIEW columns AS
753754

754755
WHERE (NOT pg_is_other_temp_schema(nc.oid))
755756

756-
AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'P')
757+
AND a.attnum > 0 AND NOT a.attisdropped
758+
AND c.relkind IN ('r', 'v', 'f', 'p')
757759

758760
AND (pg_has_role(c.relowner, 'USAGE')
759761
OR has_column_privilege(c.oid, a.attnum,
@@ -789,7 +791,7 @@ CREATE VIEW constraint_column_usage AS
789791
AND d.objid = c.oid
790792
AND c.connamespace = nc.oid
791793
AND c.contype = 'c'
792-
AND r.relkind IN ('r', 'P')
794+
AND r.relkind IN ('r', 'p')
793795
AND NOT a.attisdropped
794796

795797
UNION ALL
@@ -805,7 +807,7 @@ CREATE VIEW constraint_column_usage AS
805807
AND a.attnum = ANY (CASE c.contype WHEN 'f' THEN c.confkey ELSE c.conkey END)
806808
AND NOT a.attisdropped
807809
AND c.contype IN ('p', 'u', 'f')
808-
AND r.relkind IN ('r', 'P')
810+
AND r.relkind IN ('r', 'p')
809811

810812
) AS x (tblschema, tblname, tblowner, colname, cstrschema, cstrname)
811813

@@ -841,7 +843,7 @@ CREATE VIEW constraint_table_usage AS
841843
WHERE c.connamespace = nc.oid AND r.relnamespace = nr.oid
842844
AND ( (c.contype = 'f' AND c.confrelid = r.oid)
843845
OR (c.contype IN ('p', 'u') AND c.conrelid = r.oid) )
844-
AND r.relkind IN ('r', 'P')
846+
AND r.relkind IN ('r', 'p')
845847
AND pg_has_role(r.relowner, 'USAGE');
846848

847849
GRANT SELECT ON constraint_table_usage TO PUBLIC;
@@ -1058,7 +1060,7 @@ CREATE VIEW key_column_usage AS
10581060
AND r.oid = c.conrelid
10591061
AND nc.oid = c.connamespace
10601062
AND c.contype IN ('p', 'u', 'f')
1061-
AND r.relkind IN ('r', 'P')
1063+
AND r.relkind IN ('r', 'p')
10621064
AND (NOT pg_is_other_temp_schema(nr.oid)) ) AS ss
10631065
WHERE ss.roid = a.attrelid
10641066
AND a.attnum = (ss.x).x
@@ -1774,7 +1776,7 @@ CREATE VIEW table_constraints AS
17741776
WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace
17751777
AND c.conrelid = r.oid
17761778
AND c.contype NOT IN ('t', 'x') -- ignore nonstandard constraints
1777-
AND r.relkind IN ('r', 'P')
1779+
AND r.relkind IN ('r', 'p')
17781780
AND (NOT pg_is_other_temp_schema(nr.oid))
17791781
AND (pg_has_role(r.relowner, 'USAGE')
17801782
-- SELECT privilege omitted, per SQL standard
@@ -1804,7 +1806,7 @@ CREATE VIEW table_constraints AS
18041806
AND a.attnotnull
18051807
AND a.attnum > 0
18061808
AND NOT a.attisdropped
1807-
AND r.relkind IN ('r', 'P')
1809+
AND r.relkind IN ('r', 'p')
18081810
AND (NOT pg_is_other_temp_schema(nr.oid))
18091811
AND (pg_has_role(r.relowner, 'USAGE')
18101812
-- SELECT privilege omitted, per SQL standard
@@ -1854,7 +1856,7 @@ CREATE VIEW table_privileges AS
18541856
) AS grantee (oid, rolname)
18551857

18561858
WHERE c.relnamespace = nc.oid
1857-
AND c.relkind IN ('r', 'v', 'P')
1859+
AND c.relkind IN ('r', 'v', 'p')
18581860
AND c.grantee = grantee.oid
18591861
AND c.grantor = u_grantor.oid
18601862
AND c.prtype IN ('INSERT', 'SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER')
@@ -1898,7 +1900,7 @@ CREATE VIEW tables AS
18981900

18991901
CAST(
19001902
CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY'
1901-
WHEN c.relkind IN ('r', 'P') THEN 'BASE TABLE'
1903+
WHEN c.relkind IN ('r', 'p') THEN 'BASE TABLE'
19021904
WHEN c.relkind = 'v' THEN 'VIEW'
19031905
WHEN c.relkind = 'f' THEN 'FOREIGN TABLE'
19041906
ELSE null END
@@ -1911,7 +1913,7 @@ CREATE VIEW tables AS
19111913
CAST(nt.nspname AS sql_identifier) AS user_defined_type_schema,
19121914
CAST(t.typname AS sql_identifier) AS user_defined_type_name,
19131915

1914-
CAST(CASE WHEN c.relkind IN ('r', 'P') OR
1916+
CAST(CASE WHEN c.relkind IN ('r', 'p') OR
19151917
(c.relkind IN ('v', 'f') AND
19161918
-- 1 << CMD_INSERT
19171919
pg_relation_is_updatable(c.oid, false) & 8 = 8)
@@ -1923,7 +1925,7 @@ CREATE VIEW tables AS
19231925
FROM pg_namespace nc JOIN pg_class c ON (nc.oid = c.relnamespace)
19241926
LEFT JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON (c.reloftype = t.oid)
19251927

1926-
WHERE c.relkind IN ('r', 'v', 'f', 'P')
1928+
WHERE c.relkind IN ('r', 'v', 'f', 'p')
19271929
AND (NOT pg_is_other_temp_schema(nc.oid))
19281930
AND (pg_has_role(c.relowner, 'USAGE')
19291931
OR has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
@@ -2442,7 +2444,7 @@ CREATE VIEW view_column_usage AS
24422444
AND dt.refclassid = 'pg_catalog.pg_class'::regclass
24432445
AND dt.refobjid = t.oid
24442446
AND t.relnamespace = nt.oid
2445-
AND t.relkind IN ('r', 'v', 'f', 'P')
2447+
AND t.relkind IN ('r', 'v', 'f', 'p')
24462448
AND t.oid = a.attrelid
24472449
AND dt.refobjsubid = a.attnum
24482450
AND pg_has_role(t.relowner, 'USAGE');
@@ -2520,7 +2522,7 @@ CREATE VIEW view_table_usage AS
25202522
AND dt.refclassid = 'pg_catalog.pg_class'::regclass
25212523
AND dt.refobjid = t.oid
25222524
AND t.relnamespace = nt.oid
2523-
AND t.relkind IN ('r', 'v', 'f', 'P')
2525+
AND t.relkind IN ('r', 'v', 'f', 'p')
25242526
AND pg_has_role(t.relowner, 'USAGE');
25252527

25262528
GRANT SELECT ON view_table_usage TO PUBLIC;
@@ -2673,7 +2675,7 @@ CREATE VIEW element_types AS
26732675
a.attnum, a.atttypid, a.attcollation
26742676
FROM pg_class c, pg_attribute a
26752677
WHERE c.oid = a.attrelid
2676-
AND c.relkind IN ('r', 'v', 'f', 'c', 'P')
2678+
AND c.relkind IN ('r', 'v', 'f', 'c', 'p')
26772679
AND attnum > 0 AND NOT attisdropped
26782680

26792681
UNION ALL

src/backend/catalog/system_views.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ CREATE VIEW pg_tables AS
136136
C.relrowsecurity AS rowsecurity
137137
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
138138
LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace)
139-
WHERE C.relkind IN ('r', 'P');
139+
WHERE C.relkind IN ('r', 'p');
140140

141141
CREATE VIEW pg_matviews AS
142142
SELECT
@@ -294,7 +294,7 @@ CREATE VIEW pg_prepared_statements AS
294294
CREATE VIEW pg_seclabels AS
295295
SELECT
296296
l.objoid, l.classoid, l.objsubid,
297-
CASE WHEN rel.relkind IN ('r', 'P') THEN 'table'::text
297+
CASE WHEN rel.relkind IN ('r', 'p') THEN 'table'::text
298298
WHEN rel.relkind = 'v' THEN 'view'::text
299299
WHEN rel.relkind = 'm' THEN 'materialized view'::text
300300
WHEN rel.relkind = 'S' THEN 'sequence'::text

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201703081
56+
#define CATALOG_VERSION_NO 201703101
5757

5858
#endif

src/include/catalog/pg_class.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ DESCR("");
162162
#define RELKIND_SEQUENCE 'S' /* sequence object */
163163
#define RELKIND_TOASTVALUE 't' /* for out-of-line values */
164164
#define RELKIND_VIEW 'v' /* view */
165+
#define RELKIND_MATVIEW 'm' /* materialized view */
165166
#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */
166167
#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */
167-
#define RELKIND_MATVIEW 'm' /* materialized view */
168-
#define RELKIND_PARTITIONED_TABLE 'P' /* partitioned table */
168+
#define RELKIND_PARTITIONED_TABLE 'p' /* partitioned table */
169169

170170
#define RELPERSISTENCE_PERMANENT 'p' /* regular table */
171171
#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */
@@ -178,9 +178,10 @@ DESCR("");
178178
/* all columns are logged as replica identity */
179179
#define REPLICA_IDENTITY_FULL 'f'
180180
/*
181-
* an explicitly chosen candidate key's columns are used as identity;
182-
* will still be set if the index has been dropped, in that case it
183-
* has the same meaning as 'd'
181+
* an explicitly chosen candidate key's columns are used as replica identity.
182+
* Note this will still be set if the index has been dropped; in that case it
183+
* has the same meaning as 'd'.
184184
*/
185185
#define REPLICA_IDENTITY_INDEX 'i'
186+
186187
#endif /* PG_CLASS_H */

src/test/regress/expected/create_table.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ CREATE TABLE partitioned (
404404
SELECT relkind FROM pg_class WHERE relname = 'partitioned';
405405
relkind
406406
---------
407-
P
407+
p
408408
(1 row)
409409

410410
-- check that range partition key columns are marked NOT NULL

src/test/regress/expected/rules.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ pg_seclabels| SELECT l.objoid,
14811481
l.classoid,
14821482
l.objsubid,
14831483
CASE
1484-
WHEN (rel.relkind = ANY (ARRAY['r'::"char", 'P'::"char"])) THEN 'table'::text
1484+
WHEN (rel.relkind = ANY (ARRAY['r'::"char", 'p'::"char"])) THEN 'table'::text
14851485
WHEN (rel.relkind = 'v'::"char") THEN 'view'::text
14861486
WHEN (rel.relkind = 'm'::"char") THEN 'materialized view'::text
14871487
WHEN (rel.relkind = 'S'::"char") THEN 'sequence'::text
@@ -2171,7 +2171,7 @@ pg_tables| SELECT n.nspname AS schemaname,
21712171
FROM ((pg_class c
21722172
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
21732173
LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace)))
2174-
WHERE (c.relkind = ANY (ARRAY['r'::"char", 'P'::"char"]));
2174+
WHERE (c.relkind = ANY (ARRAY['r'::"char", 'p'::"char"]));
21752175
pg_timezone_abbrevs| SELECT pg_timezone_abbrevs.abbrev,
21762176
pg_timezone_abbrevs.utc_offset,
21772177
pg_timezone_abbrevs.is_dst

src/test/regress/expected/sanity_check.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ VACUUM;
99
\a\t
1010
SELECT relname, relhasindex
1111
FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
12-
WHERE relkind IN ('r', 'P') AND (nspname ~ '^pg_temp_') IS NOT TRUE
12+
WHERE relkind IN ('r', 'p') AND (nspname ~ '^pg_temp_') IS NOT TRUE
1313
ORDER BY relname;
1414
a|f
1515
a_star|f

src/test/regress/expected/type_sanity.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ ORDER BY 1;
464464
-- Look for illegal values in pg_class fields
465465
SELECT p1.oid, p1.relname
466466
FROM pg_class as p1
467-
WHERE relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f') OR
467+
WHERE relkind NOT IN ('r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p') OR
468468
relpersistence NOT IN ('p', 'u', 't') OR
469469
relreplident NOT IN ('d', 'n', 'f', 'i');
470470
oid | relname

src/test/regress/sql/sanity_check.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ VACUUM;
1212

1313
SELECT relname, relhasindex
1414
FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
15-
WHERE relkind IN ('r', 'P') AND (nspname ~ '^pg_temp_') IS NOT TRUE
15+
WHERE relkind IN ('r', 'p') AND (nspname ~ '^pg_temp_') IS NOT TRUE
1616
ORDER BY relname;
1717

1818
-- restore normal output mode

src/test/regress/sql/type_sanity.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ ORDER BY 1;
339339

340340
SELECT p1.oid, p1.relname
341341
FROM pg_class as p1
342-
WHERE relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f') OR
342+
WHERE relkind NOT IN ('r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p') OR
343343
relpersistence NOT IN ('p', 'u', 't') OR
344344
relreplident NOT IN ('d', 'n', 'f', 'i');
345345

0 commit comments

Comments
 (0)