########################################################################################################### ## This file is part of http://www.gplivna.eu/papers/v$session_longops.htm ########################################################################################################### ########################################################################################################### ## Creating example table and initializing environment ########################################################################################################### SQL> create table big as select * from dba_source where rownum <= 50000; Table created. Elapsed: 00:00:24.02 SQL> alter session set workarea_size_policy = manual; Session altered. Elapsed: 00:00:00.00 SQL> alter session set hash_area_size = 70000; Session altered. Elapsed: 00:00:00.00 SQL> alter session set optimizer_mode = all_rows; Session altered. Elapsed: 00:00:00.00 ########################################################################################################### ## Just run query joining table to itself to see how it works ########################################################################################################### SQL> select count(*) from ( 2 select /*+ use_hash(a, b) */ * from big a, big b 3 where a.owner = b.owner 4 and a.name = b.name 5 and a.type = b.type 6 and a.line = b.line 7 and a.text = b.text 8 ) 9 / COUNT(*) ---------- 50000 Elapsed: 00:00:44.09 ########################################################################################################### ## A delete of row in table flag is needed ## for another session to signal that work has been done in this session ########################################################################################################### SQL> create table flag (a number); Table created. Elapsed: 00:00:00.00 ########################################################################################################### ## Just insert one row ## After the work row will be deleted ########################################################################################################### SQL> insert into flag values (1); 1 row created. Elapsed: 00:00:00.00 SQL> commit; Commit complete. ########################################################################################################### ## This session just runs pl/sql block ## rows between 1 and 14999 are just fetched without any other work ## rows between 15000 and 18000 are fetched and the pl/sql sleeps for 0.03 seconds ## rows between 18001 and 50000 are just fetched without any other work ## how v$session_longops changes it's expectations can bee seen in another session's spool file ########################################################################################################### SQL> declare 2 cursor c is 3 select /*+ use_hash(a, b) */ a.* from big a, big b 4 where a.owner = b.owner 5 and a.name = b.name 6 and a.type = b.type 7 and a.line = b.line 8 and a.text = b.text; 9 k number := 0; 10 begin 11 for v in c loop 12 k := k + 1; 13 if k between 15000 and 18000 then 14 dbms_lock.sleep(0.03); 15 end if; 16 end loop; 17 delete flag; 18 commit; 19 end; 20 / PL/SQL procedure successfully completed. Elapsed: 00:02:06.07