查询 1:
select distinct email from mybigtable where account_id=345
Run Code Online (Sandbox Code Playgroud)
需要 0.1 秒
查询 2:
Select count(*) as total from mybigtable where account_id=123 and email IN (<include all from above result>)
Run Code Online (Sandbox Code Playgroud)
需要 0.2 秒
查询 3:
Select count(*) as total from mybigtable where account_id=123 and email IN (select distinct email from mybigtable where account_id=345)
Run Code Online (Sandbox Code Playgroud)
需要 22 分钟,其中 90% 处于“准备”状态。为什么要花这么多时间。
表是 innodb,在 MySQL 5.0 上有 320 万行
mysql innodb performance optimization subquery query-performance
查询 1:
SELECT c.class_id,
SUM
(
CASE
WHEN s.student_id IS NULL THEN 0
ELSE 1
END
) as total_students
FROM classes c LEFT JOIN students s ON c.class_id = s.class_id
GROUP BY c.class_id;
Run Code Online (Sandbox Code Playgroud)
结果:
453 100
461 10
462 19
464 0
471 0
499 133
Run Code Online (Sandbox Code Playgroud)
伟大的 !
查询2:(添加where条件过滤学生类型)
SELECT c.class_id,
SUM
(
CASE
WHEN s.student_id IS NULL THEN 0
ELSE 1
END
) as total_students
FROM classes c LEFT JOIN students s ON c.class_id = s.class_id WHERE s.student_type='instate'
GROUP …Run Code Online (Sandbox Code Playgroud) 之间有什么区别
SHOW /*!50000 GLOBAL */ STATUS
Run Code Online (Sandbox Code Playgroud)
和
SHOW GLOBAL STATUS
Run Code Online (Sandbox Code Playgroud)
我看到在一些脚本和调整演示中使用了第一个命令。有区别吗,如果有,50000 是什么意思?
此外,这似乎是一个很好的脚本:https : //raw.github.com/rackerhacker/MySQLTuner-perl/master/mysqltuner.pl 是否有任何类似的脚本列出重要的统计数据和显示建议