• update 改写 merge into


    update语句改写成merge into有时会提高运行速度

    看两个案例

    1.根据业务将两个嵌套子查询改写成max,速度有3min提升到3s

    UPDATE OPER_792.LL_SCB_YDKB_20120730 A
    SET A.DCP =
    (SELECT B.PROD_OFFER_NAME
    FROM OPER_792.YD_TC B
    WHERE A.SERV_ID = B.SERV_ID
    AND B.TC_TYPE = '合约计划'
    AND ROWNUM = 1),
    A.JCTC =
    (SELECT B.PROD_OFFER_NAME
    FROM OPER_792.YD_TC B
    WHERE A.SERV_ID = B.SERV_ID
    AND B.TC_TYPE = '基础套餐'
    AND ROWNUM = 1)
    WHERE A.DAY_ID = 20150125


    merge into OPER_792.LL_SCB_YDKB_20120730 A
    using (select c.SERV_ID,
    max(case
    when c.TC_TYPE = '合约计划' then
    c.PROD_OFFER_NAME
    end) col1,
    max(case
    when c.TC_TYPE = '基础套餐' then
    c.PROD_OFFER_NAME
    end) col2
    from OPER_792.YD_TC c
    group by c.SERV_ID) b
    on (A.SERV_ID = B.SERV_ID and a.day_id = 20150125)
    when matched then
    update set A.DCP = b.col1, A.JCTC = b.col2

    2.正常的将update 改写成merge into

    update tb_result r set r.vote_count=nvl((

    select temp_.vote_count

    from(

      select result_id,

      count(rv_id) as vote_count

      from tb_result_vote

      group by result_id

    ) temp_

    where temp_.result_id=r.result_id),

    r.vote_count

    );

    merge into tb_result r

    using(

    select result_id,

      count(rv_id) as vote_count

      from tb_result_vote

      group by result_id) temp_

    on(temp_.result_id=r.result_id)

    when matched then

    update set r.vote_count=nvl(temp_.vote_count,r.vote_count);

  • 相关阅读:
    全站301跳转 PHP
    linux flush memcache缓存
    php Memcache
    PHP MemCached win安装
    windows下安装memcache
    2013 年最好的 20 款免费 jQuery 插件
    License Manager 10.3启动失败解决方法
    .ecp认证文件(10.3版本)
    ArcGIS 10.3 安装及破解
    win7下安装MYSQL报错:"MYSQL 服务无法启动"的3534问题
  • 原文地址:https://www.cnblogs.com/SUN-PH/p/4283247.html
Copyright © 2020-2023  润新知