modoer列表页性能分析及优化

在 http://www.modoer.org/beijing/item/list-8 的页面中,会执行以下2个sqlselect s.sid,pid,catid,domain,name,avgsort,sort1,sort2,sort3,sort4,sort5,sort6,sort7,sort8,best,finer,pageviews,reviews,pictures,favorites,thumb,aid,map_lat,map_lng,c_tel,c_dz from modoer_subject s left join modoer_subject_shishang sf on (s.sid = sf.sid) where exists(select 1 from modoer_subjectatt st where s.shttp://www.bkjia.com/uploads/allimg/131231/0324596019-0.jpg” alt=”” /> sql运行结果如图: 仅仅一个查询数据量的sql花了44.16秒,网站根本打不开,难道技术没有测试没有优化吗?复合语句用起来很爽但是效果很差经本人暂时优化,subject_class.php中改掉以下代码,性能大大提升if($atts) { $attlist = array_values($atts); $num = count($attlist); if($num>0){ $or = ”; $sql =’select group_concat(sid) sids from( select count(sid) count,sid from ( select sid,attid from modoer_subjectatt where ‘; foreach($attlist as $attid) { //$this->db->where_exist(“select 1 from dbpre_subjectatt st where s.s); if($attiddb->query($sql);$b=$query->fetch_array();$sids=$b[‘sids’]; //$where = ‘ s.sid in(‘.$sids.’) ‘;

$this->db->where(‘s.sid’, explode(‘,’, $sids), ”); }else{ $where = ”; }还有查询数量的地方if($atts) { $attlist = array_values($atts); $num = count($attlist); if($num>0){ $or = ”; $sql =’select count(*) as nums from( select count(sid) count from ( select sid,attid from modoer_subjectatt where ‘; foreach($attlist as $attid) { //$this->db->where_exist(“select 1 from dbpre_subjectatt st where s.s); if($attid

Posted in 未分类

发表评论