Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Optimizer Dynamic Sampling doesn't work in our DB

656310Sep 6 2012 — edited Sep 6 2012
Hi,
I'm trying to explore Optimizer Dynamic Sampling functionality,but it seems that database use this feature only if I use /*+ optimizer_dynamic_sampling */ hint.
There is optimizer_dynamic_sampling=2 set on system level (init.ora) and I also set this parameter on session level. But dynamic sampling is fired only with hint. I would like to use this feature transparently without any hints needed.
Could it be some kind of bug or I'm doing something wrong?
Thanks. Filip

See example below.

DB version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
OS version: AIX-Based Systems (64-bit)

/* Check parameter setting*/
select name,value,isdefault from v$parameter p
where p.NAME='optimizer_dynamic_sampling';

NAME VALUE ISDEFAULT
optimizer_dynamic_sampling 2 TRUE

/* Create table without STATS*/
create table test_sampling as select * from all_objects;

/* Create index */
create index ix_tstsam on test_sampling (object_name, owner);

/* Check if statistics exists*/
select table_name,num_rows,last_analyzed from all_tables a where a.table_name= 'TEST_SAMPLING';
TABLE_NAME NUM_ROWS LAST_ANALYZED
------------------------------ ---------- -------------
TEST_SAMPLING NULL NULL

/* Setting Dynamic sampling on session level* /
Alter session set optimizer_dynamic_sampling=2;

/************ Explain plan - Select without hint ************/
explain plan set statement_id='TST_NOHINT' for
select sa.object_name from test_sampling sa where sa.owner = 'X';

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2834243581
-------------------------------------------
| Id | Operation | Name |
-------------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | TABLE ACCESS FULL| TEST_SAMPLING |
-------------------------------------------
Note
-----
- rule based optimizer used (consider using cbo)

/************ Explain plan - Select WITH hint ************/
explain plan set statement_id='TST_HINT' for
select /*+ dynamic_sampling(2) */ sa.object_name from test_sampling sa where sa.owner = 'X';

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3916830885
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 272 | 86 (2)| 00:00:02
|* 1 | INDEX FAST FULL SCAN| IX_TSTSAM | 8 | 272 | 86 (2)| 00:00:02
--------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2012
Added on Sep 6 2012
3 comments
312 views