Skip to content

Commit d84ffff

Browse files
committed
Add DISTINCT to information schema usage views
Since pg_depend can contain duplicate entries, we need to eliminate those in information schema views that build on pg_depend, using DISTINCT. Some of the older views already did that correctly, but some of the more recently added ones didn't. (In some of these views, it might not be possible to reproduce the issue because of how the implementation happens to deduplicate dependencies while recording them, but it seems better to keep this consistent in all cases.)
1 parent 39d0928 commit d84ffff

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/backend/catalog/information_schema.sql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ GRANT SELECT ON character_sets TO PUBLIC;
406406
*/
407407

408408
CREATE VIEW check_constraint_routine_usage AS
409-
SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
409+
SELECT DISTINCT
410+
CAST(current_database() AS sql_identifier) AS constraint_catalog,
410411
CAST(nc.nspname AS sql_identifier) AS constraint_schema,
411412
CAST(c.conname AS sql_identifier) AS constraint_name,
412413
CAST(current_database() AS sql_identifier) AS specific_catalog,
@@ -505,7 +506,8 @@ GRANT SELECT ON collation_character_set_applicability TO PUBLIC;
505506
*/
506507

507508
CREATE VIEW column_column_usage AS
508-
SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
509+
SELECT DISTINCT
510+
CAST(current_database() AS sql_identifier) AS table_catalog,
509511
CAST(n.nspname AS sql_identifier) AS table_schema,
510512
CAST(c.relname AS sql_identifier) AS table_name,
511513
CAST(ac.attname AS sql_identifier) AS column_name,
@@ -1325,7 +1327,8 @@ GRANT SELECT ON role_column_grants TO PUBLIC;
13251327
*/
13261328

13271329
CREATE VIEW routine_column_usage AS
1328-
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
1330+
SELECT DISTINCT
1331+
CAST(current_database() AS sql_identifier) AS specific_catalog,
13291332
CAST(np.nspname AS sql_identifier) AS specific_schema,
13301333
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
13311334
CAST(current_database() AS sql_identifier) AS routine_catalog,
@@ -1434,7 +1437,8 @@ GRANT SELECT ON role_routine_grants TO PUBLIC;
14341437
*/
14351438

14361439
CREATE VIEW routine_routine_usage AS
1437-
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
1440+
SELECT DISTINCT
1441+
CAST(current_database() AS sql_identifier) AS specific_catalog,
14381442
CAST(np.nspname AS sql_identifier) AS specific_schema,
14391443
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
14401444
CAST(current_database() AS sql_identifier) AS routine_catalog,
@@ -1462,7 +1466,8 @@ GRANT SELECT ON routine_routine_usage TO PUBLIC;
14621466
*/
14631467

14641468
CREATE VIEW routine_sequence_usage AS
1465-
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
1469+
SELECT DISTINCT
1470+
CAST(current_database() AS sql_identifier) AS specific_catalog,
14661471
CAST(np.nspname AS sql_identifier) AS specific_schema,
14671472
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
14681473
CAST(current_database() AS sql_identifier) AS routine_catalog,
@@ -1493,7 +1498,8 @@ GRANT SELECT ON routine_sequence_usage TO PUBLIC;
14931498
*/
14941499

14951500
CREATE VIEW routine_table_usage AS
1496-
SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
1501+
SELECT DISTINCT
1502+
CAST(current_database() AS sql_identifier) AS specific_catalog,
14971503
CAST(np.nspname AS sql_identifier) AS specific_schema,
14981504
CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
14991505
CAST(current_database() AS sql_identifier) AS routine_catalog,

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 202104201
56+
#define CATALOG_VERSION_NO 202104211
5757

5858
#endif

0 commit comments

Comments
 (0)