Skip to content

Commit

Permalink
fix sql plan monitor rows null (#359)
Browse files Browse the repository at this point in the history
fix sql plan monitor rows null
  • Loading branch information
Teingi authored Jul 23, 2024
1 parent 16c2d52 commit d060581
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 12 additions & 6 deletions handler/gather/gather_plan_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def handle_plan_monitor_from_ob(cluster_name):
sql_plan_monitor_detail_v1 = str(sql_plan_monitor_detail_template).replace("##REPLACE_TRACE_ID##", trace_id).replace("##REPLACE_ORDER_BY##", "PLAN_LINE_ID ASC, SVR_IP, SVR_PORT, CHANGE_TS, PROCESS_NAME ASC")
sql_plan_monitor_detail_v2 = str(sql_plan_monitor_detail_template).replace("##REPLACE_TRACE_ID##", trace_id).replace("##REPLACE_ORDER_BY##", "PROCESS_NAME ASC, PLAN_LINE_ID ASC, FIRST_REFRESH_TIME ASC")

sql_plan_monitor_dfo_op = self.sql_plan_monitor_dfo_op_sql(tenant_id, plan_id, trace_id)
sql_plan_monitor_dfo_op = self.sql_plan_monitor_dfo_op_sql(tenant_id, plan_id, trace_id, svr_ip, svr_port)
full_audit_sql_by_trace_id_sql = self.full_audit_sql_by_trace_id_sql(trace_id)
plan_explain_sql = self.plan_explain_sql(tenant_id, plan_id, svr_ip, svr_port)

Expand Down Expand Up @@ -740,7 +740,7 @@ def full_audit_sql_by_trace_id_sql(self, trace_id):
sql = "select /*+ sql_audit */ %s from sys.%s where trace_id = '%s' AND " "length(client_ip) > 4 ORDER BY REQUEST_ID" % (GlobalSqlMeta().get_value(key="sql_audit_item_oracle"), self.sql_audit_name, trace_id)
return sql

def sql_plan_monitor_dfo_op_sql(self, tenant_id, plan_id, trace_id):
def sql_plan_monitor_dfo_op_sql(self, tenant_id, plan_id, trace_id, svr_ip, svr_port):
if self.tenant_mode == 'mysql':
if self.ob_major_version >= 4:
sql = (
Expand All @@ -749,6 +749,8 @@ def sql_plan_monitor_dfo_op_sql(self, tenant_id, plan_id, trace_id):
.replace("##REPLACE_PLAN_ID##", str(plan_id))
.replace("##REPLACE_TENANT_ID##", str(tenant_id))
.replace("##REPLACE_PLAN_EXPLAIN_TABLE_NAME##", self.plan_explain_name)
.replace("##REPLACE_SVR_IP##", svr_ip)
.replace("##REPLACE_SVR_PORT##", str(svr_port))
)
else:
sql = (
Expand All @@ -757,25 +759,29 @@ def sql_plan_monitor_dfo_op_sql(self, tenant_id, plan_id, trace_id):
.replace("##REPLACE_PLAN_ID##", str(plan_id))
.replace("##REPLACE_TENANT_ID##", str(tenant_id))
.replace("##REPLACE_PLAN_EXPLAIN_TABLE_NAME##", self.plan_explain_name)
.replace("##REPLACE_SVR_IP##", svr_ip)
.replace("##REPLACE_SVR_PORT##", str(svr_port))
)
else:
if self.ob_major_version >= 4:
sql = (
GlobalSqlMeta()
.get_value(key="sql_plan_monitor_dfo_op_oracle_obversion4")
str(GlobalSqlMeta().get_value(key="sql_plan_monitor_dfo_op_oracle_obversion4"))
.replace("##REPLACE_TRACE_ID##", trace_id)
.replace("##REPLACE_PLAN_ID##", str(plan_id))
.replace("##REPLACE_TENANT_ID##", str(tenant_id))
.replace("##REPLACE_PLAN_EXPLAIN_TABLE_NAME##", self.plan_explain_name)
.replace("##REPLACE_SVR_IP##", svr_ip)
.replace("##REPLACE_SVR_PORT##", str(svr_port))
)
else:
sql = (
GlobalSqlMeta()
.get_value(key="sql_plan_monitor_dfo_op_oracle")
str(GlobalSqlMeta().get_value(key="sql_plan_monitor_dfo_op_oracle"))
.replace("##REPLACE_TRACE_ID##", trace_id)
.replace("##REPLACE_PLAN_ID##", str(plan_id))
.replace("##REPLACE_TENANT_ID##", str(tenant_id))
.replace("##REPLACE_PLAN_EXPLAIN_TABLE_NAME##", self.plan_explain_name)
.replace("##REPLACE_SVR_IP##", svr_ip)
.replace("##REPLACE_SVR_PORT##", str(svr_port))
)

return sql
Expand Down
8 changes: 4 additions & 4 deletions handler/meta/sql_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def rm_value(self, key):
) plan_monitor
LEFT JOIN
(
SELECT "ROWS", PLAN_LINE_ID FROM sys.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID##
SELECT "ROWS", PLAN_LINE_ID FROM sys.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID## and ip = '##REPLACE_SVR_IP##' and port = ##REPLACE_SVR_PORT##
) plan_explain
ON
plan_monitor.PLAN_LINE_ID = plan_explain.PLAN_LINE_ID
Expand Down Expand Up @@ -316,7 +316,7 @@ def rm_value(self, key):
) plan_monitor
LEFT JOIN
(
SELECT ROWS, PLAN_LINE_ID FROM oceanbase.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID##
SELECT ROWS, PLAN_LINE_ID FROM oceanbase.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID## and ip = '##REPLACE_SVR_IP##' and port = ##REPLACE_SVR_PORT##
) plan_explain
ON
plan_monitor.PLAN_LINE_ID = plan_explain.PLAN_LINE_ID
Expand Down Expand Up @@ -648,7 +648,7 @@ def rm_value(self, key):
) plan_monitor
LEFT JOIN
(
SELECT "ROWS", PLAN_LINE_ID FROM sys.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID##
SELECT "ROWS", PLAN_LINE_ID FROM sys.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID## and svr_ip = '##REPLACE_SVR_IP##' and svr_port = ##REPLACE_SVR_PORT##
) plan_explain
ON
plan_monitor.PLAN_LINE_ID = plan_explain.PLAN_LINE_ID
Expand Down Expand Up @@ -726,7 +726,7 @@ def rm_value(self, key):
) plan_monitor
LEFT JOIN
(
SELECT ROWS, PLAN_LINE_ID FROM oceanbase.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID##
SELECT ROWS, PLAN_LINE_ID FROM oceanbase.##REPLACE_PLAN_EXPLAIN_TABLE_NAME## WHERE plan_id = ##REPLACE_PLAN_ID## AND tenant_id = ##REPLACE_TENANT_ID## and svr_ip = '##REPLACE_SVR_IP##' and svr_port = ##REPLACE_SVR_PORT##
) plan_explain
ON
plan_monitor.PLAN_LINE_ID = plan_explain.PLAN_LINE_ID
Expand Down

0 comments on commit d060581

Please sign in to comment.