No room for improvement for this request? Explain the Plan attached.

There is room for improvement for this request? Table stats are updated. Suggestions, Query rewrite, adding indexes,... etc?
select sum(CONF
             when (cd.actl_qty - cd.total_alloc_qty - lsd.Q < 0) then
              0
             else
              cd.actl_qty - cd.total_alloc_qty - lsd.Q
           end)
  from (select sum(reqd_qty) as Q, ITEM_ID as ITEM
          from SHIP_DTL SD
         where exists (select 1
                  from CONF_dtl
                 where CONF_nbr = '1'
                   and ITEM_id = SD.ITEM_id)
         group by ITEM_id) lsd,
       CONF_dtl cd
 where lsd.ITEM = cd.ITEM_id
   and cd.CONF_nbr = '1'
Total number of rows in the tables involved
select count(*) from CONF_DTL;

  COUNT(*)
----------
   1785889

select count(*) from shp_dtl;

  COUNT(*)
----------
    286675
  
Explain Plan
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
Plan hash value: 2325658044

----------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                    |     1 |    39 |     4  (25)| 00:00:01 |
|   1 |  SORT AGGREGATE                     |                    |     1 |    39 |            |          |
|   2 |   VIEW                              |                    |     1 |    39 |     4  (25)| 00:00:01 |
|   3 |    HASH GROUP BY                    |                    |     1 |   117 |     4  (25)| 00:00:01 |
|   4 |     TABLE ACCESS BY INDEX ROWID     | SHIP_DTL           |     1 |    15 |     1   (0)| 00:00:01 
|   5 |      NESTED LOOPS                   |                    |     1 |   117 |     3   (0)| 00:00:01 |
|   6 |       MERGE JOIN CARTESIAN          |                    |     1 |   102 |     2   (0)| 00:00:01 |
|   7 |        TABLE ACCESS BY INDEX ROWID  | CONF_DTL           |     1 |    70 |     1   (0)| 00:00:01 |
|*  8 |         INDEX RANGE SCAN            | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
|   9 |        BUFFER SORT                  |                    |     1 |    32 |     1   (0)| 00:00:01 |
|  10 |         SORT UNIQUE                 |                    |     1 |    32 |     1   (0)| 00:00:01 |
|  11 |          TABLE ACCESS BY INDEX ROWID| CONF_DTL           |     1 |    32 |     1   (0)| 00:00:01 |
|* 12 |           INDEX RANGE SCAN          | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
|* 13 |       INDEX RANGE SCAN              | SHIP_DTL_IND_6 |     1 |       |     1   (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   8 - access("CD"."CONF_NBR"='1')
  12 - access("CONF_NBR"='1')
  13 - access("ITEM_ID"="SD"."ITEM_ID")
       filter("ITEM_ID"="CD"."ITEM_ID")
SELECT SUM(cd.actl_qty - cd.total_alloc_qty - lsd.Q)
  FROM (SELECT   SUM(reqd_qty) AS Q, ITEM_ID AS ITEM
            FROM SHIP_DTL SD
           WHERE ITEM_ID IN(SELECT ITEM_ID
                              FROM CONF_dtl
                             WHERE CONF_nbr = '1')
        GROUP BY ITEM_id) lsd,
       CONF_dtl cd
 WHERE lsd.ITEM = cd.ITEM_id AND cd.CONF_nbr = '1' AND cd.actl_qty - cd.total_alloc_qty - lsd.Q > 0

This should remove the nested loop and could lead to a hash on conf_dtl join.

Tags: Database

Similar Questions

  • I want to use InDesign, but for this month only! so if I pay for the "monthly plan" means that I pay for this month then the plan InDesign will end?

    I want to use InDesign, but for this month only! so if I pay for the "monthly plan" means that I pay for this month then the plan InDesign will end?

    Hello

    Please go through the Adobe - General conditions of subscription as well.

    Alternatively, you can contact customer service

    Hope that helps!

    Kind regards

    Sheena

  • Query must tuning; Explain the plan attached

    DB version: 10 gr 2

    Currently, the query below takes more than 28 seconds to complete. The table statistics are up to date.
    Is there a way of rewriting/tune this query?
    SELECT DISTINCT TASK_HDR.TASK_ID,
                     TASK_HDR.WHSE,
                     TASK_HDR.TASK_DESC,
                     TASK_HDR.INVN_TYPE,
                     TASK_HDR.INVN_NEED_TYPE,
                     TASK_HDR.DFLT_TASK_PRTY,
                     TASK_HDR.CURR_TASK_PRTY,
                     TASK_HDR.XPECTD_DURTN,
                     TASK_HDR.ACTL_DURTN,
                     TASK_HDR.ERLST_START_DATE_TIME,
                     TASK_HDR.LTST_START_DATE_TIME,
                     TASK_HDR.LTST_CMPL_DATE_TIME,
                     TASK_HDR.BEGIN_AREA,
                     TASK_HDR.BEGIN_ZONE,
                     TASK_HDR.BEGIN_AISLE,
                     TASK_HDR.END_AREA,
                     TASK_HDR.END_ZONE,
                     TASK_HDR.END_AISLE,
                     TASK_HDR.START_CURR_WORK_GRP,
                     TASK_HDR.START_CURR_WORK_AREA,
                     TASK_HDR.END_CURR_WORK_GRP,
                     TASK_HDR.END_CURR_WORK_AREA,
                     TASK_HDR.START_DEST_WORK_GRP,
                     TASK_HDR.START_DEST_WORK_AREA,
                     TASK_HDR.END_DEST_WORK_GRP,
                     TASK_HDR.END_DEST_WORK_AREA,
                     TASK_HDR.TASK_TYPE,
                     TASK_HDR.TASK_GENRTN_REF_CODE,
                     TASK_HDR.TASK_GENRTN_REF_NBR,
                     TASK_HDR.NEED_ID,
                     TASK_HDR.TASK_BATCH,
                     TASK_HDR.STAT_CODE,
                     TASK_HDR.CREATE_DATE_TIME,
                     TASK_HDR.MOD_DATE_TIME,
                     TASK_HDR.USER_ID,
                     TASK_HDR.RLS_DATE_TIME,
                     TASK_HDR.SKU_ID,
                     TASK_HDR.TASK_CMPL_REF_CODE,
                     TASK_HDR.TASK_CMPL_REF_NBR,
                     TASK_HDR.OWNER_USER_ID,
                     TASK_HDR.ONE_USER_PER_GRP,
                     TASK_HDR.NEXT_TASK_ID,
                     TASK_HDR.EXCEPTION_CODE,
                     TASK_HDR.CURR_LOCN_ID,
                     TASK_HDR.TASK_PARM_ID,
                     TASK_HDR.RULE_ID,
                     TASK_HDR.VOCOLLECT_ASSIGN_ID,
                     TASK_HDR.CURR_USER_ID,
                     TASK_HDR.MHE_FLAG,
                     TASK_HDR.PICK_TO_TOTE_FLAG,
                     TASK_HDR.MHE_ORD_STATE,
                     TASK_HDR.PRT_TASK_LIST_FLAG,
                     TASK_HDR.RPT_PRTR_REQSTR,
                     TASK_HDR.ORIG_TASK_ID
       FROM INVN_NEED_TYPE, TASK_DTL, TASK_HDR
        WHERE (TASK_HDR.TASK_ID = TASK_DTL.TASK_ID(+))
          AND TASK_HDR.WHSE = '01' AND TASK_HDR.STAT_CODE >= 99 AND
              TASK_HDR.INVN_NEED_TYPE = INVN_NEED_TYPE.INVN_NEED_TYPE AND
              INVN_NEED_TYPE.WHSE = TASK_HDR.WHSE AND
              (INVN_NEED_TYPE.CO = '88') AND (INVN_NEED_TYPE.DIV = '51') AND
              (TASK_DTL.PKT_CTRL_NBR IS NULL OR TASK_DTL.INVN_NEED_TYPE = 1) AND
              TASK_HDR.MOD_DATE_TIME <= sysdate-85
      ORDER BY TASK_HDR.CREATE_DATE_TIME DESC
      
    The plan of the explain command:
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------
    | Id  | Operation                        | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)|
    ---------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                 |                   | 10032 |  1969K|       |  3143   (2)|
    |   1 |  SORT ORDER BY                   |                   | 10032 |  1969K|  4232K|  3143   (2)|
    |   2 |   HASH UNIQUE                    |                   | 10032 |  1969K|  4232K|  2689   (2)|
    |   3 |    FILTER                        |                   |       |       |       |            |
    |   4 |     NESTED LOOPS OUTER           |                   | 10032 |  1969K|       |  2235   (1)|
    |   5 |      NESTED LOOPS                |                   |  3226 |   570K|       |   284   (3)|
    |   6 |       TABLE ACCESS BY INDEX ROWID| TASK_HDR          |  3412 |   559K|       |   282   (2)|
    |   7 |        INDEX RANGE SCAN          | TASK_HDR_IND_3    |  9042 |       |       |     8  (13)|
    |   8 |       INDEX UNIQUE SCAN          | PK_INVN_NEED_TYPE |     1 |    13 |       |     1   (0)|
    |   9 |      TABLE ACCESS BY INDEX ROWID | TASK_DTL          |     3 |    60 |       |     1   (0)|
    |  10 |       INDEX RANGE SCAN           | PK_TASK_DTL       |     3 |       |       |     1   (0)|
    ---------------------------------------------------------------------------------------------------

    My apologies, Yes, it is:

    SELECT TASK_HDR.TASK_ID,
                     TASK_HDR.WHSE,
                     TASK_HDR.TASK_DESC,
                     TASK_HDR.INVN_TYPE,
                     TASK_HDR.INVN_NEED_TYPE,
                     TASK_HDR.DFLT_TASK_PRTY,
                     TASK_HDR.CURR_TASK_PRTY,
                     TASK_HDR.XPECTD_DURTN,
                     TASK_HDR.ACTL_DURTN,
                     TASK_HDR.ERLST_START_DATE_TIME,
                     TASK_HDR.LTST_START_DATE_TIME,
                     TASK_HDR.LTST_CMPL_DATE_TIME,
                     TASK_HDR.BEGIN_AREA,
                     TASK_HDR.BEGIN_ZONE,
                     TASK_HDR.BEGIN_AISLE,
                     TASK_HDR.END_AREA,
                     TASK_HDR.END_ZONE,
                     TASK_HDR.END_AISLE,
                     TASK_HDR.START_CURR_WORK_GRP,
                     TASK_HDR.START_CURR_WORK_AREA,
                     TASK_HDR.END_CURR_WORK_GRP,
                     TASK_HDR.END_CURR_WORK_AREA,
                     TASK_HDR.START_DEST_WORK_GRP,
                     TASK_HDR.START_DEST_WORK_AREA,
                     TASK_HDR.END_DEST_WORK_GRP,
                     TASK_HDR.END_DEST_WORK_AREA,
                     TASK_HDR.TASK_TYPE,
                     TASK_HDR.TASK_GENRTN_REF_CODE,
                     TASK_HDR.TASK_GENRTN_REF_NBR,
                     TASK_HDR.NEED_ID,
                     TASK_HDR.TASK_BATCH,
                     TASK_HDR.STAT_CODE,
                     TASK_HDR.CREATE_DATE_TIME,
                     TASK_HDR.MOD_DATE_TIME,
                     TASK_HDR.USER_ID,
                     TASK_HDR.RLS_DATE_TIME,
                     TASK_HDR.SKU_ID,
                     TASK_HDR.TASK_CMPL_REF_CODE,
                     TASK_HDR.TASK_CMPL_REF_NBR,
                     TASK_HDR.OWNER_USER_ID,
                     TASK_HDR.ONE_USER_PER_GRP,
                     TASK_HDR.NEXT_TASK_ID,
                     TASK_HDR.EXCEPTION_CODE,
                     TASK_HDR.CURR_LOCN_ID,
                     TASK_HDR.TASK_PARM_ID,
                     TASK_HDR.RULE_ID,
                     TASK_HDR.VOCOLLECT_ASSIGN_ID,
                     TASK_HDR.CURR_USER_ID,
                     TASK_HDR.MHE_FLAG,
                     TASK_HDR.PICK_TO_TOTE_FLAG,
                     TASK_HDR.MHE_ORD_STATE,
                     TASK_HDR.PRT_TASK_LIST_FLAG,
                     TASK_HDR.RPT_PRTR_REQSTR,
                     TASK_HDR.ORIG_TASK_ID
       FROM INVN_NEED_TYPE,TASK_HDR
        WHERE TASK_HDR.WHSE = '01' AND TASK_HDR.STAT_CODE >= 99 AND
              TASK_HDR.INVN_NEED_TYPE = INVN_NEED_TYPE.INVN_NEED_TYPE AND
              INVN_NEED_TYPE.WHSE = TASK_HDR.WHSE AND
              (INVN_NEED_TYPE.CO = '88') AND (INVN_NEED_TYPE.DIV = '51') AND
              TASK_HDR.MOD_DATE_TIME <= sysdate-85
         AND EXISTS (SELECT 1
                               FROM TASK_DTL
                             WHERE TASK_HDR.TASK_ID = TASK_DTL.TASK_ID
                                AND (TASK_DTL.PKT_CTRL_NBR IS NULL OR TASK_DTL.INVN_NEED_TYPE = 1))
      ORDER BY TASK_HDR.CREATE_DATE_TIME DESC
    

    Although you have an OUTER JOIN on TASK_DTL. TASK_ID, it is converted to a JOIN IN-HOUSE with (TASK_DTL. PKT_CTRL_NBR IS NULL OR TASK_DTL. INVN_NEED_TYPE = 1), which is the equivalent of the 'EXISTS' version above.

    I could not test this situation.

  • Invalid object for this request

    Hi friends I have an another problem concerning textframe.

    my java script code is like this,

    firstLine var = xmlElement.lines.firstItem ();

    var newTextFrame = firstLine.textFrames.add ();

    -> newTextFrame.geometricBounds = [0,0,50,50]; error: Invalid object for this request

    newTextFrame.contents = queryNumber;

    newTextFrame.appliedObjectStyle = this.jrnlIDDoc.objectStyles.itemByName (((columnIndex == 0)? (("' AQ_LEFT ': 'AQ_RIGHT'));

    newTextFrame.fit (FitOptions.FRAME_TO_CONTENT);

    If (firstLine.textFrames.length > 0) {}

    newTextFrame.move (null, [0, (newTextFrame.geometricBounds [2] - newTextFrame.geometricBounds [0] + 3) * (firstLine.textFrames.length)]);

    }

    After the execution of this file, I got a error: Invalid object for this request


    If anyone knows the soln please help me.

    concerning

    Tahir.

    The frame that you add is "inline" and is oversetting image, no doubt, so its geometricBounds are inaccessible. One solution is to create as anchored to instead and then make your changes and then put it back on line if you want to:

    var newTextFrame = firstLine.textFrames.add({anchoredObjectSettings:{anchoredPosition:AnchorPosition.ANCHORED}, geometricBounds:[0, 0, 50, 50]});
    

    Jeff

  • Library meets live TV with the error: "there are currently no TV signal detected for this channel. The channel may be temporarily off the air. »

    I recently changed my TV card to an analogue of Hauppauge PVR150 at a Hauppauge DVB - S Nova S more. Media Center has worked well before.

    Media Library will recognize the new card, search and branch on 239 satellite channels, but may not display the channels giving the error message "there is currently no TV signal detected for this channel. The channel may be temporarily off the air. »

    I have installed WinTV 7 and that you can view all the channels very well in this program so obviously the map and the intensity of the signal are not the problem.

    In my quest through other forums, I heard problems re codec: mpeg2 and we tried several packs of codecs (including shark007) but with no improvement.

    My last move was to uninstall Media Center, uninstall all codec packs, uninstall the TV card and drivers, then reinstall the media library and the TV card and am still unable to view TV channels.

    Suggestions have greatly accepted.

    I've searched the Internet high and low for a solution to this problem and can lead to nothing more than what is proposed here by Divya.

    The problem seems to be fairly common and seems to be associated with codec. Most of the solutions I've come across related to the installation of media center alternatives and after several tries I finally opted for new version of Media Portal 1.1.0 beta

    Installed without a hitch and so far the interface is similar to the media library but has better customization and the ability to incorporate plug-ins.

    I did try the latest version (1.0.2) of the media portal, but said she had a few problems of stability (probably related to the W7 compatibility).

    Very happy now with Media Portal 1.1.0 Beta so will not need any other solution to this problem.

  • You try to create VHDX or another format not supported for this version of the server

    Hello

    I have a problem with vWorkSpace do not load VM and I really hope that someone here might be able to add comments. We run vWorkSpace v8.5 on a box of windows server 2012 and v6.1 Hyper-V on Windows Server 2008.

    After running then changing the main image, I've updated the image of our cloud. Once the update of the virtual machine would not load, giving the below error

    End of the action (create) (failed to create. CreateVM: Unable to create the virtual machine of provided information. : CreateVhdxDisk: try to create VHDX or other format not supported for this version of the server. Path to the virtual disk: .avhd - call stacks - to Quest.vWorkspace.VirtualCore.HyperV.HvVmService.CreateVM (VmCreateData createData, String domainNameIP)
    at HypervLocalExecutor.HvCreateVM (string strUser, strPwd, VmCreateData createData, String strDomainNameIP, VmResult String & result)
    to CHyperVClone.doClone (basic_string<>\,std::allocator > * nsHostName, basic_string<>\,std::allocator > * nsUsername, basic_string<>\,std::allocator > * nsPasswd, VmDefData * vmData, basic_string<>\,std::allocator > * strDomainIPaddress, NewVmInfo * newVmInfo)-> Quest.vWorkspace.VirtualCore.HyperV.Server2008R2.CreateVhdxDisk (String parentDiskPath, String diskPath)
    at Quest.vWorkspace.VirtualCore.HyperV.Server2008R2.CreateDiskForVM (vmMgmntObj, String vmPath, VmCreateData ManagementObject & vmData, String & vhdPath)
    at Quest.vWorkspace.VirtualCore.HyperV.Server2008R2.CreateVirtualMachine (VmCreateData vmData, String domainNameIP)
    at Quest.vWorkspace.VirtualCore.HyperV.HvVmService.CreateVM (VmCreateData createData, String domainNameIP))...
    5 March 2015 15:54:15 - 1392:8580511090155201372 - caught error: Stack Trace and stack Exception below:
    at Quest.vWorkspace.VirtualCore.HyperV.Server2008R2.CreateVhdxDisk (String parentDiskPath, String diskPath)
    at Quest.vWorkspace.VirtualCore.HyperV.Server2008R2.CreateDiskForVM (vmMgmntObj, String vmPath, VmCreateData ManagementObject & vmData, String & vhdPath)
    at Quest.vWorkspace.VirtualCore.HyperV.Server2008R2.CreateVirtualMachine (VmCreateData vmData, String domainNameIP)
    at Quest.vWorkspace.VirtualCore.HyperV.HvVmService.CreateVM (VmCreateData createData, String domainNameIP)

    We believe that it is somehow to do with Hyper-V under Windows 2008 and vWorkSpace running on Windows 2012 - the VHDX format is not supported by the version of Hyper-V server. A glance online confirms this. So my question is, how update the master image changed the format VHD vWorkSpace wants to use and is there a way to assign vWorkSpace don't know this format?

    I have widely in search of a solution to this line and not found anything it either, nor there seems a clear way in the vWorkSpace console to change that.

    Thank you

    Hello

    I suspect that you have created a snapshot on your model.  It is not supported, if you delete the snapshot so that the .avhd is merged to the vhd/vhdx and update the model in vWorkspace again.  If this does not work, you will need to delete the model of vWorkspace and then re-import.

    Concerning

    Paul

  • I just bought a new laptop with Windows 8 is installed. When I try to install my printer, I get an error saying that there is no driver. Where can I download a driver for this printer and the OS from?

    I just bought a new laptop with Windows 8 is installed. When I try to install my printer, I get an error saying that there is no driver. Where can I download a driver for this printer and the OS from?

    Also, where can I find a list of compatible printers?

    I just bought a new laptop with Windows 8 is installed. When I try to install my printer, I get an error saying that there is no driver. Where can I download a driver for this printer and the OS from?

    Also, where can I find a list of compatible printers?

    Hello

    You can use the Windows 8 Compatibility Center to find out if a device is compatible.

    Windows Compatibility Center: find updates, drivers, & downloads for Windows 8, Windows RT:
    http://www.Microsoft.com/en-us/Windows/compatibility/WinRT/CompatCenter/home

    FAQ - Windows Compatibility Center:

    http://www.Microsoft.com/en-us/Windows/compatibility/WIN8/CompatCenter/FAQ

    Concerning

  • I installed Photoshop CC2014 to CC2015 which is a single 30 day trial (?) and my CC2014 is not accessible now, why? Does this mean that I have TO pay for this upgrade at the end of 30-day track? I can't go back to CC2014?

    I installed Photoshop CC2014 to CC2015 which is a single 30 day trial (?) and my CC2014 is not accessible now (it displays an exclamation mark) why? Does this mean that I have TO pay for this upgrade at the end of 30-day track? I can't go back / stick with CC2014?

    There is a problem with your account if it does not show that your subscription is current.

    Contact adobe support by clicking on this link then "still need help" as soon as it appears, http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • I try to install Lightroom 4 on a new machine, but the media are hosted by Adobe.  I can see my license number but do not see the option for download.  Y at - it a link to the downloads for this media on the Web site?  It does not appear in my one Adobe

    I try to install Lightroom 4 on a new machine, but the media are hosted by Adobe.  I can see my license number but do not see the option for download.  Y at - it a link to the downloads for this media on the Web site?  It does not appear in my Adobe account.

    Adobe - Lightroom: For Windows

    Adobe - Lightroom: For Macintosh

    Mylenium

  • Question about cardinality (lines) to explain the plan

    I have two tables (names have been changed to protect the innocent):


    TABLE 1:


    The Null columns?    Type

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

    Table1_Primary_Key NOT NULL NUMBER

    more than 10 columns


    TABLE2:


    The Null columns?    Type

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

    Table2_Primary_Key NOT NULL NUMBER

    more than 8 columns


    Lines of table1 has 1097172


    Rows of table2 has 160960


    I am analysis request and get explain below:


    SELECT t1. Table1_Primary_Key

    --

    FROM TABLE1 t1,

    From TABLE2 T2

    --

    WHERE t1. Table1_Primary_Key = t1. Table1_Primary_Key

    AND t2. Table2_Primary_Key = 3432798

    /


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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | SELECT STATEMENT |                 |     1.    21.     5 (0) | 00:00:01 |

    |   1.  NESTED LOOPS |                 |     1.    21.     5 (0) | 00:00:01 |

    |   2.   TABLE ACCESS BY INDEX ROWID | TABLE2.     1.    12.     3 (0) | 00:00:01 |

    |*  3 |    INDEX UNIQUE SCAN | TABLE2_PK |     1.       |     2 (0) | 00:00:01 |

    |   4.   TABLE ACCESS BY INDEX ROWID | TABLE1.  1096K |  9634K |     2 (0) | 00:00:01 |

    |*  5 |    INDEX UNIQUE SCAN | TABLE1_PK |     1.       |     1 (0) | 00:00:01 |

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


    As you can see it table2 is exactly 1 row and join table1 on a correspondence of single line.


    My question is this:


    Why the plan of the explain command seems (at least for me) to indicate that it looked like all the rows in TABLE1?


    Thank you


    Thomas

    the optimizer's decisions are based on the object (and maybe system) statistics: so it's a good idea to provide as much information as possible in these statistics. Basically, there is nothing wrong with statistics automatic collection job - so I would count on that if I don't have very good reason to use anything else. Of course, there are some situations in which it's a good idea to add a few adjustions for automatic collection: sometimes, there is too much created histograms, sometimes there is too little (basically you have histograms when the distribution of the data is not yet). And if there are columns with correlated values who serve together in boundary conditions then create extensive statistics may be a good idea. To make these adjustions, you can use the routines of pref dbms_stats. And sometimes, it may even be a good idea is not to collect statistics for an object and use the sample dynamic (dynamic statistics) for more detailed information on the cardinality of distribution and join.

    In the book of my opinion Jonathan Lewis cost base Oracle Fundamentals still contains the best explanation of the use of optimizer statistics - and Christian Antognini Oracle performance troubleshooting also provides a lot of valuable information about statistics and their gathering. Of course the documentation also explains the basics in detail: Managing optimizer statistics - 11 g Release 2 (11.2). And if you want to get a shorter summary, then you can always take a look at the Web of Tim Hall site: https://oracle-base.com/articles/misc/cost-based-optimizer-and-database-statistics.

  • explain the plan of a query with variables

    Trying to Explain plan at some sql code in sql * more. The query has a variable. How can I do this?

    I look to explain the plan and dbms_xplan but did not find anything with variables

    use sqlplus variable bind:

    SQL> --define variable
    SQL> var x varchar2
    
    SQL> -- notice the colon prefixing the variable
    SQL> explain plan for select * from customer where cid = :x;
    
    Explained.
    
    SQL> select * from table( dbms_xplan.display );
    
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------
    Plan hash value: 1709312366
    
    ----------------------------------------------------------------------------------------
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |          |     1 |    67 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| CUSTOMER |     1 |    67 |     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | CID      |     1 |       |     1   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("CID"=:X)
    
    14 rows selected.
    

    the variable should not be set to explain the request, because explain does not actually run.

    Published by: shoblock on November 6, 2008 16:51

  • Generation to EXPLAIN the PLAN on a database that is open in READ ONLY mode

    Hello

    I use the Oracle 10.2.0.3 version.

    If my database is opened in READ ONLY mode, means that no insert/update/delete operations are allowed here.

    During the generation of the PLAN to EXPLAIN this, the PLAN_TABLE registrations for any SQL. But my database is opened in READ ONLY mode, means that no inserts can happen.

    So, how can I generate EXPLAIN PLAN for my SQL in this State?

    Thanks in advance.



    Best regards
    oratest

    oratest wrote:
    I use the Oracle 10.2.0.3 version.

    If my database is opened in READ ONLY mode, means that no insert/update/delete operations are allowed here.

    During the generation of the PLAN to EXPLAIN this, the PLAN_TABLE registrations for any SQL. But my database is opened in READ ONLY mode, means that no inserts can happen.

    So, how can I generate EXPLAIN PLAN for my SQL in this State?

    You can always do: 'explain the plan in some_table@remote_database' to avoid inclusion in the local database. Unfortunately 10g added an extraction of the sequence of the code "explain plan", and that's where the call fails if you have tried this distant approach on your version.

    Here's an idea that I have not tested. If you configure a link of data to your database from production to the database read-only, you could then do a "explain plan" in the database of production for the SQL statement by changing each object reference in the SQL statement to "object@readonlydatabase". In most cases this will allow the optimizer to recognize the statement as "entirely to distance" and get the optimizer on the readonly database to create the execution plan - which will be then written into the production database.

    Concerning
    Jonathan Lewis

  • Explain the plans differ as the parameter value changes

    Hi all

    My colleague posted a similar question a few days before. Happened because of some bad index. But now we are in a strange situation.

    DB:
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    We use the query below and was working fine until 13.
    SQL> explain plan for
      2  SELECT *
      3    FROM gacc_dtl_v1  acc,
      4         gcus_dtl_v1  cus,
      5         gtxn_dtl_v1  txn
      6   WHERE txn.customer_id = cus.customer_number(+)
      7   AND txn.batch_id = cus.batch_id(+)
      8   AND txn.account_number = acc.id
      9   AND acc.batch_id = '130609'
     10   AND cus.batch_id(+) = '130609'
     11   AND txn.batch_id = '130609' AND cus.target IN ('30');
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    -------------------------------------------------------------------------------------------------------------
    Plan hash value: 566819363
    
    -------------------------------------------------------------------------------------------------------------
    | Id  | Operation                     | Name                | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT              |                     |     1 |   947 |       | 16963   (1)| 00:03:24 |
    |   1 |  NESTED LOOPS                 |                     |     1 |   947 |       | 16963   (1)| 00:03:24 |
    |*  2 |   HASH JOIN                   |                     |    41 | 26322 |  9136K| 16799   (1)| 00:03:22 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| GTXN_DTL_V1         | 31055 |  8764K|       |  2430   (1)| 00:00:30 |
    |*  4 |     INDEX RANGE SCAN          | GTXN_V1_BATCHID_NDX | 60524 |       |       |   156   (2)| 00:00:02 |
    |*  5 |    TABLE ACCESS BY INDEX ROWID| GCUS_DTL_V1         |   176K|    59M|       | 10869   (1)| 00:02:11 |
    |*  6 |     INDEX RANGE SCAN          | IDX_CUS2_V1         |   198K|       |       |   527   (2)| 00:00:07 |
    |   7 |   TABLE ACCESS BY INDEX ROWID | GACC_DTL_V1         |     1 |   305 |       |     4   (0)| 00:00:01 |
    |*  8 |    INDEX RANGE SCAN           | GACC_DTL_V1_IDX     |     1 |       |       |     3   (0)| 00:00:01 |
    -------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("TXN"."CUSTOMER_ID"="CUS"."CUSTOMER_NUMBER" AND "TXN"."BATCH_ID"="CUS"."BATCH_ID")
       3 - filter("TXN"."CUSTOMER_ID" IS NOT NULL)
       4 - access("TXN"."BATCH_ID"='130609')
       5 - filter("CUS"."TARGET"='30')
       6 - access("CUS"."BATCH_ID"='130609')
       8 - access("TXN"."ACCOUNT_NUMBER"="ACC"."ID" AND "ACC"."BATCH_ID"='130609')
           filter(SUBSTR("TXN"."ACCOUNT_NUMBER",1,3)=SUBSTR("ACC"."ID",1,3))
    
    26 rows selected.
    It shows a hash join and nested with cost 16963 loops and gives the result in 2-3 seconds. It gives the same plan to explain even now if we use batch_id = '130609'

    Now all of a sudden from yesterday it gives different explain the plan below. Only difference in the query below is the value of batch_id
    SQL> explain plan for
      2  SELECT *
      3    FROM gacc_dtl_v1  acc,
      4         gcus_dtl_v1  cus,
      5         gtxn_dtl_v1  txn
      6   WHERE txn.customer_id = cus.customer_number(+)
      7   AND txn.batch_id = cus.batch_id(+)
      8   AND txn.account_number = acc.id
      9   AND acc.batch_id = '150609'
     10   AND cus.batch_id(+) = '150609'
     11   AND txn.batch_id = '150609' AND cus.target IN ('30');
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------
    Plan hash value: 773603995
    
    --------------------------------------------------------------------------------------------------------
    | Id  | Operation                     | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT              |                        |     1 |   947 |    77   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                 |                        |     1 |   947 |    77   (0)| 00:00:01 |
    |   2 |   NESTED LOOPS                |                        |     1 |   594 |    73   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS BY INDEX ROWID| GACC_DTL_V1            |     1 |   305 |     4   (0)| 00:00:01 |
    |*  4 |     INDEX RANGE SCAN          | GACC_DTL_BATCH_ID_INDX |     1 |       |     3   (0)| 00:00:01 |
    |*  5 |    TABLE ACCESS BY INDEX ROWID| GTXN_DTL_V1            |     1 |   289 |    69   (0)| 00:00:01 |
    |*  6 |     INDEX RANGE SCAN          | IDX_TXN2_V1            |   125 |       |    12   (0)| 00:00:01 |
    |*  7 |   TABLE ACCESS BY INDEX ROWID | GCUS_DTL_V1            |     1 |   353 |     4   (0)| 00:00:01 |
    |*  8 |    INDEX RANGE SCAN           | IDX_CUS3_V1            |     1 |       |     3   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("ACC"."BATCH_ID"='150609')
       5 - filter("TXN"."CUSTOMER_ID" IS NOT NULL AND "TXN"."BATCH_ID"='150609')
       6 - access("TXN"."ACCOUNT_NUMBER"="ACC"."ID")
           filter(SUBSTR("TXN"."ACCOUNT_NUMBER",1,3)=SUBSTR("ACC"."ID",1,3))
       7 - filter("CUS"."TARGET"='30')
       8 - access("CUS"."BATCH_ID"='150609' AND "TXN"."CUSTOMER_ID"="CUS"."CUSTOMER_NUMBER")
           filter("TXN"."BATCH_ID"="CUS"."BATCH_ID")
    
    26 rows selected.
    It shows two loops nested with cost 77, but works for hours. Very very slow.. No idea what's going on...
     select i.table_name,i.index_name,index_type,c.column_name,c.column_position,e.column_expression
       from all_indexes i, all_ind_columns c,all_ind_expressions e
       where c.index_name = i.index_name
       and e.index_name(+) = i.index_name
       and i.table_name in ('GCUS_DTL_V1','GACC_DTL_V1','GTXN_DTL_V')
       order by 1,2,4
    
    TABLE_NAME     INDEX_NAME          INDEX_TYPE          COLUMN_NAME     COLUMN_POSITION     COLUMN_EXPRESSION
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    GACC_DTL_V1     GACC_DTL_BATCH_ID_INDX     NORMAL               BATCH_ID          1     
    GACC_DTL_V1     GACC_DTL_V1_IDX          NORMAL               BATCH_ID          2     
    GACC_DTL_V1     GACC_DTL_V1_IDX          NORMAL               ID               1     
    GACC_DTL_V1     GACC_DTL_V1_IDX2     FUNCTION-BASED NORMAL     SYS_NC00101$          1     SUBSTR("ID",1,3)
    GACC_DTL_V1     IDX_ACC1_V1          NORMAL               CATEGORY          1     
    GACC_DTL_V1     IDX_ACC3_V1          FUNCTION-BASED NORMAL     SYS_NC00099$          1     "CUSTOMER_NUMBER"||'.'||"LIMIT_REF"
    GACC_DTL_V1     IDX_ACC4_V1          FUNCTION-BASED NORMAL     SYS_NC00100$          1     "CUSTOMER_NUMBER"||'.000'||"LIMIT_REF"
    GACC_DTL_V1     IDX_ACC5_V1          NORMAL               POSTING_RESTRICT     1     
    GACC_DTL_V1     IDX_CUS5_V1          NORMAL               CUSTOMER_NUMBER          1     
    GACC_DTL_V1     IDX_CUS6_V1          NORMAL               LIMIT_REF          1     
    GCUS_DTL_V1     GCUS_DTL_V1_IDX1     NORMAL               CUSTOMER_NUMBER          1     
    GCUS_DTL_V1     IDX_CUS2_V1          NORMAL               BATCH_ID          1     
    GCUS_DTL_V1     IDX_CUS3_V1          NORMAL               BATCH_ID          1     
    GCUS_DTL_V1     IDX_CUS3_V1          NORMAL               CUSTOMER_NUMBER          2     
    GCUS_DTL_V1     IDX_CUS3_V1          NORMAL               INDUSTRY          4     
    GCUS_DTL_V1     IDX_CUS3_V1          NORMAL               SECTOR               3     
    GCUS_DTL_V1     IDX_CUS4_V1          FUNCTION-BASED NORMAL     SYS_NC00078$          1     SUBSTR("DATE_STAMP",1,6)
    We are also do not understand why the filter (SUBSTR ("TXN". ""»(, 1, 3) ACCOUNT_NUMBER = SUBSTR ("VAC". " ID", 1, 3)) is used in both queries.

    All tables are analyzed today.

    Please share your thoughts on this.

    Thanks in advance,
    Jac

    Jac says:

    L     H     NUM_BUCKETS     LAST_ANALYZED     SAMPLE_SIZE     HISTOGRAM
    ------------------------------------------------------------------------------------------------------------------------------------------------
    010109     311208     235     13/Jun/2009     5,343     FREQUENCY
    

    You have a histogram of frequencies on the BATCH_ID column missing at least 2 values according to your index statistics (235 buckets vs 237 separate keys).

    If the value that you use in the query is missing then this could be the explanation for the estimation of cardinality bad (since you're on pre - 10.2.0.4. In 10.2.0.4 that this behavior changes).

    The size of the sample of 5 300 lines is also very low, given the 57,000,000 lines according to the index statistics.

    You have two options (which can be combined):

    -Increase the size of the sample using a parameter explicitly estimate_percent, for example at least 10 percent

    exec DBMS_STATS. GATHER_TABLE_STATS (null, 'GACC_DTL_V1', estimate_percent-online 10, method_opt => 'FOR COLUMNS SIZE 254 BATCH_ID,' waterfall-online fake)

    -Get rid of the histogram

    exec DBMS_STATS. GATHER_TABLE_STATS (null, 'GACC_DTL_V1', method_opt-online 'FOR BATCH_ID COLUMNS SIZE 1', cascade-online fake)

    Note: Is there a particular reason why you store numbers in varchar columns? This might be the reason why Oracle believes that it must generate a histogram using the AUTO SIZE option.

    I tend to promote to remove from the histogram, but you must first verify the data if the BATCH_ID values are spread out and the histogram is reasonable:

    select
            batch_id
          , count(*)
    from
            gacc_dtl_v1
    group by
            batch_id;
    

    No constarints are at the DB level. All are processed Application level.

    Have you checked this in DBA/ALL/USER_CONSTRAINTS?

    It's also a good idea to have constraints at the level of the DB. It keeps your data consistent and quite often helps the optimizer. It allows even 10.2 and later to make things like the elimination of a join table that can make a huge difference in performance.

    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/

    Published by: Randolf Geist on June 16, 2009 11:48

    Comment added constraints

  • a sql id have more than explain the plan so I'd like to come up with plan used at runtime.

    Hi all


    In a sql oracle11g having id several explain the plan so I'd like to come up with plan used at runtime.

    For example SQlID:-8yczg5zav14vt have 5 sql plan and I want to check that we execute at any time, please let me how I can check by sql queries


    Concerning

    Ranjeet

    RanjeetSohale wrote:

    I am ok for that but active only plans is right, but in accordance with the foregoing, two data line table in the table SQL V$ so both active and plan cost is high and the other is low.

    Yes that's right cost is different, he means here another effective plan for oracle will analyze the declaration again and stored as new slider of the child. Especially since I explained that.

  • explain the plan and so on

    Hello world


    could someone please provide me with details of explained the plan and I would appreciate some related details explain plan, trace and tkprof

    Thank you
    Shareef

    Hello

    PLAN of EXPLAINING is an Oracle utility that analyzes a statement and shows the expected execution plan. It may be different from the implementation plan real for a number of reasons.

    Extended SQL trace (10046 event) is a way to gather advanced diagnostic information. There are different levels, at levels 8 and 12 provide the greatest level of detail (you will be able to see the events of waiting and the bind variable values).

    TKProf is a utility that processes the raw trace files and makes shaped the output in a more readable way. However, some experts prefer to work with trace files "gross" - they are not so difficult to read, especially if you get some practice.

    There are other events of tracing: 10053 allows you to see what is happening inside the Oracle optimizer, 10104 allows to see the stats of hash etc join.

    Best regards
    Nikolai

Maybe you are looking for