Optimizer modes
Please explain value optimizer_mode = MULTIPLE CHILDREN PRESENT
for some of SQL statements in view V$SQLAREA.
null
Please read these:
When your query takes too long
When your query takes too long ...
How to Post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
Similar Messages
-
what is the difference between setting optimizer mode in oracle 10g
optimizer_mode=choose
optimizer_mode=all_rowsuser446367 wrote:
what i have to set for the below parameters . any idea ?
optimizer_index_caching
optimizer_index_cost_adjIn general you would leave them set at the default value in 10g (and probably, in most earlier versions, for most cases as well). Even if you were to change them, asking for specific values on an internet forum is rather asking for trouble, it's not dissimilar to asking "what should I set for the parameter processes?" A reasonable value will be application dependent.
The first parameter reduces the cost of some types of indexed access by assuming that only the specified percentage of index i/o actually results in a physical I/O and therefore only that percentage of the io cost is taken into account. By contrast all tablescan access and the other types of indexed access are assumed to be uncached and therefore need costing.
The second parameter just arbitrarily scales indexed access path costings.
You could argue, and some have, that you could calculate a cache hit ratio for index blocks in much the same way as you can calculate a cache hit ratio generally and then set the first parameter to this value. The standout problems with this approach are
1) It applies to all matching statements and objects not just your problem ones.
2) It doesn't necessarily even apply to your problem statements.
3) It doesn't have anything to do with query duration per se, just efficiency of one particular access path.
4) People tend to choose to round costs down and make the likelihood of two plans getting the same cost and being chosen on a tiebreaker basis higher.
The second parameter just asks you how much you like the idea of indexes generally. If you are going to change it pick a family members age or something - it'll make you smile every time you see it.
Niall Litchfield
http://www.orawin.info/ -
Hello experts,
When we set optimizer mode to first_rows_100 or first_rows etc. The fetch rows doesn't change. I am trying to understand the differences between first_rows and all_rows. It gives preference to index scan against full table scan, even the index scan is no good. And also prefers nested loop over hash join. HOWEVER, except all these, please correct me if I am wrong, I do understand that first_nows_100 only fetch 100 rows regardless default fecth row, am I wrong? What do you think about the following example in terms of CONSISTENT GETS????
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter system flush shared_pool;
Sistem dei■tirildi.
SQL> set autotrace traceonly
SQL> select * from my_test where id < 181000;
31000 sat²rlar² seildi.
Y³r³tme Plan²
Plan hash value: 1615681525
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 31001 | 605K| 53 (2)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| MY_TEST | 31001 | 605K| 53 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("ID"<181000)
¦statistikler
454 recursive calls
0 db block gets
2323 consistent gets
93 physical reads
116 redo size
843244 bytes sent via SQL*Net to client
23245 bytes received via SQL*Net from client
2068 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
31000 rows processed
SQL> select * from my_test where id < 181000;
31000 sat²rlar² seildi.
Y³r³tme Plan²
Plan hash value: 1615681525
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 31001 | 605K| 53 (2)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| MY_TEST | 31001 | 605K| 53 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("ID"<181000)
¦statistikler
0 recursive calls
0 db block gets
2235 consistent gets
0 physical reads
0 redo size
843244 bytes sent via SQL*Net to client
23245 bytes received via SQL*Net from client
2068 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
31000 rows processed
SQL> alter session set optimizer_mode = FIRST_ROWS_100;
Oturum dei■tirildi.
SQL> select * from my_test where id < 181000;
31000 sat²rlar² seildi.
Y³r³tme Plan²
Plan hash value: 509756919
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time |
| 0 | SELECT STATEMENT | | 100 | 2000 | 4 (0)
| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| MY_TEST | 100 | 2000 | 4 (0)
| 00:00:01 |
|* 2 | INDEX RANGE SCAN | SYS_C0011105 | | | 2 (0)
| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("ID"<181000)
¦statistikler
1 recursive calls
0 db block gets
4402 consistent gets
0 physical reads
0 redo size
1159430 bytes sent via SQL*Net to client
23245 bytes received via SQL*Net from client
2068 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
31000 rows processed
Thanks in adnvance.the first_rows(n) hint is only about costing and instructs the optimizer to find a plan that returns the first n rows as fast as possible - though this approach may increase the total execution time for the query. This could be useful for applications that need only the top results most the time. Consider the following example:
drop table t;
create table t (
col1 not null
, col2
as
select mod(rownum, 100) col1
, lpad('*', 50, '*') col2
from dual
connect by level <= 100000;
exec dbms_stats.gather_table_stats(user, 'T')
create index t_idx on t(col1);
explain plan for
select *
from t
where col1 = 1
order by col1;
select * from table(dbms_xplan.display);
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1000 | 54000 | 423 (0)| 00:00:03 |
|* 1 | TABLE ACCESS FULL| T | 1000 | 54000 | 423 (0)| 00:00:03 |
Predicate Information (identified by operation id):
1 - filter("COL1"=1)
explain plan for
select /*+ first_rows(10) */
from t
where col1 = 1
order by col1;
select * from table(dbms_xplan.display);
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 10 | 540 | 10 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 10 | 540 | 10 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("COL1"=1)
Obiously the hint changes the costing massively - and for the given query the top 10 results could indeed be returned faster by the index scan (though the difference would be small for this small example).
The details of the costing are not that simple and they are described in Randolf Geist's presentation http://www.sqltools-plusplus.org:7676/media/FIRST_ROWS_n%20presentation%20UKOUG%202009.pdf (titled: Everything you wanted to know about first_rows_n but were afraid to ask). -
Oracle Optimizer Mode Choose / Rule
Hello,
we have a strange behavior with Oracle 9.2
We have a application doing
SELECT to_char(COLUMNNAME)
FROM
VIEW WHERE ROWNUM = 1
This statement needs 75 seconds executed on the server within the application.
call count cpu elapsed disk query current rows
Parse 68 0.01 0.02 1 108 0 0
Execute 136 0.14 0.14 0 0 0 0
Fetch 68 68.74 75.64 119587 181628 2 68
total 272 68.89 75.81 119588 181736 2 68
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 25
Rows Row Source Operation
1 COUNT STOPKEY
1 HASH JOIN
524213 TABLE ACCESS FULL TABLEA
6 INDEX FAST FULL SCAN INDEX (object id 7026)
Optimizer mode is CHOOSE and we have generated Statistics.
When we switch to RULE the SQL will perform within millseconds
call count cpu elapsed disk query current rows
Parse 68 0.01 0.00 0 2 0 0
Execute 68 0.00 0.00 0 0 0 0
Fetch 68 0.01 0.05 68 476 0 68
total 204 0.02 0.05 68 478 0 68
Misses in library cache during parse: 1
Optimizer goal: RULE
Parsing user id: 25
Rows Row Source Operation
1 COUNT STOPKEY
1 NESTED LOOPS
1 TABLE ACCESS FULL TABLEA
1 INDEX UNIQUE SCAN INDEX (object id 7026)
Even when executing this statement within SQLPLUS on the server it takes 1 second (even too long but not 70 seconds).
Has anybody a hint where to look ?? I´m really confused.
Kind Regards,
KlausOptimizer mode choose with statistics effectively means ALL_ROWS. So I suspect that this probably is the reason why Oracle uses full scans and hash joins. On the other hand rownum = 1 should give the optimizer info that you only need 1 row back. So probably try with either optimizer_mode = first_rows_1 or hint first_rows(1) and see what happens.
Gints Plivna
http://www.gplivna.eu -
제품 : ORACLE SERVER
작성날짜 : 2002-04-08
EXPORT 와 OPTIMIZER MODE 관계
=============================
PURPOSE
다음은 EXPORT와 OPTIMIZER MODE의 관계에 대해 알아본다.
Explanation
EXPORT시 5 분 걸리던 작업이 init.ora 에 optimizer_mode=first_rows 로
하면 20 시간이 걸리는 현상이 발생된다.
이는 BUG# 391656 이었으며 optimizer_mode 를 first_rows 로 설정후
export시 rows=n 으로 주어도 export time이 굉장히 오래 걸린다는 내용으로
event 10046을 setting후 각 statement path 를 check 해보니 optimezer 가
CDEF$ 와 COL$ table 을 fulle scan 하는 것으로 나타 났다.
이들 table 은 EXU7COLU view 에 의해 실행되고 , 만일 DB 에 constraint가
많고 table comment 가 많다면 많은 시간이 걸려서 이러한 결과가 나타난다.
이 경우는 CDEF$ 와 COL$를 analyze 한다 하더라도 별 도움이 안되고
optimizer_mode=first_rows 를 사용하지 말아야 한다는 것이다.
V7.1.6 에서의 임시 workaround 로
CREATE OR REPLACE view exu7grnu AS
SELECT * from exu7grn WHERE grantorid = UID AND creatorid+0 = UID
CREATE OR REPLACE view exu7cgru AS
SELECT * from exu7cgr WHERE grantorid = UID AND creatorid+0 = UID
CREATE OR REPLACE view exu7spsu(obj#, line, source) AS
SELECT s.obj#, s.line, s.source
FROM sys.source$ s, sys.obj$ o
WHERE s.obj# = o.obj# and o.owner#+0 = UID
처럼 view 를 create 하는 방법이 있다.
Reference Ducuments
--------------------Jim,
Export does run in a background process. There are actually at least 3 processes running.
1. You have the client, which is where you run your expdp/impdp command.
2. You have the MCP processes which is a Data Pump process
3. You have a WORKER processes (or more if you use parallel) that are Data Pump processes.
I always use LINUX, but I think it works the same for Windows. Once you have the job running, you can type a CTL-C and you will get to an IMPDP> or EXPDP> prompt. This allows you to do other commands. One is to exit the client process. You can also stop the job or kill the job. Try it and type HELP at one of those prompts.
At this same prompt, you can type STATUS will will give you some idea on what is being worked on.
Some of the reasons you would want to attach to a job is
1. You previously exited and want to reattach to change something.
2. You left it running while you were in the office and now you are home and want to see the status. (you can have multiple clients attached to the same data pump job.
3. Your job stopped for some reason (power outage, failure, etc.) and you want to restart it.
Hope this helps.
Dean -
Set optimizer mode for someone else possible?
I know that I can use the sys.dbms_system package to set tracing on for another session but cannot figure how to change their optimizer mode - if it's possible at all.
I have tried this -
exec sys.dbms_system.set_bool_param_in_session(20,176,'optimizer_mode=choose',TRUE);
PL/SQL procedure successfully completed.
SQL> show parameter opt
NAME TYPE VALUE
object_cache_optimal_size integer 102400
optimizer_features_enable string 8.1.7
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_max_permutations integer 80000
optimizer_mode string RULE
optimizer_percent_parallel integer 0
Tried the 'set_int_param_in_session' but 'choose' is not an integer.
Thanks in advance for any help.Hi,
in design center, select "configure" in the context menu of a mapping. Under table operators, select a table and set the extraction hint.
Regards,
Carsten. -
Hi,
How to change the optimizer mode from ALL_ROWS
ThanksWhether we do not know the OP's Oracle version, we can assume it is not 8i or 9i. Do you realize the link you provided is very old. Still speaking about RULE optimizer, "analyze table" command (both becoming obsolete then depracted) without telling anything about more modern database such as 10g+. Moreover there're some rule of thumbs which can mislead query tuning.
Much better to refer to the Oracle document that Pierre linked to in first place.
And why not ask to the OP, why he/she wants to modify the optimizer from ALL_ROWS to what value with what expected results, based on what analyzes...
Nicolas. -
Set optimizer mode for mapping
How can i set the optimizer mode(for example, "all_rows") explicitly for a mapping?
~PrabhaHi,
in design center, select "configure" in the context menu of a mapping. Under table operators, select a table and set the extraction hint.
Regards,
Carsten. -
How can I get the optimizer mode from the database? I've tried by querying the table V$PARAMETER but I get "table or view does not exist" even if verifying in ALL_OBJECTS I see that it's indicated as Owner PUBLIC. Could you help me? Thanks
SQL> connect hr/hr
Connected.
SQL> SHOW PARAMETER OPTIMIZER_MODE
ORA-00942: table or view does not exist
SQL> connect sys/girish as sysdba
Connected.
SQL> SHOW PARAMETER OPTIMIZER_MODE
NAME TYPE VALUE
optimizer_mode string ALL_ROWSGirish Sharma -
The database wizards are kicking my tables into cost based
mode. We run our queries in rule mode. When I use the DB
Servlet Wizard or the Info Bus Data Form Wizard, any tables
I use get "analyzed" which kicks any queries into cost based
mode because our DB is set for "choose".
Any ideas how to keep it from analyzing my tables?
thanks,
bl
nullProbably not. Is it just the plan order that's changed or has the cost changed too? More importantly does either version of the query take significantly longer to execute?
Incidentally, OPTIMIZER=CHOOSE does not mean the database always uses the CBO. It means it chooses. If none of the tables in the statement has statistics it uses the RBO. If one of the tables in the statement has statistics it uses the CBO. Note that if there are tables that don't have statistics, the database estimates (ie guesses) them, which can lead to some wildly inaccurate plans. This is why we should analyze whole schemas and not individual tables.
If you want to always use the CBO you should chnage the init.ora parameter to OPTIMIZER=COST
rgds, APC -
Oracle 10g Rl- 2 (RAC)
OS- HP-UX 11i
Optimizer_mode parameter is all_rows in my database. It is OLTP enviornment.
What should be the the optimizer in this condition?pls go through this link.
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams145.htm -
Optimizer Mode - Rule or Choose
Is it ok to use
Alter session set optimizer_mode=RULE?
in Oracle9i and Oracle10g?
thanks.New book on physical database design, discussing how to design indexes, range and hash partitioning, materialized views, storage layout, RAID, warehouse design and more. The book covers Oracle and several other major databases. Lots of diagrams and examples. An excellent text for people who design and administer databases.
Available on Amazon and most other book sellers.
Physical Database Design: The Database Professional's Guide to Exploiting Indexes, Views, Storage, and More
by Sam S. Lightstone, Toby J. Teorey, Tom Nadeau
Paperback, 448 pages, publication date: MAR-2007
ISBN-13: 978-0-12-369389-1
ISBN-10: 0-12-369389-6
Series: The Morgan Kaufmann Series in Data Management Systems
Link on Amazon:
http://www.amazon.com/Physical-Database-Design-professionals-exploiting/dp/0123693896
Link on the publisher's web site:
http://www.elsevier.com/wps/find/bookdescription.cws_home/710637/description#description
Comments on the book can be sent to: [email protected] -
How to avoid full Table scan when using Rule based optimizer (Oracle817)
1. We have a Oracle 8.1.7 DB, and the optimizer_mode is set to "RULE"
2. There are three indexes on table cm_contract_supply, which is a large table having 28732830 Rows, and average row length 149 Bytes
COLUMN_NAME INDEX_NAME
PROGRESS_RECID XAK11CM_CONTRACT_SUPPLY
COMPANY_CODE XIE1CM_CONTRACT_SUPPLY
CONTRACT_NUMBER XIE1CM_CONTRACT_SUPPLY
COUNTRY_CODE XIE1CM_CONTRACT_SUPPLY
SUPPLY_TYPE_CODE XIE1CM_CONTRACT_SUPPLY
VERSION_NUMBER XIE1CM_CONTRACT_SUPPLY
CAMPAIGN_CODE XIF1290CM_CONTRACT_SUPPLY
COMPANY_CODE XIF1290CM_CONTRACT_SUPPLY
COUNTRY_CODE XIF1290CM_CONTRACT_SUPPLY
SUPPLIER_BP_ID XIF801CONTRACT_SUPPLY
COMMISSION_LETTER_CODE XIF803CONTRACT_SUPPLY
COMPANY_CODE XIF803CONTRACT_SUPPLY
COUNTRY_CODE XIF803CONTRACT_SUPPLY
COMPANY_CODE XPKCM_CONTRACT_SUPPLY
CONTRACT_NUMBER XPKCM_CONTRACT_SUPPLY
COUNTRY_CODE XPKCM_CONTRACT_SUPPLY
SUPPLY_SEQUENCE_NUMBER XPKCM_CONTRACT_SUPPLY
VERSION_NUMBER XPKCM_CONTRACT_SUPPLY
3. We are querying the table for a particular contract_number and version_number. We want to avoid full table scan.
SELECT /*+ INDEX(XAK11CM_CONTRACT_SUPPLY) */
rowid, pms.cm_contract_supply.*
FROM pms.cm_contract_supply
WHERE
contract_number = '0000000000131710'
AND version_number = 3;
However despite of giving hint, query results are fetched after full table scan.
Execution Plan
0 SELECT STATEMENT Optimizer=RULE (Cost=1182 Card=1 Bytes=742)
1 0 TABLE ACCESS (FULL) OF 'CM_CONTRACT_SUPPLY' (Cost=1182 Card=1 Bytes=742)
4. I have tried giving
SELECT /*+ FIRST_ROWS + INDEX(XAK11CM_CONTRACT_SUPPLY) */
rowid, pms.cm_contract_supply.*
FROM pms.cm_contract_supply
WHERE
contract_number = '0000000000131710'
AND version_number = 3;
and
SELECT /*+ CHOOSE + INDEX(XAK11CM_CONTRACT_SUPPLY) */
rowid, pms.cm_contract_supply.*
FROM pms.cm_contract_supply
WHERE
contract_number = '0000000000131710'
AND version_number = 3;
But it does not work.
Is there some way without changing optimizer mode and without creating an additional index, we can use the index instead of full table scan?David,
Here is my test on a Oracle 10g database.
SQL> create table mytable as select * from all_tables;
Table created.
SQL> set autot traceonly
SQL> alter session set optimizer_mode = choose;
Session altered.
SQL> select count(*) from mytable;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'MYTABLE' (TABLE)
Statistics
1 recursive calls
0 db block gets
29 consistent gets
0 physical reads
0 redo size
223 bytes sent via SQL*Net to client
276 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> analyze table mytable compute statistics;
Table analyzed.
SQL> select count(*) from mytable
2 ;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=11 Card=1)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'MYTABLE' (TABLE) (Cost=11 Card=1
788)
Statistics
1 recursive calls
0 db block gets
29 consistent gets
0 physical reads
0 redo size
222 bytes sent via SQL*Net to client
276 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> disconnect
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options -
Why is optimizer different in sql than in pl/sql?
Hello, I am running Oracle database 9i, it is running on an On-Demand hosted server, its purpose is to serve our Oracle Payroll application.
I have a certain query, and first tried it as a stand-alone query. It displayed the results almost immediatly.
Then I inserted the exact same query in a pl/sql block. It took more than one hour and canceled it. By looking at the session browser in TOAD, I saw that it was stuck on that query.
I also saw that the explain-plan for the query changed drastically from running as stand-alone sql to running inside pl/sql.
Why is this happening? How can I avoid this?
Please note that I do not intend to use optimizer hint since the indexes are built by oracle On-Demand and not me, so I don't know which indexes exist.
Here is the explain plan when running from stand-alone SQL:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 1 65
bq. SORT AGGREGATE 1 72
bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRY_VALUES_F 1 13 4
bq. bq. bq. NESTED LOOPS 1 72 65
bq. bq. bq. bq. MERGE JOIN CARTESIAN 1 59 61
bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRY_VALUES_F 1 13 4
bq. bq. bq. bq. bq. bq. NESTED LOOPS 1 36 33
bq. bq. bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRIES_F 1 23 29
bq. bq. bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRIES_F_N50 44 3
bq. bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRY_VALUES_F_N50 9 3
bq. bq. bq. bq. bq. BUFFER SORT 1 23 57
bq. bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRIES_F 1 23 28
bq. bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRIES_F_N50 44 2
bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRY_VALUES_F_N50 9 3
And here is the plan when running inside pl/sql:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 1 293463
bq. SORT AGGREGATE 1 48
bq. bq. MERGE JOIN CARTESIAN 1 M 56 M 293463
bq. bq. bq. MERGE JOIN CARTESIAN 78 3 K 3771
bq. bq. bq. bq. MERGE JOIN CARTESIAN 1 34 57
bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRIES_F 1 17 29
bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRIES_F_N50 44 3
bq. bq. bq. bq. BUFFER SORT 1 17 28
bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRIES_F 1 17 28
bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRIES_F_N50 44 2
bq. bq. bq. BUFFER SORT 15 K 107 K 3743
bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRY_VALUES_F 15 K 107 K 3714
bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRY_VALUES_F_N1 15 K 39
bq. bq. BUFFER SORT 15 K 107 K 289749
bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRY_VALUES_F 15 K 107 K 3714
bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRY_VALUES_F_N1 15 K 39
As you can see, the cost goes way up when running inside a pl/sql block.
Thank you very much for your help.
Eduardo Schñadower
Edited by: shinaco on Dec 12, 2008 4:10 PM
Added indentation. Sorry for that, I didn't realize copy-paste didn't work well here.I meant to add,
Why is optimizer different in sql than in pl/sql? It is not different, it is the same optimizer.
If you replace bind variables with literals then you have a totally different query, with much more information available to the optimizer. If you are seeing the same statement with the same literal values get a different plan within PL/SQL than in SQL*Plus or TOAD etc then there must be something else different. Unfortunately there is a lot less diagnostic info available in 9i (and I don't have 9i around to test on). Perhaps you can get a 10053 trace from each session and see if you can see what is different.
btw I still can't read the execution plan. There is more information in the DBMS_XPLAN output, and it needs to be formatted using ** tags or equivalent HTML. -
Optimizer Dynamic Sampling doesn't work in our DB
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)Yes, this was the cause. Optimizer mode was set to CHOOSE. If I change it to ALL_ROWS, Optimizer Dynamic Sampling works.
Thank you !
Maybe you are looking for
-
Upgrading 1.8 MHz Power Mac G5 (memory and OS)
I recently purchased an iMac loaded with Leopard. I would like to use the install disk to upgrade my older Power Mac G5. My machine is running 10.3.9 currently. I know I need to increase memory, but by how much? A salesman sold me additional memory s
-
Transportation Lanes in Global ATP using hierarchy
Dear experts, I want to use a hierarchy with customers/locations allocated to transportation zones and create transportation lanes between the transportation zones. When running the GATP check, transportation lane is never found via the hierarchy. If
-
Missing end sub, but where ?
Hi, I'm creating a script that will, when a technician send a mail to a client, the affiliated commercial will be put in copy. My code looks like this : ThisOutlookSession Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 'By
-
Will iPhoto 6 support importing a library?
I couldn't find anything on the site about it. iPhoto Library Manager will do merges in iPhoto 5, so I can merge first and them upgrade, but it would be quite encouraging if Apple has finally fixed the merge problem. 250,000 images. That's what iPhot
-
I just brought elements 12 photoshop and it won't let me sign in. everytime I try to sign in it just goes back to the sign in screen.