Table cost by unifying

Hello

I would like to know if there is a way to add a cost table where you can see the forecast by month or by quarter: roughly speaking, a way of linking dates with costs. I have not found how the cost of Pentecost journal.

Thank you very much in advance for your support

Thomas

The Cash Flow will give what you are looking for. You can set the prediction column in the sheet of costs as your source of cost and then you can set dates and profile curves ranges to be applied to the forecast.

Tags: Oracle Applications

Similar Questions

  • Generation of the XML from the Oracle tables

    I'm using Oracle 11 g R1.

    I have two tables header and the line:

    CREATE THE TABLE HEADER
    (
    EXPENSE_INFO VARCHAR2 (2000).
    NUMBER OF ERROR_CODE,
    REASON_OF_FAILURE VARCHAR2 (4000)
    )
    /


    CREATE THE ROW IN THE TABLE
    (
    EXPENSE_INFO VARCHAR2 (2000).
    DATE OF EXPENSE_DATE,
    EXPENSE_CODE VARCHAR2 (10),
    EXPENSE_REF VARCHAR2 (2000).
    GROSS_AMOUNT NUMBER,
    NUMBER OF TAX_AMOUNT,
    NUMBER OF ERROR_CODE,
    REASON_OF_FAILURE VARCHAR2 (4000)
    )
    /

    These tables are linked by the EXPENSE_INFO column.

    Complete the tables with the following data:

    Insert in the header (ErrorCode, EXPENSE_INFO, REASON_OF_FAILURE)
    values ('A', 0, 'SUCCESS');

    Insert (EXPENSE_INFO, EXPENSE_DATE, EXPENSE_CODE, EXPENSE_REF, GROSS_AMOUNT, TAX_AMOUNT, ERROR_CODE, REASON_OF_FAILURE) online
    values ('A', to_date (December 14, 2012 ', 'dd-mm-yyyy'), 'ABC', 'HOTEL', 100, 500, 0, 'SUCCESS');

    Insert (EXPENSE_INFO, EXPENSE_DATE, EXPENSE_CODE, EXPENSE_REF, GROSS_AMOUNT, TAX_AMOUNT, ERROR_CODE, REASON_OF_FAILURE) online
    values ('A', to_date (December 14, 2012 ', 'dd-mm-yyyy'), 'DEF', 'MOVIE', 10, 50, 1, "Cost Code does not exist.");

    Insert in the header (ErrorCode, EXPENSE_INFO, REASON_OF_FAILURE)
    values ('B', 1, "Emp Id does not exist.");

    Insert (EXPENSE_INFO, EXPENSE_DATE, EXPENSE_CODE, EXPENSE_REF, GROSS_AMOUNT, TAX_AMOUNT, ERROR_CODE, REASON_OF_FAILURE) online
    values ('B', to_date (December 14, 2012 ', 'dd-mm-yyyy'), "XYZ", "MILEAGE", 200, 300, 0, 'SUCCESS');



    I want to generate the XML following these tables:


    COSTS of <>
    < EXPENSE_DETAILS >
    < EXPENSE_INFO > is < / EXPENSE_INFO >
    < ERROR_CODE > 0 < / ERROR_CODE >
    SUCCESS of < REASON_OF_FAILURE > < / REASON_OF_FAILURE >
    < EXPENSE_LINES >
    < EXPENSE_LINE_REC >
    < EXPENSE_INFO > is < / EXPENSE_INFO >
    < EXPENSE_DATE > 14/12/2012 00:00:00 < / EXPENSE_DATE >
    ABC of < EXPENSE_CODE > < / EXPENSE_CODE >
    HOTEL < EXPENSE_REF > < / EXPENSE_REF >
    < GROSS_AMOUNT > 100 < / GROSS_AMOUNT >
    < > 500 TAX_AMOUNT < / TAX_AMOUNT >
    < ERROR_CODE > 0 < / ERROR_CODE >
    SUCCESS of < REASON_OF_FAILURE > < / REASON_OF_FAILURE >
    < / EXPENSE_LINE_REC >
    < EXPENSE_LINE_REC >
    < EXPENSE_INFO > is < / EXPENSE_INFO >
    < EXPENSE_DATE > 14/12/2012 00:00:00 < / EXPENSE_DATE >
    DEF < EXPENSE_CODE > < / EXPENSE_CODE >
    FILM of < EXPENSE_REF > < / EXPENSE_REF >
    < GROSS_AMOUNT > 10 < / GROSS_AMOUNT >
    < TAX_AMOUNT > 50 < / TAX_AMOUNT >
    < ERROR_CODE > 1 < / ERROR_CODE >
    < REASON_OF_FAILURE > fresh Code does not exist. < / REASON_OF_FAILURE >
    < / EXPENSE_LINE_REC >
    < / EXPENSE_LINES >
    < / EXPENSE_DETAILS >
    < EXPENSE_DETAILS >
    B < EXPENSE_INFO > < / EXPENSE_INFO >
    < ERROR_CODE > 1 < / ERROR_CODE >
    < REASON_OF_FAILURE > Employee Id does not exist. < / REASON_OF_FAILURE >
    < EXPENSE_LINES >
    < EXPENSE_LINE_REC >
    B < EXPENSE_INFO > < / EXPENSE_INFO >
    < EXPENSE_DATE > 14/12/2012 00:00:00 < / EXPENSE_DATE >
    XYZ < EXPENSE_CODE > < / EXPENSE_CODE >
    POINT MILE < EXPENSE_REF > < / EXPENSE_REF >
    < > 200 GROSS_AMOUNT < / GROSS_AMOUNT >
    < > 300 TAX_AMOUNT < / TAX_AMOUNT >
    < ERROR_CODE > 0 < / ERROR_CODE >
    SUCCESS of < REASON_OF_FAILURE > < / REASON_OF_FAILURE >
    < / EXPENSE_LINE_REC >
    < / EXPENSE_LINES >
    < / EXPENSE_DETAILS >
    < / SPENDING >


    I'm not able to generate the XML file. Kindly help me.

    Kind regards
    Sudhanshu

    I love working at the deepest level and then "wrap" with external level tags.

    You want to list all columns of each LINE by line. XMLFOREST is good for this:

    select xmlforest(
      expense_info, expense_date, expense_code, expense_ref,
      gross_amount, tax_amount, error_code, reason_of_failure
    )
    from line;
    
    A
    2012-12-14
    ABC
    HOTEL
    100
    500
    0
    SUCCESS
    ...
    

    Now you want to wrap this up in EXPENSE_LINE_REC

    select xmlelement("EXPENSE_LINE_REC",
      xmlforest(
        expense_info, expense_date, expense_code, expense_ref,
        gross_amount, tax_amount, error_code, reason_of_failure
      )
    )
    from line;
    
    
      A
      2012-12-14
      ABC
      HOTEL
      100
      500
      0
      SUCCESS
    
    

    So far, you have a XML fragment by line in the table of the LINE. You can use XMLAGG to put those together in a single fragment - or rather, a fragment by EXPENSE_INFO.

    Then you use XMLELEMENT again to give the name "EXPENSE_LINES" in this fragment.

    Then you gather the header values and the 'EXPENSE_LINES' fragment in "EXPENSE_DETAILS". This gives you all the information for each row header and associated lines of the LINE.

    Then, you gather all the information into one with XMLAGG header, and give everything a name with XMLELEMENT

    select xmlelement("EXPENSES",
      xmlagg(
        xmlelement("EXPENSE_DETAILS",
          xmlforest(expense_info, a.error_code, a.reason_of_failure),
          xmlelement("EXPENSE_LINES",
            xmlagg(
              xmlelement("EXPENSE_LINE_REC",
                xmlforest(
                  b.expense_date, b.expense_code, b.expense_ref,
                  b.gross_amount, b.tax_amount, b.error_code, b.reason_of_failure
                )
              )
            )
          )
        )
      )
    )
    from header a join line b using(expense_info)
    group by expense_info, a.error_code, a.reason_of_failure;
    

    _Note: _ with the GROUP BY clause, you can 'total' twice, once at the expense_info level and then overall. That's what I do with the two XMLAGGs: the second he puts just all the different stuff EXPENSE_DETAILS together in one package that I wrap "CHARGES" tag autour.

    Also, I omit EXPENSE_INFO of each LINE as it is already in the header information.

    Published by: stew Ashton on December 17, 2012 14:03

  • Group by and join of table

    Hi Expert,
    I am new to pl/sql I have a question...
    I have the table like this
    1 table productcost a column productcostID, costID, DeptID, REQUESTCOST, EXPENDITURECOST
    2. the table COST a column costID, costName, costmajorID, costtypeID
    3. the departments table has DeptID, DeptName
    4. the CostMajor table has costmajorID, costmajorName

    I want to ask productcost Table where DeptID = somevalue call X and it must contain each productcost DeptID = X and I want to choose costname to show
    and I want to group by it of costmajorID in the cost table... How can I do? Someone help me please...

    My result like this (a Table of productcost table query)

    Table 1
    costmajorName1 EXPENDITURECOST REQUESTCOST
    1000000 2000000 costName1
    1000000 2000000 costName2

    Table 2
    costmajorName2 EXPENDITURECOST REQUESTCOST
    1000000 2000000 costName3
    1000000 2000000 costName4

    Table 3
    costmajorName3 EXPENDITURECOST REQUESTCOST
    1000000 2000000 costName5
    1000000 2000000 costName6


    PS I'm not good in English, sorry if I made you do not understand...

    Search for an XML output then but take the below as a model of because I don't have a database at hand and that's all that I can find at the moment
    You can get more help in the {forum: id = 34} forum or wait until Marc appears ;) or someone else provides a working example

    select xmlelement("Table",
           xmlelement("Title",
           xmlelement("Col_1", costmajor_name),
           xmlelement("Col_2", 'expenditure_cost'),
           xmlelement("Col_3", 'request_cost')
                     )
              xmlagg (
           xmlelement("Costs",
           xmlelement("Col_1", cost_name),
           xmlelement("Col_2", expenditure_cost),
           xmlelement("Col_3", request_cost)
                     )
                     )
                     )
      from (select cm.costmajor_name,c.cost_name,pc.expenditure_cost,pc.request_cost
              from productcost pc,
                   cost c,
                   costmajor cm
             where dept_id = :dept_chosen
               and pc.cost_id = c.cost_id
               and c.costmajor_id = cm.costmajor_id
           )
      group by costmajor_name
    

    Concerning

    Etbin

  • Why the optimizer ignores Index Fast full Scan when much lower cost?

    Summary (tracking details below) - to improve the performance of a query on more than one table, I created an index on a table that included all the columns referenced in the query. With the new index in place the optimizer is still choosing a full Table Scan on an Index fast full scan. However, by removing the one query tables I reach the point where the optimizer suddenly use the Index Fast Full Scan on this table. And 'Yes', it's a lot cheaper than the full Table Scan it used before. By getting a test case, I was able to get the motion down to 4 tables with the optimizer still ignoring the index and table of 3, it will use the index.

    So why the optimizer not chooses the Index Fast Full Scan, if it is obvious that it is so much cheaper than a full Table Scan? And why the deletion of a table changes how the optimizer - I don't think that there is a problem with the number of join permutations (see below). The application is so simple that I can do, while remaining true to the original SQL application, and it still shows this reversal in the choice of access path. I can run the queries one after another, and he always uses a full Table Scan for the original query and Index fast full scan for the query that is modified with a table less.

    Watching trace 10053 output for the two motions, I can see that for the original query 4 table costs alone way of ACCESS of TABLE UNIQUE section a full Table Scan. But for the modified query with a table less, the table now has a cost for an Index fast full scan also. And the end of the join cost 10053 does not end with a message about exceeding the maximum number of permutations. So why the optimizer does not cost the IFFS for the first query, when it does for the second, nearly identical query?

    This is potentially a problem to do with OUTER joins, but why? The joins between the tables do not change when the single extra table is deleted.

    It's on 10.2.0.5 on Linux (Oracle Enterprise Linux). I did not define special settings I know. I see the same behavior on 10.2.0.4 32-bit on Windows (XP).

    Thank you
    John
    Blog of database Performance

    DETAILS
    I've reproduced the entire scenario via SQL scripts to create and populate the tables against which I can then run the queries. I've deliberately padded table so that the length of the average line of data generated is similar to that of the actual data. In this way the statistics should be similar on the number of blocks and so forth.

    System - uname - a
    Linux mysystem.localdomain 2.6.32-300.25.1.el5uek #1 SMP Tue May 15 19:55:52 EDT 2012 i686 i686 i386 GNU/Linux
    Database - v$ version
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
    PL/SQL Release 10.2.0.5.0 - Production
    CORE    10.2.0.5.0      Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    Original query (complete table below details):
    SELECT 
        episode.episode_id , episode.cross_ref_id , episode.date_required , 
        product.number_required , 
        request.site_id 
    FROM episode 
    LEFT JOIN REQUEST on episode.cross_ref_id = request.cross_ref_id 
         JOIN product ON episode.episode_id = product.episode_id 
    LEFT JOIN product_sub_type ON product.prod_sub_type_id = product_sub_type.prod_sub_type_id 
    WHERE (
            episode.department_id = 2
        and product.status = 'I'
          ) 
    ORDER BY episode.date_required
    ;
    Execution of display_cursor after the execution plan:
    SQL_ID  5ckbvabcmqzw7, child number 0
    -------------------------------------
    SELECT     episode.episode_id , episode.cross_ref_id , episode.date_required ,
    product.number_required ,     request.site_id FROM episode LEFT JOIN REQUEST on
    episode.cross_ref_id = request.cross_ref_id      JOIN product ON episode.episode_id =
    product.episode_id LEFT JOIN product_sub_type ON product.prod_sub_type_id =
    product_sub_type.prod_sub_type_id WHERE (         episode.department_id = 2 and
    product.status = 'I'       ) ORDER BY episode.date_required
    
    Plan hash value: 3976293091
    
    -----------------------------------------------------------------------------------------------------
    | Id  | Operation             | Name                | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT      |                     |       |       |       | 35357 (100)|          |
    |   1 |  SORT ORDER BY        |                     | 33333 |  1920K|  2232K| 35357   (1)| 00:07:05 |
    |   2 |   NESTED LOOPS OUTER  |                     | 33333 |  1920K|       | 34879   (1)| 00:06:59 |
    |*  3 |    HASH JOIN OUTER    |                     | 33333 |  1822K|  1728K| 34878   (1)| 00:06:59 |
    |*  4 |     HASH JOIN         |                     | 33333 |  1334K|       |   894   (1)| 00:00:11 |
    |*  5 |      TABLE ACCESS FULL| PRODUCT             | 33333 |   423K|       |   103   (1)| 00:00:02 |
    |*  6 |      TABLE ACCESS FULL| EPISODE             |   299K|  8198K|       |   788   (1)| 00:00:10 |
    |   7 |     TABLE ACCESS FULL | REQUEST             |  3989K|    57M|       | 28772   (1)| 00:05:46 |
    |*  8 |    INDEX UNIQUE SCAN  | PK_PRODUCT_SUB_TYPE |     1 |     3 |       |  0   (0)|          |
    -----------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
       3 - access("EPISODE"."CROSS_REF_ID"="REQUEST"."CROSS_REF_ID")
       4 - access("EPISODE"."EPISODE_ID"="PRODUCT"."EPISODE_ID")
       5 - filter("PRODUCT"."STATUS"='I')
       6 - filter("EPISODE"."DEPARTMENT_ID"=2)
       8 - access("PRODUCT"."PROD_SUB_TYPE_ID"="PRODUCT_SUB_TYPE"."PROD_SUB_TYPE_ID")
    Updated the Query:
    SELECT 
        episode.episode_id , episode.cross_ref_id , episode.date_required , 
        product.number_required , 
        request.site_id 
    FROM episode 
    LEFT JOIN REQUEST on episode.cross_ref_id = request.cross_ref_id 
         JOIN product ON episode.episode_id = product.episode_id 
    WHERE (
            episode.department_id = 2
        and product.status = 'I'
          ) 
    ORDER BY episode.date_required
    ;
    Execution of display_cursor after the execution plan:
    SQL_ID  gbs74rgupupxz, child number 0
    -------------------------------------
    SELECT     episode.episode_id , episode.cross_ref_id , episode.date_required ,
    product.number_required ,     request.site_id FROM episode LEFT JOIN REQUEST on
    episode.cross_ref_id = request.cross_ref_id      JOIN product ON episode.episode_id =
    product.episode_id WHERE (         episode.department_id = 2     and product.status =
    'I'       ) ORDER BY episode.date_required
    
    Plan hash value: 4250628916
    
    ----------------------------------------------------------------------------------------------
    | Id  | Operation              | Name        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT       |             |       |       |       | 10515 (100)|          |
    |   1 |  SORT ORDER BY         |             | 33333 |  1725K|  2112K| 10515   (1)| 00:02:07 |
    |*  2 |   HASH JOIN OUTER      |             | 33333 |  1725K|  1632K| 10077   (1)| 00:02:01 |
    |*  3 |    HASH JOIN           |             | 33333 |  1236K|       |   894   (1)| 00:00:11 |
    |*  4 |     TABLE ACCESS FULL  | PRODUCT     | 33333 |   325K|       |   103   (1)| 00:00:02 |
    |*  5 |     TABLE ACCESS FULL  | EPISODE     |   299K|  8198K|       |   788   (1)| 00:00:10 |
    |   6 |    INDEX FAST FULL SCAN| IX4_REQUEST |  3989K|    57M|       |  3976   (1)| 00:00:48 |
    ----------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
       2 - access("EPISODE"."CROSS_REF_ID"="REQUEST"."CROSS_REF_ID")
       3 - access("EPISODE"."EPISODE_ID"="PRODUCT"."EPISODE_ID")
       4 - filter("PRODUCT"."STATUS"='I')
       5 - filter("EPISODE"."DEPARTMENT_ID"=2)
    Creating the table and Population:
    1 create tables
    2. load data
    3 create indexes
    4. collection of statistics
    --
    -- Main table
    --
    create table episode (
    episode_id number (*,0),
    department_id number (*,0),
    date_required date,
    cross_ref_id varchar2 (11),
    padding varchar2 (80),
    constraint pk_episode primary key (episode_id)
    ) ;
    --
    -- Product tables
    --
    create table product_type (
    prod_type_id number (*,0),
    code varchar2 (10),
    binary_field number (*,0),
    padding varchar2 (80),
    constraint pk_product_type primary key (prod_type_id)
    ) ;
    --
    create table product_sub_type (
    prod_sub_type_id number (*,0),
    sub_type_name varchar2 (20),
    units varchar2 (20),
    padding varchar2 (80),
    constraint pk_product_sub_type primary key (prod_sub_type_id)
    ) ;
    --
    create table product (
    product_id number (*,0),
    prod_type_id number (*,0),
    prod_sub_type_id number (*,0),
    episode_id number (*,0),
    status varchar2 (1),
    number_required number (*,0),
    padding varchar2 (80),
    constraint pk_product primary key (product_id),
    constraint nn_product_episode check (episode_id is not null) 
    ) ;
    alter table product add constraint fk_product 
    foreign key (episode_id) references episode (episode_id) ;
    alter table product add constraint fk_product_type 
    foreign key (prod_type_id) references product_type (prod_type_id) ;
    alter table product add constraint fk_prod_sub_type
    foreign key (prod_sub_type_id) references product_sub_type (prod_sub_type_id) ;
    --
    -- Requests
    --
    create table request (
    request_id number (*,0),
    department_id number (*,0),
    site_id number (*,0),
    cross_ref_id varchar2 (11),
    padding varchar2 (80),
    padding2 varchar2 (80),
    constraint pk_request primary key (request_id),
    constraint nn_request_department check (department_id is not null),
    constraint nn_request_site_id check (site_id is not null)
    ) ;
    --
    -- Activity & Users
    --
    create table activity (
    activity_id number (*,0),
    user_id number (*,0),
    episode_id number (*,0),
    request_id number (*,0), -- always NULL!
    padding varchar2 (80),
    constraint pk_activity primary key (activity_id)
    ) ;
    alter table activity add constraint fk_activity_episode
    foreign key (episode_id) references episode (episode_id) ;
    alter table activity add constraint fk_activity_request
    foreign key (request_id) references request (request_id) ;
    --
    create table app_users (
    user_id number (*,0),
    user_name varchar2 (20),
    start_date date,
    padding varchar2 (80),
    constraint pk_users primary key (user_id)
    ) ;
    
    prompt Loading episode ...
    --
    insert into episode
    with generator as 
    (select rownum r
              from (select rownum r from dual connect by rownum <= 1000) a,
                   (select rownum r from dual connect by rownum <= 1000) b,
                   (select rownum r from dual connect by rownum <= 1000) c
             where rownum <= 1000000
           ) 
    select r, 2,
        sysdate + mod (r, 14),
        to_char (r, '0000000000'),
        'ABCDEFGHIJKLMNOPQRSTUVWXYZ' || to_char (r, '000000')
      from generator g
    where g.r <= 300000
    /
    commit ;
    --
    prompt Loading product_type ...
    --
    insert into product_type
    with generator as 
    (select rownum r
              from (select rownum r from dual connect by rownum <= 1000) a,
                   (select rownum r from dual connect by rownum <= 1000) b,
                   (select rownum r from dual connect by rownum <= 1000) c
             where rownum <= 1000000
           ) 
    select r, 
           to_char (r, '000000000'),
           mod (r, 2),
           'ABCDEFGHIJKLMNOPQRST' || to_char (r, '000000')
      from generator g
    where g.r <= 12
    /
    commit ;
    --
    prompt Loading product_sub_type ...
    --
    insert into product_sub_type
    with generator as 
    (select rownum r
              from (select rownum r from dual connect by rownum <= 1000) a,
                   (select rownum r from dual connect by rownum <= 1000) b,
                   (select rownum r from dual connect by rownum <= 1000) c
             where rownum <= 1000000
           ) 
    select r, 
           to_char (r, '000000'),
           to_char (mod (r, 3), '000000'),
           'ABCDE' || to_char (r, '000000')
      from generator g
    where g.r <= 15
    /
    commit ;
    --
    prompt Loading product ...
    --
    -- product_id prod_type_id prod_sub_type_id episode_id padding 
    insert into product
    with generator as 
    (select rownum r
              from (select rownum r from dual connect by rownum <= 1000) a,
                   (select rownum r from dual connect by rownum <= 1000) b,
                   (select rownum r from dual connect by rownum <= 1000) c
             where rownum <= 1000000
           ) 
    select r, mod (r, 12) + 1, mod (r, 15) + 1, mod (r, 300000) + 1,
           decode (mod (r, 3), 0, 'I', 1, 'C', 2, 'X', 'U'),
           dbms_random.value (1, 100), NULL
      from generator g
    where g.r <= 100000
    /
    commit ;
    --
    prompt Loading request ...
    --
    -- request_id department_id site_id cross_ref_id varchar2 (11) padding 
    insert into request
    with generator as 
    (select rownum r
              from (select rownum r from dual connect by rownum <= 1000) a,
                   (select rownum r from dual connect by rownum <= 1000) b,
                   (select rownum r from dual connect by rownum <= 1000) c
             where rownum <= 10000000
           ) 
    select r, mod (r, 4) + 1, 1, to_char (r, '0000000000'),
    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789' || to_char (r, '000000'),
    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789012345678' || to_char (r, '000000')
      from generator g
    where g.r <= 4000000
    /
    commit ;
    --
    prompt Loading activity ...
    --
    -- activity activity_id user_id episode_id request_id (NULL) padding 
    insert into activity
    with generator as 
    (select rownum r
              from (select rownum r from dual connect by rownum <= 1000) a,
                   (select rownum r from dual connect by rownum <= 1000) b,
                   (select rownum r from dual connect by rownum <= 1000) c
             where rownum <= 10000000
           ) 
    select r, mod (r, 50) + 1, mod (r, 300000) + 1, NULL, NULL
      from generator g
    where g.r <= 100000
    /
    commit ;
    --
    prompt Loading app_users ...
    --
    -- app_users user_id user_name start_date padding 
    insert into app_users
    with generator as 
    (select rownum r
              from (select rownum r from dual connect by rownum <= 1000) a,
                   (select rownum r from dual connect by rownum <= 1000) b,
                   (select rownum r from dual connect by rownum <= 1000) c
             where rownum <= 10000000
           ) 
    select r, 
           'User_' || to_char (r, '000000'),
           sysdate - mod (r, 30),
           'ABCDEFGHIJKLMNOPQRSTUVWXYZ' || to_char (r, '000000')
      from generator g
    where g.r <= 1000
    /
    commit ;
    --
    
    prompt Episode (1)
    create index ix1_episode_cross_ref on episode (cross_ref_id) ;
    --
    prompt Product (2)
    create index ix1_product_episode on product (episode_id) ;
    create index ix2_product_type on product (prod_type_id) ;
    --
    prompt Request (4)
    create index ix1_request_site on request (site_id) ;
    create index ix2_request_dept on request (department_id) ;
    create index ix3_request_cross_ref on request (cross_ref_id) ;
    -- The extra index on the referenced columns!!
    create index ix4_request on request (cross_ref_id, site_id) ;
    --
    prompt Activity (2)
    create index ix1_activity_episode on activity (episode_id) ;
    create index ix2_activity_request on activity (request_id) ;
    --
    prompt Users (1)
    create unique index ix1_users_name on app_users (user_name) ;
    --
    prompt Gather statistics on schema ...
    --
    exec dbms_stats.gather_schema_stats ('JB')
    10053 sections - original query
    ***************************************
    SINGLE TABLE ACCESS PATH
      -----------------------------------------
      BEGIN Single Table Cardinality Estimation
      -----------------------------------------
      Table: REQUEST  Alias: REQUEST
        Card: Original: 3994236  Rounded: 3994236  Computed: 3994236.00  Non Adjusted: 3994236.00
      -----------------------------------------
      END   Single Table Cardinality Estimation
      -----------------------------------------
      Access Path: TableScan
        Cost:  28806.24  Resp: 28806.24  Degree: 0
          Cost_io: 28738.00  Cost_cpu: 1594402830
          Resp_io: 28738.00  Resp_cpu: 1594402830
    ******** Begin index join costing ********
      ****** trying bitmap/domain indexes ******
      Access Path: index (FullScan)
        Index: PK_REQUEST
        resc_io: 7865.00  resc_cpu: 855378926
        ix_sel: 1  ix_sel_with_filters: 1
        Cost: 7901.61  Resp: 7901.61  Degree: 0
      Access Path: index (FullScan)
        Index: PK_REQUEST
        resc_io: 7865.00  resc_cpu: 855378926
        ix_sel: 1  ix_sel_with_filters: 1
        Cost: 7901.61  Resp: 7901.61  Degree: 0
      ****** finished trying bitmap/domain indexes ******
    ******** End index join costing ********
      Best:: AccessPath: TableScan
             Cost: 28806.24  Degree: 1  Resp: 28806.24  Card: 3994236.00  Bytes: 0
    ***************************************
    10053 - updated the Query
    ***************************************
    SINGLE TABLE ACCESS PATH
      -----------------------------------------
      BEGIN Single Table Cardinality Estimation
      -----------------------------------------
      Table: REQUEST  Alias: REQUEST
        Card: Original: 3994236  Rounded: 3994236  Computed: 3994236.00  Non Adjusted: 3994236.00
      -----------------------------------------
      END   Single Table Cardinality Estimation
      -----------------------------------------
      Access Path: TableScan
        Cost:  28806.24  Resp: 28806.24  Degree: 0
          Cost_io: 28738.00  Cost_cpu: 1594402830
          Resp_io: 28738.00  Resp_cpu: 1594402830
      Access Path: index (index (FFS))
        Index: IX4_REQUEST
        resc_io: 3927.00  resc_cpu: 583211030
        ix_sel: 0.0000e+00  ix_sel_with_filters: 1
      Access Path: index (FFS)
        Cost:  3951.96  Resp: 3951.96  Degree: 1
          Cost_io: 3927.00  Cost_cpu: 583211030
          Resp_io: 3927.00  Resp_cpu: 583211030
      Access Path: index (FullScan)
        Index: IX4_REQUEST
        resc_io: 14495.00  resc_cpu: 903225273
        ix_sel: 1  ix_sel_with_filters: 1
        Cost: 14533.66  Resp: 14533.66  Degree: 1
    ******** Begin index join costing ********
      ****** trying bitmap/domain indexes ******
      Access Path: index (FullScan)
        Index: IX4_REQUEST
        resc_io: 14495.00  resc_cpu: 903225273
        ix_sel: 1  ix_sel_with_filters: 1
        Cost: 14533.66  Resp: 14533.66  Degree: 0
      Access Path: index (FullScan)
        Index: IX4_REQUEST
        resc_io: 14495.00  resc_cpu: 903225273
        ix_sel: 1  ix_sel_with_filters: 1
        Cost: 14533.66  Resp: 14533.66  Degree: 0
      ****** finished trying bitmap/domain indexes ******
    ******** End index join costing ********
      Best:: AccessPath: IndexFFS  Index: IX4_REQUEST
             Cost: 3951.96  Degree: 1  Resp: 3951.96  Card: 3994236.00  Bytes: 0
    ***************************************

    I mentioned that it is a bug related to the ANSI SQL standard and transformation probably.

    As suggested/asked in my first reply:
    1. If you use a no_query_transformation then you should find that you get the use of the index (although not in the plan you would expect)
    2. If you use the traditional Oracle syntax, then you should not have the same problem.

  • Bought a new Seagate Barracuda ST2000dm001 - need to format as TPG, not MBR - HOW?

    This drive seems to be the MBR, same format of Seagate DiskWizard.  Windows 7 is not installed on this new disc and gives a message about a UEFI needing to be GPT, MBR.

    I tried to use Diskpart to convert, but I'm not doing anything at this point.  Any help would be appreciated.  What I am doing wrong?

    By installing windows (or try) the message says: Windows could not format a partition on disk 0.  The error occurred when preparing the partition selected for installation. Error code: 0 x 80070057.

    I tried to delete the partitions during installation as instructions of Microsoft said.  He made two partitions, a principal that we try to do the installation of.  It does not matter that we have reached the next or the Format, and then click Next, always the same error (unable to format).  At one point, he gave the above message MBR... to TPG.

    What I don't get?

    In Diskpart: I selected the disc using the disc list and select the drive and then said to convert a GPT.  He said that the specified disk is not convertible. CD-ROM and DVD is examples of discs that are not - convertible (I chose the new HD Seagate 2 TB) so I tried volume selecting volume from the list and select the volume and then convert GPT.  Always the same answer not be convertible.

    If Windows 7 is installed to a new HD 2 TB raw, and he said he'd be of TPG, so I try to use Diskpart to convert to GPT to MBR, why is it not seeming to work? I use the command Diskpart evil?

    Hello

    Master boot record (MBR) disks use the standard BIOS partition table. Disks GUID partition table (GPT) using unified extensible firmware interface (UEFI). MBR disks do not support more than four partitions on each disk. The MBR partition method is not recommended for disks larger than 2 terabytes.

    Transform a boot drive primary in a disc of Table of Partition GUID

    http://TechNet.Microsoft.com/en-us/library/cc725671.aspx#BKMK_CMD

    I also suggest you to report the issue in the Seagate forums to get information on how to convert the hard disk.

    http://forums.Seagate.com/T5/Barracuda-XT-Barracuda-Barracuda/BD-p/ata_drives

    Hope this information helps.

  • Set up a query (written Re)

    Hi Experts,

    I am facing a problem in executing the query that take a long time. And I'm new to setting up a query, kindly help me in this query to reduce the time of execution below.

    After reading the stories, I am unable to find how to get the execution of the query, but not sure about re writing the query plan. This is the execution plan.

    Please help me by rewriting the query and guide me some ground rules for rewriting where needed.

    203 rows selected.
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=5745 Card=1 Bytes=
              222)
    
    
       1    0   SORT (GROUP BY NOSORT) (Cost=5570 Card=1 Bytes=12)
       2    1     TABLE ACCESS (FULL) OF 'FAMIS_REQ' (TABLE) (Cost=5570 Ca
              rd=1 Bytes=12)
    
    
       3    0   SORT (GROUP BY NOSORT) (Cost=5563 Card=1 Bytes=8)
       4    3     TABLE ACCESS (FULL) OF 'FAMIS_REQ' (TABLE) (Cost=5563 Ca
              rd=1 Bytes=8)
    
    
       5    0   NESTED LOOPS (OUTER) (Cost=5745 Card=1 Bytes=222)
       6    5     FILTER
       7    6       NESTED LOOPS (OUTER) (Cost=5743 Card=1 Bytes=198)
       8    7         NESTED LOOPS (OUTER) (Cost=5742 Card=1 Bytes=163)
       9    8           HASH JOIN (Cost=5739 Card=1 Bytes=140)
      10    9             NESTED LOOPS
      11   10               NESTED LOOPS (Cost=5567 Card=1 Bytes=98)
      12   11                 TABLE ACCESS (FULL) OF 'FAMIS_REQ' (TABLE) (
              Cost=5565 Card=1 Bytes=90)
    
    
      13   11                 INDEX (RANGE SCAN) OF 'FAMIS_REQUESTOR1' (IN
              DEX) (Cost=1 Card=1)
    
    
      14   10               TABLE ACCESS (BY INDEX ROWID) OF 'FAMIS_REQUES
              TOR' (TABLE) (Cost=2 Card=1 Bytes=8)
    
    
      15    9             TABLE ACCESS (FULL) OF 'FAM_PERSON' (TABLE) (Cos
              t=172 Card=1074 Bytes=45108)
    
    
      16    8           TABLE ACCESS (BY INDEX ROWID) OF 'LEASE_CONTACT' (
              TABLE) (Cost=3 Card=1 Bytes=23)
    
    
      17   16             INDEX (RANGE SCAN) OF 'FK_LEASECONTACT_CONTACT'
              (INDEX) (Cost=1 Card=1)
    
    
      18    7         TABLE ACCESS (BY INDEX ROWID) OF 'LEASE' (TABLE) (Co
              st=1 Card=1 Bytes=35)
    
    
      19   18           INDEX (UNIQUE SCAN) OF 'PK_LEASE' (INDEX (UNIQUE))
               (Cost=0 Card=1)
    
    
      20    5     TABLE ACCESS (BY INDEX ROWID) OF 'FAMIS_LEASE_LOCATION'
              (TABLE) (Cost=2 Card=1 Bytes=24)
    
    
      21   20       INDEX (RANGE SCAN) OF 'FAMIS_LEASE_LOC_LEASE_FK' (INDE
              X) (Cost=1 Card=1)
    
    
    
    
    
    
    
    
    
    
    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
        8484854  consistent gets
              0  physical reads
              0  redo size
          34190  bytes sent via SQL*Net to client
           9592  bytes received via SQL*Net from client
             15  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            203  rows processed
    
    
    SQL>
    

    Apologies for any inconvenience in the reading of the application. This is the query.

    SELECT a.req_number, a.req_status, a.wo_number, a.wo_status, a.description,
              a.requestor, a.req_date, a.enter_date, a.pl_number, a.site,
              a.building, a.room, a.attribute2, b.emp_id, c.custom09, c.custom13,
              c.custom11, c.custom16 + 1 AS family_no, c.active_flag, e.leaseid,
              e.commdate, e.enddate, e.functional_status, f.site_code,
              CASE
                 WHEN c.custom09 = 'Married'
                    THEN 10
                 ELSE 0
              END AS married,
              CASE
                 WHEN (CASE
                          WHEN (c.custom16 + 1) > 4
                             THEN 10
                          ELSE (c.custom16 + 1) * 2
                       END
                      ) IS NULL
                    THEN 0
                 ELSE (CASE
                          WHEN (c.custom16 + 1) > 4
                             THEN 10
                          ELSE (c.custom16 + 1) * 2
                       END)
              END AS family,
              CASE
                 WHEN c.custom11 = 'Canadian Management'
                    THEN 8
                 ELSE 0
              END AS job,
              CASE
                 WHEN (  CASE
                            WHEN MONTHS_BETWEEN (SYSDATE,
                                                 TO_DATE (c.custom13,
                                                          'MM/DD/YYYY')
                                                ) > 36
                               THEN 6
                            ELSE 0
                         END
                       + CASE
                            WHEN MONTHS_BETWEEN (SYSDATE,
                                                 TO_DATE (c.custom13,
                                                          'MM/DD/YYYY')
                                                ) > 36
                               THEN   (  MONTHS_BETWEEN (SYSDATE,
                                                         TO_DATE (c.custom13,
                                                                  'MM/DD/YYYY'
                                                                 )
                                                        )
                                       - 36
                                      )
                                    / 24
                            ELSE   MONTHS_BETWEEN (SYSDATE,
                                                   TO_DATE (c.custom13,
                                                            'MM/DD/YYYY'
                                                           )
                                                  )
                                 / 24
                         END
                      ) IS NULL
                    THEN 0
                 ELSE (  CASE
                            WHEN MONTHS_BETWEEN (SYSDATE,
                                                 TO_DATE (c.custom13,
                                                          'MM/DD/YYYY')
                                                ) > 36
                               THEN 6
                            ELSE 0
                         END
                       + CASE
                            WHEN MONTHS_BETWEEN (SYSDATE,
                                                 TO_DATE (c.custom13,
                                                          'MM/DD/YYYY')
                                                ) > 36
                               THEN   (  MONTHS_BETWEEN (SYSDATE,
                                                         TO_DATE (c.custom13,
                                                                  'MM/DD/YYYY'
                                                                 )
                                                        )
                                       - 36
                                      )
                                    / 24
                            ELSE   MONTHS_BETWEEN (SYSDATE,
                                                   TO_DATE (c.custom13,
                                                            'MM/DD/YYYY'
                                                           )
                                                  )
                                 / 24
                         END
                      )
              END AS hire,
              CASE
                 WHEN MONTHS_BETWEEN (SYSDATE, a.req_date) * 4 > 10
                    THEN 10
                 ELSE MONTHS_BETWEEN (SYSDATE, a.req_date) * 4
              END AS entered,
                CASE
                   WHEN c.custom09 = 'Married'
                      THEN 10
                   ELSE 0
                END
              + CASE
                   WHEN (CASE
                            WHEN (c.custom16 + 1) > 4
                               THEN 10
                            ELSE (c.custom16 + 1) * 2
                         END
                        ) IS NULL
                      THEN 0
                   ELSE (CASE
                            WHEN (c.custom16 + 1) > 4
                               THEN 10
                            ELSE (c.custom16 + 1) * 2
                         END
                        )
                END
              + CASE
                   WHEN c.custom11 = 'Canadian Management'
                      THEN 8
                   ELSE 0
                END
              + CASE
                   WHEN (  CASE
                              WHEN MONTHS_BETWEEN (SYSDATE,
                                                   TO_DATE (c.custom13,
                                                            'MM/DD/YYYY'
                                                           )
                                                  ) > 36
                                 THEN 6
                              ELSE 0
                           END
                         + CASE
                              WHEN MONTHS_BETWEEN (SYSDATE,
                                                   TO_DATE (c.custom13,
                                                            'MM/DD/YYYY'
                                                           )
                                                  ) > 36
                                 THEN   (  MONTHS_BETWEEN (SYSDATE,
                                                           TO_DATE (c.custom13,
                                                                    'MM/DD/YYYY'
                                                                   )
                                                          )
                                         - 36
                                        )
                                      / 24
                              ELSE   MONTHS_BETWEEN (SYSDATE,
                                                     TO_DATE (c.custom13,
                                                              'MM/DD/YYYY'
                                                             )
                                                    )
                                   / 24
                           END
                        ) IS NULL
                      THEN 0
                   ELSE (  CASE
                              WHEN MONTHS_BETWEEN (SYSDATE,
                                                   TO_DATE (c.custom13,
                                                            'MM/DD/YYYY'
                                                           )
                                                  ) > 36
                                 THEN 6
                              ELSE 0
                           END
                         + CASE
                              WHEN MONTHS_BETWEEN (SYSDATE,
                                                   TO_DATE (c.custom13,
                                                            'MM/DD/YYYY'
                                                           )
                                                  ) > 36
                                 THEN   (  MONTHS_BETWEEN (SYSDATE,
                                                           TO_DATE (c.custom13,
                                                                    'MM/DD/YYYY'
                                                                   )
                                                          )
                                         - 36
                                        )
                                      / 24
                              ELSE   MONTHS_BETWEEN (SYSDATE,
                                                     TO_DATE (c.custom13,
                                                              'MM/DD/YYYY'
                                                             )
                                                    )
                                   / 24
                           END
                        )
                END
              + CASE
                   WHEN MONTHS_BETWEEN (SYSDATE, a.req_date) * 4 > 10
                      THEN 10
                   ELSE MONTHS_BETWEEN (SYSDATE, a.req_date) * 4
                END
              + CASE
                   WHEN a.attribute2 IS NULL
                      THEN '0'
                   ELSE a.attribute2
                END AS total,
              CASE
                 WHEN f.site_code IN ('AJ1', 'AJ2', 'AJ3', 'RG1')
                    THEN f.building_code
                 ELSE f.space_code
              END AS SPACE,
              CASE
                 WHEN a.site IN ('AJ1', 'AJ2', 'AJ3', 'RG1')
                    THEN a.building
                 ELSE a.room
              END AS space_req,
              CASE
                 WHEN a.pl_number = '002002001'
                    THEN 'Villa to Villa'
                 ELSE (CASE
                          WHEN a.pl_number = '002002002'
                             THEN 'Apartment to Villa'
                          ELSE (CASE
                                   WHEN a.pl_number = '002002003'
                                      THEN 'Apartment to Apartment'
                                   ELSE 'Villa to Apartment'
                                END
                               )
                       END
                      )
              END AS TYPE,
              (SELECT   MAX (g.req_date)
                   FROM famis_req g
                  WHERE g.req_date < a.req_date
                    AND g.requestor_id = a.requestor_id
                    AND g.pl_number IN
                             ('002002001', '002002002', '002002003', '002002004')
                    AND g.wo_status = 'CLOSED'
               GROUP BY g.requestor_id) AS last_move,
              (SELECT   COUNT (g.req_number)
                   FROM famis_req g
                  WHERE g.req_date <> a.req_date
                    AND g.requestor_id = a.requestor_id
                    AND g.pl_number IN
                             ('002002001', '002002002', '002002003', '002002004')
                    AND g.req_status NOT IN ('REJECTED', 'CANCELED')
               GROUP BY g.requestor_id) AS requests
         FROM famis_req a JOIN famis_requestor b ON a.requestor_id =
                                                                    b.requestor_id
              JOIN fam_person c ON b.emp_id = c.person_code
              LEFT JOIN lease_contact d ON c.person_code = d.contact_id
              LEFT JOIN lease e ON d.leaseid = e.leaseid
              LEFT JOIN famis_lease_location f ON e.leaseid = f.lease_code
        WHERE site <> 'CNAQ1'
          AND pl_number IN ('002002001', '002002002', '002002003', '002002004')
          AND (a.enter_date < e.enddate OR e.enddate IS NULL)
          AND (e.functional_status = 'OCCUPIED' OR e.functional_status IS NULL)
    

    Thank you.

    It is difficult to read anything not formatted output of the explain plan.

    In any case, there is a hughe number of becomes coherent.

    I'm just guessing that the reason might be the two groups of subqueries.

    You can try to replace them with

    1 Inline views or subquery (with article) plants which are connected to the result set

    or

    2 analysis functions

    Here is an example of the latter approach. You can try if this changes something (after make sure you that they lead to correct results).

    , max (case when a.wo_status = 'CLOSED' then a.req_date any other purpose) over (partition by a.requestor_id of a.req_date order

    range between unbounded preceding and interval "0.1"(seconde précédant) as last_move "."

    , count (case when not in a.req_status ('DENIED', 'CANCELLED') then a.req_number any other purpose))

    a.requestor_id partition)

    -count (case when not in a.req_status ('DENIED', 'CANCELLED') then a.req_number any other purpose))

    partition a.requestor_id, a.req_date) as applications

    Note that I assume that req_date is of date data type. If it is of type timestamp, the interval should be adapted.

  • Noob in SQL Tuning seeking help

    I am learning SQL Tuning and operation of it. I know that the first step is probably explain the sql statement execution plan? My problem is that I do not understand what am I suppose to collect from the execution plan.
    SQL> set autotrace traceonly explain
    SQL> select * from employees A
         where A.last_employed =
         ( SELECT TO_CHAR(MAX(TO_DATE(PAY_DATE,'MMRR')),'MMYY')
           FROM PAYROLL_VW1 B
           WHERE B.SSN = A.SSN AND B.PAY_TYPE_CODE IN ('02','12','22','32')
          AND STATUS = 'ACTIVE' AND A.BRANCH=B.BRANCH
         );
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=47427 Card=1 Bytes
              =180)
    
       1    0   FILTER
       2    1     TABLE ACCESS (FULL) OF 'EMPLOYEES' (TABLE) (Cost=1618 Card
              =297964 Bytes=53633520)
    
       3    1     SORT (AGGREGATE)
       4    3       VIEW OF 'PAYROLL_VW1' (VIEW) (Cost=2290 Card=2 Bytes=
              46)
    
       5    4         SORT (UNIQUE) (Cost=2290 Card=2 Bytes=217)
       6    5           UNION-ALL
       7    6             FILTER
       8    7               TABLE ACCESS (FULL) OF 'PAYROLL2012' (TABLE) (C
              ost=2284 Card=1 Bytes=105)
    
       9    6             FILTER
      10    9               TABLE ACCESS (BY INDEX ROWID) OF 'PAYROLL2011'
              (TABLE) (Cost=4 Card=1 Bytes=112)
    
      11   10                 INDEX (RANGE SCAN) OF 'PAYROLL2011_IDX1' (IND
              EX) (Cost=3 Card=29)
    Then what should I do with the execution plan? What else should I check on it? How to grant the request?

    Edited by: apex_disco may 1, 2012 05:57

    I don't know how the licenses work. There is a difference between EM and Grid Control. I think that if you have just one instance, Enterprise Manager is installed, and if nothing is free I think it would be. Now, how much diagnosis is free? Who knows.

    But it may not be important. If you simply play "learning SQL Tuning" say, at home on a Linux machine, you can install anything you want and play with him.

    If adding an accelerated things index (in your re-written query logic now) then you must have had a considerable amount of documents in one of these tables not indexed. If you look at the plan to explain it now, it will probably show the indexes used, fewer files searched, less costly, etc as the other plan.

    But maybe I missed your point of departure. You want to learn how to set up queries in general or you try to resolve this particular application? I took the first for my previous answers.

    As for your results, your statistics say at least high level info. Becomes coherent and physical readings went down WAY.

    Initial statistics
    ----------------------------------------------------------
    0 recursive calls
    0 db block Gets
    1172490142 compatible Gets
    4914 physical reads
    Redo 191496 size

    2340 bytes sent via SQL * Net to client
    329 bytes received via SQL * Net from client
    1 SQL * Net back and forth to and from the client
    115881 sorts (memory)
    0 sorts (disk)
    0 rows processed

    on these tables and below are my stats. I think this is a major improvement. Elapsed time was reduced significantly to 00:00:00.65

    To listen statistics
    ----------------------------------------------------------
    352 recursive calls
    0 db block Gets
    31498 compatible Gets
    1101 physical reads
    0 redo size

    2340 bytes sent via SQL * Net to client
    329 bytes received via SQL * Net from client
    1 SQL * Net back and forth to and from the client
    13 sorts (memory)
    0 sorts (disk)
    0 rows processed

    Published by: gaffe on May 1, 2012 13:18

  • slow query

    I have a h takes SQL to execute. may in any case to improve the way in which this query is written.

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0

    SQL > SET AUTOTRACE TRACEONLY EXPLAIN
    SQL > SELECT R.*
    2, NVL(PRODUCTS,0) DIG_PRODUCTS
    3, NVL(ACCOUNTS,0) DIG_ACCOUNTS
    4, NVL(ADS_AMTS,0) DIG_ADS_AMTS
    5, NVL(OTHER_AMTS,0) DIG_OTHER_AMTS
    6 OF
    7 (SELECT
    ADVERTISER_ID 8,.
    BRAND_CODE 9,.
    10 MEDIA_TYPE,
    ORDER_ID 11,
    DIRECTORY_CODE 12,
    DIRECTORY_ISSUE_NUM 13,
    SUM (PREV_TOTAL_OC_AMOUNT) 14 PREV_OC_AMT,
    SUM (TOTAL_OC_AMOUNT) 15 CURR_OC_AMT,
    16 SUM (TOTAL_OC_DISC_AMOUNT) DISC_OC_AMT,
    NETT_OC_AMT 17 SUM (TOTAL_OC_AMOUNT + TOTAL_OC_DISC_AMOUNT)
    18 FROM pstdr. SLS_OM_REVENUE
    19. WHERE LATEST_VERSION_IND = 'Y '.
    20 AND DIRECTORY_ISSUE_NUM = 32
    21 AND BRAND_CODE = "YELPRINT."
    22 AND DISCOUNT1_CODE = '2080225'
    23 AND TOTAL_OC_AMOUNT + PREV_TOTAL_OC_AMOUNT > 0
    24 GROUP OF
    25 ADVERTISER_ID,
    BRAND_CODE 26,
    27 MEDIA_TYPE,
    ORDER_ID 28,
    DIRECTORY_CODE 29,
    R 30 DIRECTORY_ISSUE_NUM),
    31 (SELECT / * + ORDERED * /)
    32 obl.advertiser_id
    33, count (distinct obl.pd_product_code) PRODUCTS
    34, count (distinct obl.account_id) ACCOUNTS
    35, SUM (DECODE(charge_type,'ADS',charge_amt,0)) ADS_AMTS
    36, SUM (DECODE(charge_type,'ADS',0,charge_amt)) OTHER_AMTS
    37 sdw_icob.iv_obligation obl
    38, sdw_icob.iv_obligation_amount amt
    39, (SELECT PRODUCT_CODE
    40, PRODUCTVERSION
    41, DECODE(MEDIA_TYPE,'PRINT','PRINT','DIGITAL') MEDIA_TYPE
    Sdw_nrt 42. PRD PD_PRODUCT)
    43 WHERE obl.account_id = amt.account_id
    44 and obl.obligation_id = amt.obligation_id
    45 and obl.obligation_version = amt.obligation_version
    46 and obl. PD_PRODUCT_CODE = prd. PRODUCT_CODE
    47 and obl. PD_PRODUCT_VERSION = prd. PRODUCTVERSION
    48 and obl.last_version_ind = 'Y '.
    49 and amt.last_version_ind = 'Y '.
    50 and prd.media_type = "DIGITAL."
    51 and obl.advertiser_id in
    52 (SELECT DISTINCT advertiser_id
    Pstdr 53. SLS_OM_REVENUE
    54. WHERE LATEST_VERSION_IND = 'Y '.
    55 AND DIRECTORY_ISSUE_NUM = 32
    56 AND BRAND_CODE = "YELPRINT."
    57 AND DISCOUNT1_CODE = '2080225'
    58 AND TOTAL_OC_AMOUNT + PREV_TOTAL_OC_AMOUNT > 0)
    Group by obl.advertiser_id 59) O
    60 WHERE R.advertiser_id = O.advertiser_id (+)
    ORDER 61 BY 1,2,3
    62;

    Execution plan
    ----------------------------------------------------------
    0 SELECT STATEMENT Optimizer = ALL_ROWS (cost = card 26 = 1 bytes = 23
    2)

    1 0 SORTING (ORDER BY) (cost = card 26 = 1 bytes = 232)
    2 1 HASH JOIN (EXTERNAL) (cost = 25 card = 1 bytes = 232)
    3 2 VIEW (cost = 1 card = 1 bytes = 173)
    4 3 (GROUP BY) HASH (cost = 1 card = 1 bytes = 198)
    5 SCORE RANGE (SINGLE) 4 (cost = 0 card = 1 bytes = 198)
    6 LIST of PARTITION 5 (SINGLE) (cost = 0 card = 1 bytes = 198
    )

    7 6 ACCESS (BY INDEX ROWID LOCAL) TABLE OF ' SLS_OM
    _REVENUE' (TABLE) (cost = 0 card = 1 bytes = 198)

    8 7 INDEX (SKIP SCAN) OF "SLS_OM_REVENUE_I11" (I).
    NDEX) (cost = 0 = 1 card)

    9 2 VIEW (cost = 23 card = 1 bytes = 59)
    10 9 (GROUP BY) SORT (cost = 23 card = 1 bytes = 240)
    11 10 ACCESS (BY INDEX ROWID) OF "PD_PRODUCT" (TAB TABLE
    THE) (cost = 4 cards = 1 bytes = 21)

    12 11 LOOPS IMBRIQUEES (cost = 22 card = 1 bytes = 240)
    13 12 LOOPS IMBRIQUEES (cost = 18 card = 1 bytes = 219)
    14 13 LOOPS IMBRIQUEES (cost = 9 card = 1 bytes = 178)
    15 14 (SINGLE) SORT (cost = 0 card = 1 bytes = 112)
    16 15 PARTITION RANGE (SINGLE) (cost = 0 = 1 card
    Bytes = 112)

    17 16 PARTITION LIST (SINGLE) (cost = 0 = 1 card
    Bytes = 112)

    18 17 TABLE ACCESS (BY INDEX ROWID LOCAL)
    OF "SLS_OM_REVENUE" (TABLE) (cost = 0 card = 1 bytes = 112)

    19 18 INDEX (SKIP SCAN) OF ' SLS_OM_REVEN
    UE_I11' (INDEX) (cost = 0 = 1 card)

    20 14 PARTITION LIST (ALL) (cost = card 8 = 1 bytes =
    66)

    "21 20 ACCESS (BY INDEX ROWID LOCAL) TABLE OF.
    IV_OBLIGATION' (TABLE) (cost = card 8 = 1 bytes = 66)

    22 21 INDEX (LINE SCAN) OF ' IV_OBLIGATION_I
    02' (INDEX) (cost = card 8 = 50)

    23 13 PARTITION the LIST (ALL) (cost = 9 card = 1 bytes = 41
    )

    24 23 ACCESS (BY INDEX ROWID LOCAL) TABLE OF ' IV
    OBLIGATION AMOUNT "(TABLE) (cost = 9 card = 1 bytes = 41)"

    25 24 INDEX (LINE SCAN) OF ' IV_OBLIGATION_AMO
    UNT_AK01' (INDEX) (cost = 8 = 1 card)

    26 12 INDEX (LINE SCAN) OF 'PD_PRODUCT_AK01' (INDEX
    ) (Cost = 1 card = 3)
  • Problem with Textfield autocomplete--&gt; only use the INSTR function

    Hello team dev,

    I use the new "textfield autocomplete" item type APEX and you have a crazy problem with it.

    I have a table with an index on the same column I want to search with AutoComplete field.

    Index:
    CREATE BITMAP INDEX TEST.GEO_DATA_IDX1 ON TEST.GEO_DATA (postcode)
    NOLOGGING TABLESPACE TS_INDEX;
    Select which is automatically generated by APEX 4:
    SELECT   a.*
      FROM   (  SELECT   DISTINCT postcode AS RV
                  FROM   TEST.GEO_DATA
                 WHERE   country_id = :P1_COUNTRY
              ORDER BY   1) a
     WHERE   INSTR ("RV", :p$_search_string) > 0 AND ROWNUM <= :p$_max_rows;
    
    -- plan
    Plan
    SELECT STATEMENT  ALL_ROWSCost: 4,308  Bytes: 45,31  Cardinality: 1,97            
         2 SORT UNIQUE  Cost: 4,307  Bytes: 45,31  Cardinality: 1,97       
              1 TABLE ACCESS FULL TABLE #TABLE# Cost: 4,306  Bytes: 47,311  Cardinality: 2,057  
    The APEX 3, I used the addon of Tyler Muth with my own Select:
    SELECT   DISTINCT
                postcode AS DV,
                postcode AS RV
         FROM   TEST.GEO_DATA
         WHERE   country_id = L_COUNTRY
         AND    postcode like l_search||'%'
         ORDER BY 1
    
    -- Plan
    SELECT STATEMENT  ALL_ROWSCost: 840  Bytes: 152,867  Cardinality: 13,897                                
         8 SORT ORDER BY  Cost: 840  Bytes: 152,867  Cardinality: 13,897                           
              7 HASH UNIQUE  Cost: 838  Bytes: 152,867  Cardinality: 13,897                      
                   6 VIEW VIEW index$_join$_001 Cost: 836  Bytes: 232,111  Cardinality: 21,101                 
                        5 HASH JOIN            
                             2 BITMAP CONVERSION TO ROWIDS  Cost: 31  Bytes: 232,111  Cardinality: 21,101       
                                  1 BITMAP INDEX RANGE SCAN INDEX (BITMAP) #INDEX#
                             4 BITMAP CONVERSION TO ROWIDS  Cost: 45  Bytes: 232,111  Cardinality: 21,101       
                                  3 BITMAP INDEX SINGLE VALUE INDEX (BITMAP) #INDEX#
    Is there a chance to get my INDEX used by the new element of the APEX? I do not. But I still want to ask before I just rebuild. :)

    Best regards

    Tobias

    Hi Tobias,.

    I guess that you are currently using "contains and case sensitivity ' to the attribute of"search ". Have you ever tried out "Exact and case sensitivity? Because that internally uses the LIKE operator as does your original query and the % is at the end, she must allow the use of an index. But it might still work, because ORDER BY can be run at a different time in your original example, but it's worth a try.

    Concerning
    Patrick
    -----------
    My Blog: http://www.inside-oracle-apex.com
    APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • If the INSTR function will not use the INDEX o?

    Hi all


    I have a querry as
        Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0 ;
    Is simple index on column Col1. If we use the index will be used or full table scan will happen in this scenario?

    Please give me explanatory answer because I have doubts


    Dhabas

    Hello

    You must use the index function if you want to avoid the full table scan. Check this box

    SQL> create table tab1(col1 varchar(20))
      2  /
    
    Table created.
    
    SQL> insert into tab1 values ('XXAB')
      2  /
    
    1 row created.
    
    SQL> create index col1_idx on tab1(col1);
    
    Index created.
    
    SQL> explain plan for Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0;
    
    Explained.
    
    SQL> set autotrace on
    SQL> Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0;
    XXAB
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=5 Card=1 Bytes=12)
       1    0   TABLE ACCESS (FULL) OF 'TAB1' (TABLE) (Cost=5 Card=1 Bytes
              =12)
    
    Statistics
    ----------------------------------------------------------
              4  recursive calls
              0  db block gets
             32  consistent gets
              0  physical reads
              0  redo size
            234  bytes sent via SQL*Net to client
            280  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    
    SQL>  create index col1_idx2 on tab1(Instr(Col1,'XX'));
    
    Index created.
    
    SQL> Select * from Tab1 Where Instr(Tab1.Col1,'XX') >0;
    XXAB
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=1 Bytes=12)
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TAB1' (TABLE) (Cost=2 Ca
              rd=1 Bytes=12)
    
       2    1     INDEX (RANGE SCAN) OF 'COL1_IDX2' (INDEX) (Cost=1 Card=1
              )
    
    Statistics
    ----------------------------------------------------------
             28  recursive calls
              0  db block gets
             22  consistent gets
              0  physical reads
              0  redo size
            234  bytes sent via SQL*Net to client
            280  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    
    SQL> 
    

    Thank you
    AJ

  • Interview with slow and fast 32 bit Oracle series control in oracle 64-bit.

    Hello
    I need help.
    I have a machine with Windows with Oracle 10.2.0.4 32 bits (DB - A)
    And a machine with 64 bit HPUNIX with Oracle 10.2.0.4 (DB - B)

    A query that I run on DB series - has in 140 mili sec

    And the same query on DB - B takes 10 Sec.

    The delay on DB - B is the only sort Index which is used to sort the data in ascending order. (DB - A uses this same index if present)

    Now I just googled around, I got some suspicion as "being 64-bit has more sorting area optimizer Oracle 32-bit choose from uses the index" is this true?

    Waiting for your response.

    Thank you and best regards,
    Vinay Mistry
    OFSSTORES.net s/n
    Atos Origin India

    Explain plans: -.
    DEVELOPMENT
    Plan
    INSTRUCTION SELECT ALL_ROWS cost: 137 bytes: 6 384 cardinality: 8
    ORDER of SORTING 63 BY cost: 137 bytes: 6 384 cardinality: 8
    62 of HASH JOIN cost EXTERNAL: 136 bytes: 6 384 cardinality: 8
    Cost EXTERNAL 60 NESTED LOOPS: 133 bytes: 6 304 cardinality: 8
    57 LOOPS IMBRIQUEES cost: 132 bytes: 6 152 cardinality: 8
    54 HASH JOIN cost EXTERNAL: 116 bytes: 5 584 cardinality: 8
    52 HASH JOIN EXTERNAL cost: 112 bytes: 5 440 cardinality: 8
    50 LOOPS IMBRIQUEES EXTERNAL cost: 109 bytes: 5 296 cardinality: 8
    HASH JOIN cost EXTERNAL 47: 101 bytes: 5 160 cardinality: 8
    Cost EXTERNAL 45 NESTED LOOPS: 95 bytes: 4 912 cardinality: 8
    Cost EXTERNAL 42 NESTED LOOPS: 87 bytes: 4 416 cardinality: 8
    Cost EXTERNAL NESTED LOOPS 39: 79 bytes: 4 344 cardinality: 8
    Cost EXTERNAL 36 NESTED LOOPS: 71 bytes: 4 208 cardinality: 8
    Cost EXTERNAL 33 NESTED LOOPS: 63 bytes: 3 736 cardinality: 8
    Cost EXTERNAL LOOPS IMBRIQUEES 30: 58 bytes: 3 360 cardinality: 8
    Cost EXTERNAL 27 NESTED LOOPS: 54 bytes: 3 136 cardinality: 8
    Cost EXTERNAL 24 NESTED LOOPS: 52 bytes: 2 912 cardinality: 8
    Cost EXTERNAL NESTED LOOPS 21: 44 bytes: 2 568 cardinality: 8
    LOOPS IMBRIQUEES EXTERNAL cost 18: 43 bytes: 2 416 cardinality: 8
    15 LOOPS IMBRIQUEES of EXTERNAL cost: 27 bytes: 2 152 cardinality: 8
    Cost EXTERNAL 12 NESTED LOOPS: 11 bytes: 1 928 cardinality: 8
    Cost 10 NESTED LOOPS: 7 bytes: 1 664 cardinality: 8
    Cost EXTERNAL 7 NESTED LOOPS: cardinality 3 bytes: 70: 1
    Cost EXTERNAL NESTED LOOPS 4: 02:00 cardinality: 1
    OFS_ST_DB_CH. cost R_TXN TABLE TABLE ACCESS BY INDEX ROWID 2: 02:00 cardinality: 1
    1 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_TXN cost: cardinality 1: 1
    3 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_STO cost: 0 bytes: 25 552 cardinality: 3 194
    TABLE 6 ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_AU cost: 1 bytes: 316 176: 11 292 cardinality
    5 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_AU cost: cardinality 0: 1
    9 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_TXN_PRO_STO cost: 4 bytes: 1 104 cardinality: 8
    8 INDEX RANGE SCAN INDEX OFS_ST_DB_CH. TXN__TXN_PRO_STO_FK cost: cardinality 2: 8
    11 INDEX RANGE SCAN (SINGLE) OFS_ST_DB_CH INDEX. Cost PK_PRO_VEN_DET: 02:00 cardinality: 1
    OFS_ST_DB_CH. cost R_STO_PRO TABLE TABLE ACCESS BY INDEX ROWID 14: 02:00 cardinality: 1
    13 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_STO_PRO cost: cardinality 1: 1
    OFS_ST_DB_CH. cost R_STO_PRO TABLE TABLE ACCESS BY INDEX ROWID 17: 02:00 cardinality: 1
    16 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_STO_PRO cost: cardinality 1: 1
    TABLE 20 ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_SRP cost: 1 bytes: cardinality 1: 19
    19 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_SRP cost: cardinality 0: 1
    23 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_VEN_PRO_CAT cost: 1 bytes: cardinality 1: 43
    22 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_VEN_PRO_CAT cost: cardinality 0: 1
    26 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_AU cost: 1 bytes: cardinality 1: 28
    25 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_AU cost: cardinality 0: 1
    29 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_AU cost: 1 bytes: cardinality 1: 28
    28 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_AU cost: cardinality 0: 1
    32 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_PAC cost: 1 bytes: cardinality 1: 47
    31 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_PAC cost: cardinality 0: 1
    35 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_STO cost: 1 bytes: cardinality 1: 59
    34. THE INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_STO cost: cardinality 0: 1
    38 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_GEO_STR cost: 1 bytes: cardinality 1: 17
    37. THE INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_GEO_STR cost: cardinality 0: 1
    41 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_VEN_DET cost: 1 bytes: cardinality 1: 9
    40 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_VEN_DET cost: cardinality 0: 1
    44 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_STO cost: 1 bytes: cardinality 62: 1
    43. THE INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_STO cost: cardinality 0: 1
    TABLE 46 ACCESS COMPLETE OF THE TABLE OFS_ST_DB_CH. R_CO cost: 5 bytes: 22 103 cardinality: 713
    49 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_GEO_STR cost: 1 bytes: cardinality 1: 17
    48 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_GEO_STR cost: cardinality 0: 1
    TABLE 51 ACCESS COMPLETE OF THE TABLE OFS_ST_DB_CH. R_STO_TYP cost: 3 bytes: 270 cardinality: 15
    TABLE 53 ACCESS COMPLETE OF THE TABLE OFS_ST_DB_CH. R_STO_TYP cost: 3 bytes: 270 cardinality: 15
    56 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_PRO cost: 2 bytes: 71 cardinality: 1
    55 INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_PRO cost: cardinality 1: 1
    59 TABLE ACCESS BY INDEX ROWID TABLE. OFS_ST_DB_CH R_SRP cost: 1 bytes: cardinality 1: 19
    58. THE INDEX UNIQUE INDEX (SINGLE) OFS_ST_DB_CH SCAN. PK_SRP cost: cardinality 0: 1
    61 FULL TABLE ACCESS TABLE. OFS_ST_DB_CH cost R_PAR_TYP: 03:00 cardinality: 4



    QA
    Plan
    INSTRUCTION SELECT FIRST_ROWS cost: 342 389 bytes: 326 230 cardinality: 190
    Cost EXTERNAL 67 NESTED LOOPS: 342 389 bytes: 326 230 cardinality: 190
    Cost EXTERNAL 64 LOOPS IMBRIQUEES: 342 202 bytes: 324 330 cardinality: 190
    Cost of 61 LOOPS IMBRIQUEES: 342 178 bytes: 320 720 cardinality: 190
    Cost EXTERNAL 58 NESTED LOOPS: 341 796 bytes: 307 230 cardinality: 190
    Cost EXTERNAL 55 NESTED LOOPS: 341 794 bytes: 303 620 cardinality: 190
    Cost EXTERNAL 52 NESTED LOOPS: 341 750 bytes: 282 340 cardinality: 190
    Cost EXTERNAL 49 NESTED LOOPS: 341 705 bytes: 263 720 cardinality: 190
    Cost EXTERNAL 46 NESTED LOOPS: 341 514 bytes: 262 010 cardinality: 190
    Cost EXTERNAL 43 NESTED LOOPS: 341 322 bytes: 255 930 cardinality: 190
    Cost EXTERNAL 40 NESTED LOOPS: 341 087 bytes: 249 660 cardinality: 190
    Cost EXTERNAL 37 NESTED LOOPS: 341 026 bytes: 240 730 cardinality: 190
    Cost EXTERNAL 34 NESTED LOOPS: 340 980 bytes: 235 410 cardinality: 190
    Cost EXTERNAL 31 NESTED LOOPS: 340 933 bytes: 230 090 cardinality: 190
    Cost EXTERNAL 28 NESTED LOOPS: 340 741 bytes: 226 860 cardinality: 190
    Cost EXTERNAL 25 NESTED LOOPS: 340 550 bytes: 220 970 cardinality: 190
    Cost EXTERNAL 22 NESTED LOOPS: 340 536 bytes: 217 550 cardinality: 190
    Cost EXTERNAL 19 NESTED LOOPS: 340 535 bytes: 205 770 cardinality: 190
    Cost EXTERNAL 16 NESTED LOOPS: 340 344 bytes: 202 540 cardinality: 190
    Cost EXTERNAL LOOPS IMBRIQUEES 13: 340 329 bytes: 199 120 cardinality: 190
    Cost 10 NESTED LOOPS: 340 328 bytes: 188 100 cardinality: 190
    Cost EXTERNAL 7 NESTED LOOPS: cardinality 3 bytes: 68: 1
    Cost EXTERNAL NESTED LOOPS 4: 02:00 cardinality: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_TXN cost 2: 02:00 cardinality: 1
    1 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_TXN SCAN cost: cardinality 1: 1
    3 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_STO SCAN cost: cardinality of 0 bytes: 58 815: 6 535
    TABLE ACCESS BY INDEX ROWID OFS_V3_4.R_AU cost TABLE 6: 1 bytes: 301 140: 10 755 cardinality
    5 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_AU SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE cost OFS_V3_4.R_TXN_PRO_STO 9: 340 325 bytes: 71 820 cardinality: 190
    8 INDEX FULL SCAN INDEX OFS_V3_4.TXN_PRO_STO__NO_LIN_IX cost: 1 285: 547 206 cardinality
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_STO cost 12: 1 bytes: cardinality 1: 58
    11 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_STO SCAN cost: cardinality 0: 1
    TABLE 15 ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_STO_TYP cost: 1 bytes: cardinality 18: 1
    14 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_STO_TYP SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_GEO_STR cost 18: 1 bytes: cardinality 1: 17
    17 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_GEO_STR SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_STO cost 21: 1 bytes: cardinality 62: 1
    20 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_STO SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_STO_TYP cost 24: 1 bytes: cardinality 18: 1
    23 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_STO_TYP SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_CO cost 27: 1 bytes: cardinality 1: 31
    26 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_CO SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_GEO_STR cost 30: 1 bytes: cardinality 1: 17
    29 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_GEO_STR SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_AU cost 33: 1 bytes: cardinality 1: 28
    32 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_AU SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_AU cost 36: 1 bytes: cardinality 1: 28
    35 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_AU SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_PAC cost 39: 1 bytes: cardinality 1: 47
    38 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_PAC SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_PRO_VEN_DET cost 42: 33 octets: 33 cardinality: 1
    41 INDEX RANGE SCAN INDEX OFS_V3_4.STO__PRO_VEN_DET_FK cost: cardinality 1: 457
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_VEN_PRO_CAT cost 45: 1 bytes: cardinality 1: 32
    44 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_VEN_PRO_CAT SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_VEN_DET cost 48: 1 bytes: cardinality 1: 9
    47 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_VEN_DET SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_STO_PRO cost 51: 1 bytes: cardinality 1: 98
    50 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_STO_PRO SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_STO_PRO cost 54: 1 bytes: cardinality 1: 112
    53 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_STO_PRO SCAN cost: cardinality 0: 1
    TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_SRP cost 57: 1 bytes: cardinality 1: 19
    56 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_SRP SCAN cost: cardinality 0: 1
    60 TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_PRO cost: cardinality of 2 bytes: 71: 1
    59 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_PRO SCAN cost: cardinality 1: 1
    63 TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_SRP cost: 1 bytes: cardinality 1: 19
    62 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_SRP SCAN cost: cardinality 0: 1
    66 TABLE ACCESS BY INDEX ROWID TABLE OFS_V3_4.R_PAR_TYP cost: 1 bytes: cardinality 1: 10
    65 INDEX UNIQUE INDEX (SINGLE) OFS_V3_4.PK_PAR_TYP SCAN cost: cardinality 0: 1

    Except for the fact that the tables listed in the two execution plans are totally different, I can see that the two database have a different place (ALL_ROWS vs FIRST_ROWS) optimizer.

    In addition, there is a big difference in the number of rows processed every step of execution.

  • Bind variables in the SQL causes slow

    We have a strange problem in our PeopleSoft system that I traced to a SELECT statement using bind variables, if hardcode us them values in SQL, it runs very fast.
    but using bindings (what the application does) a problem of efficiency. I'm going to re - write the code that is based on a view of three tables joined to go against
    the base tables and I don't think I'll have a problem. However, I would like to know why the problem exists in the first place. Here is what info I have:
    Oracle version: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

    It's the 'good' application without links:
    SELECT COUNT(*)
    FROM sysadm.PS_ERN_PROG_DESCR A
    WHERE A.ERN_PROGRAM = 'VT'
    AND A.ERNCD         = '01'
    AND EFFDT           =
      (SELECT MAX(B.EFFDT)
      FROM sysadm.PS_ERN_PROG_DESCR B
      WHERE B.ERN_PROGRAM = 'VT'
      AND B.EFFDT        <= TO_DATE('2009-10-10','YYYY-MM-DD')
      );
    And the 'good' explains the plan:
     Plan hash value: 3344976101
    
    -------------------------------------------------------------------------------------------------------------
    | Id  | Operation                              | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                       |                    |     1 |    33 |    58  (23)| 00:00:01 |
    |   1 |  SORT AGGREGATE                        |                    |     1 |    33 |            |          |
    |   2 |   NESTED LOOPS                         |                    |     1 |    33 |     3   (0)| 00:00:01 |
    |   3 |    NESTED LOOPS                        |                    |     1 |    22 |     2   (0)| 00:00:01 |
    |*  4 |     INDEX UNIQUE SCAN                  | PS_ERN_PROGRAM_DEF |     1 |    12 |     1   (0)| 00:00:01 |
    |   5 |      SORT AGGREGATE                    |                    |     1 |     9 |            |          |
    |   6 |       VIEW                             |                    |    23 |   207 |    51  (26)| 00:00:01 |
    |*  7 |        FILTER                          |                    |       |       |            |          |
    |   8 |         SORT GROUP BY                  |                    |    23 |  1748 |    51  (26)| 00:00:01 |
    |*  9 |          HASH JOIN                     |                    |  2995 |   222K|    49  (23)| 00:00:01 |
    |* 10 |           TABLE ACCESS FULL            | PS_EARNINGS_TBL    |  1913 | 24869 |    15   (7)| 00:00:01 |
    |* 11 |           HASH JOIN                    |                    | 13621 |   838K|    30  (20)| 00:00:01 |
    |  12 |            TABLE ACCESS FULL           | PS_EARNINGS_TBL    |  1913 | 42086 |    14   (0)| 00:00:01 |
    |* 13 |            HASH JOIN                   |                    |  3097 |   124K|    14  (29)| 00:00:01 |
    |* 14 |             TABLE ACCESS BY INDEX ROWID| PS_ERN_PROGRAM_TBL |     9 |   207 |     2   (0)| 00:00:01 |
    |* 15 |              INDEX RANGE SCAN          | PS_ERN_PROGRAM_TBL |    18 |       |     1   (0)| 00:00:01 |
    |* 16 |             TABLE ACCESS FULL          | PS_ERN_PROGRAM_DEF | 12035 |   211K|    10  (20)| 00:00:01 |
    |* 17 |     INDEX RANGE SCAN                   | PS_EARNINGS_TBL    |     1 |    10 |     1   (0)| 00:00:01 |
    |  18 |      SORT AGGREGATE                    |                    |     1 |    10 |            |          |
    |* 19 |       INDEX RANGE SCAN                 | PS_EARNINGS_TBL    |     1 |    10 |     2   (0)| 00:00:01 |
    |* 20 |    TABLE ACCESS BY INDEX ROWID         | PS_ERN_PROGRAM_TBL |     1 |    11 |     1   (0)| 00:00:01 |
    |* 21 |     INDEX UNIQUE SCAN                  | PS_ERN_PROGRAM_TBL |     1 |       |     0   (0)| 00:00:01 |
    -------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("A"."ERN_PROGRAM"='VT' AND "A"."EFFDT"= (SELECT MAX("$vm_col_2") FROM  (SELECT /*+ */
                  "EFFDT" "$vm_col_1","A"."EFFDT" "$vm_col_2" FROM SYSADM."PS_EARNINGS_TBL"
                  "C",SYSADM."PS_ERN_PROGRAM_TBL" "B",SYSADM."PS_ERN_PROGRAM_DEF" "A",SYSADM."PS_EARNINGS_TBL" "D"
                  WHERE "D"."EFFDT"<="A"."EFFDT" AND "D"."ERNCD"="C"."ERNCD" AND "D"."EFFDT"<=TO_DATE(' 2009-10-10
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."EFFDT"="B"."EFFDT" AND
                  "A"."ERN_PROGRAM"="B"."ERN_PROGRAM" AND "A"."ERN_PROGRAM"='VT' AND "A"."EFFDT"<=TO_DATE(' 2009-10-10
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "B"."EFFDT"<=TO_DATE(' 2009-10-10 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "B"."ERN_PROGRAM"='VT' AND "B"."EFF_STATUS"='A' AND "C"."ERNCD"="A"."ERNCD" GROUP
                  BY "D"."ERNCD",ROWID,ROWID,ROWID,ROWID,"A"."EFFDT","EFFDT" HAVING "EFFDT"=MAX("D"."EFFDT"))
                  "$vm_view") AND "A"."ERNCD"='01')
       7 - filter("EFFDT"=MAX("D"."EFFDT"))
       9 - access("D"."ERNCD"="C"."ERNCD")
           filter("D"."EFFDT"<="A"."EFFDT")
      10 - filter("D"."EFFDT"<=TO_DATE(' 2009-10-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      11 - access("C"."ERNCD"="A"."ERNCD")
      13 - access("A"."ERN_PROGRAM"="B"."ERN_PROGRAM" AND "A"."EFFDT"="B"."EFFDT")
      14 - filter("B"."EFF_STATUS"='A')
      15 - access("B"."ERN_PROGRAM"='VT' AND "B"."EFFDT"<=TO_DATE(' 2009-10-10 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss'))
      16 - filter("A"."ERN_PROGRAM"='VT' AND "A"."EFFDT"<=TO_DATE(' 2009-10-10 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss'))
      17 - access("C"."ERNCD"='01')
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))= (SELECT
                  MAX(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))) FROM SYSADM."PS_EARNINGS_TBL" "D" WHERE
                  SYS_OP_DESCEND("EFFDT") IS NOT NULL AND SYS_OP_DESCEND("EFFDT")>=SYS_OP_DESCEND(:B1) AND
                  "D"."ERNCD"=:B2 AND SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=:B3))
      19 - access("D"."ERNCD"=:B1 AND SYS_OP_DESCEND("EFFDT")>=SYS_OP_DESCEND(:B2) AND
                  SYS_OP_DESCEND("EFFDT") IS NOT NULL)
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=:B1)
      20 - filter("B"."EFF_STATUS"='A')
      21 - access("B"."ERN_PROGRAM"='VT' AND "A"."EFFDT"="B"."EFFDT")
    Here is the 'good' autotrace:
    SQL> variable ppe_date varchar2(10)
    SQL> variable erncd varchar2(3)
    SQL> exec :ppe_date := '2009-10-10'
    SQL> exec :erncd := '01'
    SQL> SELECT COUNT(*)
      2  FROM PS_ERN_PROG_DESCR A
      3  WHERE A.ERN_PROGRAM = 'VT'
      4  AND A.ERNCD         = '01'
      5  AND EFFDT           =
      6    (SELECT MAX(B.EFFDT)
      7    FROM PS_ERN_PROG_DESCR B
      8    WHERE B.ERN_PROGRAM = 'VT'
      9    AND B.EFFDT        <= TO_DATE('2009-10-10','YYYY-MM-DD')
     10    );
    
      COUNT(*)
    ----------
             1
    
    Elapsed: 00:00:01.23
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=59 Card=1 Bytes=33)
       1    0   SORT (AGGREGATE)
       2    1     NESTED LOOPS (Cost=3 Card=1 Bytes=33)
       3    2       NESTED LOOPS (Cost=2 Card=1 Bytes=22)
       4    3         INDEX (UNIQUE SCAN) OF 'PS_ERN_PROGRAM_DEF' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=12)
       5    4           SORT (AGGREGATE)
       6    5             VIEW (Cost=52 Card=24 Bytes=216)
       7    6               FILTER
       8    7                 SORT (GROUP BY) (Cost=52 Card=24 Bytes=1824)
       9    8                   HASH JOIN (Cost=50 Card=3177 Bytes=241452)
      10    9                     TABLE ACCESS (FULL) OF 'PS_EARNINGS_TBL' (TABLE) (Cost=15 Card=1921 Bytes=24973)
      11    9                     HASH JOIN (Cost=31 Card=14488 Bytes=912744)
      12   11                       TABLE ACCESS (FULL) OF 'PS_EARNINGS_TBL' (TABLE) (Cost=14 Card=1921 Bytes=42262)
      13   11                       HASH JOIN (Cost=15 Card=3303 Bytes=135423)
      14   13                         TABLE ACCESS (FULL) OF 'PS_ERN_PROGRAM_TBL' (TABLE) (Cost=2 Card=9 Bytes=207)
      15   13                         TABLE ACCESS (FULL) OF 'PS_ERN_PROGRAM_DEF' (TABLE) (Cost=12 Card=12856 Bytes=231408)
      16    3         INDEX (RANGE SCAN) OF 'PS_EARNINGS_TBL' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=10)
      17   16           SORT (AGGREGATE)
      18   17             INDEX (RANGE SCAN) OF 'PS_EARNINGS_TBL' (INDEX (UNIQUE)) (Cost=2 Card=1 Bytes=10)
      19    2       TABLE ACCESS (BY INDEX ROWID) OF 'PS_ERN_PROGRAM_TBL' (TABLE) (Cost=1 Card=1 Bytes=11)
      20   19         INDEX (UNIQUE SCAN) OF 'PS_ERN_PROGRAM_TBL' (INDEX (UNIQUE)) (Cost=0 Card=1)
    
    
    
    
    
    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
            182  consistent gets
              0  physical reads
              0  redo size
            232  bytes sent via SQL*Net to client
            278  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
              1  rows processed
    
    SQL> spool off
    ===================================
    This is the 'bad' query using bindings:
    ===================================
    SELECT COUNT(*)
    FROM sysadm.PS_ERN_PROG_DESCR A
    WHERE A.ERN_PROGRAM = 'VT'
    AND A.ERNCD         = :erncd
    AND EFFDT           =
      (SELECT MAX(B.EFFDT)
      FROM sysadm.PS_ERN_PROG_DESCR B
      WHERE B.ERN_PROGRAM = 'VT'
      AND B.EFFDT        <= TO_DATE(:ppe_date,'YYYY-MM-DD')
      );
    The 'bad' explain plan
    explain plan succeeded.
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 337039962
    
    --------------------------------------------------------------------------------------------------------
    | Id  | Operation                         | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                  |                    |     1 |    33 |    20  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE                   |                    |     1 |    33 |            |          |
    |   2 |   NESTED LOOPS                    |                    |     1 |    33 |     3   (0)| 00:00:01 |
    |   3 |    NESTED LOOPS                   |                    |     1 |    22 |     2   (0)| 00:00:01 |
    |*  4 |     INDEX UNIQUE SCAN             | PS_ERN_PROGRAM_DEF |     1 |    12 |     1   (0)| 00:00:01 |
    |   5 |      SORT AGGREGATE               |                    |     1 |    63 |            |          |
    |   6 |       NESTED LOOPS                |                    |     1 |    63 |    13  (39)| 00:00:01 |
    |   7 |        NESTED LOOPS               |                    |     1 |    52 |    12  (42)| 00:00:01 |
    |*  8 |         HASH JOIN                 |                    |     4 |   168 |    12  (42)| 00:00:01 |
    |   9 |          VIEW                     | VW_SQ_1            |    88 |  2112 |     9  (45)| 00:00:01 |
    |  10 |           SORT GROUP BY           |                    |    88 |  2728 |     9  (45)| 00:00:01 |
    |  11 |            MERGE JOIN             |                    |  3087 | 95697 |     7  (29)| 00:00:01 |
    |  12 |             SORT JOIN             |                    |   643 | 11574 |     2   (0)| 00:00:01 |
    |* 13 |              INDEX RANGE SCAN     | PS_ERN_PROGRAM_DEF |   643 | 11574 |     2   (0)| 00:00:01 |
    |* 14 |             SORT JOIN             |                    |    96 |  1248 |     5  (40)| 00:00:01 |
    |* 15 |              INDEX FAST FULL SCAN | PS_EARNINGS_TBL    |    96 |  1248 |     4  (25)| 00:00:01 |
    |* 16 |          INDEX RANGE SCAN         | PS_ERN_PROGRAM_DEF |   643 | 11574 |     2   (0)| 00:00:01 |
    |* 17 |         INDEX UNIQUE SCAN         | PS_EARNINGS_TBL    |     1 |    10 |     0   (0)| 00:00:01 |
    |* 18 |        TABLE ACCESS BY INDEX ROWID| PS_ERN_PROGRAM_TBL |     1 |    11 |     1   (0)| 00:00:01 |
    |* 19 |         INDEX UNIQUE SCAN         | PS_ERN_PROGRAM_TBL |     1 |       |     0   (0)| 00:00:01 |
    |* 20 |     INDEX RANGE SCAN              | PS_EARNINGS_TBL    |     1 |    10 |     1   (0)| 00:00:01 |
    |  21 |      SORT AGGREGATE               |                    |     1 |    10 |            |          |
    |* 22 |       INDEX RANGE SCAN            | PS_EARNINGS_TBL    |     1 |    10 |     2   (0)| 00:00:01 |
    |* 23 |    TABLE ACCESS BY INDEX ROWID    | PS_ERN_PROGRAM_TBL |     1 |    11 |     1   (0)| 00:00:01 |
    |* 24 |     INDEX UNIQUE SCAN             | PS_ERN_PROGRAM_TBL |     1 |       |     0   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("A"."ERN_PROGRAM"='VT' AND "A"."EFFDT"= (SELECT MAX("A"."EFFDT") FROM
                  SYSADM."PS_EARNINGS_TBL" "C",SYSADM."PS_ERN_PROGRAM_TBL" "B",SYSADM."PS_ERN_PROGRAM_DEF" "A",
                  (SELECT MAX(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))) "VW_COL_1","D"."ERNCD" "ERNCD",ROWID
                  "ROWID" FROM SYSADM."PS_EARNINGS_TBL" "D","PS_ERN_PROGRAM_DEF" "A" WHERE
                  "A"."EFFDT"<=TO_DATE(:PPE_DATE,'YYYY-MM-DD') AND "A"."ERN_PROGRAM"='VT' AND
                  SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=INTERNAL_FUNCTION("A"."EFFDT") AND
                  SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=TO_DATE(:PPE_DATE,'YYYY-MM-DD') GROUP BY
                  "D"."ERNCD",ROWID) "VW_SQ_1" WHERE "ROWID"=ROWID AND
                  "A"."EFFDT"<=TO_DATE(:PPE_DATE,'YYYY-MM-DD') AND "A"."ERN_PROGRAM"='VT' AND
                  "A"."EFFDT"="B"."EFFDT" AND "B"."ERN_PROGRAM"='VT' AND "B"."EFF_STATUS"='A' AND
                  "B"."EFFDT"<=TO_DATE(:PPE_DATE,'YYYY-MM-DD') AND
                  SYS_OP_DESCEND("EFFDT")=SYS_OP_DESCEND("VW_COL_1") AND "ERNCD"="C"."ERNCD" AND
                  "C"."ERNCD"="A"."ERNCD" AND SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))="VW_COL_1") AND
                  "A"."ERNCD"=:ERNCD)
       8 - access("ROWID"=ROWID)
      13 - access("A"."ERN_PROGRAM"='VT' AND "A"."EFFDT"<=TO_DATE(:PPE_DATE,'YYYY-MM-DD'))
      14 - access(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=INTERNAL_FUNCTION("A"."EFFDT"))
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=INTERNAL_FUNCTION("A"."EFFDT"))
      15 - filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=TO_DATE(:PPE_DATE,'YYYY-MM-DD'))
      16 - access("A"."ERN_PROGRAM"='VT' AND "A"."EFFDT"<=TO_DATE(:PPE_DATE,'YYYY-MM-DD'))
      17 - access("ERNCD"="C"."ERNCD" AND SYS_OP_DESCEND("EFFDT")=SYS_OP_DESCEND("VW_COL_1"))
           filter("C"."ERNCD"="A"."ERNCD" AND SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))="VW_COL_1")
      18 - filter("B"."EFF_STATUS"='A')
      19 - access("B"."ERN_PROGRAM"='VT' AND "A"."EFFDT"="B"."EFFDT")
           filter("B"."EFFDT"<=TO_DATE(:PPE_DATE,'YYYY-MM-DD'))
      20 - access("C"."ERNCD"=:ERNCD)
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))= (SELECT
                  MAX(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))) FROM SYSADM."PS_EARNINGS_TBL" "D" WHERE
                  SYS_OP_DESCEND("EFFDT") IS NOT NULL AND SYS_OP_DESCEND("EFFDT")>=SYS_OP_DESCEND(:B1) AND
                  "D"."ERNCD"=:B2 AND SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=:B3))
      22 - access("D"."ERNCD"=:B1 AND SYS_OP_DESCEND("EFFDT")>=SYS_OP_DESCEND(:B2) AND
                  SYS_OP_DESCEND("EFFDT") IS NOT NULL)
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("EFFDT"))<=:B1)
      23 - filter("B"."EFF_STATUS"='A')
      24 - access("B"."ERN_PROGRAM"='VT' AND "A"."EFFDT"="B"."EFFDT")
    Here's the bad autotrace:
    SQL> variable ppe_date varchar2(10)
    SQL> variable erncd varchar2(3)
    SQL> exec :ppe_date := '2009-10-10'
    SQL> exec :erncd := '01'
    SQL> SELECT COUNT(*)
      2  FROM PS_ERN_PROG_DESCR A
      3  WHERE A.ERN_PROGRAM = 'VT'
      4  AND A.ERNCD         = :erncd
      5  AND EFFDT           =
      6    (SELECT MAX(B.EFFDT)
      7    FROM PS_ERN_PROG_DESCR B
      8    WHERE B.ERN_PROGRAM = 'VT'
      9    AND B.EFFDT        <= TO_DATE(:ppe_date,'YYYY-MM-DD')
     10    );
    
      COUNT(*)
    ----------
             1
    
    Elapsed: 00:04:07.40
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=20 Card=1 Bytes=33)
       1    0   SORT (AGGREGATE)
       2    1     NESTED LOOPS (Cost=3 Card=1 Bytes=33)
       3    2       NESTED LOOPS (Cost=2 Card=1 Bytes=22)
       4    3         INDEX (UNIQUE SCAN) OF 'PS_ERN_PROGRAM_DEF' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=12)
       5    4           SORT (AGGREGATE)
       6    5             NESTED LOOPS (Cost=13 Card=1 Bytes=63)
       7    6               NESTED LOOPS (Cost=12 Card=1 Bytes=52)
       8    7                 HASH JOIN (Cost=12 Card=4 Bytes=168)
       9    8                   VIEW OF 'VW_SQ_1' (VIEW) (Cost=9 Card=88 Bytes=2112)
      10    9                     SORT (GROUP BY) (Cost=9 Card=88 Bytes=2728)
      11   10                       MERGE JOIN (Cost=7 Card=3087 Bytes=95697)
      12   11                         SORT (JOIN) (Cost=2 Card=643 Bytes=11574)
      13   12                           INDEX (RANGE SCAN) OF 'PS_ERN_PROGRAM_DEF' (INDEX (UNIQUE)) (Cost=2 Card=643 Bytes=11574)
      14   11                         SORT (JOIN) (Cost=5 Card=96 Bytes=1248)
      15   14                           INDEX (FAST FULL SCAN) OF 'PS_EARNINGS_TBL' (INDEX (UNIQUE)) (Cost=4 Card=96 Bytes=1248)
      16    8                   INDEX (RANGE SCAN) OF 'PS_ERN_PROGRAM_DEF' (INDEX (UNIQUE)) (Cost=2 Card=643 Bytes=11574)
      17    7                 INDEX (UNIQUE SCAN) OF 'PS_EARNINGS_TBL' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=10)
      18    6               TABLE ACCESS (BY INDEX ROWID) OF 'PS_ERN_PROGRAM_TBL' (TABLE) (Cost=1 Card=1 Bytes=11)
      19   18                 INDEX (UNIQUE SCAN) OF 'PS_ERN_PROGRAM_TBL' (INDEX (UNIQUE)) (Cost=0 Card=1)
      20    3         INDEX (RANGE SCAN) OF 'PS_EARNINGS_TBL' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=10)
      21   20           SORT (AGGREGATE)
      22   21             INDEX (RANGE SCAN) OF 'PS_EARNINGS_TBL' (INDEX (UNIQUE)) (Cost=2 Card=1 Bytes=10)
      23    2       TABLE ACCESS (BY INDEX ROWID) OF 'PS_ERN_PROGRAM_TBL' (TABLE) (Cost=1 Card=1 Bytes=11)
      24   23         INDEX (UNIQUE SCAN) OF 'PS_ERN_PROGRAM_TBL' (INDEX (UNIQUE)) (Cost=0 Card=1)
    
    Statistics
    ----------------------------------------------------------
           3820  recursive calls
             66  db block gets
        4677728  consistent gets
          80608  physical reads
              0  redo size
            232  bytes sent via SQL*Net to client
            278  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              2  sorts (memory)
              1  sorts (disk)
              1  rows processed
    
    SQL> spool off

    I think you have to hit some sort of bug in the optimizer. Do you have the histograms on the EFFDT column.

  • Using the index function in where clause of Exchange.

    Hello friends,

    I need your help with a problem.

    I have a query that uses two table Say T1 and T2, where C1 is common column with which both are joined.
    C1 is the primary key in T1, but no index available in Q2 for the C1. T1C2 is the column that we want to select.
    (Note that table may be a Master table)

    Now let's see the query:
    Select T1C2
    From T1, T2
    where T2. C1 = T1. C1

    Here where the clause may have other conditions and From clause can have other tables as needed.

    I want to know that if I have change the query as continuation of leave my query to use the index available of T1. C1.

    Select T1C2
    from T1, T2
    where T1. C1 = T2.C1

    Then, the query uses the index available of T1. and I get better performance. Even a small improvement of performance help me much because this type of query is used in a loop where clause (so it will be run several times).

    Please advise on this...

    Kind regards
    Lifexisxnotxsoxbeautiful...

    Hello

    18:43:17 rel15_real_p>create table t1(c1 number primary key, c2 number);
    
    Table created.
    
    18:43:26 rel15_real_p>create table t2(c1 number, c2 number);
    
    18:45:08 rel15_real_p>
    18:45:09 rel15_real_p>begin
    18:45:09   2  for i in 1..100
    18:45:09   3  loop
    18:45:09   4        insert into t1(c1,c2) values (i,i+100);
    18:45:09   5  end loop;
    18:45:09   6  commit;
    18:45:09   7  end;
    18:45:09   8  /
    
    PL/SQL procedure successfully completed.
    
    18:45:09 rel15_real_p>
    18:45:09 rel15_real_p>
    18:45:09 rel15_real_p>begin
    18:45:09   2  for i in 1..100
    18:45:09   3  loop
    18:45:09   4        insert into t2(c1,c2) values (i,i+200);
    18:45:09   5  end loop;
    18:45:09   6  commit;
    18:45:09   7  end;
    18:45:09   8  /
    
    18:45:23 rel15_real_p>select count(*) from t1;
    
      COUNT(*)
    ----------
           100
    
    18:45:30 rel15_real_p>select count(*) from t2;
    
      COUNT(*)
    ----------
           100
    
    18:45:49 rel15_real_p>select index_name,index_type from user_indexes where table
    _name='T1';
    
    INDEX_NAME                     INDEX_TYPE
    ------------------------------ ---------------------------
    SYS_C0013059                   NORMAL
    
    18:48:21 rel15_real_p>set autotrace on
    18:52:25 rel15_real_p>Select T1.C2
    18:52:29   2  From T1, T2
    18:52:29   3  where T2.C1 = T1.C1
    18:52:29   4  /
    
            C2
    ----------
           101
           102
           103
           104
           105
      .....
      ......
    
            C2
    ----------
           200
    
    100 rows selected.
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=7 Card=100 Bytes=
              900)
    
       1    0   HASH JOIN (Cost=7 Card=100 Bytes=3900)
       2    1     TABLE ACCESS (FULL) OF 'T1' (TABLE) (Cost=3 Card=100 By
              es=2600)
    
       3    1     TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 By
              es=1300)
    
    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
             21  consistent gets
              0  physical reads
              0  redo size
           1393  bytes sent via SQL*Net to client
            562  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            100  rows processed
    
    18:52:31 rel15_real_p>analyze table t1 compute statistics;
    
    Table analyzed.
    
    18:55:35 rel15_real_p>analyze table t2 compute statistics;
    
    18:55:38 rel15_real_p>set autotrace on
    18:55:42 rel15_real_p>Select T1.C2
    18:55:43   2  From T1, T2
    18:55:45   3  where T2.C1 = T1.C1
    18:55:46   4  /
    
            C2
    ----------
           101
           102
           103
           104
           105
    
      .....
      ......
    
            C2
    ----------
           200
    
    100 rows selected.
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=100 Bytes=7
              00)
    
       1    0   MERGE JOIN (Cost=6 Card=100 Bytes=700)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'T1' (TABLE) (Cost=2 Ca
              rd=100 Bytes=500)
    
       3    2       INDEX (FULL SCAN) OF 'SYS_C0013059' (INDEX (UNIQUE)) (
              Cost=1 Card=100)
    
       4    1     SORT (JOIN) (Cost=4 Card=100 Bytes=200)
       5    4       TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 B
              ytes=200)
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
             23  consistent gets
              0  physical reads
              0  redo size
           1393  bytes sent via SQL*Net to client
            562  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
            100  rows processed
    
    18:56:56 rel15_real_p>Select T1.C2
    18:56:56   2  From T1, T2
    18:56:56   3  where T1.C1 = T2.C1
    18:56:58   4  /
    
            C2
    ----------
           101
           102
           103
           104
           105
    
      .....
      ......
    
            C2
    ----------
           200
    
    100 rows selected.
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=100 Bytes=7
              00)
    
       1    0   MERGE JOIN (Cost=6 Card=100 Bytes=700)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'T1' (TABLE) (Cost=2 Ca
              rd=100 Bytes=500)
    
       3    2       INDEX (FULL SCAN) OF 'SYS_C0013059' (INDEX (UNIQUE)) (
              Cost=1 Card=100)
    
       4    1     SORT (JOIN) (Cost=4 Card=100 Bytes=200)
       5    4       TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 B
              ytes=200)
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
             23  consistent gets
              0  physical reads
              0  redo size
           1393  bytes sent via SQL*Net to client
            562  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
            100  rows processed
    

    -Pavan Kumar N

  • Query Plan changes when a static value is assigned to an update

    I have a table
    SQL> create table test
      2  as
      3  select '001' col
      4    from dual
      5  connect by level <= 15000
      6  /
    
    Table created.
    
    SQL> exec dbms_stats.gather_table_stats('SYSADM','TEST',CASCADE=>TRUE)
    
    PL/SQL procedure successfully completed.
    Now, I want to update the table so that each 5000 lines to be incremented as the value pass
    001.002... and so on.

    I did it.
    SQL> set autotrace traceonly explain
    SQL> set timing on
    SQL> update test t
      2     set col = (select to_char(trunc(rno/5000)+1,'fm009')
      3             from (select row_number() over(order by rowid) rno,
      4                               rowid
      5                     from test) t1
      6             where t.rowid = t1.rowid)
      7  /
    
    15000 rows updated.
    
    Elapsed: 00:03:49.06
    
    Execution Plan
    ----------------------------------------------------------
       0      UPDATE STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=15000 Bytes=60000)
       1    0   UPDATE OF 'TEST'
       2    1     TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=8 Card=15000 Bytes=60000)
       3    1     VIEW (Cost=55 Card=15000 Bytes=375000)
       4    3       WINDOW (SORT) (Cost=55 Card=15000 Bytes=60000)
       5    4         TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=8 Card=15000 Bytes=60000)
    
    SQL> rollback
      2  /
    
    Rollback complete.
    
    Elapsed: 00:00:01.00
    It works very well. But what I discovered is. When I change the update above. And replace the
    TO_CHAR (trunc(RNO/5000) + 1, 'fm009') with a static value as '1' the query plan changes and
    It runs very quickly.
    SQL> update test t
      2     set col = (select '1'--to_char(trunc(rno/5000)+1,'fm009')
      3             from (select row_number() over(order by rowid) rno,
      4                               rowid
      5                     from test) t1
      6             where t.rowid = t1.rowid)
      7  /
    
    15000 rows updated.
    
    Elapsed: 00:00:00.01
    
    
    Execution Plan
    ----------------------------------------------------------
       0      UPDATE STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=15000 Bytes =60000)
       1    0   UPDATE OF 'TEST'
       2    1     TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=8 Card=15000 Bytes=60000)
       3    1     TABLE ACCESS (BY USER ROWID) OF 'TEST' (TABLE) (Cost=1 Card=1 Bytes=4)
    
    SQL> rollback
      2  /
    
    Rollback complete.
    
    Elapsed: 00:00:01.00
    Why is it so. Can someone explain?

    Karthick_Arp wrote:
    SQL > update of test t
    2 set col = (select to_char (trunc(rno/5000) + 1, 'fm009'))
    3 from (select row_number() over (order by rowid) rno,
    4 rowid
    5 test) t1
    6 where t.rowid = t1.rowid)
    7.

    15000 lines to date.

    Execution plan
    ----------------------------------------------------------
    STATEMENT UPDATE 0 = ALL_ROWS optimizer (cost = card 8 = 15000 bytes = 60000)
    1 0 UPDATE OF 'TEST '.
    2 1 TABLE ACCESS (FULL) 'TEST' (TABLE) (cost = card 8 = 15000 bytes = 60000)
    3 1 VIEW (cost = map 55 = 15000 bytes = 375000)
    4 WINDOW 3 (TRI) (cost = map 55 = 15000 bytes = 60000)
    5 4 TABLE ACCESS (FULL) 'TEST' (TABLE) (cost = card 8 = 15000 bytes = 60000)

    SQL > update of test t
    2 set col = (select '1' - to_char (trunc(rno/5000) + 1, 'fm009'))
    3 from (select row_number() over (order by rowid) rno,
    4 rowid
    5 test) t1
    6 where t.rowid = t1.rowid)
    7.

    15000 lines to date.

    Execution plan
    ----------------------------------------------------------
    STATEMENT UPDATE 0 = ALL_ROWS optimizer (cost = card 8 = 15000 bytes = 60000)
    1 0 UPDATE OF 'TEST '.
    2 1 TABLE ACCESS (FULL) 'TEST' (TABLE) (cost = card 8 = 15000 bytes = 60000)
    3 1 ACCESS TABLE (BY USER ROWID) OF 'TEST' (TABLE) (cost = 1 card = 1 bytes = 4)

    Why is it so. Can someone explain?

    In addition to what Rob has already said, the answer to your question is: given that the optimizer is smart and recognizes that your WINDOW TYPE in your second query (aka NWR) is never accessible and therefore simply ignores this part of the application. It turns it to a simple statement like this:

    update test t
       set col = (select '1'
               from (select rowid
                       from test) t1
               where t.rowid = t1.rowid);
    

    who can simply access the TEST table for each row of rowid, while your first query should do recursively for each TEST line full table scan. Using a statistics AUTOTRACE, you should see a large difference in e/s logic for both statements.

    Using DBMS_XPLAN. DISPLAY could reveal more details what happens, if you're already on 9i or later version (seems to be 9iR2).

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • Split string with regular model and expression(10g)

    Hello world

    Could I ask you, your opinion on this query (tuning)?


    SQL * more: version 10.1.0.4.2 - Production on Tue October 21 10:40:07 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.


    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64 bit Production
    With partitioning, OLAP and Data Mining options


    SQL > select * from test_1;

    NR X
    ---------- -----------------------------------------------------------------------------------------
    1 F01
    2 F02
    3 D01:D02
    4 F03:G45:D34
    5 G56:Y45:U89:E56


    SQL > SELECT NR, STRING
    2 FROM TEST_1
    MODEL 3
    4 RETURN THE UPDATED LINES
    5 PARTITION BY (NR)
    6 DIMENSION (POSITION 0)
    MEASURES 7 (CAST (' ' AS VARCHAR2 (50)) AS STRING, X, LENGTH (REGEXP_REPLACE (X,'[^:] + ",")) + 1 NB_MOT)
    8 RULES
    9 (STRING [FOR POSITION 1 TO INCREMENT 1 NVL(NB_MOT[0],1)] =
    10 CASES WHERE NB_MOT [0] IS NULL THEN X [0] ELSE REGEXP_SUBSTR (X [0], "[^:] +', 1, CV (POSITION)") END)
    11 ORDER BY 1;

    STRING OF NR
    ---------- --------------------------------------------------
    1 F01
    2 F02
    3 D01
    3 D02
    4 G45
    4 F03
    4 D34
    5 G56
    5 Y45
    U89 5
    5 E56

    11 row (s) selected (s).


    Execution plan
    ----------------------------------------------------------
    0 SELECT STATEMENT Optimizer = ALL_ROWS (cost = 5 card = 5 bytes = 325
    )

    1 0 SORTING (ORDER BY) (cost = 5 card = 5 bytes = 325)
    2 1 MODEL (ORDERED) SQL (cost = 5 card = 5 bytes = 325)
    3 2 TABLE ACCESS (FULL) 'TEST_1' (TABLE) (cost = 4 = 5 bytes map = 325)



    Kind regards
    Salim.

    Why?

    How long takes now?

    Can you explain?

    Kind regards.

    LOULOU.

Maybe you are looking for

  • Why is the text of different sizes?

    Hello The text with this browser shows different sizes of text on a web page? Some is normal, then some is tiny. I you pinch the page upward to read the small text, normal text is very large. It ruins the reading a web page. Why this happens, and can

  • Windows 7 is not recognized on my laptop satellite

    My windows 7 is no longer recognized by my laptop and the button at the bottom of my laptop has been rubbed by far. Is it possible to fix this or am I required to pay for a new key?

  • HP Deskjet F2200: Brown printed in purple!

    Due to the almost empty cartridge, I installed 2 brand new ink cartridges (black [21] and tri-color [22]). Do you have the necessary alignment by following the instructions. However, when printing, and whenever the intended color is Brown, it was in

  • Windows Media Center has suddenly stopped working...

    I hope someone here can help me with this little mystery. Also recently 2 days ago everything worked fine on my Vista Home Premium machine. Today, I noticed that my TV shows that I put to record have not been recorded. I went to Windows Media Center

  • installation of Windows 8 for officejet 4620. software available?

    The software available on the hp site does not install with windows 8. All solutions?