MySQL 为什么在有索引时记录为慢查询/日志查询不使用索引?

标签 mysql sql performance indexing myisam

Mysql 5.1.x

在 my.cnf 中:

log-queries-not-using-indexes = 1
long_query_time = 30
and slow queries are logged

为什么我在日志中显示这个?速度不慢,所有字段都已建立索引。

来自 mysql.slow.log:

# Query_time: 0.001492  Lock_time: 0.000031 Rows_sent: 229  Rows_examined: 458
use database1;
SET timestamp=1393342939;
SELECT id,name FROM database1 ORDER BY name ASC;

该表有 229 行,MYISAM。

id and name are indexed
id = auto increment int unsigned
name = varchar(255) utf-8

你能解释一下为什么我在未索引/慢查询日志中显示此内容吗?

摘要和更多信息:

MYISAM 表,229 行,更多列,但全部,229 需要 id 和 name 列。两者都有索引。查询时需要显示所有 229 行。

我想要两件事:

  • 1.: 不要在慢速查询/不使用索引日志中显示该查询。
  • 2.:使查询尽可能快。

谢谢。

最佳答案

您正在对表进行文字完整扫描,因为您没有 WHERE 谓词作为索引。

关于MySQL 为什么在有索引时记录为慢查询/日志查询不使用索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22024148/

相关文章:

sql - 修改SQL Server中的xml元素名称

php - 如何解决这个sql查询?

javascript - 同位素过滤是否可以很好地处理数百个项目和多个类别?

css - 如何最小化加载 Font Awesome 图标的延迟?

php - mysqli_connect 延迟

php - 如何通过id查询数据库中的所有条目?

mysql - 消息 7391 : linked server unable to begin a distributed transaction (both svrs running locally)

mysql - 使用 R 在 mySQL 查询中发布增量日期字段

mysql - 从 mysql 数据生成直方图

performance - 加快 MATLAB 的傅里叶级数循环