SELECT ID,CODE FROM V_PORT_CS WHERE CODE = '//1' -- 40.11 SECONDS
SELECT ID,NAME FROM V_PORT_CS WHERE NAME = '1' --0.078 SECONDS
如上:只要加上CODE 这个字段,去查V_PORT_CS这个视图就会超级慢(40.11秒),用其他字段都不会有问题,比如用name等去查。
以下是其他相关信息:
1. SELECT COUNT(*) FROM V_PORT_CS; -- 322212
该视图共32万条数据
2.视图定义
create or replace view v_port_cs as
(select
ID,
MBID,
MRID,
MSID,
coderule(CODE,ID,'E_NPORT') AS CODE,
NAME,
RESOURCEID
from e_nport
where kindcode in (-99,1,2,3,6,200,101,9,108,4,8,7));
3. 函数定义
create or replace function coderule(object_code in varchar2,tableid in number,tablename in varchar2) return varchar2 is
rvalue varchar2(1000);
eqcode varchar2(1000);
efcode varchar2(1000);
efidx number;
modulecode varchar2(1000);
begin
if tablename='E_NPORT' then
begin
select efid into efidx from E_NPORT where id=tableid;
select (select name from e_equipment where id=e.object_id) into eqcode from e_eqframe e where e.id=efidx;
EXCEPTION
when others then
dbms_output.put_line(sqlerrm);
end;
begin
select (select code from e_eqframe where id=e.efid) into efcode from E_NPORT e where e.id=tableid;
EXCEPTION
when others then
dbms_output.put_line(sqlerrm);
end;
begin
select (select code from e_module where id=e.moduleid) into modulecode from E_NPORT e where e.id=tableid;
EXCEPTION
when others then
dbms_output.put_line(sqlerrm);
end;
if modulecode IS NULL then
rvalue:=eqcode||'/'||efcode||'/'||object_code;
end if;
if modulecode IS NOT NULL then
rvalue:=eqcode||'/'||efcode||'/'||modulecode||'/'||object_code;
end if;
end if;
return rvalue;
end coderule;
5
对于 视图中的name,code 等均做了索引
以上。
求解!