小编Ste*_*wie的帖子

MySQL 子查询显着减慢,但它们独立工作正常

查询 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

9
推荐指数
2
解决办法
1万
查看次数

我无法理解的连接聚合行为

查询 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)

mysql query

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

SHOW /*!50000 GLOBAL */ STATUS 有什么作用?

之间有什么区别

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 是否有任何类似的脚本列出重要的统计数据和显示建议

mysql performance database-tuning

3
推荐指数
1
解决办法
1036
查看次数