zoukankan      html  css  js  c++  java
  • 自定义函数引发的性能问题

    ---执行1次
    select count(1)
      from LOAN_DUEBILLDATA bd
      left join LOAN_CONTRACTDATA bc
        on bd.RelativeSerialNo2 = bc.SerialNo
     where nvl(bd.ActualMaturity, bd.Maturity) <= '2014/08/06'
       and nvl(bd.ActualMaturity, bd.Maturity) >= '2014/07/07'
       and (bd.FinishDate is null or bd.FinishDate = '')
       and (bc.ManageUserID = '00717' or
            getCustomerManager(bc.CustomerId) = '00717')
    ----返回4条记录
    
    ---getCustomerManager函数里的sql执行3619次
    SELECT USERID FROM CUSTOMER_BELONG WHERE CUSTOMERID = :B1 AND BELONGATTRIBUTE='1'
    
    
    select  count(1)
      from LOAN_DUEBILLDATA bd
      left join LOAN_CONTRACTDATA bc
        on bd.RelativeSerialNo2 = bc.SerialNo
     where nvl(bd.ActualMaturity, bd.Maturity) <= '2014/08/06'
       and nvl(bd.ActualMaturity, bd.Maturity) >= '2014/07/07'
       and (bd.FinishDate is null or bd.FinishDate = '')
       and (bc.ManageUserID = '00717' or
            getCustomerManager(bc.CustomerId) = '00717');
    
    
    初步改写为:
    select count(1)
      from LOAN_DUEBILLDATA bd, LOAN_CONTRACTDATA bc, (select CustomerId FROM CUSTOMER_BELONG WHERE BELONGATTRIBUTE='1') be
     where bd.RelativeSerialNo2 = bc.SerialNo(+)
       and nvl(bd.ActualMaturity, bd.Maturity) <= '2014/08/06'
       and nvl(bd.ActualMaturity, bd.Maturity) >= '2014/07/07'
       and (bd.FinishDate is null or bd.FinishDate = '')
       and be.CustomerId = bc.CustomerId
       and (bc.ManageUserID = '00717' or be.customerid = '00717')
    

  • 相关阅读:
    【并查集】亲戚
    【图论】Car的旅行线路 NOIP 2001
    【贪心】排座椅
    【DP】花店橱窗布置
    【NOIP】NOIP考纲总结+NOIP考前经验谈
    【NOIP】考前须知
    NOIP 2016 PJ T4 魔法阵
    NOIP 2016 PJ T3 海港
    【高精度】麦森数 NOIP 2003
    【带权并查集】食物链 NOIP 2001
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352226.html
Copyright © 2011-2022 走看看