diff --git a/plugins/data_query/sql_mysql.py b/plugins/data_query/sql_mysql.py index 19df8bd09..68ac3c6ad 100755 --- a/plugins/data_query/sql_mysql.py +++ b/plugins/data_query/sql_mysql.py @@ -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) + diff --git a/plugins/data_query/static/js/app.js b/plugins/data_query/static/js/app.js index 07648cb98..b97fe5558 100755 --- a/plugins/data_query/static/js/app.js +++ b/plugins/data_query/static/js/app.js @@ -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 = ''; + t += ''+items[i]['table_schema']+''; + t += ''+items[i]['table_name']+''; + t += ''+items[i]['redundant_index_name']+''; + t += ''+items[i]['redundant_index_columns']+''; + t += ''+items[i]['sql_drop_index']+''; + t += ''; + 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: '
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
数据库名表名冗余索引名冗余索引列名删除冗余索引SQL
\ +
', + success:function(i,l){ + renderSQL(); + } + }); +} + function mysqlCommonFunc(){ $('#mysql_common').click(function(){ layer.open({ @@ -432,8 +481,9 @@ function mysqlCommonFunc(){ closeBtn: 1, shadeClose: false, content: '
\ - \ - \ + \ + \ + \
', 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(); + }); } }); });