![](/img/trans.png)
[英]My query is not using my indexes, how do i use explain plan and fix this slow query with MySQL
[英]which tool do you use to determine if a query is using indexes?
您使用哪种工具来确定查询是否使用符合 ANSI 标准的数据库中的索引?
正如其他人提到的,您没有说明您正在使用哪个 DBMS,所以我已经向您提供了有关在 MSSQL 2014 上运行的知识。
您可以使用索引监控功能来检查应用程序是否使用了索引。 如果您为索引设置了 MONITORING USAGE 属性,您可以查询 v$object_usage 以查看索引是否正在使用。 下面是一个例子:
SQL> CREATE TABLE t1 (c1 NUMBER);
Table created.
SQL> CREATE INDEX t1_idx ON t1(c1);
Index created.
SQL> ALTER INDEX t1_idx MONITORING USAGE;
Index altered.
SQL> SELECT table_name, index_name, monitoring, used FROM v$object_usage;
TABLE_NAME INDEX_NAME MON USE
------------------------------ ------------------------------ --- ---
T1 T1_IDX YES NO
SQL> SELECT * FROM t1 WHERE c1 = 1;
no rows selected
SQL> SELECT table_name, index_name, monitoring, used FROM v$object_usage;
TABLE_NAME INDEX_NAME MON USE
------------------------------ ------------------------------ --- ---
T1 T1_IDX YES YES
To reset the values in the v$object_usage view, disable index monitoring and re-enable it:
ALTER INDEX indexname NOMONITORING USAGE;
ALTER INDEX indexname MONITORING USAGE;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.