上次发贴问题还未解决,再发一贴(急)
关于mysql 占用资源问题
我的程序中用到了这样的查询语句
String SchoolSql="select sid from school where sid<>1";
ResultSet SchoolRs=aDBC.SelectDB(db,false,"",SchoolSql);
if(SchoolRs!=null){
while(SchoolRs.next()){
ResultSet stuRs = aDBC.SelectDB(db, false, "", "select count(id) from student where sid= "+SchoolRs.getString(sid)+" and mphone>='13500000000' and mphone<='13999999999' group by groupid,mphone");
if (stuRs != null) {
stuRs.last();
this.studenttotal += stuRs.getRow();
stuRs.close();
stuRs = null;
}
}
SchoolRs.close();
SchoolRs=null;
}
还有其他查询语句,但都是一些类似“select * from area”的查询语句(没有包含where)
问题就是我一运行这程序的时候,mysqld线程cpu使用率是80%以上,而且查询也比较慢,查询结果是studenttotal=167120,请问这sql语句该怎样优化,为什么cpu使用率这么高?(student表中已建索引sid和mphone)
school表有400条记录左右,student表有20万条记录左右
我试过不用group by groupid,mphone, 那cpu使用率就在40%-50%左右,所以肯定是group by语句的问题,可是这group by语句一定要啊,请问高手有什么好的方法解决这问题?