Home  >  Article  >  Backend Development  >  mysql count 怎么提交效率

mysql count 怎么提交效率

WBOY
WBOYOriginal
2016-06-06 20:24:391174browse

有一个程序,先从user表查一定数量的用户$data,再foreach数组,从user表里count(*) where pid=$value['id'] 来统计子集数量

循环200条数据需要5秒多,要是数据多估计就卡死了,该怎么优化?

回复内容:

有一个程序,先从user表查一定数量的用户$data,再foreach数组,从user表里count(*) where pid=$value['id'] 来统计子集数量

循环200条数据需要5秒多,要是数据多估计就卡死了,该怎么优化?

连接查询count(*)使用group by

用Count(1)而不是count(*)可以有一定改善

Statement:
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