首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更喜欢大容量数据表的MySql优化技术

更喜欢大容量数据表的MySql优化技术
EN

Stack Overflow用户
提问于 2014-04-11 09:23:12
回答 2查看 226关注 0票数 1

我在MySql中遇到了大量数据的查询处理问题。我需要通过联接函数将数据提取到四个以上的表中。查询在服务器上运行得非常慢。

如何优化多个联接查询的处理时间。

我目前正在使用innodb引擎。大容量数据表是可以的。

我有这样的桌子

考试,学生,科目,subject_tests,subject_test_mark,total_subject,表中的数据

我得到了所有学生本次考试的记录。

这将在以前由多个for循环处理。连续数据库访问这是减缓我的进程的一个原因。如何通过SQL避免这些方案。给我一些受欢迎的想法。

我对此有一些怀疑。表引擎innodb是否正常。索引是否支持此过程?

代码语言:javascript
复制
SELECT `sub`.student_id,
((sum( `sub`.total / `main`.max_total )) / count( sub.id )) *10 AS percent,
GROUP_CONCAT((sub.total / main.max_total) *10 ORDER BY (sub.total / main.max_total) *10 DESC SEPARATOR ',' ) AS marks
FROM 
`cmark_batch` AS `main`
LEFT JOIN `cmark_para_total` AS `sub` 
ON `sub`.mark_batch_id = `main`.id
WHERE main.batch_id =29
AND main.term =4
AND main.subject_id =64
AND main.status = 'A'
GROUP BY student_id

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra   
1   SIMPLE  main    ref     search  search  8   const   85  Using index condition; Using where; Using temporary; Using filesort
1   SIMPLE  sub     ref     finder  finder  8   newlive.main.id     14  NULL
代码语言:javascript
复制
SELECT t1.mark_batch_id, t1.id, t1.param_name, t1.max_mark,t2.student, t2.mark
FROM `cmark_parameter` AS t1
LEFT JOIN `cmark_parameter_mark` AS t2 ON t1.id = t2.mark_parameter_id
WHERE t1.mark_batch_id
IN (621,620,623,622)
AND t1.status = 'A'
AND t2.status = 'A'
ORDER BY `t2`.`student` ASC

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra   
1   SIMPLE  t2  ALL     NULL    NULL    NULL    NULL    78835   Using where; Using filesort
1   SIMPLE  t1  eq_ref  PRIMARY     PRIMARY     8   newlive.t2.cmark_parameter_id   1   Using where
代码语言:javascript
复制
SELECT t1.student_id, t1.mark_batch_id, t1.total
FROM `cmark_para_total` AS t1
WHERE t1.mark_batch_id
IN (621,620,623,622)
AND t1.status = 'A'
ORDER BY `t1`.`id` ASC


id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra   
1   SIMPLE  t1  range   finder  finder  8   NULL    111     Using index condition; Using where; Using filesort

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-11 09:31:31

使用关键字“解释”来确定是什么导致了缓慢,以及您可以做什么来优化。

这里有更多内容:

https://dev.mysql.com/doc/refman/5.0/en/using-explain.html

票数 0
EN

Stack Overflow用户

发布于 2014-04-11 09:33:03

可以使用数据库缓存来减少加载复杂查询的时间。Mysql手册中描述了如何启用数据库缓存:

http://dev.mysql.com/doc/refman/5.1/en/query-cache.html

在查询中,必须添加属性SQL_CACHE以启用缓存,例如:

从客户中选择SQL_CACHE id,名称;

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23008547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档