`
eyejava
  • 浏览: 1255306 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

对于超多关联的select SQL,性能优化好像能做的事情很少

    博客分类:
  • DB
阅读更多
14个join的select语句,头大!
能做性能优化修改的地方有以下几个:
1.where 和on条件中尽可能按照index顺序来排列条件,并且尽可能不在条件左边使用函数,比如substr可以用like 替代。如果非得使用函数,则把带有函数的条件排到后面。
2.按照业务逻辑能用inner join的地方不使用left join,这个语句有个地方inner join ls换成left join,时间要增加8倍!分别是30秒和240秒
3.join 后面的表尽可能不使用子查询

insert into bills
  select
    *--简化
  from  ixqdwdel d
  inner join (select s.entity,s.deal_no,s.step_open_date,
        nvl(nvl(s.offering_date,s.rel_date_b),s.rel_date_a) rel_date
        from ixqdwstp s where s.entity=entity_c and s.step_id = 'ISS000'
        and s.step_status='4') iss
        on iss.entity=d.entity and iss.deal_no=d.deal_no
  inner join ixqdwcna c --customer info
        on d.customer_id=c.customer_id and d.entity=c.entity
  inner join (select * from (select x.entity,x.currency_code,x.rate_1/10000000 rate,x.rate_2/10000000 rate2,
            dense_rank() over (partition by x.entity,x.currency_code order by x.date_key) d,x.date_key
             from ixqap098 x
            where x.entity=entity_c ) a where a.d=1) x
        on d.entity=x.entity and d.deal_curr=x.currency_code
  left join (select * from
       (select l.*,dense_rank() over(partition by l.deal_no order by substr(l.step_id,4,3) desc)seq
       from ixqdwolc l where l.entity=entity_c) l where l.seq=1) l --LC/LG
       on d.entity=l.entity and d.deal_no=l.deal_no
  left join ixqdwicd i on d.deal_no=i.deal_no and d.entity=i.entity and i.step_id='ISS000'
  
  left join ixqdwdpr p
       on d.entity=p.entity and d.deal_no=p.deal_no and p.step_id='ISS000' and p.party_code='ISB' 
  left join ixqdwexs be
       on p.party_id=be.party_id and be.entity=p.entity and p.party_ext=be.extension_no
  left join ixqdwdpr rp
       on d.entity=rp.entity and d.deal_no=rp.deal_no and rp.step_id='ISS000' and rp.party_code='RMB'
  
  left join ixqdwexs ber
       on rp.party_id=ber.party_id and ber.entity=rp.entity and rp.party_ext=ber.extension_no
  left join (select * from (select s.*,dense_rank() over(partition by s.deal_no order by s.time_stamp desc) seq
       from ixqdwstp s where s.entity=entity_c and s.step_status='4'
       and (s.step_id like 'PAY%' or s.step_id like 'ACP%')) s where seq=1) doc
       on d.entity=doc.entity and d.deal_no=doc.deal_no
  inner join (select * from (select s.*,dense_rank() over(partition by s.deal_no order by s.time_stamp desc) seq
       from ixqdwstp s where s.entity=entity_c and s.step_status='4') s where seq=1) ls
       on d.entity=d.entity and d.deal_no=ls.deal_no
  left join (select trim(ld.owner_id) owner_id,ld.limit_key,ld.limit_no,
            ld.limit_categ_desc,ld.deal_no,ld.entity from (
       select ld.*,lm001.limit_categ_desc,dense_rank()
       over(partition by ld.entity,ld.deal_no order by ld.limit_key) seq from
       ixqdwlde ld inner join ixqlm001 lm001
       on ld.entity=lm001.entity and ld.limit_key=lm001.limit_categ_code
       where ld.entity=entity_c and lm001.funded_unfunded='U'
       ) ld where seq=1 )lm
      on d.entity=lm.entity and d.deal_no=lm.deal_no     
  
  left join ixqdwchg ch on d.entity=ch.entity and d.deal_no=ch.deal_no
          and ch.entity=entity_c and (ch.charge_id like '90%1')
          and ch.step_type ='ISS'
  left join ixqap129 ap129--
            on ch.entity=ap129.entity and ch.charge_id=ap129.debit_credit_id
            and ch.charge_curr = ap129.currency_code
  

  where d.entity=entity_c
  and d.product in ('01','02','11','12')
  and d.last_rel_step_id not like 'BKF%'
  and length(trim(d.customer_id))=10
  and translate(trim(d.customer_id),'\1234567890','\') is null
  ;

分享到:
评论

相关推荐

    SQL查询安全性及性能优化

    子查询嵌套过多对性能有影响,查询关联的表特别多也影响性能  频繁访问数据等等 SQL如何被SQLServer执行的 SQL执行原理  解释:首先解释SQL语句【语法是否正确】  解析:检验语句的出现的对象是否有效...

    oracle的sql优化

     对于复杂的存储过程可以多次提交的数据的要多分多次Commit,否则长事务对系统性能影响很大  Distinct和Having子句都是耗时操作,应该尽可能少使用  在不需要考虑重复记录合并时候用Union All来代替Union  使用...

    SQL 优化原则

    对于海量数据,劣质SQL语句和优质SQL语句之间的速度差别可以达到上百倍,可见对于一个系统不是简单地能实现其功能就可,而是要写出高质量的SQL语句,提高系统的可用性。  在多数情况下,Oracle使用索引来更快地遍...

    经典SQL语句大全

    1、1=1,1=2的使用,在SQL语句组合时用的较多 “where 1=1” 是表示选择全部 “where 1=2”全部不选, 如: if @strWhere !='' begin set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' + ...

    MySQL在关联复杂情况下所能做出的一些优化

    查询所返回的结果集,通常查询返回的结果集很少,是有信心进行优化的;  第二.驱动表的选择至关重要,通过查看执行计划,可以看到优化器选择的驱动表,从执行计划中的rows可以大致反映出问题的所在;  第三.理清各...

    sql经典语句一部分

    1、1=1,1=2的使用,在SQL语句组合时用的较多 “where 1=1” 是表示选择全部 “where 1=2”全部不选, 如: if @strWhere !='' begin set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' + ...

    数据库操作语句大全(sql)

    1、1=1,1=2的使用,在SQL语句组合时用的较多 “where 1=1” 是表示选择全部 “where 1=2”全部不选, 如: if @strWhere !='' begin set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' +...

    Toad 使用快速入门

    在Oracle应用程序的开发过程中,访问数据库对象和编写SQL程序是一件乏味且耗费时间的工作,对数据库进行日常管理也是需要很多SQL脚本才能完成的。Quest Software为此提供了高效的Oracle应用开发工具-Toad(Tools of ...

    Node.js的DAO框架bearcat-dao.zip

    很少有哪一种软件技术敢声称自己像关系数据库和SQL那样经受住了时间的考验。因此,关系数据库和SQL仍然很有价值,我们可能都曾有这样的经历,应用程序的源代码(经历了很多版本)随着时间的流逝最终还是过时了(无法...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    Access 微软 Access是一种桌面数据库,只适合数据量少的应用,在处理少量 数据和单机访问的数据库时是很好的,效率也很高 小型企业 三、 Oracle数据库概述 ORACLE数据库系统是美国ORACLE公司(甲骨文)提供的以...

    asp.net知识库

    关于能自定义格式的、支持多语言的、支持多数据库的代码生成器的想法 发布Oracle存储过程包c#代码生成工具(CodeRobot) New Folder XCodeFactory3.0完全攻略--序 XCodeFactory3.0完全攻略--基本思想 XCodeFactory...

    Oracle In和exists not in和not exists的比较分析

    in和exist的区别 从sql编程角度来说,in直观,exists不直观多一个select, in可以用于各种子查询,而exists好像只用于关联子查询 从性能上来看 exists是用loop的方式,循环的次数影响大,外表要记录数少,内表就...

    springmybatis

    而且也比较轻量级,因为当时在项目中,没来的及做很很多笔记。后来项目结束了,我也没写总结文档。已经过去好久了。但最近突然又对这个ORM 工具感兴趣。因为接下来自己的项目中很有可能采用这个ORM工具。所以在此...

    Oracle9i的init.ora参数中文说明

    只有行锁将用于SELECT FOR UPDATE, 但在更新时将获取表锁。 值范围: ALWAYS | DEFAULT | INTENT 默认值: ALWAYS shared_servers 说明 : 指定在启动例程后, 要为共享服务器环境创建的服务器进程的数量。 值范围: ...

    一个好用的数据库类

    要说明的是,这两个类可以说比较简单,两个类的代码量很少,所以建议感兴趣的朋友看一下它的代码,下图是本代码运行效果图: <br> <br>二、原理 其实无论是使用ODBC API还是使用ORACLE的OCI(对于ORACLE的...

    Hibernate注解

    * 5.identity 使用SQL Server和MySQL的自增字段,这个方法不能放到Oracle中,Oracle不支持自增字段,要设定sequence(MySQL和SQL Server中很常用)。等同于JPA中的IDENTITY * 例:@GeneratedValue(generator = ...

    软件工程工资管理系统

    工资管理信息系统对企业加强工资管理有着重要的作用,就一般的大型企业来说,它的设计内容非常复杂而且繁多,比如拥有工资计算功能,工资统计功能,报表输出功能,而且设计的模块也很多,比如工资管理模块,工资...

    ado[1].net中文手册 学习 ado.net的重要资料

    在已部署系统的生存期中,适度的更改是可能的,但由于十分困难,所以很少尝试进行实质的结构更改。这是很遗憾的,因为在事件的自然过程中,这种实质上的更改会变得很有必要。例如,当已部署的应用程序越来越受用户...

    [数据库设计]超市管理系统设计

     数据库是实现有组织地,动态地存储大量关联数据,方便多用户访问的计算机软硬件组成的系统;它与文件系统的重要区别是数据的充分共享,交叉访问,与应用程序的高度独立性。  由于本软件的整体结构比较简单,所...

Global site tag (gtag.js) - Google Analytics