| 订阅 | 在线投稿
分享
 
 
 

视图上含有row_number分析函数没法走索引

来源:互联网  宽屏版  评论
2008-06-01 02:13:21

问题:有如下的sql性能差:

select rowid,PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE,PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE,a.* from V_CUST_DEPOSIT_LIST a where ( account_code='27902')

V_CUST_DEPOSIT_LIST 是一个视图如下:

create or replace view v_cust_deposit_list as

select row_number() over(order by tcdl.account_code,

trunc(tcdl.deposit_date), to_number(decode(tcd.distri_type,

'1', 1, '2', 5, '3', decode(tpf.fee_type, 169, 2, 69, 6),

'10', 3, '71', 4, '8', 9, 8))) rn,tcdl.*

from t_cust_deposit_list tcdl,

t_capital_distribute tcd,

t_product_fee tpf

where tcdl.capital_id = tcd.capital_id(+)

and tcd.prem_id = tpf.list_id(+)

order by tcdl.account_code,

trunc(tcdl.deposit_date),

to_number(decode(tcd.distri_type,'1',1,'2',5,'3',

decode(tpf.fee_type, 169, 2, 69, 6),'10',3,'71',4,'8',9,8));

在t_cust_deposit_list有account_code;

原因:由于在视图上含有row_number分析函数,所以没法走索引:把语句改为:

select rowid,

PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE,

PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE,

a.*

from (

select row_number() over (order by tcdl.account_code,trunc(tcdl.deposit_date),to_number(decode(tcd.distri_type,'1',1,'3',decode(tpf.fee_type,169,2,69,5),'10',3,'71',4,'2',9,8))) rn,tcdl.*

from

(select tcd2.* from t_cust_deposit_list tcd2

where tcd2.account_code='27902') tcdl,t_capital_distribute tcd,t_product_fee tpf

where tcdl.capital_id = tcd.capital_id(+) and tcd.prem_id = tpf.list_id(+)

order by tcdl.account_code,trunc(tcdl.deposit_date),to_number(decode(tcd.distri_type,'1',1,'3',decode(tpf.fee_type,169,2,69,5),'10',3,'71',4,'2',9,8))

) a

 
问题:有如下的sql性能差: select rowid,PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE,PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE,a.* from V_CUST_DEPOSIT_LIST a where ( account_code='27902') V_CUST_DEPOSIT_LIST 是一个视图如下: create or replace view v_cust_deposit_list as select row_number() over(order by tcdl.account_code, trunc(tcdl.deposit_date), to_number(decode(tcd.distri_type, '1', 1, '2', 5, '3', decode(tpf.fee_type, 169, 2, 69, 6), '10', 3, '71', 4, '8', 9, 8))) rn,tcdl.* from t_cust_deposit_list tcdl, t_capital_distribute tcd, t_product_fee tpf where tcdl.capital_id = tcd.capital_id(+) and tcd.prem_id = tpf.list_id(+) order by tcdl.account_code, trunc(tcdl.deposit_date), to_number(decode(tcd.distri_type,'1',1,'2',5,'3', decode(tpf.fee_type, 169, 2, 69, 6),'10',3,'71',4,'8',9,8)); 在t_cust_deposit_list有account_code; 原因:由于在视图上含有row_number分析函数,所以没法走索引:把语句改为: select rowid, PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE, PKG_LIFE_QUERY_FUNC.F_GET_DEPOSIT_ACCOUNT_VALUE(DEPOSIT_ID,ACCOUNT_CODE) as ACCOUNT_VALUE, a.* from ( select row_number() over (order by tcdl.account_code,trunc(tcdl.deposit_date),to_number(decode(tcd.distri_type,'1',1,'3',decode(tpf.fee_type,169,2,69,5),'10',3,'71',4,'2',9,8))) rn,tcdl.* from (select tcd2.* from t_cust_deposit_list tcd2 where tcd2.account_code='27902') tcdl,t_capital_distribute tcd,t_product_fee tpf where tcdl.capital_id = tcd.capital_id(+) and tcd.prem_id = tpf.list_id(+) order by tcdl.account_code,trunc(tcdl.deposit_date),to_number(decode(tcd.distri_type,'1',1,'3',decode(tpf.fee_type,169,2,69,5),'10',3,'71',4,'2',9,8)) ) a
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有