....
You can workaround this by setting workspace management to manual for that session and explicitly nominating sort size parameters. "
....
runquery.sqlset serveroutput off;
column sid new_val SID
select userenv('sid') sid from dual;
alter session set workarea_size_policy=MANUAL;
alter session set sort_area_size=&1;
prompt run @reset_stats.sql &SID and @watch_stats in another session here!
pause
prompt running the sql to sort
set termout off;
select * from t order by 1,2,3,4;
set termout on;
prompt run @watch_stats in another session here!
pause
watch_stats.sqlcolumn name format a40 trunc;
column KbytesWrites format 99999999999;
column Diff_KbytesWrites format 99999999999;
merge into session_stats t1 using
( select s1.name, s2.value
from v$sysstat s1,
v$sesstat s2
where ( s1.name like '%ga%'
or s1.name like '%direct%temp%' )
and s1.statistic# = s2.statistic#
and s2.sid = :sid ) t2
on (t1.name = t2.name)
when matched then
update set
t1.diff = t2.value - t1.value,
t1.value = t2.value
when not matched then
insert (t1.name,t1.value,t1.diff)
values (t2.name,t2.value,NULL)
/
select name,
CASE when name like '%ga%'
then round(value/1024)
else value
end as KbytesWrites,
CASE when name like '%ga%'
then round(diff/1024)
else value
end as Diff_KbytesWrites
from session_stats
order by name
/
run_query.sqlset serveroutput off;
column sid new_val SID
select userenv('sid') sid from dual;
alter session set workarea_size_policy=MANUAL;
alter session set sort_area_size=&1;
prompt run @reset_stats.sql &SID and @watch_stats in another session here!
pause
prompt running the sql to sort
set termout off;
select * from t order by 1,2,3,4;
set termout on;
prompt run @watch_stats in another session here!
pause
Run#1Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
demo@ORA12C> @run_query.sql 65536
SID
----------
365
Session altered.
old 1: alter session set sort_area_size=&1
new 1: alter session set sort_area_size=65536
Session altered.
run @reset_stats.sql 365 and @watch_stats in another session here!
running the sql to sort
run @watch_stats in another session here!
demo@ORA12C> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
The other session(session#2) reported the Temp Space usage like this.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
demo@ORA12C> @reset_stats.sql 365
Table dropped.
Table created.
PL/SQL procedure successfully completed.
demo@ORA12C> @watch_stats
17 rows merged.
NAME KBYTESWRITES DIFF_KBYTESWRITES
---------------------------------------- ------------ -----------------
HSC OLTP negative compression 0
OLAP Aggregate Function Calc 0
OLAP Aggregate Function Logical NA 0
OLAP Aggregate Function Precompute 0
Workload Replay: time gain 0
calls to kcmgas 0
foreground propagated tracked transactio 0
index cmph ld, CU negative comp 0
ka wait calls for invalid kga 0
physical reads direct temporary tablespa 0 0
physical writes direct temporary tablesp 0 0
redo write gather time 0
session pga memory 1729
session pga memory max 2241
session uga memory 852
session uga memory max 1228
slave propagated tracked transactions 0
17 rows selected.
demo@ORA12C> @watch_stats
17 rows merged.
NAME KBYTESWRITES DIFF_KBYTESWRITES
---------------------------------------- ------------ -----------------
HSC OLTP negative compression 0 0
OLAP Aggregate Function Calc 0 0
OLAP Aggregate Function Logical NA 0 0
OLAP Aggregate Function Precompute 0 0
Workload Replay: time gain 0 0
calls to kcmgas 0 0
foreground propagated tracked transactio 0 0
index cmph ld, CU negative comp 0 0
ka wait calls for invalid kga 0 0
physical reads direct temporary tablespa 7181 7181
physical writes direct temporary tablesp 7181 7181
redo write gather time 0 0
session pga memory 1857 128
session pga memory max 2689 448
session uga memory 1235 384
session uga memory max 1749 520
slave propagated tracked transactions 0 0
17 rows selected.
demo@ORA12C> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Run#2Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
demo@ORA12C> @run_query.sql 1048576
SID
----------
365
Session altered.
old 1: alter session set sort_area_size=&1
new 1: alter session set sort_area_size=1048576
Session altered.
run @reset_stats.sql 365 and @watch_stats in another session here!
running the sql to sort
run @watch_stats in another session here!
demo@ORA12C> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
The other session(session#2) reported the Temp Space usage like this.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
demo@ORA12C> @reset_stats.sql 365
Table dropped.
Table created.
PL/SQL procedure successfully completed.
demo@ORA12C> @watch_stats
17 rows merged.
NAME KBYTESWRITES DIFF_KBYTESWRITES
---------------------------------------- ------------ -----------------
HSC OLTP negative compression 0
OLAP Aggregate Function Calc 0
OLAP Aggregate Function Logical NA 0
OLAP Aggregate Function Precompute 0
Workload Replay: time gain 0
calls to kcmgas 0
foreground propagated tracked transactio 0
index cmph ld, CU negative comp 0
ka wait calls for invalid kga 0
physical reads direct temporary tablespa 0 0
physical writes direct temporary tablesp 0 0
redo write gather time 0
session pga memory 1665
session pga memory max 1985
session uga memory 852
session uga memory max 1036
slave propagated tracked transactions 0
17 rows selected.
demo@ORA12C> @watch_stats
17 rows merged.
NAME KBYTESWRITES DIFF_KBYTESWRITES
---------------------------------------- ------------ -----------------
HSC OLTP negative compression 0 0
OLAP Aggregate Function Calc 0 0
OLAP Aggregate Function Logical NA 0 0
OLAP Aggregate Function Precompute 0 0
Workload Replay: time gain 0 0
calls to kcmgas 0 0
foreground propagated tracked transactio 0 0
index cmph ld, CU negative comp 0 0
ka wait calls for invalid kga 0 0
physical reads direct temporary tablespa 1425 1425
physical writes direct temporary tablesp 1425 1425
redo write gather time 0 0
session pga memory 3905 2240
session pga memory max 3905 1920
session uga memory 3218 2366
session uga memory max 3218 2182
slave propagated tracked transactions 0 0
17 rows selected.
demo@ORA12C> exit
Run#3demo@ORA12C> @run_query.sql 104857600
SID
----------
365
Session altered.
old 1: alter session set sort_area_size=&1
new 1: alter session set sort_area_size=104857600
Session altered.
run @reset_stats.sql 365 and @watch_stats in another session here!
running the sql to sort
run @watch_stats in another session here!
demo@ORA12C>
The other session(session#2) reported the Temp Space usage like this.
demo@ORA12C> @reset_stats.sql 365
Table dropped.
Table created.
PL/SQL procedure successfully completed.
demo@ORA12C> @watch_stats
17 rows merged.
NAME KBYTESWRITES DIFF_KBYTESWRITES
---------------------------------------- ------------ -----------------
HSC OLTP negative compression 0
OLAP Aggregate Function Calc 0
OLAP Aggregate Function Logical NA 0
OLAP Aggregate Function Precompute 0
Workload Replay: time gain 0
calls to kcmgas 0
foreground propagated tracked transactio 0
index cmph ld, CU negative comp 0
ka wait calls for invalid kga 0
physical reads direct temporary tablespa 0 0
physical writes direct temporary tablesp 0 0
redo write gather time 0
session pga memory 1025
session pga memory max 1537
session uga memory 404
session uga memory max 1036
slave propagated tracked transactions 0
17 rows selected.
demo@ORA12C> @watch_stats
17 rows merged.
NAME KBYTESWRITES DIFF_KBYTESWRITES
---------------------------------------- ------------ -----------------
HSC OLTP negative compression 0 0
OLAP Aggregate Function Calc 0 0
OLAP Aggregate Function Logical NA 0 0
OLAP Aggregate Function Precompute 0 0
Workload Replay: time gain 0 0
calls to kcmgas 0 0
foreground propagated tracked transactio 0 0
index cmph ld, CU negative comp 0 0
ka wait calls for invalid kga 0 0
physical reads direct temporary tablespa 0 0
physical writes direct temporary tablesp 0 0
redo write gather time 0 0
session pga memory 1217 192
session pga memory max 14529 12992
session uga memory 660 256
session uga memory max 13707 12670
slave propagated tracked transactions 0 0
17 rows selected.
demo@ORA12C>
The observation here is when workarea_size_policy is set to MANUAL, we depend on sort_area_size values rather than PGA_AGGREGATE_TARGET - so during each run, i keep increasing the sort_area_size values that inturn reduces the physical IO ( "physical reads(writes) direct temporary tablespace" ) Temp space, and does the sorting entirely in-memory.