diff --git a/docs/en_US/release_notes_8_1.rst b/docs/en_US/release_notes_8_1.rst index 4e1e83610..6a9246340 100644 --- a/docs/en_US/release_notes_8_1.rst +++ b/docs/en_US/release_notes_8_1.rst @@ -30,6 +30,7 @@ Housekeeping Bug fixes ********* + | `Issue #6717 `_ - Ensure that automatically created indexes should be shown in the treeview. | `Issue #6803 `_ - Fixed an issue where reading process logs throws an error when DATA_DIR is moved to a networked drive. | `Issue #6887 `_ - Fixed an issue where syntax error was not highlighting in query tool. | `Issue #6921 `_ - Fixed an issue where on entering full screen, the option label is not changed to 'Exit Full Screen' in desktop mode. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py index 61dae1630..94eafc6d7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py @@ -384,7 +384,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): """ SQL = render_template( - "/".join([self.template_path, self._NODES_SQL]), tid=tid + "/".join([self.template_path, self._NODES_SQL]), tid=tid, + show_sys_objects=self.blueprint.show_system_objects ) status, res = self.conn.execute_dict(SQL) @@ -414,7 +415,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): """ SQL = render_template( "/".join([self.template_path, self._NODES_SQL]), - tid=tid, idx=idx + tid=tid, idx=idx, + show_sys_objects=self.blueprint.show_system_objects ) status, rset = self.conn.execute_2darray(SQL) if not status: @@ -453,7 +455,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): """ res = [] SQL = render_template( - "/".join([self.template_path, self._NODES_SQL]), tid=tid + "/".join([self.template_path, self._NODES_SQL]), tid=tid, + show_sys_objects=self.blueprint.show_system_objects ) status, rset = self.conn.execute_2darray(SQL) if not status: @@ -511,7 +514,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): SQL = render_template( "/".join([self.template_path, self._PROPERTIES_SQL]), did=did, tid=tid, idx=idx, - datlastsysoid=self._DATABASE_LAST_SYSTEM_OID + datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, + show_sys_objects=self.blueprint.show_system_objects ) status, res = self.conn.execute_dict(SQL) @@ -717,7 +721,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): SQL = render_template( "/".join([self.template_path, self._PROPERTIES_SQL]), did=did, tid=tid, idx=idx, - datlastsysoid=self._DATABASE_LAST_SYSTEM_OID + datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, + show_sys_objects=self.blueprint.show_system_objects ) status, res = self.conn.execute_dict(SQL) @@ -774,7 +779,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): try: SQL, name = index_utils.get_sql( self.conn, data=data, did=did, tid=tid, idx=idx, - datlastsysoid=self._DATABASE_LAST_SYSTEM_OID) + datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, + show_sys_objects=self.blueprint.show_system_objects) if not isinstance(SQL, str): return SQL SQL = SQL.strip('\n').strip(' ') @@ -839,7 +845,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): try: sql, name = index_utils.get_sql( self.conn, data=data, did=did, tid=tid, idx=idx, - datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, mode='create') + datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, mode='create', + show_sys_objects=self.blueprint.show_system_objects) if not isinstance(sql, str): return sql sql = sql.strip('\n').strip(' ') @@ -869,7 +876,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): SQL = index_utils.get_reverse_engineered_sql( self.conn, schema=self.schema, table=self.table, did=did, tid=tid, idx=idx, datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, - add_not_exists_clause=True + add_not_exists_clause=True, + show_sys_objects=self.blueprint.show_system_objects ) return ajax_response(response=SQL) @@ -899,7 +907,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): sql, name = index_utils.get_sql( self.conn, data=data, did=did, tid=tid, idx=idx, - datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, mode='create') + datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, mode='create', + show_sys_objects=self.blueprint.show_system_objects) sql = sql.strip('\n').strip(' ') @@ -909,7 +918,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): table=self.table, did=did, tid=tid, idx=idx, datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, template_path=None, with_header=False, - add_not_exists_clause=True + add_not_exists_clause=True, + show_sys_objects=self.blueprint.show_system_objects ) drop_sql = '' @@ -1004,7 +1014,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): SQL = render_template( "/".join([self.template_path, self._PROPERTIES_SQL]), did=did, tid=tid, idx=idx, - datlastsysoid=self._DATABASE_LAST_SYSTEM_OID + datlastsysoid=self._DATABASE_LAST_SYSTEM_OID, + show_sys_objects=self.blueprint.show_system_objects ) status, res = self.conn.execute_dict(SQL) if not status: diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py index def4e8bc4..5a45a6214 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py @@ -15,6 +15,12 @@ from pgadmin.utils.ajax import internal_server_error from pgadmin.utils.exception import ObjectGone, ExecuteError from functools import wraps +AUTO_CREATE_INDEX_MSG = "-- This primary key index is automatically " \ + "generated from a constraint with an identical name.\n-- " \ + "For more details, refer to the Constraints node. Note that this type " \ + "of index is only visible \n-- when the 'Show system objects?' is set " \ + "to True in the Preferences.\n\n" + def get_template_path(f): """ @@ -233,12 +239,14 @@ def get_sql(conn, **kwargs): mode = kwargs.get('mode', None) template_path = kwargs.get('template_path', None) if_exists_flag = kwargs.get('if_exists_flag', False) + show_sys_obj = kwargs.get('show_sys_objects', False) name = data['name'] if 'name' in data else None if idx is not None: sql = render_template("/".join([template_path, 'properties.sql']), did=did, tid=tid, idx=idx, - datlastsysoid=datlastsysoid) + datlastsysoid=datlastsysoid, + show_sys_objects=show_sys_obj) status, res = conn.execute_dict(sql) if not status: @@ -300,10 +308,12 @@ def get_reverse_engineered_sql(conn, **kwargs): template_path = kwargs.get('template_path', None) with_header = kwargs.get('with_header', True) if_exists_flag = kwargs.get('add_not_exists_clause', False) + show_sys_obj = kwargs.get('show_sys_objects', False) SQL = render_template("/".join([template_path, 'properties.sql']), did=did, tid=tid, idx=idx, - datlastsysoid=datlastsysoid) + datlastsysoid=datlastsysoid, + show_sys_objects=show_sys_obj) status, res = conn.execute_dict(SQL) if not status: @@ -336,7 +346,12 @@ def get_reverse_engineered_sql(conn, **kwargs): if_exists_flag=if_exists_flag) if with_header: - sql_header = "-- Index: {0}\n\n-- ".format(data['name']) + sql_header = '' + # Add a Note if index is automatically created. + if 'conname' in data and data['conname'] is not None: + sql_header += AUTO_CREATE_INDEX_MSG + + sql_header += "-- Index: {0}\n\n-- ".format(data['name']) sql_header += render_template("/".join([template_path, 'delete.sql']), data=data, conn=conn) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/properties.sql index 270441fa6..2a67c61ac 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/properties.sql @@ -4,7 +4,7 @@ SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, (SELECT sp.spcname FROM pg_catalog.pg_database dtb JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid WHERE dtb.oid = {{ did }}::oid) - END as spcname, + END as spcname, conname, tab.relname as tabname, indclass, con.oid AS conoid, CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description ELSE des.description END AS description, @@ -29,6 +29,8 @@ FROM pg_catalog.pg_index idx LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=cls.oid AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_catalog.pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0 AND desp.classoid='pg_constraint'::regclass) WHERE indrelid = {{tid}}::OID +{% if not show_sys_objects %} AND conname is NULL +{% endif %} {% if idx %}AND cls.oid = {{idx}}::OID {% endif %} ORDER BY cls.relname diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/13_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/13_plus/properties.sql index e42d50c6b..6cafb2357 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/13_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/13_plus/properties.sql @@ -4,7 +4,7 @@ SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, (SELECT sp.spcname FROM pg_catalog.pg_database dtb JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid WHERE dtb.oid = {{ did }}::oid) - END as spcname, + END as spcname, conname, tab.relname as tabname, indclass, con.oid AS conoid, CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description ELSE des.description END AS description, @@ -30,6 +30,8 @@ FROM pg_catalog.pg_index idx LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=cls.oid AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_catalog.pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0 AND desp.classoid='pg_constraint'::regclass) WHERE indrelid = {{tid}}::OID +{% if not show_sys_objects %} AND conname is NULL +{% endif %} {% if idx %}AND cls.oid = {{idx}}::OID {% endif %} ORDER BY cls.relname diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/15_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/15_plus/properties.sql index e8bf148ae..71613bea0 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/15_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/15_plus/properties.sql @@ -4,7 +4,7 @@ SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, (SELECT sp.spcname FROM pg_catalog.pg_database dtb JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid WHERE dtb.oid = {{ did }}::oid) - END as spcname, + END as spcname, conname, tab.relname as tabname, indclass, con.oid AS conoid, CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description ELSE des.description END AS description, @@ -30,6 +30,8 @@ FROM pg_catalog.pg_index idx LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=cls.oid AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_catalog.pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0 AND desp.classoid='pg_constraint'::regclass) WHERE indrelid = {{tid}}::OID +{% if not show_sys_objects %} AND conname is NULL +{% endif %} {% if idx %}AND cls.oid = {{idx}}::OID {% endif %} ORDER BY cls.relname diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/count.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/count.sql index 2f375997b..ba340c8cd 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/count.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/count.sql @@ -4,4 +4,7 @@ FROM pg_catalog.pg_index idx LEFT JOIN pg_catalog.pg_depend dep ON (dep.classid = cls.tableoid AND dep.objid = cls.oid AND dep.refobjsubid = '0' AND dep.refclassid=(SELECT oid FROM pg_catalog.pg_class WHERE relname='pg_constraint') AND dep.deptype='i') LEFT OUTER JOIN pg_catalog.pg_constraint con ON (con.tableoid = dep.refclassid AND con.oid = dep.refobjid) WHERE indrelid = {{tid}}::OID +{### To show system objects ###} +{% if not showsysobj %} AND conname is NULL +{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/nodes.sql index 621d41d1a..0af057680 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/nodes.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/nodes.sql @@ -12,7 +12,9 @@ FROM pg_catalog.pg_index idx LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=cls.oid AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_catalog.pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0 AND desp.classoid='pg_constraint'::regclass) WHERE indrelid = {{tid}}::OID +{% if not show_sys_objects %} AND conname is NULL +{% endif %} {% if idx %} AND cls.oid = {{ idx }}::OID {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/properties.sql index 37dace967..23214d8bd 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/properties.sql @@ -4,7 +4,7 @@ SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, (SELECT sp.spcname FROM pg_catalog.pg_database dtb JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid WHERE dtb.oid = {{ did }}::oid) - END as spcname, + END as spcname, conname, tab.relname as tabname, indclass, con.oid AS conoid, CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description ELSE des.description END AS description, @@ -23,6 +23,8 @@ FROM pg_catalog.pg_index idx LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=cls.oid AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_catalog.pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0 AND desp.classoid='pg_constraint'::regclass) WHERE indrelid = {{tid}}::OID +{% if not show_sys_objects %} AND conname is NULL +{% endif %} {% if idx %}AND cls.oid = {{idx}}::OID {% endif %} ORDER BY cls.relname