- 论坛徽章:
- 0
|
我写的SQL文关联了3个表,从环境读入三个变量,在ORACLE9下执行时花了很长时间,最后进程被杀死。
select A.user, A.code,B.rate from table1 A, table2 B where
:flg = '1'
and A.user = :user
and A.yymd = :yymd
and (:flg2 = '1'
or A.flg2 = :flg2)
and (:flg3 = '1'
or A.flg3 = :flg3)
and A.user = B.user
and A.yymd = B.yymd
and A.code in (
select distinct minicode from table3
where user = :user
and valid_yymd = :sysyymd)
order by 1,2
名字前面带冒号的是传入的变量。上面这代码会造成执行超时(A,B表数据量很大),如果把
:flg2 = '1', :flg3 = '1'
去掉,代码就会变成不到一秒就执行完了。别人说是因为用了变量并且又用了OR,却又说不出个所起然了,百思不得其解啊!!! 有谁明白个中原理吗?谢谢大家了。UNIX是HP9000 |
|