zoukankan      html  css  js  c++  java
  • mysql性能优化

    索引使用;

    1、not in;某列重复数据过多就直接走全表扫码了;隐式类型转换;函数;or如果有一列没有加索引则不走索引;避免select *;尽量走覆盖索引

    2、使用联合索引而不是单列索引,如果是单列索引:

    数据库会选择一个最优的索引(辨识度最高索引)来使用,并不会使用全部索引 ;

    3、索引量>5个会影响性能;

    4、使用exists作为筛选条件效果还是很不错的:

    SELECT
    a.id,
    a.area_code,
    a.bill_code,
    a.NAME,
    a.credit_level,
    a.without_approval,
    a.apply_credit_days,
    a.recommend_credit_limit,
    a.recommend_credit_days,
    a.STATUS,
    a.model_type,
    a.create_date,
    a.confirm_date,
    a.operator,
    a.dept_code,
    b.peopleFollow mgr_emp_code,
    a.current_credit_level,
    a.current_credit_limit,
    a.current_credit_days,
    c.emp_code head_receiver,
    '857767' empCode
    FROM
    enterprise_customer_reassess_record a
    LEFT JOIN sasp_ccm_business_account b ON a.bill_code = b.businessAccount
    LEFT JOIN cc_area_charge c ON a.area_code = c.area_code
    LEFT JOIN tm_department_ccm d ON a.dept_code = d.DEPT_CODE
    WHERE
    1 = 1
    AND (
    1 = 1
    AND EXISTS (
    SELECT
    1
    FROM
    cc_emp_data_right x
    WHERE
    1 = 1
    AND x.`emp_code` = '857767'
    AND (
    x.`dept_code` = '001'
    OR d.`dept_code` = x.`dept_code`
    OR d.`DIVISION_CODE` = x.`dept_code`
    OR d.`AREA_CODE` = x.`dept_code`
    OR d.`HQ_CODE` = x.`dept_code`
    )
    )
    OR b.peopleFollow = '857767'
    )

  • 相关阅读:
    MySql 用户 及权限操作
    MAC 重置MySQL root 密码
    在mac系统安装Apache Tomcat的详细步骤[转]
    Maven:mirror和repository 区别
    ES6 入门系列
    转场动画CALayer (Transition)
    OC 异常处理
    Foundation 框架
    Enum枚举
    Invalid App Store Icon. The App Store Icon in the asset catalog in 'xxx.app' can’t be transparent nor contain an alpha channel.
  • 原文地址:https://www.cnblogs.com/gendway/p/12120906.html
Copyright © 2011-2022 走看看