zoukankan      html  css  js  c++  java
  • 数据库执行存储过程优化(1)

     下面的old 是原来的查询, 大概花了 58秒, 下面经过优化后的, 执行了22秒.

    核心思想:  先缩小数据范围, 然后再和其他的表做 关联查询.

      ----new 2018-07-03 
      insert into @tab_xmxkxx
        select  DISTINCT CONVERT(NVARCHAR(50),GETDATE(),112) AS jhrq,
        tab_sgxkdwxx.wsslbh as wsslbh,
        tab_xmxkxx.xmmc as xmmc,
        tab_sgxkdwxx.dwmc AS zbdwmc,
        CONVERT(NVARCHAR(50),tab_xmxkxx.sdrq,112) AS hfxkzrq,
        tab_xmxkxx.fzdwmc AS hfxkzbm
    
        from 
           (select bjbh,bdh,wsslbh,dwmc FROM [SgXk].[tab_zbb_xmxkxx_dwxx] AS sgxkdwxx where ISNULL(sgxkdwxx.wsslbh,'') <> ''  AND sgxkdwxx.dwlb = 'sg') tab_sgxkdwxx,
           (select bjbh,bdh,xmmc,fzdwmc,sdrq from sgxk.tab_zbb_xmxkxx xmxkxx where  xmxkxx.state='SdApproved' and xmxkxx.fzrq BETWEEN @startTime AND @endTime) tab_xmxkxx,
              @tab_htxx as tab_htxx
        where tab_sgxkdwxx.bjbh = tab_xmxkxx.bjbh  COLLATE Chinese_PRC_CS_AS and tab_sgxkdwxx.bdh = tab_xmxkxx.bdh   COLLATE Chinese_PRC_CS_AS
         and tab_sgxkdwxx.wsslbh = tab_htxx.wsslbh;
         
    -----------------------------------------------------------------------------------------------------------------------------------
       
    /*
    -- old 2018-06-12
    insert into @tab_xmxkxx
        SELECT DISTINCT CONVERT(NVARCHAR(50),GETDATE(),112) AS jhrq,
            sgxkdwxx.wsslbh AS wsslbh,
            xmxkxx.xmmc AS xmmc,
            sgxkdwxx.dwmc AS zbdwmc,
            CONVERT(NVARCHAR(50),xmxkxx.sdrq,112) AS hfxkzrq,
            xmxkxx.fzdwmc AS hfxkzbm FROM [SgXk].[tab_zbb_xmxkxx_dwxx] AS sgxkdwxx
           LEFT JOIN sgxk.tab_zbb_xmxkxx xmxkxx ON xmxkxx.bjbh COLLATE Chinese_PRC_CS_AS = sgxkdwxx.bjbh COLLATE Chinese_PRC_CS_AS AND sgxkdwxx.bdh COLLATE Chinese_PRC_CS_AS = xmxkxx.bdh COLLATE Chinese_PRC_CS_AS 
        WHERE ISNULL(sgxkdwxx.wsslbh,'') <> '' AND xmxkxx.state='SdApproved' AND sgxkdwxx.dwlb = 'sg' 
        
        AND sgxkdwxx.wsslbh IN (SELECT wsslbh FROM @tab_htxx)
    */    
    -------------------------------------------------------------------------------------
  • 相关阅读:
    gcc/g++命令参数笔记
    周总结
    帆软FineBI试用
    C++输入流
    tt
    linux6 安装oracle11g
    linux下修改/dev/shm tmpfs文件系统大小
    centos6.5_x86_64 下安装 Oracle11gR2 的详细过程
    Linux Network配置
    安装KornShell(KSH)
  • 原文地址:https://www.cnblogs.com/mjxxsc/p/9257756.html
Copyright © 2011-2022 走看看