From 76024526596163c5dcddaf0367eefec1d57b6634 Mon Sep 17 00:00:00 2001 From: Umar Farooq Ghumman Date: Tue, 21 Jan 2025 15:27:12 -0600 Subject: [PATCH] QueryProfiler - Tooltip display for opeartors that produce variable length data --- verticapy/performance/vertica/qprof.py | 59 ++++++++++++++++++- .../performance/vertica/qprof_utility.py | 1 + verticapy/performance/vertica/tree.py | 8 ++- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/verticapy/performance/vertica/qprof.py b/verticapy/performance/vertica/qprof.py index 562ad2f9b..929ad8e4b 100755 --- a/verticapy/performance/vertica/qprof.py +++ b/verticapy/performance/vertica/qprof.py @@ -1460,6 +1460,8 @@ def _v_table_dict() -> dict: "projection_columns": "v_catalog", "resource_acquisitions": "v_monitor", "resource_pools": "v_catalog", + "dc_plan_step_properties": "v_internal", + "dc_plan_steps": "v_internal", } @staticmethod @@ -2881,13 +2883,14 @@ def _get_metric_val(self) -> tuple: title="Getting the metrics for each operator.", method="fetchall", ) + res = self._get_ool_metric(res) metric_value_op = {} for me in res: if me[0] not in metric_value_op: metric_value_op[me[0]] = {} if me[2] not in metric_value_op[me[0]]: metric_value_op[me[0]][me[2]] = {} - for idx, col in enumerate(cols): + for idx, col in enumerate(cols + ["ool"]): current_metric = me[3 + idx] if not isinstance(current_metric, NoneType): if current_metric == int(current_metric): @@ -2897,7 +2900,6 @@ def _get_metric_val(self) -> tuple: else: current_metric = -1 metric_value_op[me[0]][me[2]][col] = current_metric - # Summary. query = self.get_qexecution_report(granularity=2, genSQL=True) res = _executeSQL( @@ -2926,6 +2928,59 @@ def _get_metric_val(self) -> tuple: # Returning the metric. return metric_value_op, metric_value + def _get_ool_metric(self, list_of_metrics): + for i, data in enumerate(list_of_metrics): + path_id = data[0] + baseplan_id = data[1] + operator = data[2] + + query = f""" + SELECT + ps.path_id, + ps.baseplan_id, + ps.step_type AS operator_name, + MAX(CASE WHEN LOWER(pp.property_name) LIKE '%ool%' THEN 1 ELSE 0 END) AS has_ool + FROM + v_internal.dc_plan_step_properties pp + JOIN + v_internal.dc_plan_steps ps + ON + pp.transaction_id = ps.transaction_id AND + pp.statement_id = ps.statement_id AND + pp.plan_id = ps.plan_id AND + pp.step_key = ps.step_key AND + pp.node_name = ps.node_name + WHERE + pp.transaction_id = {self.transaction_id} AND + pp.statement_id = {self.statement_id} AND + ps.path_id = {path_id} AND + ps.baseplan_id = {baseplan_id} AND + ps.step_type = '{operator}' + GROUP BY + ps.path_id, + ps.baseplan_id, + ps.step_type + ORDER BY + ps.path_id, + ps.baseplan_id, + ps.step_type; + """ + query = self._replace_schema_in_query(query) + try: + res = _executeSQL( + query, + title="Getting the corresponding query", + method="fetchall", + ) + if res: + list_of_metrics[i].append(res[0][3]) + else: + list_of_metrics[i].append(None) + except: + res = [] + + return list_of_metrics + def _get_all_op(self) -> list[str]: """ Returns the input ``transaction`` diff --git a/verticapy/performance/vertica/qprof_utility.py b/verticapy/performance/vertica/qprof_utility.py index babda60ec..391b098a7 100644 --- a/verticapy/performance/vertica/qprof_utility.py +++ b/verticapy/performance/vertica/qprof_utility.py @@ -397,6 +397,7 @@ def _get_metrics_name(metric: str, inv: bool = False) -> str: "rows_processed_sip": "Rows processed by SIPs expression", "total_rows_read_join_sort": "Total rows read in join sort", "total_rows_read_sort": "Total rows read in sort", + "ool": "Produces variable length data", } if inv: look_up_table_inv = {v: k for k, v in look_up_table.items()} diff --git a/verticapy/performance/vertica/tree.py b/verticapy/performance/vertica/tree.py index f9ea0715d..691123f82 100644 --- a/verticapy/performance/vertica/tree.py +++ b/verticapy/performance/vertica/tree.py @@ -398,6 +398,7 @@ def _set_style(self, d: dict) -> None: "proc_rows", "prod_rows", "thread_count", + "ool", ] self.style = d @@ -722,7 +723,12 @@ def _format_metrics(self, path_id: int) -> str: else: me_val_str = format(round(me_val_str, 3), ",") metric_name = QprofUtility._get_metrics_name(me) - info += f" - {metric_name}: {me_val_str}\n" + if not (me == "ool" and (me_val_str != "1")): + # Skipping if ool is not True + if me == "ool" and me_val_str == "1": + info += f" - {metric_name}: True\n" + else: + info += f" - {metric_name}: {me_val_str}\n" if len(info) > 0 and info[-1] == "\n": info = info[:-1] return info