小编AOv*_*ero的帖子

MySQL InnoDB查询性能

我正在尝试优化一个简单的SQL查询,该查询将在很多次数据上运行.

这是场景:

  • MySQL与InnoDB表
  • 在where和join中使用的所有字段都是Indexed.表有FK.
  • 我不需要整个查询缓存,但每个表的缓存都是可能的.
  • 表有更多更新/插入的读取.

一个真实的查询:

SELECT one_field, another_field
FROM big_table 
INNER JOIN medium_table ON ( ... ) 
INNER JOIN small_table ON ( ... ) 
WHERE week >= #number AND week <= #number AND year >= #number AND year <= #number 
AND medium_table.indexed_field = #number
AND small_table.pk= #number
Run Code Online (Sandbox Code Playgroud)

一些测试结果:

  • 平均查询时间:2,3374s
  • 测试表包含真实表的第十部分数据(甚至更少),例如big_test_table的75.000行.
  • 查询返回(在测试用例中)6500行.
  • Navicat表示99.95%的查询时间用于"发送数据"
  • 我尝试过MyISAM,平均查询时间是:2,1898s

如何改进查询或数据库方案?

最好连接我的年/周字段和[yearweek]索引字段?

在一些基准测试中,我看到MyISAM比Innodb更快,但似乎我有一点改进:

http://www.mysqlperformanceblog.com/files/benchmarks/innodb-myisam-falcon.html
http://www.jortk.nl/2008/12/mysql-performance-benchmark-myisam-versus-innodb/
Run Code Online (Sandbox Code Playgroud)

是否值得失去FK并前往MyISAM?

谢谢!


更新:

解释选择:

1   SIMPLE  small_table const   PRIMARY PRIMARY 4   const   1   Using index
1   SIMPLE  medium_table    index_merge PRIMARY,Fk_small_table, …
Run Code Online (Sandbox Code Playgroud)

mysql performance myisam innodb

5
推荐指数
1
解决办法
4724
查看次数

标签 统计

innodb ×1

myisam ×1

mysql ×1

performance ×1