Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提供数据字典和执行计划进行SQL分析 #568

Closed
12 tasks done
ColdWaterLW opened this issue Jun 1, 2022 · 0 comments
Closed
12 tasks done

提供数据字典和执行计划进行SQL分析 #568

ColdWaterLW opened this issue Jun 1, 2022 · 0 comments
Assignees
Labels
ee the problem for Enterprise Edition feature not_compatible not compatible old version ui this issue is is related to the FE
Milestone

Comments

@ColdWaterLW
Copy link
Collaborator

ColdWaterLW commented Jun 1, 2022

需求背景

  1. 在业务人员进行SQL查询时,编辑SQL可能会需要知道一些相关的信息,比如数据库下有哪些表,某张表有哪些列或索引等,这时如果有一个数据字典供其查询就会很方便。提供执行计划可以方便用户在查询之前了解即将执行的查询的性能。
  2. 在进行SQL审核时,审核人员拿到自动审核的结果,可能希望进一步了解SQL的情况或进行人工审核,这时提供SQL相关的表信息和SQL的执行计划会很有帮助

开发方案

新增http接口

URI 请求方式 功能简述
/v1/audit_plans/reports/{audit_plan_report_id}/sqls/{number}/analysis get 获取审核任务报告相关的SQL执行计划和表元数据
/v1/instances/{instance_name}/schemas/{schema_name}/tables get 获取数据库下的所有表
/v1/instances/{instance_name}/schemas/{schema_name}/tables/{table_name}/metadata get 根据给定的表获取表元数据
/v1/sql_query/explain get sql查询页面获取SQL执行计划
/v1/tasks/audits/{task_id}/sqls/{number}/analysis get 获取task(工单页面)相关的SQL执行计划和表元数据

需要变更的http接口

URI 请求方式 变更内容
/v2/audit_plans/{audit_plan_name}/reports/{audit_plan_report_id}/sqls get 返回的sql对象新增number字段,用于表明具体是哪条sql

任务拆分

  • “获取审核任务报告相关的SQL执行计划和表元数据” 接口实现 @taolx0
  • “获取数据库下的所有表” 接口实现 @taolx0
  • “根据给定的表获取表元数据” 接口实现 @taolx0
  • “sql查询页面获取SQL执行计划” 接口实现 @taolx0
  • “获取task相关的SQL执行计划和表元数据” 接口实现 @taolx0
  • 更新旧接口 @ColdWaterLW
  • 插件接口定义 @ColdWaterLW
  • mysql插件list table功能实现 @ColdWaterLW
  • mysql插件explain功能实现 @ColdWaterLW
  • mysql插件获取表元数据功能实现 @ColdWaterLW
  • 插件公共部分的代码实现 @ColdWaterLW
  • 重构插件代码 @ColdWaterLW

升级方案

sqle.audit_plan_report_sqls_v2增加number字段,执行如下存储过程

DELIMITER $$
CREATE PROCEDURE updateAuditPlanReport()
BEGIN
  DECLARE report_end_flag int DEFAULT 0;
  DECLARE last_report_id int DEFAULT 0;
  DECLARE num int DEFAULT 1;
  DECLARE val_id int(10) unsigned;
  DECLARE val_audit_plan_report_id int(10) unsigned;
  DECLARE val_number int(10) unsigned;
  DECLARE cur_report CURSOR FOR SELECT id,audit_plan_report_id,number FROM sqle.audit_plan_report_sqls_v2 WHERE number IS NULL AND deleted_at IS NULL;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET report_end_flag=1;
  
  OPEN cur_report;
  FETCH cur_report INTO val_id,val_audit_plan_report_id,val_number;
  WHILE report_end_flag <>1 DO
    IF val_audit_plan_report_id!=last_report_id THEN
      SET num=1;
      SET last_report_id=val_audit_plan_report_id;
    END IF;
    UPDATE sqle.audit_plan_report_sqls_v2
    SET number=num
    WHERE id=val_id;
    SET num=num+1;
    FETCH cur_report INTO val_id,val_audit_plan_report_id,val_number;
  END WHILE;
END; 
$$
DELIMITER ;
CALL updateAuditPlanReport();
@ColdWaterLW ColdWaterLW added ui this issue is is related to the FE feature labels Jun 1, 2022
@ColdWaterLW ColdWaterLW mentioned this issue Jun 2, 2022
@ColdWaterLW ColdWaterLW self-assigned this Jun 6, 2022
@ColdWaterLW ColdWaterLW added the not_compatible not compatible old version label Jun 10, 2022
@sjjian sjjian added the ee the problem for Enterprise Edition label Jun 13, 2022
This was referenced Jun 16, 2022
@sjjian sjjian added this to the v1.2206.0 milestone Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ee the problem for Enterprise Edition feature not_compatible not compatible old version ui this issue is is related to the FE
Projects
None yet
Development

No branches or pull requests

2 participants