Same SQL different execution Plans in two different database instances.

Hi all

I run a different query on two instances of database. On one instance, the query takes 30 minutes and the other it takes 10 hours to complete. Data on the two instances are the same. When I generated the execution plan, on the two cases, it was different.

OS: Redhat Linux 5
Database version: 11.2.02 (on two instances)

Plan on 1 Instance that takes 30 minutes.
SELECT 
     X_REPLEN_RQST_INV_STG.BUSINESS_UNIT, 
     NVL(SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, 
     INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', -1, 1) - LENGTH(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM)),'N/A') AS DOC_ID, 
     W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_ITEM, 
     W_PURCH_SCHEDULE_LINE_F.PURCH_SCHEDULE_NUM, 
     X_REPLEN_RQST_INV_STG.INV_ITEM_ID, 
     X_REPLEN_RQST_INV_STG.PROCESS_DATE AS REPLEN_PROCESS_DT, 
     X_REPLEN_RQST_INV_STG.EXPECTED_DATE AS REPLEN_EXPECTED_DT, 
     X_REPLEN_RQST_INV_STG.REORDER_QTY AS REPLEN_REORDER_QTY, 
     X_ITEM_ATTRIB_D.REPLENISH_CLASS AS REPLEN_CLASS, 
     X_REPLEN_RQST_INV_STG.REPLEN_STATUS, 
     X_REPLEN_RQST_INV_STG.REPLENISH_TYPE AS REPLEN_TYPE, 
     X_REPLEN_RQST_INV_STG.REQ_ID, 
     X_REPLEN_RQST_INV_STG.REQ_LINE_NBR, 
     X_REPLEN_RQST_INV_STG.REQ_SCHED_NBR, 
     X_REPLEN_RQST_INV_STG.REQ_DISTRIB_NBR, 
     P.FIRST_PO_DISP_DT, 
     W_PURCH_SCHEDULE_LINE_F.DATASOURCE_NUM_ID
FROM 
     X_REPLEN_RQST_INV_STG LEFT OUTER JOIN W_RQSTN_LINE_COST_F 
               ON X_REPLEN_RQST_INV_STG.RQSTN_LN_COST_INTG_ID = W_RQSTN_LINE_COST_F.INTEGRATION_ID 
                    AND X_REPLEN_RQST_INV_STG.DATASOURCE_NUM_ID = W_RQSTN_LINE_COST_F.DATASOURCE_NUM_ID 
     LEFT OUTER JOIN W_PURCH_COST_F 
               ON W_RQSTN_LINE_COST_F.INTEGRATION_ID = W_PURCH_COST_F.REQ_DISTR_INTG_ID 
                    AND W_RQSTN_LINE_COST_F.DATASOURCE_NUM_ID = W_PURCH_COST_F.DATASOURCE_NUM_ID 
     INNER join W_PURCH_SCHEDULE_LINE_F 
               ON W_PURCH_COST_F.PURCH_SCHEDULE_INTG_ID = W_PURCH_SCHEDULE_LINE_F.INTEGRATION_ID 
                    AND W_PURCH_COST_F.DATASOURCE_NUM_ID = W_PURCH_SCHEDULE_LINE_F.DATASOURCE_NUM_ID 
     LEFT OUTER JOIN W_STATUS_D S1 
               ON W_RQSTN_LINE_COST_F.APPROVAL_STATUS_WID = S1.ROW_WID 
                    AND W_RQSTN_LINE_COST_F.DATASOURCE_NUM_ID = S1.DATASOURCE_NUM_ID 
                    AND 'PURCH_APPROVE' = S1.W_STATUS_CLASS 
     LEFT OUTER JOIN W_STATUS_D S2 
               ON W_PURCH_COST_F.APPROVAL_STATUS_WID = S2.ROW_WID 
                    AND W_PURCH_COST_F.DATASOURCE_NUM_ID = S2.DATASOURCE_NUM_ID 
                    AND 'PURCH_APPROVE' = S2.W_STATUS_CLASS 
     LEFT OUTER JOIN (SELECT p1.BUSINESS_UNIT, p1.PO_ID, MIN(p1.DATETIME_DISP) AS FIRST_PO_DISP_DT
FROM 
          X_PS_PO_DISPATCHED p1 GROUP BY p1.BUSINESS_UNIT, p1.PO_ID) P 
               ON SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, 1, INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', 1, 1)-1) = P.BUSINESS_UNIT 
                    AND SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', -1, 1) - LENGTH(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM)) = 

P.PO_ID      
     LEFT OUTER JOIN W_PRODUCT_D 
               ON W_PURCH_SCHEDULE_LINE_F.PRODUCT_WID = W_PRODUCT_D.ROW_WID 
     LEFT OUTER JOIN X_ITEM_ATTRIB_D 
               ON SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, 1, INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', 1, 1)-1) = X_ITEM_ATTRIB_D.BUSINESS_UNIT 
                    AND W_PRODUCT_D.PART_NUM = X_ITEM_ATTRIB_D.INV_ITEM_ID
WHERE 
     TRIM(X_REPLEN_RQST_INV_STG.req_id) IS NOT NULL 
     AND X_REPLEN_RQST_INV_STG.replenish_type = '1' 
     AND X_REPLEN_RQST_INV_STG.replen_status = '4' 
     AND X_ITEM_ATTRIB_D.REPLENISH_CLASS = 'A' 
     AND S1.STATUS_CODE != 'X' 
     AND S2.STATUS_CODE != 'X' 
     AND P.FIRST_PO_DISP_DT IS NOT NULL

Execution Plan
----------------------------------------------------------
Plan hash value: 1674299164

----------------------------------------------------------------------------------------------------------------
| Id  | Operation                            | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                     |                         |     1 |   461 | 13942   (1)| 00:04:11 |
|*  1 |  HASH JOIN                           |                         |     1 |   461 | 13942   (1)| 00:04:11 |
|   2 |   NESTED LOOPS                       |                         |       |       |            |          |
|   3 |    NESTED LOOPS                      |                         |     1 |   441 | 10409   (1)| 00:03:08 |
|   4 |     NESTED LOOPS                     |                         |     1 |   421 | 10407   (1)| 00:03:08 |
|   5 |      NESTED LOOPS                    |                         |     1 |   388 | 10406   (1)| 00:03:08 |
|   6 |       NESTED LOOPS                   |                         |     1 |   319 | 10405   (1)| 00:03:08 |
|   7 |        NESTED LOOPS                  |                         |     1 |   280 | 10404   (1)| 00:03:08 |
|*  8 |         HASH JOIN                    |                         |     1 |   220 | 10401   (1)| 00:03:08 |
|   9 |          NESTED LOOPS                |                         |       |       |            |          |
|  10 |           NESTED LOOPS               |                         |    16 |  2896 | 10392   (1)| 00:03:08 |
|* 11 |            TABLE ACCESS FULL         | X_REPLEN_RQST_INV_STG   |    16 |  2432 | 10375   (1)| 00:03:07 |
|* 12 |            INDEX UNIQUE SCAN         | W_RQST_LN_CS_F_U1       |     1 |       |     1   (0)| 00:00:01 |
|  13 |           TABLE ACCESS BY INDEX ROWID| W_RQSTN_LINE_COST_F     |     1 |    29 |     2   (0)| 00:00:01 |
|* 14 |          TABLE ACCESS FULL           | W_STATUS_D              |     1 |    39 |     8   (0)| 00:00:01 |
|  15 |         TABLE ACCESS BY INDEX ROWID  | W_PURCH_COST_F          |     1 |    60 |     3   (0)| 00:00:01 |
|* 16 |          INDEX RANGE SCAN            | W_PURCH_COST_F_M1       |     1 |       |     2   (0)| 00:00:01 |
|* 17 |        TABLE ACCESS BY INDEX ROWID   | W_STATUS_D              |     1 |    39 |     1   (0)| 00:00:01 |
|* 18 |         INDEX UNIQUE SCAN            | W_STATUS_D_P1           |     1 |       |     0   (0)| 00:00:01 |
|  19 |       TABLE ACCESS BY INDEX ROWID    | W_PURCH_SCHEDULE_LINE_F |     1 |    69 |     1   (0)| 00:00:01 |
|* 20 |        INDEX UNIQUE SCAN             | W_PRCH_SC_LN_F_U1       |     1 |       |     1   (0)| 00:00:01 |
|  21 |      TABLE ACCESS BY INDEX ROWID     | W_PRODUCT_D             |     1 |    33 |     1   (0)| 00:00:01 |
|* 22 |       INDEX UNIQUE SCAN              | W_PRODUCT_D_P1          |     1 |       |     0   (0)| 00:00:01 |
|* 23 |     INDEX RANGE SCAN                 | X_ITEM_ATTRIB_U01       |     1 |       |     1   (0)| 00:00:01 |
|* 24 |    TABLE ACCESS BY INDEX ROWID       | X_ITEM_ATTRIB_D         |     1 |    20 |     2   (0)| 00:00:01 |
|  25 |   VIEW                               |                         |  1428K|    27M|  3529   (2)| 00:01:04 |
|* 26 |    FILTER                            |                         |       |       |            |          |
|  27 |     HASH GROUP BY                    |                         |  1428K|    27M|  3529   (2)| 00:01:04 |
|  28 |      TABLE ACCESS FULL               | X_PS_PO_DISPATCHED      |  1428K|    27M|  3493   (1)| 00:01:03 |
----------------------------------------------------------------------------------------------------------------
On the Instance 2
SELECT 
     X_REPLEN_RQST_INV_STG.BUSINESS_UNIT, 
     NVL(SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, 
     INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', -1, 1) - LENGTH(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM)),'N/A') AS DOC_ID, 
     W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_ITEM, 
     W_PURCH_SCHEDULE_LINE_F.PURCH_SCHEDULE_NUM, 
     X_REPLEN_RQST_INV_STG.INV_ITEM_ID, 
     X_REPLEN_RQST_INV_STG.PROCESS_DATE AS REPLEN_PROCESS_DT, 
     X_REPLEN_RQST_INV_STG.EXPECTED_DATE AS REPLEN_EXPECTED_DT, 
     X_REPLEN_RQST_INV_STG.REORDER_QTY AS REPLEN_REORDER_QTY, 
     X_ITEM_ATTRIB_D.REPLENISH_CLASS AS REPLEN_CLASS, 
     X_REPLEN_RQST_INV_STG.REPLEN_STATUS, 
     X_REPLEN_RQST_INV_STG.REPLENISH_TYPE AS REPLEN_TYPE, 
     X_REPLEN_RQST_INV_STG.REQ_ID, 
     X_REPLEN_RQST_INV_STG.REQ_LINE_NBR, 
     X_REPLEN_RQST_INV_STG.REQ_SCHED_NBR, 
     X_REPLEN_RQST_INV_STG.REQ_DISTRIB_NBR, 
     P.FIRST_PO_DISP_DT, 
     W_PURCH_SCHEDULE_LINE_F.DATASOURCE_NUM_ID
FROM 
     X_REPLEN_RQST_INV_STG LEFT OUTER JOIN W_RQSTN_LINE_COST_F 
               ON X_REPLEN_RQST_INV_STG.RQSTN_LN_COST_INTG_ID = W_RQSTN_LINE_COST_F.INTEGRATION_ID 
                    AND X_REPLEN_RQST_INV_STG.DATASOURCE_NUM_ID = W_RQSTN_LINE_COST_F.DATASOURCE_NUM_ID 
     LEFT OUTER JOIN W_PURCH_COST_F 
               ON W_RQSTN_LINE_COST_F.INTEGRATION_ID = W_PURCH_COST_F.REQ_DISTR_INTG_ID 
                    AND W_RQSTN_LINE_COST_F.DATASOURCE_NUM_ID = W_PURCH_COST_F.DATASOURCE_NUM_ID 
     INNER join W_PURCH_SCHEDULE_LINE_F 
               ON W_PURCH_COST_F.PURCH_SCHEDULE_INTG_ID = W_PURCH_SCHEDULE_LINE_F.INTEGRATION_ID 
                    AND W_PURCH_COST_F.DATASOURCE_NUM_ID = W_PURCH_SCHEDULE_LINE_F.DATASOURCE_NUM_ID 
     LEFT OUTER JOIN W_STATUS_D S1 
               ON W_RQSTN_LINE_COST_F.APPROVAL_STATUS_WID = S1.ROW_WID 
                    AND W_RQSTN_LINE_COST_F.DATASOURCE_NUM_ID = S1.DATASOURCE_NUM_ID 
                    AND 'PURCH_APPROVE' = S1.W_STATUS_CLASS 
     LEFT OUTER JOIN W_STATUS_D S2 
               ON W_PURCH_COST_F.APPROVAL_STATUS_WID = S2.ROW_WID 
                    AND W_PURCH_COST_F.DATASOURCE_NUM_ID = S2.DATASOURCE_NUM_ID 
                    AND 'PURCH_APPROVE' = S2.W_STATUS_CLASS 
     LEFT OUTER JOIN (SELECT p1.BUSINESS_UNIT, p1.PO_ID, MIN(p1.DATETIME_DISP) AS FIRST_PO_DISP_DT
FROM 
          X_PS_PO_DISPATCHED p1 GROUP BY p1.BUSINESS_UNIT, p1.PO_ID) P 
               ON SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, 1, INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', 1, 1)-1) = P.BUSINESS_UNIT 
                    AND SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', -1, 1) - LENGTH(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM)) = 

P.PO_ID      
     LEFT OUTER JOIN W_PRODUCT_D 
               ON W_PURCH_SCHEDULE_LINE_F.PRODUCT_WID = W_PRODUCT_D.ROW_WID 
     LEFT OUTER JOIN X_ITEM_ATTRIB_D 
               ON SUBSTR (W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, 1, INSTR(W_PURCH_SCHEDULE_LINE_F.PURCH_ORDER_NUM, '~', 1, 1)-1) = X_ITEM_ATTRIB_D.BUSINESS_UNIT 
                    AND W_PRODUCT_D.PART_NUM = X_ITEM_ATTRIB_D.INV_ITEM_ID
WHERE 
     TRIM(X_REPLEN_RQST_INV_STG.req_id) IS NOT NULL 
     AND X_REPLEN_RQST_INV_STG.replenish_type = '1' 
     AND X_REPLEN_RQST_INV_STG.replen_status = '4' 
     AND X_ITEM_ATTRIB_D.REPLENISH_CLASS = 'A' 
     AND S1.STATUS_CODE != 'X' 
     AND S2.STATUS_CODE != 'X' 
     AND P.FIRST_PO_DISP_DT IS NOT NULL


---------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                         |     1 |   420 | 19630   (1)| 00:04:35 |
|   1 |  NESTED LOOPS                       |                         |       |       |            |       |
|   2 |   NESTED LOOPS                      |                         |     1 |   420 | 19630   (1)| 00:04:35 |
|   3 |    NESTED LOOPS                     |                         |     1 |   400 | 19627   (1)| 00:04:35 |
|   4 |     NESTED LOOPS                    |                         |     1 |   386 | 19626   (1)| 00:04:35 |
|   5 |      NESTED LOOPS                   |                         |     1 |   317 | 19625   (1)| 00:04:35 |
|   6 |       NESTED LOOPS                  |                         |     1 |   289 | 19624   (1)| 00:04:35 |
|   7 |        NESTED LOOPS                 |                         |     1 |   229 | 19621   (1)| 00:04:35 |
|   8 |         NESTED LOOPS                |                         |     1 |   201 | 19620   (1)| 00:04:35 |
|   9 |          MERGE JOIN CARTESIAN       |                         |     1 |   172 | 19619   (1)| 00:04:35 |
|  10 |           VIEW                      |                         |     1 |    20 |  4942   (2)| 00:01:10 |
|* 11 |            FILTER                   |                         |       |       |            |       |
|  12 |             HASH GROUP BY           |                         |     1 |    20 |  4942   (2)| 00:01:10 |
|  13 |              TABLE ACCESS FULL      | X_PS_PO_DISPATCHED      |  1428K|    27M|  4902   (1)| 00:01:09 |
|  14 |           BUFFER SORT               |                         |     1 |   152 | 19619   (1)| 00:04:35 |
|* 15 |            TABLE ACCESS FULL        | X_REPLEN_RQST_INV_STG   |     1 |   152 | 14676   (1)| 00:03:26 |
|  16 |          TABLE ACCESS BY INDEX ROWID| W_RQSTN_LINE_COST_F     |     1 |    29 |     1   (0)| 00:00:01 |
|* 17 |           INDEX UNIQUE SCAN         | W_RQST_LN_CS_F_U1       |     1 |       |     1   (0)| 00:00:01 |
|* 18 |         TABLE ACCESS BY INDEX ROWID | W_STATUS_D              |     1 |    28 |     1   (0)| 00:00:01 |
|* 19 |          INDEX UNIQUE SCAN          | W_STATUS_D_P1           |     1 |       |     0   (0)| 00:00:01 |
|  20 |        TABLE ACCESS BY INDEX ROWID  | W_PURCH_COST_F          |     3 |   180 |     3   (0)| 00:00:01 |
|* 21 |         INDEX RANGE SCAN            | W_PURCH_COST_F_M1       |     1 |       |     2   (0)| 00:00:01 |
|* 22 |       TABLE ACCESS BY INDEX ROWID   | W_STATUS_D              |     1 |    28 |     1   (0)| 00:00:01 |
|* 23 |        INDEX UNIQUE SCAN            | W_STATUS_D_P1           |     1 |       |     0   (0)| 00:00:01 |
|* 24 |      TABLE ACCESS BY INDEX ROWID    | W_PURCH_SCHEDULE_LINE_F |     1 |    69 |     1   (0)| 00:00:01 |
|* 25 |       INDEX UNIQUE SCAN             | W_PRCH_SC_LN_F_U1       |     1 |       |     1   (0)| 00:00:01 |
|* 26 |     TABLE ACCESS BY INDEX ROWID     | W_PRODUCT_D             |     1 |    14 |     1   (0)| 00:00:01 |
|* 27 |      INDEX UNIQUE SCAN              | W_PRODUCT_D_P1          |     1 |       |     0   (0)| 00:00:01 |
|* 28 |    INDEX RANGE SCAN                 | X_ITEM_ATTRIB_U01       |     1 |       |     2   (0)| 00:00:01 |
|* 29 |   TABLE ACCESS BY INDEX ROWID       | X_ITEM_ATTRIB_D         |     1 |    20 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------
In the second execution plan, we can see that it uses a Cartesian product.

Thank you.

Oceaner wrote:
Hi all

I run a different query on two instances of database. On one instance, the query takes 30 minutes and the other it takes 10 hours to complete. Data on the two instances are the same. When I generated the execution plan, on the two cases, it was different.

The most obvious difference is the subquery total inline:

Quick plan:

----------------------------------------------------------------------------------------------------------------
| Id  | Operation                            | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------------------------
|*  1 |  HASH JOIN                           |                         |     1 |   461 | 13942   (1)| 00:04:11 |
|   2 |   NESTED LOOPS                       |                         |       |       |            |          |
...
|  25 |   VIEW                               |                         |  1428K|    27M|  3529   (2)| 00:01:04 |
|* 26 |    FILTER                            |                         |       |       |            |          |
|  27 |     HASH GROUP BY                    |                         |  1428K|    27M|  3529   (2)| 00:01:04 |
|  28 |      TABLE ACCESS FULL               | X_PS_PO_DISPATCHED      |  1428K|    27M|  3493   (1)| 00:01:03 |
----------------------------------------------------------------------------------------------------------------

Plan of slow

---------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------------------
...
|   9 |          MERGE JOIN CARTESIAN       |                         |     1 |   172 | 19619   (1)| 00:04:35 |
|  10 |           VIEW                      |                         |     1 |    20 |  4942   (2)| 00:01:10 |
|* 11 |            FILTER                   |                         |       |       |            |          |
|  12 |             HASH GROUP BY           |                         |     1 |    20 |  4942   (2)| 00:01:10 |
|  13 |              TABLE ACCESS FULL      | X_PS_PO_DISPATCHED      |  1428K|    27M|  4902   (1)| 00:01:09 |
|  14 |           BUFFER SORT               |                         |     1 |   152 | 19619   (1)| 00:04:35 |
|* 15 |            TABLE ACCESS FULL        | X_REPLEN_RQST_INV_STG   |     1 |   152 | 14676   (1)| 00:03:26 |
...
---------------------------------------------------------------------------------------------------------------

Note the value of lines given to the operation - VIEW


One for the slow plan - that of why Oracle chose display online as a starting point for the query and used a Cartesian merge join to join to the table nearby.

1.4Million for the fast plan - this is why Oracle has decided to visit the table set and use it as the table of the probe in a hash join.

I think we can assume that the estimation of the single line is a big mistake. We can also assume that the two series of statistics (or possibly index definitions) on the tables two versions do not match.

It would be useful, of course, see the comprehensive implementation plan, and preferably one from memory: (http://jonathanlewis.wordpress.com/2006/12/22/dbms_xplan-again/).

You might notice that you outer joins are not relevant - maybe this SQL is a framework for a more general query - given that the plan shows that they have all been turned away.

Concerning
Jonathan Lewis
http://jonathanlewis.WordPress.com
Author: core Oracle

Tags: Database

Similar Questions

  • To connect two different database instance, what configuration in web cleint is necessary?


    Hi all

    We had two P6 database instance as a DEV and PROD

    We want to configure the web client so that the user can select either DEV or PROD according to the requirement by the same URL.

    Can you please tell me what I need to do in the web to work with two DB instance client?

    Normally, changes are reflected without bouncing the middle tier (weblogic Server). If t is not then rebound / restart the server managed by admin / when P6 application is deployed.

    Kind regards

    Sachin Gupta

  • Error after migrating APEX app to a different database instance

    Oracle EE 11 GR 2

    APEX 4.2.x

    ------------------------

    After the migration of an APEX application and underlying database objects into a new database, I get the following error (blackened my name of component specific to the application and the id for security reasons):

    APEX_ERROR.PNG

    In APEX, this error occurs when you try to run the application after logging in the workspace of the application.

    A specific to APEX table might be damaged or not migrated as it should have?  No tables starting with APEX were imported.

    No, these can be customized (self defined) so it's to the application developer.

    If you go to the request of the manufacturer and open the application and go to "shared components", then the "authorisation schemes' and open the schema with the name mentioned in your error message (behind" component name: ') you should see the authorization code that fails somehow. Search for the tables and the data mentioned in this piece of code.

  • Need help to get the actual execution plan

    I need to get the actual execution plan of a query and its actual cost.
    If I understand correctly explaining the plan gives only the estimated according to my plan. Can someone help me please?

    I'm doing this:

    SQL> select OBJECT_NAME,DATA_OBJECT_ID,STATUS from dba_objects where owner='SANTU';
    
    OBJECT_NAME
                                                     DATA_OBJECT_ID STATUS
    --------------------------------------------------------------------------------
    ------------------------------------------------ -------------- -------
    TST_REDEF
                                                              73444 VALID
    REDEF_PK
                                                              73447 VALID
    
    SQL> select sql_id,sql_text from v$sqlarea where sql_text like '%DATA_OBJECT_ID,STATUS from dba_objects%';
    
    SQL_ID
    -------------
    SQL_TEXT
    --------------------------------------------------------------------------------
    gbvnfhs59t98f
    select sql_id,sql_text from v$sqlarea where sql_text like '%DATA_OBJECT_ID,STATUS from dba_objects%'
    
    bxdyf6ph2g3ay
    select OBJECT_NAME,DATA_OBJECT_ID,STATUS from dba_objects where owner='SANTU'
    
    SQL> select * from table(dbms_xplan.display_cursor('bxdyf6ph2g3ay'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    SQL_ID  bxdyf6ph2g3ay, child number 0
    -------------------------------------
    select OBJECT_NAME,DATA_OBJECT_ID,STATUS from dba_objects where
    owner='SANTU'
    
    Plan hash value: 2160718650
    
    ------------------------------------------------------------------------------------------------
    | Id  | Operation                        | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                 |             |       |       |    47 (100)|          |
    |   1 |  VIEW                            | DBA_OBJECTS |  1638 |   161K|    47 (3)| 00:00:01 |
    |   2 |   UNION-ALL                      |             |       |       |    |          |
    |*  3 |    FILTER                        |             |       |       |    |          |
    |*  4 |     HASH JOIN                    |             |  1830 |   209K|    46 (3)| 00:00:01 |
    |   5 |      INDEX FULL SCAN             | I_USER2     |    88 |  1936 |     1 (0)| 00:00:01 |
    |   6 |      NESTED LOOPS                |             |  1830 |   169K|    45 (3)| 00:00:01 |
    |   7 |       TABLE ACCESS BY INDEX ROWID| USER$       |     1 |    18 |     1 (0)| 00:00:01 |
    |*  8 |        INDEX UNIQUE SCAN         | I_USER1     |     1 |       |     0 (0)|          |
    |*  9 |       TABLE ACCESS FULL          | OBJ$        |  1830 |   137K|    44 (3)| 00:00:01 |
    |* 10 |     TABLE ACCESS BY INDEX ROWID  | IND$        |     1 |     8 |     2 (0)| 00:00:01 |
    |* 11 |      INDEX UNIQUE SCAN           | I_IND1      |     1 |       |     1 (0)| 00:00:01 |
    |  12 |     NESTED LOOPS                 |             |     1 |    29 |     2 (0)| 00:00:01 |
    |* 13 |      INDEX FULL SCAN             | I_USER2     |     1 |    20 |     1 (0)| 00:00:01 |
    |* 14 |      INDEX RANGE SCAN            | I_OBJ4      |     1 |     9 |     1 (0)| 00:00:01 |
    |  15 |    NESTED LOOPS                  |             |     1 |    97 |     1 (0)| 00:00:01 |
    |  16 |     TABLE ACCESS BY INDEX ROWID  | USER$       |     1 |    18 |     1 (0)| 00:00:01 |
    |* 17 |      INDEX UNIQUE SCAN           | I_USER1     |     1 |       |     0 (0)|          |
    |* 18 |     INDEX RANGE SCAN             | I_LINK1     |     1 |    79 |     0 (0)|          |
    ------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(((("O"."TYPE#"<>1 AND "O"."TYPE#"<>10) OR ("O"."TYPE#"=1 AND =1))
    AND
                  (("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND
                  "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND
                  "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND "O"."TYPE#"<>87 AND
                  "O"."TYPE#"<>88) OR BITAND("U"."SPARE1",16)=0 OR (INTERNAL_FUNCTION("O"."TYPE#") AND
                  ((SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR
                  ("U"."TYPE#"=2 AND "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
                  OR  IS NOT NULL)))))
       4 - access("O"."OWNER#"="U"."USER#")
       8 - access("U"."NAME"='SANTU')
       9 - filter(("O"."NAME"<>'_NEXT_OBJECT' AND "O"."NAME"<>'_default_auditing_opt
    ions_'
                  AND "O"."LINKNAME" IS NULL AND BITAND("O"."FLAGS",128)=0 AND "O"."
    SPARE3"="U"."USER#"))
      10 - filter(("I"."TYPE#"=1 OR "I"."TYPE#"=2 OR "I"."TYPE#"=3 OR "I"."TYPE#"=4
    OR
                  "I"."TYPE#"=6 OR "I"."TYPE#"=7 OR "I"."TYPE#"=9))
      11 - access("I"."OBJ#"=:B1)
      13 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','
    current_
                  edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv',
    'current
                  _edition_id'))))
      14 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."US
    ER#")
      17 - access("U"."NAME"='SANTU')
      18 - access("L"."OWNER#"="U"."USER#")
    
    57 rows selected.
    
    SQL>
    

    Execution plans

    Kind regards
    S.K.

  • Why I have two different execution plans for the same query on two different servers

    Hello everyone.

    I need your help to solve the problem quickly.

    In a nutshell, we have two servers that have the same version of Oracle RDBMS (11.2.0.4 EE). One of them for purposes of development and another is a production one.

    We have therefore two different execution plans for the same query executed on both servers. The only case of execution is OK and another is too slow.

    So I have to slow down the work of query using the same scheme to explain that young.

    Fence wire.

  • Version 12: Same SQL, another scheme == &gt; different execution plan?

    I'm testing a huge application with a database middleware sophisticated against the Oracle 12 database. So far, it works well with Pervasive SQL, MSSQL and Oracle 8 database... 11.

    There are many questions about execution plans changed from Version 11 to 12. Oracle will tell what all of the improvements are (or at least have to improvements), and I can't really denied him. It's not the subject.

    But I met some SQLs with horrible execution time, especially connected to Crystal Reports. Whenever I tried to check them, the queries have been executed quickly. As far as I can see, this has to do with the schema/user who executes the SQL statement in a first time. Here are the details:

    = ADMIN, DML = GUI DDL: all data are stored in a scheme of the ADMIN. The ADMIN user creates the tables, views and so on. It grants access to and creates synonyms for users, but it cannot modify the data using DML, given that triggers prevent him. End users, named 'GUI' users, are allowed to use the DML, but they have no privileges DDL.

    • Database of reports (on paper) are generally quite complex. They have only a limited data set (must fit on sheets of paper!), and the Oracle optimizer optimizes often against this goal. Because Crystal Reports generates no advice, most of the reports are based on a view ADMIN. < xyz > (with the necessary information) and are accessible via a GUI. < xyz > synonym of user GUI.

    • Crystal Reports running slowly (~ 5 minutes) connected as a GUI. I export it, get the SQL export, log in as an ADMINISTRATORand run the query, it works quickly (~ 2 seconds). Well, I've probably changed some white space, the line endings and others then copy / paste, I don't?

    • I tried many things, connecting both GUI and ADMIN, simplifying the application, execution and so on. Then I got confused version of who this query: when the ADMIN has added an additional space character it was fast, removed again and it was slow again. Whitespace have an influence on the execution plan? Probably not, and if yes, my vision of the world would collapse.

    • Later, I found out: in Version 12, depends on the user executing this query. Nail down us the source of the query for the synonym GUI. < xyz >. Let us make a new version of it (coded by white space - smile), and if run you it like GUI first, it's slow. Even if you re - log on as ADMINISTRATOR, the same version of this query is still slow. (This is a bug!)

    Question 1: When I prepend the SQL with 'EXPLAIN PLAN FOR', I seem to be changing. As GUI has no plan_table and no privilege to explain a plan, I can't spy on the implementation plan of 'bad '. I don't want to give too much GUI, and I fear it could alter the execution plan. Is there a trick to get the plan of execution of a SQL statement in v$ sql or v$ sqlarea? (Means: execute the query: GUI and explain it as an ADMINISTRATOR)

    Question 2: Is this on the privileges of the GUI? What you think, what direction will further investigate?

    Oracle database generates an execution plan based on SQL, the dictionary, the statistics, the privileges of the user of the analysis and database and session settings. One of the privileges is GRANT MERGE [ALL] DISPLAY, which was responsible for the difference in this particular example and in this particular version.

    When you log on as another user and run the same code in SQL, Oracle database verifies all required components before she reuses the old execution plan. This is a minor bug, but it is.

    In the example, the privilege GRANT MERGE ANY NOTICE was given implicitly by the DBA privilege. Because MERGE ANY VIEW disables security controls, the privilege of s/n, default, also disables security controls. This is not a desired behavior from the DBA privilege.

  • Cost of the execution plan is different in the two databases

    Hi gurus,

    I have two databases, which are 12 C.

    The execution plan cost is different in the two databases for the same query.

    is it possible to copy the execution to another plan.

    Thank you in advance

    Kind regards

    REDA

    Jr.Raj wrote:

    There are a few differences.

    The machine that has a high cost, has setup up, linux, 2-node RAC, more CPU.

    and

    other machine windows server less Setup and less cpus.

    Please explain, cost really makes a difference.

    Thank you & best regards

    REDA

    You simply can't compare costs like that. It does not work like that. Especially through two different systems.  Here is a very good read: column the COST of the PLAN to EXPLAIN. Oracle FAQ

  • Different plan for the same sql id

    Hello

    Our team of application reported recently that a query ran longer than usual.

    Search in tables AWR (dba_hist_active_sess_history & dba_hist_sqlstat), it was a change of plan_hash_value. The next day, without intervention from anyone (collect statistics did not run, no change in the tables involved) the sql used the former plan and completed quickly.

    The differences in the plan was the index that was used to access the table.

    What could be the reason for the optimizer to choose a bad plan and return once more the good thing. ?

    The code sql that has been run twice & three in one day and then it years off cursor cache.

    Regime shifts are normal.

    Flipfloppping plans are quite normal.

    I'd be willing to bet that a large percentage of your SQL shows variations in implementation plans and you never notice.

    And there are several reasons why you might get a different plan.

    1 bind variable peeking - it is normal SQL for the age from the cache and then get analyzed once again with different bind variable leading to different cardinality estimates and plans

    2. the statistics change - it is normal that the statistics of change over time causing different cardinality estimates and the various plans, especially if the histograms are involved and changing buckets

    3. data change - especially if you use dynamic sampling it is normal to get a different sample of data leading to different cardinality estimates and plans

    4 SYSDATE - it's normal for queries with SYSDATE in them to recognize that time is never on leave and which, in conjunction with statistics or data, can lead to different cardinality estimates and plans

    5. integrated optimization features - it's normal for features like ACS to kick in and notice that they got forecasts wrong in an execution plan and force the recalculation to a different plan with an adjusted cardinality.

    Using DBMS_XPLAN. DISPLAY_CURSOR or DISPLAY_AWR you can get different plans (provided that they are in memory or AWR). The notes section should indicate cardinality comments have been a factor. You can also get links peeked with format mask of "+ PEEKED_BINDS".

  • Execution of the SQL query through 2 different databases to Oracle

    Hi all

    In Microsoft SQL server, we can run on 2 different databases depending on the type of SQL query:

    Select * from TEST1.dbo.GENERIC_TABLE1 union select * from TEST2.dbo.GENERIC_TABLE2;

    Test1 and TEST2 here is 2 different databases.

    Can we do the same in Oracle?

    Of course you can do it.
    Create a [database join | http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_5005.htm] from DB1 to DB2.

    Grant select on the tables of the DB2 schema with which you want to connect.

    And then, you can you can query as

    select * from DB1schema.emp
    union
    select * from emp@dblink_name;
    
  • Plans of multiple executions for the same SQL statement

    Dear experts,

    awrsqrpt. SQL shows several plans for a single SQL statement executions. How is it possible that a single SQL statement will be several Plans of executions within the AWR report.

    Here is the output of the awrsqrpt for your reference.

    WORKLOAD REPOSITORY SQL Report
    
    Snapshot Period Summary
    
    DB Name         DB Id    Instance     Inst Num Release     RAC Host
    ------------ ----------- ------------ -------- ----------- --- ------------
    TESTDB          2157605839 TESTDB1               1 10.2.0.3.0  YES testhost1
    
                  Snap Id      Snap Time      Sessions Curs/Sess
                --------- ------------------- -------- ---------
    Begin Snap:     32541 11-Oct-08 21:00:13       248     141.1
      End Snap:     32542 11-Oct-08 21:15:06       245     143.4
       Elapsed:               14.88 (mins)
       DB Time:               12.18 (mins)
    
    SQL Summary                            DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    
                    Elapsed
       SQL Id      Time (ms)
    ------------- ----------
    51szt7b736bmg     25,131
    Module: SQL*Plus
    UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(ACCT_DR_BAL,
    0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND TEST_ACC_NB = ACCT_ACC_NB(+)) WHERE
     TEST_BATCH_DT = (:B1 )
    
              -------------------------------------------------------------
    
    SQL ID: 51szt7b736bmg                  DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> 1st Capture and Last Capture Snap IDs
       refer to Snapshot IDs witin the snapshot range
    -> UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(AC...
    
        Plan Hash           Total Elapsed                 1st Capture   Last Capture
    #   Value                    Time(ms)    Executions       Snap ID        Snap ID
    --- ---------------- ---------------- ------------- ------------- --------------
    1   2960830398                 25,131             1         32542          32542
    2   3834848140                      0             0         32542          32542
              -------------------------------------------------------------
    
    
    Plan 1(PHV: 2960830398)
    -----------------------
    
    Plan Statistics                        DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> % Total DB Time is the Elapsed Time of the SQL statement divided
       into the Total Database Time multiplied by 100
    
    Stat Name                                Statement   Per Execution % Snap
    ---------------------------------------- ---------- -------------- -------
    Elapsed Time (ms)                            25,131       25,130.7     3.4
    CPU Time (ms)                                23,270       23,270.2     3.9
    Executions                                        1            N/A     N/A
    Buffer Gets                               2,626,166    2,626,166.0    14.6
    Disk Reads                                      305          305.0     0.3
    Parse Calls                                       1            1.0     0.0
    Rows                                        371,735      371,735.0     N/A
    User I/O Wait Time (ms)                         564            N/A     N/A
    Cluster Wait Time (ms)                            0            N/A     N/A
    Application Wait Time (ms)                        0            N/A     N/A
    Concurrency Wait Time (ms)                        0            N/A     N/A
    Invalidations                                     0            N/A     N/A
    Version Count                                     2            N/A     N/A
    Sharable Mem(KB)                                 26            N/A     N/A
              -------------------------------------------------------------
    
    Execution Plan
    ------------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------------
    |   0 | UPDATE STATEMENT             |                 |       |       |  1110 (100)|          |
    |   1 |  UPDATE                      | TEST            |       |       |            |          |
    |   2 |   TABLE ACCESS FULL          | TEST            |   116K|  2740K|  1110   (2)| 00:00:14 |
    |   3 |   TABLE ACCESS BY INDEX ROWID| ACCT            |     1 |    26 |     5   (0)| 00:00:01 |
    |   4 |    INDEX RANGE SCAN          | ACCT_DT_ACC_IDX |     1 |       |     4   (0)| 00:00:01 |
    ------------------------------------------------------------------------------------------------
    
    
    
    
    Plan 2(PHV: 3834848140)
    -----------------------
    
    Plan Statistics                        DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> % Total DB Time is the Elapsed Time of the SQL statement divided
       into the Total Database Time multiplied by 100
    
    Stat Name                                Statement   Per Execution % Snap
    ---------------------------------------- ---------- -------------- -------
    Elapsed Time (ms)                                 0            N/A     0.0
    CPU Time (ms)                                     0            N/A     0.0
    Executions                                        0            N/A     N/A
    Buffer Gets                                       0            N/A     0.0
    Disk Reads                                        0            N/A     0.0
    Parse Calls                                       0            N/A     0.0
    Rows                                              0            N/A     N/A
    User I/O Wait Time (ms)                           0            N/A     N/A
    Cluster Wait Time (ms)                            0            N/A     N/A
    Application Wait Time (ms)                        0            N/A     N/A
    Concurrency Wait Time (ms)                        0            N/A     N/A
    Invalidations                                     0            N/A     N/A
    Version Count                                     2            N/A     N/A
    Sharable Mem(KB)                                 26            N/A     N/A
              -------------------------------------------------------------
    
    Execution Plan
    ---------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------------------
    |   0 | UPDATE STATEMENT             |              |       |       |     2 (100)|          |
    |   1 |  UPDATE                      | TEST         |       |       |            |          |
    |   2 |   TABLE ACCESS BY INDEX ROWID| TEST         |     1 |    28 |     2   (0)| 00:00:01 |
    |   3 |    INDEX RANGE SCAN          | TEST_DT_IND  |     1 |       |     1   (0)| 00:00:01 |
    |   4 |   TABLE ACCESS BY INDEX ROWID| ACCT         |     1 |    26 |     4   (0)| 00:00:01 |
    |   5 |    INDEX RANGE SCAN          | INDX_ACCT_DT |     1 |       |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------------
    
    
    
    Full SQL Text
    
    SQL ID       SQL Text
    ------------ -----------------------------------------------------------------
    51szt7b736bm UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL, 0) +
                  NVL(ACCT_DR_BAL, 0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND PB
                 RN_ACC_NB = ACCT_ACC_NB(+)) WHERE TEST_BATCH_DT = (:B1 )
    Your contribution is very much appreciated.

    Thank you for taking your time to answer my question.


    Concerning

    Oracle Lover3 wrote:
    How will I know (from Plan 1 and Plan 2) whose execution plan chose for the current run?

    Since you're already on 10.2, you can identify the actual execution plan by checking in V$ SESSION SQL_ID and SQL_CHILD_NUMBER column. This can be used to identify the plan in V$ SQL_PLAN (columns SQL_ID and CHILD_NUMBER) and in 10g, you can use the convenient DBMS_XPLAN. Function DISPLAY_CURSOR for the information of the real plan using these two parameters.

    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/

  • The execution plan changes for the same query.

    Hi all

    This issue was raised before also, but still not able to find the real cause of this.

    Thread1:
    Re: Research of fragmentation of the table in Oracle 8.1.6.3.0

    Thread2:
    CBC latch and buffer busy await you on the same table.

    It comes, sometimes hammers server 100% CPU utilization with free latch and buffer busy wait events.

    We found a single query consumes high CPU usage that is run by different sessions.

    This query have two types of execution plans, where one is accurate and is not (its primary key hit index index no appropriate means present on the table)

    Because its primary key index hit repeatedly at various sessions, some sessions are powerful db file sequential read and a few sessions waiting buffer busy waits for event. Also during this time a few sessions waiting for latch free event.

    My doubt is how to sql even with different literal values execution plan changes and causes a prob.
    select count(*),event from v$session_wait group by event;
      COUNT(*) EVENT
    ---------- ----------------------------------------------------------------
           165 SQL*Net message from client
             1 SQL*Net message to client
             3 buffer busy waits
             2 db file parallel read
            18 db file sequential read
            10 latch free
             5 log file sync
             1 pmon timer
             6 rdbms ipc message
             1 smon timer
    
    SQL> select sid from v$session_wait where event='db file sequential read';
           SID
    ----------
            26
            58
            82
           107
           116
           223
           212
           203
           192
           173
           161
           157
           150
           147
           254
           238
           229
           112
           101
            81
            68
    
    SQL> select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=&SID;
    Enter value for sid: 161
    old   1: select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=&SID
    new   1: select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=161
    
    SPID             SID    SERIAL# PROGRAM
    --------- ---------- ---------- ------------------------------------------------
    4231             161      49569 oracle@tfrdb3 (TNS V1-V3)
    
    
    SQL> select sql_text
    from v$process a,
         v$session b,  2    3
         v$sql c
    where a.addr = b.paddr and
         b.sql_hash_value = c.hash_value and
        a.spid = &PID;  4    5    6    7
    Enter value for pid: 4231
    old   7:     a.spid = &PID
    new   7:     a.spid = 4231
    
    SQL_TEXT
    --------------------------------------------------------------------------------
    SELECT ERROR,TIME_STAMP,O_RESOURCE,QUEUE,NEW_QUEUE FROM LOG WHERE ID = '09292AMR
    10B41FE' AND TYPE IN (11, 28, 25, 18, 60, 13) AND (LOG_SEQ>'234225222' OR TYPE =
     18 AND LOG_SEQ='234225222') ORDER BY TIME_STAMP ASC
    
    SQL> set autotrace traceonly exp
    SQL> SELECT ERROR,TIME_STAMP,O_RESOURCE,QUEUE,NEW_QUEUE FROM amrwf1.LOG WHERE ID = '09292AMR10B41FE' AND TYPE IN (11, 28, 25, 18, 60, 13) AND (LOG_SEQ>'234225222' OR TYPE =18 AND LOG_SEQ='234225222') ORDER BY TIME_STAMP ASC;
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=11 Card=2 Bytes=126)
       1    0   SORT (ORDER BY) (Cost=11 Card=2 Bytes=126)
       2    1     CONCATENATION
       3    2       TABLE ACCESS (BY INDEX ROWID) OF 'LOG' (Cost=4 Card=1
              Bytes=63)
    
       4    3         INDEX (UNIQUE SCAN) OF 'PK_LOG_LOG_SEQ' (UNIQUE) (Co
              st=3 Card=1)
    
       5    2       TABLE ACCESS (BY INDEX ROWID) OF 'LOG' (Cost=4 Card=1
              Bytes=63)
    
       6    5         INDEX (RANGE SCAN) OF 'PK_LOG_LOG_SEQ' (UNIQUE) (Cos
              t=3 Card=1)
    
    
    SQL> select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=&SID;
    Enter value for sid: 147
    old   1: select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=&SID
    new   1: select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=147
    
    SPID             SID    SERIAL# PROGRAM
    --------- ---------- ---------- ------------------------------------------------
    6255             147      38306 oracle@tfrdb3 (TNS V1-V3)
    
    SQL> select sql_text
    from v$process a,
         v$session b,
         v$sql c  2    3
    where a.addr = b.paddr and
         b.sql_hash_value = c.hash_value and
        a.spid = &PID;  4    5    6    7
    Enter value for pid: 6255
    old   7:     a.spid = &PID
    new   7:     a.spid = 6255
    
    SQL_TEXT
    --------------------------------------------------------------------------------
    SELECT ERROR,TIME_STAMP,O_RESOURCE,QUEUE,NEW_QUEUE FROM LOG WHERE ID = '09273AMR
    62B4894' AND TYPE IN (11, 28, 25, 18, 60, 13) AND (LOG_SEQ>'223324996' OR TYPE =
     18 AND LOG_SEQ='223324996') ORDER BY TIME_STAMP ASC
    
    
    SQL> set autotrace traceonly exp
    SQL> SELECT ERROR,TIME_STAMP,O_RESOURCE,QUEUE,NEW_QUEUE FROM amrwf1.LOG WHERE ID = '09273AMR62B4894' AND TYPE IN (11, 28, 25, 18, 60, 13) AND (LOG_SEQ>'223324996' OR TYPE =18 AND LOG_SEQ='223324996') ORDER BY TIME_STAMP ASC;
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=1538 Card=736 Bytes=
              46368)
    
       1    0   SORT (ORDER BY) (Cost=1538 Card=736 Bytes=46368)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'LOG' (Cost=1527 Card=7
              36 Bytes=46368)
    
       3    2       INDEX (RANGE SCAN) OF 'LOG_ID' (NON-UNIQUE) (Cost=32 C
              ard=736)
    
    
    
    SQL> select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=&SID;
    Enter value for sid: 82
    old   1: select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=&SID
    new   1: select spid, sid, s.serial#, p.program from v$session s, v$process p where paddr=addr and sid=82
    
    SPID             SID    SERIAL# PROGRAM
    --------- ---------- ---------- ------------------------------------------------
    6172              82      45378 oracle@tfrdb3 (TNS V1-V3)
    
    
    SQL> select sql_text
    from v$process a,
         v$session b,
         v$sql c
    where a.addr = b.paddr and
         b.sql_hash_value = c.hash_value and  2
      3      a.spid = &PID;  4    5    6    7
    Enter value for pid: 6172
    old   7:     a.spid = &PID
    new   7:     a.spid = 6172
    
    SQL_TEXT
    --------------------------------------------------------------------------------
    INSERT INTO LOG (ID,TIME_STAMP,TYPE,ERROR,INSTANCE,RULE_NUM,RULE_TYPE,PRIORITY,F
    LAGS,NAME,BATCH,O_RESOURCE,QUEUE,NEW_QUEUE,SERVER,FORM,WORKSET) VALUES (:V001,:V
    002,11,0,0,3,1,0,1,:V003,:V004,:V005,:V006,:V007,:V008,:V009,:V010)
    
    INSERT INTO LOG (ID,TIME_STAMP,TYPE,ERROR,INSTANCE,RULE_NUM,RULE_TYPE,PRIORITY,F
    LAGS,NAME,BATCH,O_RESOURCE,QUEUE,NEW_QUEUE,SERVER,FORM,WORKSET) VALUES (:V001,:V
    002,11,0,0,3,1,0,1,:V003,:V004,:V005,:V006,:V007,:V008,:V009,:V010)
    
    INSERT INTO LOG (ID,TIME_STAMP,TYPE,ERROR,INSTANCE,RULE_NUM,RULE_TYPE,PRIORITY,F
    LAGS,NAME,BATCH,O_RESOURCE,QUEUE,NEW_QUEUE,SERVER,FORM,WORKSET) VALUES (:V001,:V
    002,11,0,0,3,1,0,1,:V003,:V004,:V005,:V006,:V007,:V008,:V009,:V010)
    
    SQL_TEXT
    --------------------------------------------------------------------------------
    
    INSERT INTO LOG (ID,TIME_STAMP,TYPE,ERROR,INSTANCE,RULE_NUM,RULE_TYPE,PRIORITY,F
    LAGS,NAME,BATCH,O_RESOURCE,QUEUE,NEW_QUEUE,SERVER,FORM,WORKSET) VALUES (:V001,:V
    002,11,0,0,3,1,0,1,:V003,:V004,:V005,:V006,:V007,:V008,:V009,:V010)
    
    INSERT INTO LOG (ID,TIME_STAMP,TYPE,ERROR,INSTANCE,RULE_NUM,RULE_TYPE,PRIORITY,F
    LAGS,NAME,BATCH,O_RESOURCE,QUEUE,NEW_QUEUE,SERVER,FORM,WORKSET) VALUES (:V001,:V
    002,11,0,0,3,1,0,1,:V003,:V004,:V005,:V006,:V007,:V008,:V009,:V010)
    
    INSERT INTO LOG (ID,TIME_STAMP,TYPE,ERROR,INSTANCE,RULE_NUM,RULE_TYPE,PRIORITY,F
    LAGS,NAME,BATCH,O_RESOURCE,QUEUE,NEW_QUEUE,SERVER,FORM,WORKSET) VALUES (:V001,:V
    
    SQL_TEXT
    --------------------------------------------------------------------------------
    002,11,0,0,3,1,0,1,:V003,:V004,:V005,:V006,:V007,:V008,:V009,:V010)
    
    INSERT INTO LOG (ID,TIME_STAMP,TYPE,ERROR,INSTANCE,RULE_NUM,RULE_TYPE,PRIORITY,F
    LAGS,NAME,BATCH,O_RESOURCE,QUEUE,NEW_QUEUE,SERVER,FORM,WORKSET) VALUES (:V001,:V
    002,11,0,0,3,1,0,1,:V003,:V004,:V005,:V006,:V007,:V008,:V009,:V010)
    How to avoid this... why its different execution plan using (I mean bad index PK)

    Is it possible to avoid this?

    If any details please check out some of my previous post on this specific URL (above)

    -Yasser

    My doubt is how to sql even with different literal values execution plan changes and causes a prob.

    Different literal values cause analysis difficult.
    Hard analysis includes the re-evaluation of the best path.
    Literal value is included in the assessment of the selectivity for the scan interval (log_seq >...)

    See
    http://www.centrexcc.com/A%20Look%20under%20The%20Hood%20Of%20CBO%20-%20The%2010053%20Event.ppt.PDF
    http://www.centrexcc.com/fallacies%20Of%20The%20Cost%20Based%20Optimizer.PDF
    more the book of Jonathan Lewis which other threads, I believe that you already have.

    You must lower your CPU.
    Previous discussions, if the situation is still the same, it sounded like hard analysis particularly with this SELECTION against the NEWSPAPER plays an important role in that.

    How to avoid this... why its different execution plan using (I mean bad index PK)

    The points raised in the previous discussion remain valid.
    -Do you have access to this SQL to change?
    for example using bind variable or trick it if necessary due to problems caused by data as discussed in the previous thread.
    - Or you could it repoint the view to a view and a hint?
    -If a particular user makes this sql, could affect you cursor_sharing just for this user. If not, you should consider implementing pan-Canadian database.

    Oracle 8.1.6 still?

  • How to create a Pool of connections to two different databases in OBIEE

    Hello

    I have a requirement where few reports coming from databases and a few others to another database. I created two pools of connections and added the frame connection details. But when I created the report I get error as below.

    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 17001] Oracle error code: 942, message: ORA-00942: table or view does not exist to the call of the OCIStmtExecute OIC. [nQSError: 17010] Prepare the SQL statement failed. (HY000)

    Now, I would like to see if I can create a pool of connections to two different databases. If so, how that happen.

    Thank you!

    Hi Antonio,.

    Cross database joins are possible, no problem for it. But you do not do so in an object of unique data base in the physical layer using 2 pools of connections connection to the source A and B, then adding objects to A and B children of your unique database.

    You create 2 databases in the physical layer, each with its own connection pool, then you can do your knuckles crossed on the physical schema.

    As a picture is worth a thousand words, take a look:

    The physical diagram uses objects of A and B and define the rules of the join between them, it is a cross-database join. But in the physical layer of the database A and B are 2 separate objects each with its own pool of connections.

  • Trace SQL execution plan

    Hello

    I need to get the execution plan for a particular SQL, but I don't have it. Application it issues for a second or two and then his party so I think that the definition of a trace on specific user. Is it possible to get the execution plan of the query like this? Thank you!

    Find the sql code, you are interested in v$ sql using the sql_text column and get the SQL_ID and CHILD_NUMBER. Entry of these two values for the query to get the execution below plan.

    Select * from table

    (dbms_xplan.display_cursor ('> ',>, 'ALLSTATS'));

  • How to understand the implementation of the plan in oracle I mean if I see two implementation plans for a single sql_id plans 2 How to determine the best execution plan? Links and answers are much appreciated. Thank you

    How to understand the implementation of the plan in oracle I mean if I see two implementation plans for a single sql_id plans 2 How to determine the best execution plan? Links and answers are much appreciated. Thank you

    How to understand the implementation of the plan in oracle I mean if I see two implementation plans for a single sql_id plans 2 How to determine the best execution plan? Links and answers are much appreciated. Thank you

    After two execution plans that have the same sql_id, so we can see what you're talking about.

    See "Oracle Explain Explain Plan optimizer" by Maria Colgan of the Oracle optimizer group

    http://www.Oracle.com/technetwork/database/bi-Datawarehousing/TWP-explain-the-explain-plan-052011-393674.PDF

    Examine the various aspects of a selectivity to parallel execution plan

    performance and understand what information you should be brilliant

    the plan can be overwhelming even for the most experienced DBA. This document

    offers a detailed explanation on each of the aspects of the execution plan and a

    Overview of what caused the CBO to make the decision, he did.

  • Get the SQL execution plan that is currently running in 9i

    Hello

    Apologies for the magnitude of this issue, but I was wondering if someone could help me to the more accurate/efficient way to get a piece of running Oracle 9i SQL execution plan.

    in 10g and 11g of course dbms_xplan.display_cursor (sql_id) can be used.

    How can this be achieved in 9i, currently I am just get the SQL_TEXT and then executing a plan to explain ("EXPLAIN PLAN for.") - I think that this is not neccesserally the same plan to explain that will be used for the sql code that runs if

    Any help would be appreciated.

    Thank you

    The plan exists after analysis difficult.
    Statistics of actual execution will require a completed.
    That is why sql followed in real time is so great in 11g.
    In 9i, difficult.

Maybe you are looking for