How to setup a query plan in effective at any time for SP or SQL query?

I have a SP which include a group by SQL statement. It retrieve data from a couple of tables which are over 1G size,
When I run this SP at first time, it take more than 5 minutes to get the result. then I run it again and again, Finally, it become very quick, I can get the result within second.
Not sure why. I guess it is because of query plan.
How to make it running at first time to get result within second? How to force a better best query plan in effective at first time to run the query?
If the engine has better plan in memory, could it be lost at some point? because I have the complain from end user said some times it is fast, sometime it is very slow.
How to resolve this problem?

thanks, kevin. Here is the pesudo query( I modify table name as business rule from my company). you are right, mytab3 is a lookup table.
Select d.stock,i.description,c.categoryname,
Round(IsNull(Sum(d.qty),0),2) AS qty,
From mytab1 d,mytab2 s,invent i,mytab3 c       
Where
d.stock != 'param1'
And d.id1 = s.id1    --id1: univarchar(11)        
And i.code = c.code   --code:univarchar(2)         
And d.stock = i.stock  --stock: univarchar(12)           
And i.code2 = d.code2  --code2: univarchar(2)
And d.code2 = 'param2'
And s.id2 = 'param3'   --id2: univarchar(6)
Group By  c.categoryname,d.stock,i.description
Order By d.stock
here is the query plan when run this query:
The command completed with no results returned
QUERY PLAN FOR STATEMENT 1 (at line 1).
Executed in parallel by coordinating process and 4 worker processes.
    STEP 1
        The type of query is SELECT (into Worktable1).
        GROUP BY
        Evaluate Grouped SUM OR AVERAGE AGGREGATE.
        Evaluate Grouped SUM OR AVERAGE AGGREGATE.
        Evaluate Grouped SUM OR AVERAGE AGGREGATE.
        Executed in parallel by coordinating process and 4 worker processes.
        FROM TABLE
            mytab2
            s
        Nested iteration.
        Index : ind_mytab2 _id2
        Forward scan.
        Positioning by key.
        Keys are:
            id2  ASC
        Executed in parallel with a 4-way hash scan.
        Using I/O Size 16 Kbytes for index leaf pages.
        With LRU Buffer Replacement Strategy for index leaf pages.
        Using I/O Size 16 Kbytes for data pages.
        With LRU Buffer Replacement Strategy for data pages.
        FROM TABLE
            mytab1
            d
        Nested iteration.
        Index : ind_det_inv
        Forward scan.
        Positioning by key.
        Keys are:
            id1  ASC
        Using I/O Size 16 Kbytes for index leaf pages.
        With LRU Buffer Replacement Strategy for index leaf pages.
        Using I/O Size 16 Kbytes for data pages.
        With LRU Buffer Replacement Strategy for data pages.
        FROM TABLE
            invent
            i
        Nested iteration.
        Using Clustered Index.
        Index : invent_pk
        Forward scan.
        Positioning by key.
        Keys are:
            stock  ASC
            code2  ASC
        Using I/O Size 2 Kbytes for data pages.
        With LRU Buffer Replacement Strategy for data pages.
        FROM TABLE
            mytab3
            c
        Nested iteration.
        Table Scan.
        Forward scan.
        Positioning at start of table.
        Using I/O Size 2 Kbytes for data pages.
        With LRU Buffer Replacement Strategy for data pages.
        TO TABLE
            Worktable1.
        Parallel work table merge.
    STEP 2
        The type of query is INSERT.
        The update mode is direct.
        Executed by coordinating process.
        Worktable2 created, in allpages locking mode, for ORDER BY.
        FROM TABLE
            Worktable1.
        Nested iteration.
        Table Scan.
        Forward scan.
        Positioning at start of table.
        Using I/O Size 8 Kbytes for data pages.
        With MRU Buffer Replacement Strategy for data pages.
        TO TABLE
            Worktable2.
    STEP 3
        The type of query is SELECT.
        Executed by coordinating process.
        This step involves sorting.
        FROM TABLE
            Worktable2.
        Using GETSORTED
        Table Scan.
        Forward scan.
        Positioning at start of table.
        Using I/O Size 8 Kbytes for data pages.
        With MRU Buffer Replacement Strategy for data pages.
Total estimated I/O cost for statement 1 (at line 1): 1409882.
The sort for Worktable2 is done in Serial

Similar Messages

  • How to get the time for executing an SQL statement?

    hi all...
    How can I get the total execution time for a given SQL statement to a ViewObject which is created dynamically for this SQL so that the end user knows it before hand and try to stop it or go further..?
    Please post any ideas if you have got..!!!
    thanx in advance..
    grüss
    K°vi

    This is not really a question for the JDeveloper forum, but rather for the DB forum.
    Since Oracle9i there is a way to estimate how long a query will take, before executing it.
    Check it out in the Oracle DB documentation or ask on the DB forum.
    There is no built-in functionality for this in JDeveloper, but you should be able to call out to the DB from your Java code to get the estimate.

  • How to setup the WRT350N to use a USB NTFS Drive for backup storage?

    My network consists of a WRT350N Router/AP/NAS (with a 500GB NTFS formatted USB drive), a Windows Vista Ultimate Desktop (wired connection), a Windows Pro SP2 Desktop (wired connection) and a Windows Pro SP2 Laptop (wireless connection).
    Does anyone know what settings to use for the WRT350N and how to setup each of the computers to allow me to use the WRT350N for Backup file Storage?
    For example: Can I/should I enable and use the ftp server functions?  Can I just use the guest user account for all logins; etc.?  Do I have to reformat the USB Drive to FAT32?
    Any help would be appreciated!

    Here is the clue to your question.
    1.If you have formatted your Disk with the help of your computer it will be better if you reformat it with the "Erase" button
    available on the Storage Tab of the Linksys
    router's Setup page.
    2.After that You need to make sure that you have
    public IP address as your WAN IP on the status of the router to setup a FTP server.
    3.You can use guest account for all your users but
    please make sure that you select guest as group
    while creating user.

  • How do I select more than one message at a time for archiving

    I want to archive multiple messages into one archive folder. How do I select more than one message at a time?

    Really appreciate the help. Many thanks

  • How do I stop my iPhone highlighting events dates any times?

    How do I stop my iPhone highlighting events, dates and times in web pages, notes and just about anything I do with text. I'm sure I have seen the setting somewhere. But can't find it now despite looking hard for it. I don 't see it in the iPhone manual either. Even worse than the existence of this intrusive highlighting is it's light yellow link colour that makes the text difficult to read.

    Settings> Mail, Contacts, Calendars> change the Sync setting in the Calendars section to All Events.

  • How to setup ODBC query with schema

    I am trying to setup DIAdem to query a SQLserver database that was orginally created by Rockwell's Historian (a PLC database). This database is structured around a schema called "RSBizWare". To properly query the database, this schema name must be in the naming structure. I have been attemping to use some of the SQL examples posted in this forum but I cannot figure out how to include this schema field. Any help would ba appreciated.
    Thanks

    Hi RandallW,
    You have two options, you can set up a Windows ODBC Administrator profile that successfully applies the required schema, then use the DIAdem ODBC functions, which all start with SQL_...(), or you can construct an ADO connection string which successfully applies the required schema, the use native Windows ADO objects in a VBScript to query the data base.  If both are available, and you have DIAdem 10.1 or higher, I would recommend the ADO approach.  I really don't know how to tell you to apply this schema in your connection to your data base.  Do you have any other software that can connect to that data base?  There may be information on connecting to that data base available on the web.  Once you can connect to it, we can help you use that connection in DIAdem.
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • How to setup a query filter?

    I'm trying to run the query cards method using a queryfilter object[][]. Can someone provide a working example of the filter. What I'm using below is throwing a SQL error:
    SQL Open Error (0x80040e21): SELECT DISTINCT C.OBJECTID, C.NAME, C.LASTMODIFIED, C.IMAGEUUID, C.URL1, C.URL2, C.URL3, C.URL4, FC.FOLDERID FROM PTCARDS C, PTFOLDERCARDS FC, PTCARDSECURITY CS, PTVGROUPMEMBERSHIP GM1, PTFOLDERSECURITY FS, PTVGROUPMEMBERSHIP GM2 WHERE C.CRAWLERID = ? AND C.OBJECTID = FC.CARDID AND FC.CARDSTATE = 2 AND C.OBJECTID = CS.OBJECTID AND CS.GROUPID = GM1.GROUPID AND GM1.USERID = ? AND FC.FOLDERID = FS.OBJECTID AND FS.GROUPID = GM2.GROUPID AND GM2.USERID = ? ADO Error: count = 1, return code = 0x80040e21 Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. (SQL State (null))
    object[][] aQuery = {
    new object[] {PT_PROPIDS.PT_PROPID_NAME},
    new object[] {PT_FILTEROPS.PT_FILTEROP_CONTAINS},
    new object[] {"Presentation"}
    IPTQueryResult pResult = pCatalog.QueryCards(PT_CLASSIDS.PT_CRAWLER_ID,203,false,false,PT_PROPIDS.PT_PROPID_NAME | PT_PROPIDS.PT_PROPID_LASTMODIFIED | PT_PROPIDS.PT_PROPID_OBJECTID | PT_PROPIDS.PT_PROPID_FOLDER_PATH | PT_PROPIDS.PT_PROPID_CARD_PARENTFOLDERID | PT_PROPIDS.PT_PROPID_IMAGEUUID,null,0,100,aQuery);

    I'm trying to run the query cards method using a queryfilter object[][]. Can someone provide a working example of the filter. What I'm using below is throwing a SQL error:
    SQL Open Error (0x80040e21): SELECT DISTINCT C.OBJECTID, C.NAME, C.LASTMODIFIED, C.IMAGEUUID, C.URL1, C.URL2, C.URL3, C.URL4, FC.FOLDERID FROM PTCARDS C, PTFOLDERCARDS FC, PTCARDSECURITY CS, PTVGROUPMEMBERSHIP GM1, PTFOLDERSECURITY FS, PTVGROUPMEMBERSHIP GM2 WHERE C.CRAWLERID = ? AND C.OBJECTID = FC.CARDID AND FC.CARDSTATE = 2 AND C.OBJECTID = CS.OBJECTID AND CS.GROUPID = GM1.GROUPID AND GM1.USERID = ? AND FC.FOLDERID = FS.OBJECTID AND FS.GROUPID = GM2.GROUPID AND GM2.USERID = ? ADO Error: count = 1, return code = 0x80040e21 Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. (SQL State (null))
    object[][] aQuery = {
    new object[] {PT_PROPIDS.PT_PROPID_NAME},
    new object[] {PT_FILTEROPS.PT_FILTEROP_CONTAINS},
    new object[] {"Presentation"}
    IPTQueryResult pResult = pCatalog.QueryCards(PT_CLASSIDS.PT_CRAWLER_ID,203,false,false,PT_PROPIDS.PT_PROPID_NAME | PT_PROPIDS.PT_PROPID_LASTMODIFIED | PT_PROPIDS.PT_PROPID_OBJECTID | PT_PROPIDS.PT_PROPID_FOLDER_PATH | PT_PROPIDS.PT_PROPID_CARD_PARENTFOLDERID | PT_PROPIDS.PT_PROPID_IMAGEUUID,null,0,100,aQuery);

  • How to setup AT&T U-Verse Pace 5031NV Gateway router for Remote Web Access?

    The Pace 5031NV Gateway router is not UPnP able.
    logged into the router
    http://192.168.1.254/xslt?PAGE=C_3_1b_POST&NEXTPAGE=C_3_1b_POST I defined "Firewall Application Profile Definition "Windows Server 2012 RWA"
      I did NOT select an Application Type
    Windows Home Server 2011 required port 80 forwarding but the instructions for Windows Server 2012 r2 refers only to port 443.  Then the wizard attempts to setup RWA and returns two red errors   One refers to posts 443 and 80 so I added 80
    port forwarding.  I believe 80 is for http and 443 is for https.  following is the error screen shot after retrying with both ports forwarded.
    I can also say that I had no success trying to do the same with Windows Home Server 2011 and the 2Wire AT&T U-Verse gateway modem though there are a number of forums with discussion about this.  But now I have the newest ATT gateway modem from Pace.   
    Does anyone use RWA with AT&T U-Verse? 
    Eric Robert Lewis, Ph.D.

    Hi,
    Before you manually configure the router to forward the required ports to Windows Server Essentials, did you
    assign the server a static IP address
    by DHCP reservation of an IP address or by assigning an IP address that is outside of the DHCP address range? Just a confirmation, thanks for your understanding.
    Please refer to following articles and check if can help you.
    Windows
    Server 2012 Essentials: Router Setup
    Configure a Router - Windows Server Essentials
    By the way, if you select “I want to skip the listed issues for now and run the wizard again later”
    option and click Close button, then type RWA website in IE, can you access RWA website successfully? Or get any error message?
    If any update, please feel free to let me know.
    Hope this helps.
    Best regards,
    Justin Gu

  • How can I cancel my plan when none of the avenues for cancelling that you say you provide are actually provided/available to me?

    I want to cancel my plan now.

    This is a user to user Forum, so you are not really addressing Adobe here, even though some Adobe employees thankfully have been dropping by.
    Maybe you should try
    Contact Customer Care

  • HT204088 how to report a problem -i have been charged several times for a purchase of single app

    i have been charged several times for purchase a single app!!

    Welcome to the Apple Community.
    Select the content which is causing a problem and use the 'Report a problem' button in Your Purchase History on your computer.
    Currently, if your purchase happens to be your most recent purchase you will not be redirected to the report form, in this case use the report a problem option from the invoice that was emailed to you.

  • How can I make the message date appear with the time for unread messages?

    Mail systems I am moving from display the date & time with the messages. I need this displayed to determine aging and importance of received mail. When archiving/saving old mail it helps filing mail off and not duplicate archived messages.

    Thunderbird displays time and date for all messages except for the present day messages. The time only is displayed for today and the date is appended at midnight.

  • How do I get help if I was billed 3 times for the same album?

    I purchased an album this morning and was charged 3 times on my bank statement but my iTunes account says I only have one order #.

    If you just purchased it this morning I assume the charges are still pending on your account. I have seen in the past where iTunes has done multiple authorizations but only one charges actually posts to the account.
    Apple won't be able to do anything until the charges actually post, but it wouldn't hurt to contact them and let them know what happened: http://www.apple.com/support/contact

  • How to setup the security based on roles in Organization.

    Hi,
    How to setup the security based on roles in Organization.
    For example:Few users are Manager and a few user are Non Manager .Manager should have access to all work data including Non Manager and Non Manager should access based role.How to setup this? How OBI server identify the user role?
    kindly let me know.
    Regards.,
    CHR

    Hi,
    You need to have Back End support to achieve this. In Back End you need to create two groups . You need to know what joins has to be made for which group (which is more important) and also make session variable for the userrole (with SQL supporting it). In the BMM layer, we need to put the security join conditions in the 'where clause'.
    And make a common report. User loggin in with the respective userid will have userrole and joins assigned in the Back end. And they will be viewing the report according to their access.
    Hope this will solve your problem.
    Regards
    MuRam

  • How to setup CCMS with Solution Manager

    Hi, All
    My question is how to setup or satallite connection with Solution manager 4.0 for CCMS alerts
    Is that RFC connection using both sites, trusted and satellite system ?
    I would like to setup CCMS alerts through Solution manager and R/3 ccms
    please anyone has some guide or URL or any idea send me
    We are using SAP NW 2004 620 4.6C (SLD=DV,QA,PR) and solution manager 4.0
    Thanks in advanced
    J
    Edited by: issue2008 on Sep 19, 2008 12:13 PM

    you need to install CCMS agents(sapccm4x, sapccmsr) on satellite systems & configure them with the central system(solman).

  • How to setup System propterty in 10g EM

    Can anyone tell me how to setup System property in 10g EM or any system config file?
    My existing application has following code to access System property:
    this.logDir = System.getProperty("ServletLogDirectory");
    My current application server is oas 4.0. I am upgrading the application from oas 4.0 to 10g.
    Thanks in advance
    Don

    On the OAS Control's OC4J section, there is a place you can set the OC4J instance server settings. You can create certain number of JVMs and their runtime properties.

Maybe you are looking for

  • Nokia 5800 Settings

    My Nokia 5800 has all the settings from Vodafone NZ on it and most of them work ok, I have also added wireless LAN, the settings I have are: WLAN VF NZ Internet (INTERNET) VF NZ PXT (MMS) VF NZ Gateway (WAP) The problem I have is that when I check my

  • Importing to Adobe photoshop Elements 9 from copier

    When I bought Elements 9 I was told I could import my photo's from my copier.  Don't see how to do this import.  I had Photoshop 5 and had no problems it was right there in import.

  • Exchange Server 2013 cannot connect to Shell getting error Message

    New-PSSession : ******* Connecting to remote server ki-edm-vsrv-01 failed with the following error message : [************,TimeStamp=2014-03-18 3:05:46 PM] Access is denied. For more information, see the about_Remote_Troubleshooting Help topic. At li

  • How to download previously purchased CS6 to new computer

    I purchased CS6 for design and web in 2012 on the web and want to download it on my new computer. I went to www.adobe.com/go/getserial and put in my serial number, but it was denied. Please help. Thanks!

  • Auto Select Clip with playhead

    Hopefully this will be an easy query to answer. I would like to have premiere auto select a clip on the timeline via the playhead position. Eg: if I'm using the up & down arrows to go to next and previouse edit, I want the clips to auto select when t