语句如下select t.company_id,t.user_id,t.id,t.provide_area,t.price,t.base_dic_id,t.purveyNumber,t.purveyNumber_dw,t.cas,t.casing,t.product_cname,t.product_ename,t.product_spec,t.define,t.issuance_date,t.auditing_date,t.abate_date,t.key_word,t.chem_alias_name,t.variety,t.producing_area,t.chemical_bond,t.molecular_weight,t.consistency,t.content,t.boil,t.safety_level,a.company_whole_name,a.email,a.phone,a.true_name,t.product_pic_url,a.mobile,a.fax,a.company_web,a.address  from purvey_product t,v_product_user a where t.user_id=a.product_user_id and t.abate_date >= now() and t.auditing_state = 1 and a.flag = 0 and a.auditing_state = 1 and a.freeze_state = 0 order by t.auditing_date desc
一个表和试图的联合查询,order by之后非常慢,执行了几分钟了还没出结果

解决方案 »

  1.   


    select t.company_id,
           t.user_id,
           t.id,
           t.provide_area,
           t.price,
           t.base_dic_id,
           t.purveyNumber,
           t.purveyNumber_dw,
           t.cas,
           t.casing,
           t.product_cname,
           t.product_ename,
           t.product_spec,
           t.define,
           t.issuance_date,
           t.auditing_date,
           t.abate_date,
           t.key_word,
           t.chem_alias_name,
           t.variety,
           t.producing_area,
           t.chemical_bond,
           t.molecular_weight,
           t.consistency,
           t.content,
           t.boil,
           t.safety_level,
           a.company_whole_name,
           a.email,
           a.phone,
           a.true_name,
           t.product_pic_url,
           a.mobile,
           a.fax,
           a.company_web,
           a.address
      from purvey_product t, v_product_user a
     where t.user_id = a.product_user_id
       and t.abate_date >= now()
       and t.auditing_state = 1
       and a.flag = 0
       and a.auditing_state = 1
       and a.freeze_state = 0
     order by t.auditing_date desc
    在user_id上建索引吧
      

  2.   

    调整where条件的顺序或许能快点
      

  3.   

    获取sql语句的执行计划,然后分析其中cost较高的步骤,对症下药,就能解决问题,
      

  4.   

    我也觉得。 可以调整下试试,把t.user_id=a.product_user_id 放在最后
    user_id和product_user_id 加索引试试
      

  5.   

    就两个表,应该没问题的啊,除非你的数据有上千万~~~把ORDER BY后面的排序去掉,看看是否快点,或快则说明要加一个索引
      

  6.   

    执行顺序是从右到左的,调整一下where子句的顺序