zoukankan      html  css  js  c++  java
  • 关于SQL优化的一个小试例子

    原SQL:


    select ta.serialno,
           ta.accepttime,
           ta.subsnumber,
           ta.subsname,
           ta.contactphone1,
           ta.servicecontent,
           ta.address,
           r.region_name,
           s.contactchannel_name,
           p.name,
           p.fullname,
           rownum
      from (select t.serialno,
                   t.accepttime,
                   t.subsnumber,
                   t.subsname,
                   t.contactphone1,
                   t.servicecontent,
                   t.address,
                   t.contactchannel,
                   t.srtypeid,
                   t.partition_id_region
              FROM report_threed_problemprocess t,
                   (select trim(t1.para) p1
                      FROM System_Parameters_t t1
                     WHERE t1.para_flag = 'OVER_GONGXINBYCL_TYPE') a,
                   (SELECT trim(t2.para) p2
                      FROM System_Parameters_t t2
                     WHERE t2.para_flag = 'OVER_GONGXINBYCL_CHANNEL') b,
                   (SELECT TRIM(t3.para) p3
                      FROM System_Parameters_t t3
                     WHERE t3.para_flag = 'OVER_96180_TYPE') c
             WHERE t.partition_id_month = uf_get_partition_month(201306)
               and t.accepttime>=to_date(201306||'01','yyyymmdd') and t.accepttime<add_months(to_date(201306||'01','yyyymmdd'),1)
               and t.partition_id_region in
                   (SELECT rt.ioid_id0 region_id
                      FROM region_t rt
                     WHERE rt.region_level = 4
                       AND rt.ioid_id0 >= 1001
                       AND rt.ioid_id0 <= 1018)
               AND t.srtypeid IN (SELECT spp.srtype_id
                                    FROM sdt_para_pro_com_tsnote spp
                                   WHERE spp.pro_com_id =1025
                                     AND state = 1)
            AND ((substr(t.srtypeid, 1, 6) = a.p1 and t.contactchannel = b.p2) or
            (substr(t.srtypeid, 1, 6) = c.p3 and t.contactchannel = b.p2))
            ) ta --96180
     inner join sdt_para_contactchannel s
        on ta.contactchannel = s.contactchannel
     inner join sdt_servicerequesttype p
        on ta.srtypeid = p.srtypeid
     inner join region_t r
        on r.ioid_id0=ta.partition_id_region;
       

    在数据库上的执行时间为:65.969s

    改进后的SQL:

    select ta.serialno,
           ta.accepttime,
           ta.subsnumber,
           ta.subsname,
           ta.contactphone1,
           ta.servicecontent,
           ta.address,
           (SELECT r.region_name FROM region_t r WHERE  r.ioid_id0=ta.partition_id_region)region_name,
           (SELECT s.contactchannel_name FROM sdt_para_contactchannel s WHERE ta.contactchannel = s.contactchannel) contactchannel_name,
           p.name,
           p.fullname,
           rownum
      from (select t.serialno,
                   t.accepttime,
                   t.subsnumber,
                   t.subsname,
                   t.contactphone1,
                   t.servicecontent,
                   t.address,
                   t.contactchannel,
                   t.srtypeid,
                   t.partition_id_region
              FROM report_threed_problemprocess t
             WHERE t.partition_id_month = uf_get_partition_month(201306)
               and t.accepttime>=to_date(201306||'01','yyyymmdd') and t.accepttime<add_months(to_date(201306||'01','yyyymmdd'),1)
               AND t.srtypeid IN (SELECT spp.srtype_id FROM sdt_para_pro_com_tsnote spp
                                   WHERE spp.pro_com_id =1025 AND state = 1)
            AND
            (
              (substr(t.srtypeid, 1, 6) =(select trim(t1.para) FROM System_Parameters_t t1 WHERE t1.para_flag = 'OVER_GONGXINBYCL_TYPE')
                    and t.contactchannel =(SELECT trim(t2.para) p2 FROM System_Parameters_t t2 WHERE t2.para_flag = 'OVER_GONGXINBYCL_CHANNEL')
               )
               or
              (substr(t.srtypeid, 1, 6) =(SELECT TRIM(t3.para) p3 FROM System_Parameters_t t3 WHERE t3.para_flag = 'OVER_96180_TYPE')
               and t.contactchannel =(SELECT trim(t2.para) p2 FROM System_Parameters_t t2 WHERE t2.para_flag = 'OVER_GONGXINBYCL_CHANNEL')
              )
             )
      ) ta --96180
     inner join sdt_servicerequesttype p
        on ta.srtypeid = p.srtypeid;
       执行时长:9.17s

    暂时记这么多。

  • 相关阅读:
    Byteart Retail V3 全新的面向.NET与领域驱动设计的企业应用实践案例
    算法设计和数据结构学习堆排序
    OutputCacheProvider OutputCache的一点点认识
    使用beetle简单地实现高效的http基础服务
    The IoC container
    使用Visual Studio 2010进行UI自动化测试
    PortalBasic Java Web 应用开发框架 v2.6.1(源码、示例及文档)
    发展中的 CSS3
    C#数据结构与算法揭秘十
    Sql Server Profiler跟踪查询
  • 原文地址:https://www.cnblogs.com/Alex-Zeng/p/3178207.html
Copyright © 2011-2022 走看看