i've got a huge Oracle Trace file. The application, wich produced this file, runned 1 hour and 15 minutes. In this Tracefile i found 4 Selects with together a little bit over a hour runtime. The problem is these selects are sampled by the Optimizer.
SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS IGNORE_WHERE_CLAUSE
NO_PARALLEL(SAMPLESUB) opt_param('parallel_execution_enabled', 'false')
NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),:"SYS_B_00"),
NVL(SUM(C2),:"SYS_B_01")
FROM
(SELECT /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("LST_G") FULL("LST_G")
NO_PARALLEL_INDEX("LST_G") */ :"SYS_B_02" AS C1, CASE WHEN
"LST_G"."SENDUNG_TIX"=:"SYS_B_03" AND "LST_G"."LST_K"=:"SYS_B_04" AND
"LST_G"."LST_ART"=:"SYS_B_05" AND "LST_G"."FAK_TIX"=(-:"SYS_B_06") THEN
:"SYS_B_07" ELSE :"SYS_B_08" END AS C2 FROM "TMS1033"."LST_G" SAMPLE BLOCK
(:"SYS_B_09" , :"SYS_B_10") SEED (:"SYS_B_11") "LST_G") SAMPLESUB
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 56076 3.93 4.21 0 0 0 0
Execute 56076 1.98 1.80 0 0 0 0
Fetch 56076 1127.54 1122.77 222 46487004 0 56076
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 168228 1133.45 1128.79 222 46487004 0 56076
This is one of the four, they look nearly the same. I think i found the original Statements and these are executed from a Uniface-Service. I have no idea how Uniface works, i am only the db guy.
The problem is that i have no Idea why the Optimizer rebuild this statement. The original one don't use the dynamic_sample
hint. Also i found these, i think so, original Statments additionally in the trace file .
select count(*)
from
lst_g where sendung_tix = 10330805990396 and lst_k = 'E' and lst_art = 'G'
and fak_tix = -4
Thats why i am not sure what these sampled Statements are. Any idea?
Thanks a lot.
Dynamic sampling is turned on for that query. Either
/*+ DYNAMIC_SAMPLING */
hintalter session set optimizer_dynamic_sampling=
commandFor example
alter session set OPTIMIZER_DYNAMIC_SAMPLING = 2;
Then issue a query against a big table with a very selective (but not exact) condition that can use an index.
select * from mtl_system_items /* biiig table */
where organization_id = 92
and segment1 LIKE 'DY_' /* very selective condition with index */
Run it and you get data back quickly. But then,
alter session set OPTIMIZER_DYNAMIC_SAMPLING = 10;
and re-run the same SELECT
and it's out to lunch, sampling every block in the table.