我的编程空间,编程开发者的网络收藏夹
学习永远不晚

Percona 5.5如何定位未使用的索引

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

Percona 5.5如何定位未使用的索引

这篇文章主要为大家展示了“Percona 5.5如何定位未使用的索引”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Percona 5.5如何定位未使用的索引”这篇文章吧。

打开userstat参数,然后让MySQL运行一段时间。
之后可以在INFORMATION_SCHEMA.INDEX_STATISTICS表中查询到索引的使用频率。

  1. mysql> show global variables like '%users%';

  2. +---------------+-------+

  3. | Variable_name | Value |

  4. +---------------+-------+

  5. | userstat | OFF |

  6. +---------------+-------+

  7. 1 row in set (0.00 sec)


  8. mysql> select * from information_schema.index_statistics;

  9. Empty set (0.00 sec)


  10. mysql> set global userstat=1;

  11. Query OK, 0 rows affected (0.00 sec)


  12. mysql> show global variables like '%users%';

  13. +---------------+-------+

  14. | Variable_name | Value |

  15. +---------------+-------+

  16. | userstat | ON |

  17. +---------------+-------+

  18. 1 row in set (0.00 sec)


  19. mysql> select * from information_schema.index_statistics;

  20. Empty set (0.00 sec)


  21. mysql> explain select * from emp where hiredate > '1982-01-01' and deptno = 20;

  22. +----+-------------+-------+-------+---------------------------+------------------+---------+------+------+-------------+

  23. | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

  24. +----+-------------+-------+-------+---------------------------+------------------+---------+------+------+-------------+

  25. | 1 | SIMPLE | emp | range | idx_date_sal_job,idx_date | idx_date_sal_job | 4 | NULL | 3 | Using where |

  26. +----+-------------+-------+-------+---------------------------+------------------+---------+------+------+-------------+

  27. 1 row in set (0.00 sec)


  28. mysql> select * from information_schema.index_statistics;

  29. Empty set (0.00 sec)


  30. mysql> select * from emp where hiredate > '1982-01-01' and deptno = 20;

  31. +-------+-------+---------+------+---------------------+------+------+--------+

  32. | empno | ename | job | mgr | hiredate | sal | comm | deptno |

  33. +-------+-------+---------+------+---------------------+------+------+--------+

  34. | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |

  35. | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |

  36. +-------+-------+---------+------+---------------------+------+------+--------+

  37. 2 rows in set (0.00 sec)


  38. mysql> select * from information_schema.index_statistics;

  39. +--------------+------------+------------------+-----------+

  40. | TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ |

  41. +--------------+------------+------------------+-----------+

  42. | test | emp | idx_date_sal_job | 3 |

  43. +--------------+------------+------------------+-----------+

  44. 1 row in set (0.04 sec)


  45. mysql> select * from emp;

  46. +-------+--------+-----------+------+---------------------+------+------+--------+

  47. | empno | ename | job | mgr | hiredate | sal | comm | deptno |

  48. +-------+--------+-----------+------+---------------------+------+------+--------+

  49. | 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800 | NULL | 20 |

  50. | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600 | 300 | 30 |

  51. | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 500 | 30 |

  52. | 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975 | NULL | 20 |

  53. | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250 | 1400 | 30 |

  54. | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850 | NULL | 30 |

  55. | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450 | NULL | 10 |

  56. | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |

  57. | 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000 | NULL | 10 |

  58. | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500 | 0 | 30 |

  59. | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |

  60. | 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950 | NULL | 30 |

  61. | 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000 | NULL | 20 |

  62. | 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300 | NULL | 10 |

  63. +-------+--------+-----------+------+---------------------+------+------+--------+

  64. 14 rows in set (0.00 sec)


  65. mysql> select * from information_schema.index_statistics;

  66. +--------------+------------+------------------+-----------+

  67. | TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ |

  68. +--------------+------------+------------------+-----------+

  69. | test | emp | PRIMARY | 14 |

  70. | test | emp | idx_date_sal_job | 3 |

  71. +--------------+------------+------------------+-----------+

  72. 2 rows in set (0.00 sec)


  73. mysql> select * from emp where hiredate > '1982-01-01' and deptno = 20;

  74. +-------+-------+---------+------+---------------------+------+------+--------+

  75. | empno | ename | job | mgr | hiredate | sal | comm | deptno |

  76. +-------+-------+---------+------+---------------------+------+------+--------+

  77. | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |

  78. | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |

  79. +-------+-------+---------+------+---------------------+------+------+--------+

  80. 2 rows in set (0.00 sec)


  81. mysql> select * from emp;

  82. +-------+--------+-----------+------+---------------------+------+------+--------+

  83. | empno | ename | job | mgr | hiredate | sal | comm | deptno |

  84. +-------+--------+-----------+------+---------------------+------+------+--------+

  85. | 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800 | NULL | 20 |

  86. | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600 | 300 | 30 |

  87. | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 500 | 30 |

  88. | 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975 | NULL | 20 |

  89. | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250 | 1400 | 30 |

  90. | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850 | NULL | 30 |

  91. | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450 | NULL | 10 |

  92. | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |

  93. | 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000 | NULL | 10 |

  94. | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500 | 0 | 30 |

  95. | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |

  96. | 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950 | NULL | 30 |

  97. | 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000 | NULL | 20 |

  98. | 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300 | NULL | 10 |

  99. +-------+--------+-----------+------+---------------------+------+------+--------+

  100. 14 rows in set (0.00 sec)


  101. mysql> select * from information_schema.index_statistics;

  102. +--------------+------------+------------------+-----------+

  103. | TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ |

  104. +--------------+------------+------------------+-----------+

  105. | test | emp | PRIMARY | 28 |

  106. | test | emp | idx_date_sal_job | 6 |

  107. +--------------+------------+------------------+-----------+

  108. 2 rows in set (0.00 sec)

以上是“Percona 5.5如何定位未使用的索引”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

Percona 5.5如何定位未使用的索引

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

CMS与搜索引擎的未来趋势:如何让您的网站在未来搜索结果中保持领先地位

CMS(内容管理系统)与搜索引擎未来发展紧密相关,网站应使用最新CMS技术,结合优质内容以提升搜索排名,优化用户体验,确保在搜索结果中始终处于领先地位。
CMS与搜索引擎的未来趋势:如何让您的网站在未来搜索结果中保持领先地位
2024-02-02

学习如何使用固定定位:掌握固定定位的用法和技巧

如何使用固定定位?学习固定定位的具体用法和技巧固定定位(fixed positioning)是CSS中的一种定位方式,可以将元素固定在浏览器窗口的特定位置,不会随滚动条滚动而改变位置。在Web开发中,固定定位经常用于创建导航栏、侧边栏和悬
学习如何使用固定定位:掌握固定定位的用法和技巧
2024-01-20

在 MySQL 中,如何使用查询未检索到的列来指定排序顺序?

实际上,我们知道我们可以借助 ORDER BY 子句指定排序顺序。我们需要编写 ORDER BY 关键字,后跟要对表进行排序的列的名称。我们不必在查询中的 SELECT 关键字后面使用该列名称。示例mysql> Select Sr, Ite
2023-10-22

编程热搜

目录