关于oracle调优

时间:2021-01-08 10:47:49   收藏:0   阅读:0

场景1:查询时间过长

 select u.*,t.*
        (select sum(l.all_pl2)
           from TABLE_A l
          where 1 = 1
            and l.tx_dt <= ‘20201223‘
            and u.investor_id = l.investor_idas sum_all_pl2
   from TABLE_C u
  inner join (select t2.*
                from (select t.*
                             rank() over(partition by investor_id order by tx_dt desc) rowno
                        from TABLE_B t
                       where t.tx_dt <= ‘20201223‘) t2
               where 1 = 1
                 and t2.rowno = 1) t3 on u.investor_id = t3.investor_id
  where 1 = 1
order by HEX(CONVERTa.create_date USING GBK ))
select count(1from TABLE_A;--结果集1104207
select count(1)from TABLE_B;--结果集7257
1.查看表是否有索引,为关联字段添加索引
create index idx_tablieatxdtinvid on TABLE_A (INVESTOR_ID, TX_DT);
create index idx_tablieatxdt on TABLE_A (TX_DT);
create index idx_tablieainvid on TABLE_A (INVESTOR_ID);
2.表字段的索引主要针对数值型的varchar2或者number有效。
3.排序字段最好使用数值的varchar2或者number。尽量不使用非数字排序(yyyy-dd-mm,uuid,中英文等)
4.关联字段的类型最好统一,尽量不要用varchar2和number关联(varchar2的数值和number字段关联,减少oracle的隐式转换)
5.主键可以使用封装的@getNextSequence方法获取





来自为知笔记(Wiz)


评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!