Skip to content

Instantly share code, notes, and snippets.

@Tracnac
Last active September 23, 2022 17:01
Show Gist options
  • Select an option

  • Save Tracnac/b9675aa7b0e22bd3dbb71a12a8d43e6c to your computer and use it in GitHub Desktop.

Select an option

Save Tracnac/b9675aa7b0e22bd3dbb71a12a8d43e6c to your computer and use it in GitHub Desktop.
Valeur d’essai pour optimizer_index_cost_adj #oracle #performance

Determining a starting value for optimizer_index_cost_adj

We can see that the optimal setting for optimizer_index_cost_adj is partially a function of the I/O waits for sequential reads vs. scattered reads:

select
a.average_wait c1,
b.average_wait c2,
a.total_waits /(a.total_waits + b.total_waits)*100 c3,
b.total_waits /(a.total_waits + b.total_waits)*100 c4,
(b.average_wait / a.average_wait)*100 c5
from
v$system_event a,
v$system_event b
where
a.event = 'db file scattered read'
and
b.event = 'db file sequential read';

Here is sample output from a real system showing an empirical test of disk I/O speed. We always expert scattered reads (full-table scans) to be far faster than sequential reads (index probes) because of Oracle sequential prefetch (see db_file_multiblock_read_count):

  • scattered read (full table scans) are fast at 13ms (c3)
  • sequential reads (index probes) take much longer 86ms (c4)
  • starting setting for optimizer_index_cost_adj at 36:

C1 C2 C3 C4 C5


13,824 5,072 13 86 36

In Oracle 10g, you can use this script using the dba_hist_system_event table:

col c1 heading 'Average Waits for|Full Scan Read I/O' format 9999.999
col c2 heading 'Average Waits for|Index Read I/O' format 9999.999
col c3 heading 'Percent of| I/O Waits|for scattered|Full Scans' format 9.99
col c4 heading 'Percent of| I/O Waits|for sequential|Index Scans' format 9.99
col c5 heading 'Starting|Value|for|optimizer|index|cost|adj' format 999


select
sum(a.time_waited_micro)/sum(a.total_waits)/1000000 c1,
sum(b.time_waited_micro)/sum(b.total_waits)/1000000 c2,
(
sum(a.total_waits) /
sum(a.total_waits + b.total_waits)
) * 100 c3,
(
sum(b.total_waits) /
sum(a.total_waits + b.total_waits)
) * 100 c4,
(
sum(b.time_waited_micro) /
sum(b.total_waits)) /
(sum(a.time_waited_micro)/sum(a.total_waits)
) * 100 c5
from
dba_hist_system_event a,
dba_hist_system_event b
where
a.snap_id = b.snap_id
and
a.event_name = 'db file scattered read'
and
b.event_name = 'db file sequential read';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment