?????????????ЩORACLE SQL??????????????о????????????SQL??????????????????????С???????????????Щ???????????????????
?????????oracle?????1???????ж???????hash???????????????????????hash join?????;
?????????oracle?????1???????ж????????????????????????????????order by?????
???????????????????????????

??????????????????????????sqlplus??У??????????????CPU??????????
?????????????hash????????????


declare
i             integer;
int1          integer;
t1            number;
t2            number;
t_all         number;
t_select      number;
execute_count number := 10;
function getnumfromtimestamp(iTime timestamp) return number is
Result        number;
v_hour        number;
v_minute      number;
v_second      number;
v_millisecond number;
begin
v_hour   := EXTRACT(hour from iTime);
v_minute := EXTRACT(minute from iTime);
v_second := EXTRACT(second from iTime);
Result   := (v_hour + 1) * 3600 + (v_minute + 1) * 60 + v_second;
return(Result);
end;
begin
select /*+use_hash(a??b)*/
count(*)
into int1
from (select rownum + 20000000 rn from dual connect by rownum <= 1000000) a??
(select rownum + 10000000 rn from dual connect by rownum <= 1000000) b
where a.rn = b.rn;
t1 := getnumfromtimestamp(systimestamp);
for i in 1 .. execute_count loop
select /*+use_hash(a??b)*/
count(*)
into int1
from (select rownum + 20000000 rn
from dual
connect by rownum <= 1000000) a??
(select rownum + 10000000 rn
from dual
connect by rownum <= 1000000) b
where a.rn = b.rn;
end loop;
t2    := getnumfromtimestamp(systimestamp);
t_all := t2 - t1;
select count(*)
into int1
from (select rownum + 20000000 rn from dual connect by rownum <= 1000000);
t1 := getnumfromtimestamp(systimestamp);
for i in 1 .. execute_count loop
select count(*)
into int1
from (select rownum + 20000000 rn
from dual
connect by rownum <= 1000000);
end loop;
t2       := getnumfromtimestamp(systimestamp);
t_select := t2 - t1;
dbms_output.put_line('hash_times:' ||
trunc(1000 /
((t_all - t_select) / (2 * execute_count))));
end;
/

?????????????sort????????????