建表语句:
create table test(col1 number,col2 number,col3 number,col4 number,col5 number,col6 number,col7 number,col8 number);
insert into test values(10,20,30,40,50,60,70,80);
commit;
查询语句:
select (case
when col7 < 100 then 100
when col7 < 200 then 200
when col7 < 300 then 300
when col7 < 400 then 400
when col7 < 500 then 500
when col7 < 600 then 600
else 700 end) + col8 as col8
from(select (case
when col6 < 100 then 100
when col6 < 200 then 200
when col6 < 300 then 300
when col6 < 400 then 400
when col6 < 500 then 500
when col6 < 600 then 600
else 700 end) + col7 as col7,col8
from(select (case
when col5 < 100 then 100
when col5 < 200 then 200
when col5 < 300 then 300
when col5 < 400 then 400
when col5 < 500 then 500
when col5 < 600 then 600
else 700 end) + col6 as col6,col7,col8
from(select (case
when col4 < 100 then 100
when col4 < 200 then 200
when col4 < 300 then 300
when col4 < 400 then 400
when col4 < 500 then 500
when col4 < 600 then 600
else 700 end) + col5 as col5,col6,col7,col8
from(select (case
when col3 < 100 then 100
when col3 < 200 then 200
when col3 < 300 then 300
when col3 < 400 then 400
when col3 < 500 then 500
when col3 < 600 then 600
else 700 end) + col4 as col4,col5,col6,col7,col8
from(select (case
when col2 < 100 then 100
when col2 < 200 then 200
when col2 < 300 then 300
when col2 < 400 then 400
when col2 < 500 then 500
when col2 < 600 then 600
else 700 end) + col3 as col3,col4,col5,col6,col7,col8
from (select (case
when col1 < 100 then 100
when col1 < 200 then 200
when col1 < 300 then 300
when col1 < 400 then 400
when col1 < 500 then 500
when col1 < 600 then 600
else 700 end) + col2 as col2,col3,col4,col5,col6,col7,col8
from test))))));
在我的电脑上这个执行要80秒,10046报表查看时间全是在硬解析上。
如果在外面减去一层子查询,解析就很快。但在外再加一层子查询的话解析就得几十分钟
请问这是什么原因?
(请不要关注这个SQL写的方式,实际上不会这样写SQL,我就是想请问下造成这样长的解析时间的原因。)
谢谢