Optimizer mode confusion

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² seildi.
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² seildi.
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² seildi.
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).

Similar Messages

  • 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,
    Klaus

    Optimizer 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

  • Optimizer mode in oracle 10g

    what is the difference between setting optimizer mode in oracle 10g
    optimizer_mode=choose
    optimizer_mode=all_rows

    user446367 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/

  • EXPORT 와 OPTIMIZER MODE

    제품 : 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.

  • About optimizer mode

    Hi,
    How to change the optimizer mode from ALL_ROWS
    Thanks

    Whether 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?
    ~Prabha

    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.

  • How to get the Optimizer Mode

    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

  • Is the Full Screen Mode confusing?

    apple is known for its good user interfaces, but am i the only one who thinks that the new user interface of iphoto is bad? especially the "fullscreen mode" is very difficult to use for a beginner. first of all: didn't jobs say that the green button on the top enters fullscreen? well, it doesn't.
    once you are in fullscreen there is no way to switch between windows and or start new programs as the dock is gone. not good! confusing! it also seems like some things are done a different way in the fullscreen mode, you feel "disabled" when using it.
    other things that are not good:
    - where is search? every other program uses a little square where you can enter text - not iphoto! the icon morphs to the text box when clicking... why changing a behaviour we are all used to?
    - where is "add a new folder/intelligent album etc")? the known user interface element for this is gone! iphoto is now inconsistent with itunes or other programs that add new things by the "+" button. oh well, there IS a plus button, but he is placed on a totally different place on the right! it just doesn't feel right that way.
    - where can i make the map larger when editing photos and selecting the gps position?
    - how can i get rid of the visual clutter in edit mode?
    - why can't i display 2 or more photos without going in edit mode?
    this release makes me really sad. i had so many hopes in what the program can do, but it is just a step backwards in a very confusing direction with the user interface.

    I feel the same way. iPhoto'11 has many flaws that need to be fixed. I really miss full screen editing mode with no visual clutter. Really disapointted.

  • Spot and Process colors - Color Mode confusion?

    I have a question about how to choose colors in the New Color Swatch window. I think that I understand the difference between spot and process colors, but the dropdown options confuse me because whether I choose Spot or Process in the Color Type dropdown, the same list of libraries appears in the Color Mode dropdown. How does that work, or why does that happen? Is it a conversion? For example, if I choose Process as the Color Type, but then choose Pantone Solid Coated in the Color Mode, it shows me the colors available, but aren't the Pantone libraries for spot colors? And if I choose Spot as the Color Type, but then pick CMYK in the Color Mode, it gives the CMYK sliders. But shouldn't I be forced to pick from a Pantone library for a spot color? I would appreciate any explanations of this as I want to make sure that I pick the appropriate colors for my printed projects. Thank you!

    You can create a spot color with a custom CMYK mix (and even name it the same as a library color if you want). The utility here is that you can create a custom spot color with a custom process conversion, or use your own own conversion numbers for one of the book colors if you think you have a better mix. I recently had to do a special mix for a Pantone spot conversion to fit a particualr press in order to get a better match to some other materials. That's how we handled it, though I did it by aliasing the pantone swatch to my custom spot and then changing that to process in the ink manager, rather than messing with the library color directly, which meant I could have either the custom or the book values, depending on the settings I chose, if the job went to another press.
    There are, I believe, four sets of process libraries included in ID. The Pantone Process libraries are sets of stepped percentage mixes of the four process inks and have names that start with DS followed by some numbers. I think TrueMatch is a simialr system, though I've never worked with a printer who used it. Pantone Color Bridge and Solid to Process libraries are both process simulations of the Pantone Solid spot libraries. The Color Bridge is newer, and I think is largely replacing the solid to process.
    You  can get printed swatch books for any of the included libraries (spot and process) and you should do so for any library that you are going to use to specify color. Spot colors in particular may not render well on your monitor, and the press operator couldn't care less what you see on your screen. He's going to pull out his swatch book to verify that the color he puts on the page is the same as you specified.

  • Optimizer Mode

    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
    null

    Probably 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

  • Hue Blend Mode Confusion

    Hello,
      In reading about the Hue blend mode, I have come to understand (perhaps erroneously) that given two layers (T)op and (B)ottom, that if the Blend Mode of T is set to Hue, then the hue information in T will be blended with the saturation and luminosity in B, which essentially means that the hue information in B is replaced by the hue information in T. However, in running some experiments, I've noticed that when dealing with a very simple document comprised of two layers only, that setting the Blend Mode to Hue also changes the saturation and brightness.
    Here are the steps to duplicate the observed phenomena using two regular layers:
    Create a new blank document.
    Fill with the color that corresponds to the HSB values (0, 70, 50).
    Add a new layer above the existing layer (blend mode Normal).
    Fill the topmost layer with the color that corresponds to the HSB values (230, 70, 50).
    Using the Info panel, the HSB values for the document should read as (230, 70, 50).
    Change the Blend Mode of the topmost layer to Hue.
    Using the Info panel, the HSB values for the document should read as (230, 70, 50), but instead read as (230, 66, 53).
    And here are the steps to duplicate the observed phenomena using a regular layer and an adjustment layer:
    Create a new blank document.
    Fill with the color that corresponds to the HSB values (0, 70, 50).
    Add a Hue/Saturation adjustment layer (blend mode Normal).
    Adjust the Hue value in the Properties panel for the Hue/Saturation adjustment layer to be -130.
    Using the Info panel, the HSB values for the document should read as (230, 70, 50).
    Change the Blend Mode for the Hue/Saturation layer to be Hue.
    Using the Info panel, the HSB values for the document should read as (230, 70, 50), but instead read as (230, 66, 53).
    The results in both (for me) are identical. Am I misunderstanding the Hue blend mode?
    Thanks,
    Matt
    Photoshop Info:     13.0.1 x64 Extended
    OS:                        Windows 7 64-bit
    CPU:                      Dual Xeon E5440
    RAM:                     16 GB
    Video:                    Nvidia GeForce GTX-580

    Hi Chris,
      Thanks very much for your straightforward and helpful answer. So, it would appear that my simplistic understanding of the Hue blend mode as 'replacing' the hue of the underlying layer(s) is incorrect. Would a fair rendering of what the Hue blend mode actually does be as follows?
    "The Hue blend mode will perform a direct replacement of the hue in the underlying layer(s). The brightness and saturation of the underlying layer(s) will not be affected *unless* the resultant hue, saturation, and brightness 3-tuple would result in an illegal HSL combination, in which case the saturation and brightness of the resultant pixels will be altered to bring the HSL values into compliance."
    Also, is there a way for the Info panel to display HSL values?
    Thanks again,
    Matt

  • Firewire Target Disk mode confusion

    Alright, so after 1.5yrs my PowerMac decides to crash...after spending time on phone with Apple support and internet, only option is complete reinstall. So I was told about Firewire Target Disk Mode and the ability to transfer all data from crashed computer to a working one, and after reading countless post on this forum as well as others, Im still a little bit in the grey on which is the Host and which is the target, so I felt that I would see if I could get a case-specific answer from my friends here...
    If please could someone select correct answer.
    Both computers off, start the (crashed/working) computer while holding the "T" key.
    Also, is there any way I could cause any data loss to the working computer? Its my roommates and it would be terrible in if fixing mine it destroyed his!!!
    PowerMac G4 Mac OS X (10.4.8)
    Thank you very much in advance...and please flame me if I didnt make any sense, but hopefully will understand what Im trying to do and help a desperate man out. Thanks again!!!

    I'm still a little bit in the grey on which is the Host
    and which is the target, so I felt that I would see
    if I could get a case-specific answer from my friends
    here...
    The "Target" in Target Disk Mode ("TDM") is the computer that is placed into TDM. The paradigm is that, by booting the TDM computer with the "T" key depressed, it becomes just a fancy Firewire disk (with the TDM icon on the screen) just like any other Firewire disk, and can be mounted on any other working Macintosh computer (the "Host") as an external drive.
    In most cases (but not yours), it actually can be done with either computer as the "Host" and the other one as the TDM (Target). Because you can't boot your computer, it will have to be the Target so that the boot ROM can do the Firewire magic to make the drive be a Firewire TDM drive.
    If please could someone select correct answer.
    Both computers off, start the (crashed/working)
    computer while holding the "T" key.
    In your case (see above), it should be the "crashed" computer that is put into TDM mode by booting with the T key depressed.
    Also, is there any way I could cause any data loss to
    the working computer?
    Oh sure, just like you could operating on any Computer. You could drag all of the files on the Host computer to the trash, and many would go there (some would need the admin password). You could erase the disk (Mac OS won't let you erase the boot disk, but you could boot from a CD/DVD on the Host computer and erase the boot drive. And you could make the mistake of copying the files from the TDM drive (the crashed computer) on top of similar but possibly different files on the Host. But connecting the TDM computer as a mounted drive, without more, won't cause data loss. It will require some mistake by the person at the keyboard (you).
    Hope this helps,
    Russ

  • What should be optimizer mode

    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 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

Maybe you are looking for