zoukankan      html  css  js  c++  java
  • oracle优化技巧及实例(总结)

    1.关于exists和in

    in是循环的方式,在内存中处理,

    exists是执行数据库查询,

    select tpd.personaccountid,sum(nvl(tpd.CREDIT_SUM, 0)) as bjsr, sum(nvl(tpd.INTEREST_INCOME, 0)) as bjsr, sum(nvl(tpd.DEBIT_SUM, 0)) as bjzc from TGP_PERSON_DETAIL tpd
    left join TAP_FUNDBUSINESS tfb
    on tpd.FUNDBUSINESS_ID = tfb.FUNDBUSINESS_ID
    where tpd.PERSONACCOUNTID
    in (
    select personaccountid from TGP_PERSONACCOUNT pa
    left join tgp_person person
    on pa.personid = person.personid
    where person.zjhm = '330903196209160251'
    ) group by tpd.personaccountid

    执行100次 耗时0.017S左右

    select tpd.personaccountid,sum(nvl(tpd.CREDIT_SUM, 0)) as bjsr, sum(nvl(tpd.INTEREST_INCOME, 0)) as bjsr, sum(nvl(tpd.DEBIT_SUM, 0)) as bjzc from TGP_PERSON_DETAIL tpd
    left join TAP_FUNDBUSINESS tfb
    on tpd.FUNDBUSINESS_ID = tfb.FUNDBUSINESS_ID
    where
    exists (
    select personaccountid from (select personaccountid from TGP_PERSONACCOUNT pa
    left join tgp_person person
    on pa.personid = person.personid
    where person.zjhm = '330903196209160251') a
    where tpd.personaccountid = a.personaccountid
    ) group by tpd.personaccountid

    执行100次 耗时0.020S左右

    以上都为SELECT FORM a IN b(OR EXISTS B)  B中数据少的时候 采用IN 多的时候采用EXISTS  

    select tpd.personaccountid,sum(nvl(tpd.CREDIT_SUM, 0)) as bjsr, sum(nvl(tpd.INTEREST_INCOME, 0)) as bjsr, sum(nvl(tpd.DEBIT_SUM, 0)) as bjzc from TGP_PERSON_DETAIL tpd
    left join TAP_FUNDBUSINESS tfb
    on tpd.FUNDBUSINESS_ID = tfb.FUNDBUSINESS_ID
    HAVING
    exists (
    select personaccountid from (select personaccountid from TGP_PERSONACCOUNT pa
    left join tgp_person person
    on pa.personid = person.personid
    where person.zjhm = '330903196209160251') a
    where tpd.personaccountid = a.personaccountid
    ) group by tpd.personaccountid

    执行100次 耗时2.36S左右

    因此先筛选数据再分组 效率更高

  • 相关阅读:
    bzoj 3035 二分答案+二分图最大匹配
    bzoj 1058 bst
    bzoj 1093 缩点+DP
    bzoj 1452 二维树状数组
    bzoj 1968 数学
    bzoj 1034 贪心
    牛客小白月赛12 I (tarjan求割边)
    Loj 103、10043 (KMP统计子串个数)
    poj 2356 (抽屉原理)
    hdu 1907 (尼姆博弈)
  • 原文地址:https://www.cnblogs.com/UUUz/p/10120625.html
Copyright © 2011-2022 走看看