原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

暂时记这么多。

关于SQL优化的一个小试例子的更多相关文章

  1. 简单聊聊TiDB中sql优化的一个规则---左连接消除(Left Out Join Elimination)

    我们看看 TiDB 一段代码的实现 --- 左外连接(Left Out Join)的消除; select 的优化一般是这样的过程: 在逻辑执行计划的优化阶段, 会有很多关系代数的规则, 需要将逻辑执行 ...

  2. 关于sql优化的一个小总结

    1.数据量大的时候,可以分多次查询2.有些数据的存储可以分主次表,此表存一些不常用的数据3.union all 比union效率要高4.尽量不要用distinct5.不返回不需要的行和列6.根据条件加 ...

  3. SQL优化 MySQL版 - 避免索引失效原则(二)

    避免索引失效原则(二) 注:继上一篇文章继续讲解: 避免索引失效原则(一)https://www.cnblogs.com/StanleyBlogs/p/10482048.html#4195062 作者 ...

  4. 聊聊sql优化的15个小技巧

    前言 sql优化是一个大家都比较关注的热门话题,无论你在面试,还是工作中,都很有可能会遇到. 如果某天你负责的某个线上接口,出现了性能问题,需要做优化.那么你首先想到的很有可能是优化sql语句,因为它 ...

  5. 关于SQL优化的辟谣

    列举一些关于 SQL 语句的谣言,避免一些生瓜蛋子面试的时候被另外一群生瓜蛋子的 SQL 优化宝典给坑了. 以下所有内容都是 SQL Server 中的,其他数据库只能参考和借鉴 一.全表扫描 全表扫 ...

  6. 基于MySQL 的 SQL 优化总结

    文章首发于我的个人博客,欢迎访问.https://blog.itzhouq.cn/mysql1 基于MySQL 的 SQL 优化总结 在数据库运维过程中,优化 SQL 是 DBA 团队的日常任务.例行 ...

  7. BATJ解决千万级别数据之MySQL 的 SQL 优化大总结

    引用 在数据库运维过程中,优化 SQL 是 DBA 团队的日常任务.例行 SQL 优化,不仅可以提高程序性能,还能减低线上故障的概率. 目前常用的 SQL 优化方式包括但不限于:业务层优化.SQL 逻 ...

  8. SQL优化基础 使用索引(一个小例子)

    按照本文操作和体会,会对sql优化有个基本最简单的了解,其他深入还需要更多资料和实践的学习: 1. 建表: 复制代码代码如下: create table site_user ( id int IDEN ...

  9. sql优化经典例子

    场景 我用的数据库是mysql5.6,下面简单的介绍下场景 课程表 create table Course( c_id int PRIMARY KEY, name varchar(10) ) 数据10 ...

随机推荐

  1. android131 360 05 手势触摸滑动,sim卡,开机启动的广播,手机联系人,SharedPreferences,拦截短信

    安卓手势触摸滑动: package com.itheima52.mobilesafe.activity; import android.app.Activity; import android.con ...

  2. careercup-C和C++ 13.4

    13.4 深拷贝和浅拷贝有什么区别,如何使用? 解答 浅拷贝并不复制数据,只复制指向数据的指针,因此是多个指针指向同一份数据. 深拷贝会复制原始数据,每个指针指向一份独立的数据.通过下面的代码, 可以 ...

  3. select option jquery javascript

    jQuery获取Select选择的Text和Value: $('#myselect').find('option:selected').attr('ent_id');      $('#ent_id' ...

  4. php验证字符串长度问题

    C:\Users\Administrator>php -r "echo strlen('你好')";4C:\Users\Administrator>php -r &qu ...

  5. Database ORM

    Database ORM Introduction Basic Usage Mass Assignment Insert, Update, Delete Soft Deleting Timestamp ...

  6. 如何查找局域网的外网ip

    方法一:一个简单的方法 用你电脑打开www.ip138.com 就可以看到自己的公网IP地址 方法二:如果一定要从路由器里面看 那就打开路由的配置页面 一般在系统状态里面 会有个WAN口IP 那就是你 ...

  7. Android_menu_SubMenu

    menu.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" > <!-- ...

  8. posix thread互斥量

    互斥量 互斥量(Mutex)是“mutual exclusion”的缩写.互斥量是实现线程同步,和保护同时写共享数据的主要方法.使用互斥量的典型顺序如下:1. 创建和初始一个互斥量 2. 多个线程尝试 ...

  9. 【转载】Hadoop和大数据:60款顶级大数据开源工具

    一.Hadoop相关工具 1. Hadoop Apache的Hadoop项目已几乎与大数据划上了等号.它不断壮大起来,已成为一个完整的生态系统,众多开源工具面向高度扩展的分布式计算. 支持的操作系统: ...

  10. gVim多标签页

    我们一般使用的文本编辑器,如:editplus.ultraEdit等都是支持多标签页的,可以同时打开多个文件,方便切换,以前gVim只能打开多个窗口,或者一个窗口切出多个窗口来编辑,自从7.0以后Vi ...