Fixed an issue where indexes showing TABLESPACE pg_default for partition SQL, which should not be shown. 

refs #6329
This commit is contained in:
Rahul Shirsat 2021-04-27 11:54:56 +05:30 committed by Akshay Joshi
parent 5a302684f7
commit f5ef022ef5
3 changed files with 14 additions and 2 deletions

View File

@ -1,4 +1,5 @@
SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name,
(SELECT (CASE WHEN count(i.inhrelid) > 0 THEN true ELSE false END) FROM pg_inherits i WHERE i.inhrelid = cls.oid) as is_inherited
FROM pg_catalog.pg_index idx FROM pg_catalog.pg_index idx
JOIN pg_catalog.pg_class cls ON cls.oid=indexrelid JOIN pg_catalog.pg_class cls ON cls.oid=indexrelid
JOIN pg_catalog.pg_class tab ON tab.oid=indrelid JOIN pg_catalog.pg_class tab ON tab.oid=indrelid

View File

@ -1,6 +1,6 @@
SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, indisclustered, SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, indisclustered,
indisvalid, indisunique, indisprimary, n.nspname,indnatts,cls.reltablespace AS spcoid, indisvalid, indisunique, indisprimary, n.nspname,indnatts,cls.reltablespace AS spcoid,
CASE WHEN length(spcname::text) > 0 THEN spcname ELSE CASE WHEN (length(spcname::text) > 0 OR cls.relkind = 'I') THEN spcname ELSE
(SELECT sp.spcname FROM pg_catalog.pg_database dtb (SELECT sp.spcname FROM pg_catalog.pg_database dtb
JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid) WHERE dtb.oid = {{ did }}::oid)
@ -9,6 +9,7 @@ SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey,
CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description
ELSE des.description END AS description, ELSE des.description END AS description,
pg_catalog.pg_get_expr(indpred, indrelid, true) as indconstraint, contype, condeferrable, condeferred, amname, pg_catalog.pg_get_expr(indpred, indrelid, true) as indconstraint, contype, condeferrable, condeferred, amname,
(SELECT (CASE WHEN count(i.inhrelid) > 0 THEN true ELSE false END) FROM pg_inherits i WHERE i.inhrelid = cls.oid) as is_inherited,
substring(pg_catalog.array_to_string(cls.reloptions, ',') from 'fillfactor=([0-9]*)') AS fillfactor substring(pg_catalog.array_to_string(cls.reloptions, ',') from 'fillfactor=([0-9]*)') AS fillfactor
{% if datlastsysoid %}, (CASE WHEN cls.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_idx {% endif %} {% if datlastsysoid %}, (CASE WHEN cls.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_idx {% endif %}
FROM pg_catalog.pg_index idx FROM pg_catalog.pg_index idx

View File

@ -703,6 +703,12 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
from pgadmin.browser.server_groups.servers.databases.schemas. \ from pgadmin.browser.server_groups.servers.databases.schemas. \
tables.indexes import utils as index_utils tables.indexes import utils as index_utils
for row in rset['rows']: for row in rset['rows']:
# Do not include inherited indexes as those are automatically
# created by postgres. If index is inherited, exclude it
# from main sql
if 'is_inherited' in row and row['is_inherited'] is True:
continue
index_sql = index_utils.get_reverse_engineered_sql( index_sql = index_utils.get_reverse_engineered_sql(
self.conn, schema=schema, table=table, did=did, tid=tid, self.conn, schema=schema, table=table, did=did, tid=tid,
idx=row['oid'], datlastsysoid=self.datlastsysoid, idx=row['oid'], datlastsysoid=self.datlastsysoid,
@ -943,6 +949,10 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
# Add into partition sql to partition array # Add into partition sql to partition array
partition_sql_arr.append(partition_main_sql) partition_sql_arr.append(partition_main_sql)
# Get Reverse engineered sql for index
self._get_resql_for_index(did, row['oid'], partition_sql_arr,
json_resp, schema, table)
# Get Reverse engineered sql for ROW SECURITY POLICY # Get Reverse engineered sql for ROW SECURITY POLICY
self._get_resql_for_row_security_policy(scid, row['oid'], self._get_resql_for_row_security_policy(scid, row['oid'],
json_resp, json_resp,