pull/632/head
Mr Chen 5 months ago
parent 00002a8540
commit d3b3b526db
  1. 23
      plugins/data_query/sql_mysql.py
  2. 58
      plugins/data_query/static/js/app.js

@ -363,6 +363,24 @@ class nosqlMySQLCtr():
return mw.returnData(False, "查询失败!")
return mw.returnData(True, 'ok', data)
# 查看重复或冗余的索引
def getRedundantIndexes(self, args):
sid = args['sid']
my_instance = self.getInstanceBySid(sid).conn()
if my_instance is False:
return mw.returnData(False,'无法链接')
is_performance_schema = my_instance.find("SELECT @@performance_schema")
if is_performance_schema["@@performance_schema"] == 0:
msg = "performance_schema参数未开启。\n"
msg += "在my.cnf配置文件里添加performance_schema=1,并重启mysqld进程生效。"
return mw.returnData(False, msg)
data = my_instance.query("select table_schema,table_name,redundant_index_name,redundant_index_columns,sql_drop_index from sys.schema_redundant_indexes")
if data is None:
return mw.returnData(False, "查询失败!")
# print(data)
return mw.returnData(True, 'ok', data)
# ---------------------------------- run ----------------------------------
# 获取 mysql 列表
def get_db_list(args):
@ -400,6 +418,11 @@ def get_net_list(args):
t = nosqlMySQLCtr()
return t.getNetList(args)
# 查看重复或冗余的索引
def get_redundant_indexes(args):
t = nosqlMySQLCtr()
return t.getRedundantIndexes(args)

@ -423,6 +423,55 @@ function mysqlCommonFuncMysqlNet(){
});
}
function mysqlCommonFuncRedundantIndexes(){
function renderSQL(){
var sid = mysqlGetSid();
myPostCBN('get_redundant_indexes',{'sid':sid} ,function(rdata){
var data = rdata.data;
if (data['status']){
var items = data.data;
var tbody = '';
for (var i = 0; i < items.length; i++) {
var t = '<tr>';
t += '<td>'+items[i]['table_schema']+'</td>';
t += '<td>'+items[i]['table_name']+'</td>';
t += '<td>'+items[i]['redundant_index_name']+'</td>';
t += '<td>'+items[i]['redundant_index_columns']+'</td>';
t += '<td>'+items[i]['sql_drop_index']+'</td>';
t += '</tr>';
tbody += t;
}
$('#redundant_indexes tbody').html(tbody);
} else {
layer.msg(data.msg,{icon:2});
}
});
}
layer.open({
type: 1,
title: "查看重复或冗余的索引",
area: ['1100px', '400px'],
closeBtn: 1,
shadeClose: false,
content: '<div class="bt-form pd20 divtable taskdivtable">\
<table class="table table-hover" id="redundant_indexes">\
<thead>\
<th style="width:100px;">数据库名</th>\
<th style="width:50px;">表名</th>\
<th style="width:50px;">冗余索引名</th>\
<th style="width:50px;">冗余索引列名</th>\
<th style="width:300px;">删除冗余索引SQL</th>\
</thead>\
<tbody></tbody>\
</table>\
</div>',
success:function(i,l){
renderSQL();
}
});
}
function mysqlCommonFunc(){
$('#mysql_common').click(function(){
layer.open({
@ -432,8 +481,9 @@ function mysqlCommonFunc(){
closeBtn: 1,
shadeClose: false,
content: '<div class="bt-form pd20">\
<button id="mysql_top_nsql" type="button" class="btn btn-default btn-sm">查询执行次数最频繁的前N条SQL语句</button>\
<button id="mysql_net_stat" type="button" class="btn btn-default btn-sm">MySQL服务器的QPS/TPS/网络带宽指标</button>\
<button style="margin-bottom: 8px;" id="mysql_top_nsql" type="button" class="btn btn-default btn-sm">查询执行次数最频繁的前N条SQL语句</button>\
<button style="margin-bottom: 8px;" id="mysql_net_stat" type="button" class="btn btn-default btn-sm">MySQL服务器的QPS/TPS/网络带宽指标</button>\
<button style="margin-bottom: 8px;" id="mysql_redundant_indexes" type="button" class="btn btn-default btn-sm">查看重复或冗余的索引</button>\
</div>',
success:function(i,l){
$('#mysql_top_nsql').click(function(){
@ -443,6 +493,10 @@ function mysqlCommonFunc(){
$('#mysql_net_stat').click(function(){
mysqlCommonFuncMysqlNet();
});
$('#mysql_redundant_indexes').click(function(){
mysqlCommonFuncRedundantIndexes();
});
}
});
});

Loading…
Cancel
Save