Home > Backend Development > PHP Tutorial > 大量数据 group by 求 优化解决方法

大量数据 group by 求 优化解决方法

WBOY
Release: 2016-06-13 13:34:51
Original
1865 people have browsed it

大量数据 group by 求 优化
一个表普通表, 就单个表 例如有1000W条数据

表名domain 表字段:
domainid , 
domain,
url,
date, 
userid,



select count(*) from domain group by domain order by domain asc 

domain 加索引了,这个group by 要时间过长,怎能优化???

有什么好的方法??



------解决方案--------------------
没有WHERE条件?你可以EXPLAIN看下。
------解决方案--------------------
你先explain分析 一下有没有用到索引

然后你试着把order by条件去掉,因为既然你已经索引了那个字段,那就默认是已经排好序了 的。
------解决方案--------------------
select count(*) from domain group by domain 这样直接统计出domain的个数
------解决方案--------------------
select count(*) from domain group by domain order by domain asc LIMIT 0,10000; 

几万的查询不可?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template