Improved performance while fetching edit types for each column.

Edit types query is executed for every column when open properties dialog of the table.
Change the logic to fetch the edit types for all the distinct column types used in the table at once.
This commit is contained in:
Aditya Toshniwal 2019-12-16 18:26:22 +05:30 committed by Akshay Joshi
parent 1f5ccd1c3b
commit ded71be73f
4 changed files with 37 additions and 24 deletions

View File

@ -717,7 +717,10 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
column_utils.type_formatter(data['cltype'])
# We will add table & schema as well
data = column_utils.column_formatter(self.conn, tid, clid, data)
# Passing edit_types_list param so that it does not fetch
# edit types. It is not required here.
data = column_utils.column_formatter(self.conn, tid, clid,
data, [])
SQL, name = self.get_sql(scid, tid, None, data, is_sql=True)
if not isinstance(SQL, (str, unicode)):

View File

@ -64,7 +64,8 @@ def get_parent(conn, tid, template_path=None):
@get_template_path
def column_formatter(conn, tid, clid, data, template_path=None):
def column_formatter(conn, tid, clid, data, edit_types_list=None,
template_path=None):
"""
This function will return formatted output of query result
as per client model format for column node
@ -144,25 +145,17 @@ def column_formatter(conn, tid, clid, data, template_path=None):
# we will send filtered types related to current type
type_id = data['atttypid']
SQL = render_template("/".join([template_path, 'is_referenced.sql']),
tid=tid, clid=clid)
status, is_reference = conn.execute_scalar(SQL)
edit_types_list = list()
# We will need present type in edit mode
edit_types_list.append(data['cltype'])
if int(is_reference) == 0:
if edit_types_list is None:
edit_types_list = []
SQL = render_template("/".join([template_path,
'edit_mode_types.sql']),
type_id=type_id)
status, rset = conn.execute_2darray(SQL)
edit_types_list = [row['typname'] for row in rset['rows']]
for row in rset['rows']:
edit_types_list.append(row['typname'])
data['edit_types'] = edit_types_list
# We will need present type in edit mode
edit_types_list.append(data['cltype'])
data['edit_types_list'] = edit_types_list
data['cltype'] = DataTypeReader.parse_type_name(data['cltype'])
@ -191,9 +184,10 @@ def get_formatted_columns(conn, tid, data, other_columns,
raise Exception(res)
all_columns = res['rows']
edit_types = {}
# Add inherited from details from other columns - type, table
for col in all_columns:
edit_types[col['atttypid']] = []
for other_col in other_columns:
if col['name'] == other_col['name']:
col['inheritedfrom' + table_or_type] = \
@ -202,8 +196,17 @@ def get_formatted_columns(conn, tid, data, other_columns,
data['columns'] = all_columns
if 'columns' in data and len(data['columns']) > 0:
SQL = render_template("/".join([template_path,
'edit_mode_types_multi.sql']),
type_ids=",".join(map(lambda x: str(x),
edit_types.keys())))
status, res = conn.execute_2darray(SQL)
for row in res['rows']:
edit_types[row['main_oid']] = row['edit_types']
for column in data['columns']:
column_formatter(conn, tid, column['attnum'], column)
column_formatter(conn, tid, column['attnum'], column,
edit_types[col['atttypid']])
return data

View File

@ -0,0 +1,13 @@
SELECT t.main_oid, ARRAY_AGG(t.typname) as edit_types
FROM
(SELECT pc.castsource AS main_oid, format_type(tt.oid,NULL) AS typname
FROM pg_type tt
JOIN pg_cast pc ON tt.oid=pc.casttarget
WHERE pc.castsource IN ({{type_ids}})
AND pc.castcontext IN ('i', 'a')
UNION
SELECT tt.typbasetype AS main_oid, format_type(tt.oid,NULL) AS typname
FROM pg_type tt
WHERE tt.typbasetype IN ({{type_ids}})
) t
GROUP BY t.main_oid;

View File

@ -1,6 +0,0 @@
SELECT COUNT(1)
FROM pg_depend dep
JOIN pg_class cl ON dep.classid=cl.oid AND relname='pg_rewrite'
WHERE refobjid= {{tid}}::oid
AND classid='pg_class'::regclass
AND refobjsubid= {{clid|qtLiteral}};