• MySQL SQL初级优化的具体方案;


    select company.* from cu_role_extend_company company where 1=1 and company.role_id in(select role.id from cu_role role where 1=1 and role.id in(select relation.role_id from cu_role_relation relation where 1=1 and relation.parent_role_id = (select role.id from cu_role role where 1=1 and role.concerned_id = ( select unionT.id from cu_concerned_union unionT where unionT.id = (select inst.concerned_id from cu_extend_inst inst where 1=1 and inst.inst_code = 'XJ')))));

    传统where子查询情况下=>SQL运行下来需要0.666s;查询出来50+数据;筛选数据总量大概在400左右(所有表的数据总量);

    SELECT
    companyW.id, companyW.tnt_inst_id, companyW.role_id, companyW.name, companyW.merchant_code,
    companyW.person_source,
    companyW.settlement_cycle, companyW.settlement_type,
    companyW.operation_scope,
    companyW.creator_id, companyW.create_time, companyW.modifier_id, companyW.modify_time,companyW.max_amt_set,
    companyW.min_amt_set,companyW.notify_url,companyW.latitude,companyW.longitude,companyW.settl_cycle_ctrl,companyW.org_code,
    companyW.exn,companyW.exn1,companyW.exn2
    FROM
    cu_role_extend_company companyW
    INNER JOIN (
    SELECT DISTINCT
    ( company.id )
    FROM
    cu_role_extend_company company
    INNER JOIN (
    SELECT
    role.id
    FROM
    cu_role role
    INNER JOIN (
    SELECT
    relation.role_id
    FROM
    cu_role_relation relation
    INNER JOIN (
    SELECT
    role.id
    FROM
    cu_role role
    INNER JOIN (
    SELECT
    unionT.id
    FROM
    cu_concerned_union unionT
    LEFT JOIN cu_extend_inst inst ON unionT.id = inst.concerned_id
    WHERE
    1 = 1
    AND inst.inst_code = 'XJ'
    ) x ON role.concerned_id = x.id
    ) z ON relation.parent_role_id = z.id
    ) c ON role.id = c.role_id
    ) v ON company.role_id = v.id
    ) b ON companyW.id = b.id;

    inner join 单字段写全部 情况下,SQL的运行稳定在0.610s左右;

    SELECT
    *
    FROM
    cu_role_extend_company companyW
    INNER JOIN (
    SELECT DISTINCT
    ( company.id )
    FROM
    cu_role_extend_company company
    INNER JOIN (
    SELECT
    role.id
    FROM
    cu_role role
    INNER JOIN (
    SELECT
    relation.role_id
    FROM
    cu_role_relation relation
    INNER JOIN (
    SELECT
    role.id
    FROM
    cu_role role
    INNER JOIN (
    SELECT
    unionT.id
    FROM
    cu_concerned_union unionT
    LEFT JOIN cu_extend_inst inst ON unionT.id = inst.concerned_id
    WHERE
    1 = 1
    AND inst.inst_code = 'XJ'
    ) x ON role.concerned_id = x.id
    ) z ON relation.parent_role_id = z.id
    ) c ON role.id = c.role_id
    ) v ON company.role_id = v.id
    ) b ON companyW.id = b.id;

    inner join 用*查全量字段情况下,SQL的运行稳定在0.460s左右;

  • 相关阅读:
    关于DISCUZ!NT发布的问题整理!
    javascript 文字滚动显示[zhuan ]
    Bot Framework Emulator应用与调试
    Bot Framework的简单实现
    命名空间在扩展方法中的妙用
    Error:Execution failed for task ':app:transformClassesWithDexForDebug"
    C#中WebApi接口传参不再困惑:传参详解
    贝塞尔曲线
    从枚举值获取对应的文本描述
    常用正则表达式收集
  • 原文地址:https://www.cnblogs.com/llja/p/14686538.html
Copyright © 2020-2023  润新知