Modoer列表页性能分析及优化_PHP教程

php中文网
发布: 2016-07-13 17:17:22
原创
1005人浏览过

在 http://www.modoer.org/beijing/item/list-8 的页面中,会执行以下2个sql

select 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.sid=st.sid and attid=173) and exists(select 1 from modoer_subjectatt st where s.sid=st.sid and attid=4) order by finer desc limit 0, 20 



select count(*) from modoer_subject s where exists(select 1 from modoer_subjectatt st where s.sid=st.sid and attid=173) and exists(select 1 from modoer_subjectatt st where s.sid=st.sid and attid=4)

如果数据量不大的话,还凑活,如果数据量大的话呢?以本人的数据为例,分别是subjectatt数据量和subject数据量
 
 

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.sid=st.sid and attid=$attid");
                                        if($attid
                                         $sql .= $or . ' attid='.$attid;
                                         $or = ' or ';
                                }
                                $sql .=  ') as temp
                                group by sid) as temp1
                                where count='.$num;
                        }
                        $query=$this->db->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.sid=st.sid AND attid=$attid");
                                        if($attid
                                         $sql .= $or . ' attid='.$attid;
                                         $or = ' or ';
                                }
                                $sql .=  ') as temp
                                group by sid) as temp1
                                where count='.$num;
                        }
        }


希望有用到的朋友可以改下,也只是暂时解决办法。另有问题请联系qq  272164179

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/626609.htmlTechArticle在 http://www.modoer.org/beijing/item/list-8 的页面中,会执行以下2个sql SELECT s.sid,pid,catid,domain,name,avgsort,sort1,sort2,sort3,sort4,sort5,sort6,sort7,sort8,best,...
数码产品性能查询
数码产品性能查询

该软件包括了市面上所有手机CPU,手机跑分情况,电脑CPU,电脑产品信息等等,方便需要大家查阅数码产品最新情况,了解产品特性,能够进行对比选择最具性价比的商品。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号