Add DISTINCT to information schema usage views
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 21 Apr 2021 09:54:47 +0000 (11:54 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 21 Apr 2021 09:54:47 +0000 (11:54 +0200)
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.)

src/backend/catalog/information_schema.sql
src/include/catalog/catversion.h

index 0f2c1833e9f36a61781e31eb8d461ea32eb4d00e..11d9dd60c20898c8fdd9d2365c3a61862d5c1ac1 100644 (file)
@@ -406,7 +406,8 @@ GRANT SELECT ON character_sets TO PUBLIC;
  */
 
 CREATE VIEW check_constraint_routine_usage AS
-    SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog,
+    SELECT DISTINCT
+           CAST(current_database() AS sql_identifier) AS constraint_catalog,
            CAST(nc.nspname AS sql_identifier) AS constraint_schema,
            CAST(c.conname AS sql_identifier) AS constraint_name,
            CAST(current_database() AS sql_identifier) AS specific_catalog,
@@ -505,7 +506,8 @@ GRANT SELECT ON collation_character_set_applicability TO PUBLIC;
  */
 
 CREATE VIEW column_column_usage AS
-    SELECT CAST(current_database() AS sql_identifier) AS table_catalog,
+    SELECT DISTINCT
+           CAST(current_database() AS sql_identifier) AS table_catalog,
            CAST(n.nspname AS sql_identifier) AS table_schema,
            CAST(c.relname AS sql_identifier) AS table_name,
            CAST(ac.attname AS sql_identifier) AS column_name,
@@ -1325,7 +1327,8 @@ GRANT SELECT ON role_column_grants TO PUBLIC;
  */
 
 CREATE VIEW routine_column_usage AS
-    SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
+    SELECT DISTINCT
+           CAST(current_database() AS sql_identifier) AS specific_catalog,
            CAST(np.nspname AS sql_identifier) AS specific_schema,
            CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
            CAST(current_database() AS sql_identifier) AS routine_catalog,
@@ -1434,7 +1437,8 @@ GRANT SELECT ON role_routine_grants TO PUBLIC;
  */
 
 CREATE VIEW routine_routine_usage AS
-    SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
+    SELECT DISTINCT
+           CAST(current_database() AS sql_identifier) AS specific_catalog,
            CAST(np.nspname AS sql_identifier) AS specific_schema,
            CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
            CAST(current_database() AS sql_identifier) AS routine_catalog,
@@ -1462,7 +1466,8 @@ GRANT SELECT ON routine_routine_usage TO PUBLIC;
  */
 
 CREATE VIEW routine_sequence_usage AS
-    SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
+    SELECT DISTINCT
+           CAST(current_database() AS sql_identifier) AS specific_catalog,
            CAST(np.nspname AS sql_identifier) AS specific_schema,
            CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
            CAST(current_database() AS sql_identifier) AS routine_catalog,
@@ -1493,7 +1498,8 @@ GRANT SELECT ON routine_sequence_usage TO PUBLIC;
  */
 
 CREATE VIEW routine_table_usage AS
-    SELECT CAST(current_database() AS sql_identifier) AS specific_catalog,
+    SELECT DISTINCT
+           CAST(current_database() AS sql_identifier) AS specific_catalog,
            CAST(np.nspname AS sql_identifier) AS specific_schema,
            CAST(nameconcatoid(p.proname, p.oid) AS sql_identifier) AS specific_name,
            CAST(current_database() AS sql_identifier) AS routine_catalog,
index a185f0c313c108b49737330fc34b078cdca42b8d..c32c5b2731a6fb42f42864e50bc10ecb45ee1fb1 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     202104201
+#define CATALOG_VERSION_NO     202104211
 
 #endif