当前位置:首页 > 数据库 > 正文

关于oracle调优

场景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_id) as 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(CONVERT( a.create_date USING GBK ))
select count(1) from 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)