请问以下代码 数据库的索引应该如何设计 案例哈 谢谢啦

控制器

        $PointProductModel=D('PointProduct');
        $list= $PointProductModel->getPointProduct($id=null,$no,array('in','0,1'),
            $isdelete=0,null,$pointortime);

模型

    public function getPointProduct($id,$no,$condition,
                                    $isdelete,$chinesename,$pointortime){

        $m=M('point_product');

        if($id){
            $con['pointproduct_id']=$id;
        }

        if($no){
            $con['pointproduct_no']=$no;
        }

        if($condition!==null){
            $con['pointproduct_condition']=$condition;
        }

        if($isdelete!==null){
            $con['pointproduct_isdelete']=$isdelete;
        }

        if($chinesename){
            $con['pointproduct_chinesename']=$chinesename;
        }

        if($pointortime){
            $con['pointproduct_pointortime']=$pointortime;
        }


        $result=$m->where($con)->order("pointproduct_sort desc")->select();

}

数据库如何优化
代码如何优化
性能最高

阅读 2.3k
5 个回答

出现频率最高的字段加索引

首先 你要看出现什么问题了,如果不用索引效果也不错,那就不要用索引!!索引是用来优化的,不是必须的~~~
其次,一般来说索引建立在where之后的语句中,索引的好坏要explain看一下。

的确除了主键 ,其他索引不是必须的,自己觉得需要高频率where order 等查询才加 ,我觉得出现慢sql时候 才优化,
首先用explain,再分析,加索引,索引分普通索引,联合索引,和primary key 建表我觉得是必须的

表结构,
数据分布情况,
完整SQL

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题