How to optimize the mentioned SQL Query

Hi,
I have a query like this:
SELECT XYZ.B1, XYZ.B2 FROM
SELECT * from A where ( A.C1 IN ( 0,1,2,3,4 ) ) AND ( A.C2 IN ( 1,2 ) )
AND (( A.C3 =15 ) and (A.C4 = 0 or A.C5 = 0)) AND A.C6 >= TO_DATE('2002-01-01
06:30:00', 'YYYY-MM-DD HH24:MI:SS') AND A.CP < 376137 ORDER BY A.CP DESC) XYZ
WHERE ROWNUM < 602
WHERE A.CP is the primary key and also the primary indexing is on that A.CP.
I have around 4 lakhs record in the Table A. The query is taking more than
2 minutes to execute on my m/c.
My basic requirement is to read last 602 records from A with CP less than
376137 plus matching other criteria mentioned in the query. It will be highly
grateful if someone provides with a much optimal query to perform the task.
TIA,
Tuhin

Hi John,
Thanks for the Response.
Below is explain plan you have asked for.
select AlmEvtTbl.AlmEvtId, AlmEvtTbl.AlmType, AlmEvtTbl.ComponentId,
          AlmEvtTbl.TimeStamp, AlmEvtTbl.Severity, AlmEvtTbl.State,
AlmEvtTbl.Category,          AlmEvtTbl.CauseType, AlmEvtTbl.CauseCode,
AlmEvtTbl.UnitType, AlmEvtTbl.UnitId,          AlmEvtTbl.UnitName,
AlmEvtTbl.ServerName, AlmEvtTbl.StrParam, AlmEvtTbl.ParentCustId,
          AlmEvtTbl.ExtraParam1, AlmEvtTbl.ExtraParam2, AlmEvtTbl.ExtraParam3,
AlmEvtTbl.ExtraStrParam, AlmEvtTbl.SrcIPAddress,          AlmEvtTbl.DestIPAddress,
AlmEvtTbl.DestPort, AlmEvtTbl.SessionDir,           AlmEvtTbl.CustomerId,
AlmEvtTbl.ProfileId, AlmEvtTbl.ParentProfileId, AlmEvtTbl.CustomerName
from
(select AlmEvtSysPeView.* from AlmEvtSysPeView where (
AlmEvtSysPeView.Severity IN ( 0,1,2,3,4 ) ) and ( AlmEvtSysPeView.State
IN ( 1,2 ) ) and (( AlmEvtSysPeView.Category =3 or
AlmEvtSysPeView.Category =14 ) and (AlmEvtSysPeView.Customerid = 0 or
AlmEvtSysPeView.ParentCustId = 0)) and AlmEvtSysPeView.TimeStamp >=
TO_DATE('2002-01-01 06:30:00', 'YYYY-MM-DD HH24:MI:SS') and
AlmEvtSysPeView.AlmEvtId < 376137 order by AlmEvtSysPeView.almevtid desc)
almevttbl where rownum < 202
call count cpu elapsed disk query current rows
Parse 1 0.02 0.02 0 0 0 0
Execute 2 0.01 0.01 0 0 0 0
Fetch 2 7.61 85.03 19469 1848476 2153 201
total 5 7.64 85.06 19469 1848476 2153 201
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 77 (SKAGARWAL)
Rows Row Source Operation
201 COUNT STOPKEY
201 VIEW
201 SORT ORDER BY STOPKEY
306899 NESTED LOOPS OUTER
306900 NESTED LOOPS OUTER
306900 TABLE ACCESS BY INDEX ROWID ALMEVTTBL
374210 INDEX RANGE SCAN (object id 205151)
306899 INDEX UNIQUE SCAN (object id 205144)
306899 TABLE ACCESS BY INDEX ROWID ALMEVTPETBL
613798 INDEX UNIQUE SCAN (object id 205146)
Rows Execution Plan
0 SELECT STATEMENT GOAL: CHOOSE
201 COUNT (STOPKEY)
201 VIEW
201 SORT (ORDER BY STOPKEY)
306899 NESTED LOOPS (OUTER)
306900 NESTED LOOPS (OUTER)
306900 TABLE ACCESS (BY INDEX ROWID) OF 'ALMEVTTBL'
374210 INDEX (RANGE SCAN) OF 'ALMEVTTBL_PK' (UNIQUE)
306899 INDEX (UNIQUE SCAN) OF 'ALMEVTIDSURLTBL_PK' (UNIQUE)
306899 TABLE ACCESS (BY INDEX ROWID) OF 'ALMEVTPETBL'
613798 INDEX (UNIQUE SCAN) OF 'ALMEVTPETBL_PK' (UNIQUE)
Thanks,
Tuhin
Hi Tuhin,
You haven't posted the EXPLAIN PLAN for the query -
that would be useful.
400,000 records isn't a lot and 2 minuets seems a
long time.
The first thing I'd try is creating (and analysing)
an index on C6 - see if that helps.
d.

Similar Messages

  • How to find the backend  SQL query of the JSP page in OIC

    Does anybody how the best way to find the backend SQL QUERY of OIV JSP page?

    How To Generate Trace Files in in HTML/JSP (using Profile Option)
    •     • Note: This requires proper responsibility to set SQL Initialization statement using Profile option.      
         Step 1.     Login to the desired Form application.     
         Step 2.     Select +Profile >> System ('Find System Profile Values' screen will pop up)     
         Step 3.     Check 'User' and Type in the Username (in which the account for that user will be trace)     
         Step 4.     Type 'Initialization%' in the Profile box and Hit 'Find' (Click here for preview.)     
         Step 5.     In the User box, type the following statement and Hit 'Save' (Click here for preview)
         BEGIN FND_CTL.FND_SESS_CTL('','','TRUE','TRUE','','ALTER SESSION SET TRACEFILE_IDENTIFIER = TESTING MAX_DUMP_FILE_SIZE = 5000000 EVENTS ='||''''||' 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12'||'''');END;     
         Note:     specify any name you like to identify your trace, in this case, testing is the end name on the trace. You can also specify the amount of data allowable to be in the trace, in this case, 5000000 is the amount set. Make sure you hit 'Save' afterwards.[Quotes in the statement are all 'Single' quotes.]
              specifying TRACEFILE_IDENTIFIER value is mandatory when setting up the trace using the above profile option value
         Step 6.     Login to HTML / JSP page with username/password and start your flow. (Everything you do once login to HTML / JSP will get trace.)     
         Step 7.     Logout of HTML / JSP application once you completed with your flow.      
         Step 8.     Go back to the Profile option in the Form application and delete the Initialization SQL statement, and Hit 'Save'.     
         Step 9.     Log in to the database server or login server and retrieve your trace file.
         Identify and retrieve the trace file using the tracefile_identifier specified in Step 5.
         In this case the tracefile_identifier is “TESTING”. (Click here for Trace file locations) *     
         Note:     If you need to regenerate your trace or tracing a new flow, then repeat Step 1 to Step 8. To avoid self-confusion, choose a different name for your trace identifier everytime you set to trace.     
         Step 10.     See TKPROF section on how to format trace file into readable text.
         Trace Options Definition
         No Trace          Tracing is not activated
         Activities will not get traced.
         Regular Trace
         (Level 1)          Contains SQL, execution statistics, and execution plan.
         Provides execution path, row counts as well as produces smallest flat file.
         Trace with Binds
         (Level 4)          Regular Trace plus value supplied to SQL statement via local variables.
         Trace with Waits
         (Level 8)          Regular Trace plus database operation timings that the SQL waited to have done in order to complete, i.e. disk access.
         Trace with Binds and Waits
         (Level 12)          Regular trace with both waits and binds information.
         Contains the most complete information and will produce the largest trace file.
    ****Send me an email to [email protected],I will share the document with you.

  • How to obtain the transformed SQL query using SEM_MATCH

    Dear all,
    Is it possible to get the transformed relational SQL query when using the SEM_MATCH prefix, by querying directly on the database. We are able to obtain the relational SQL query using Joseki/Jena, however this is not the way to go for us. We would like (if possible) to get it straight from the oracle database by logging or something.
    Kind regards.
    Max

    Hi Max,
    Just to clarify. What SEM_MATCH prefix are you talking about?
    A SEM_MATCH based query is indeed a SQL query as SEM_MATCH is a SQL table function. So if you don't want to go through Java APIs or web service endpoint, then running SEM_MATCH directly should give you what you need. Or maybe you just want to see the underlying generated (from SEM_MATCH) SQL query. If that is true, can you please tell us why?
    Thanks,
    Zhe Wu

  • MultiProvider: How to decipher the underlying SQL query

    Hello Guys,
    I have joined 2 cubes using MultiProvider. I created a query which takes Key Figure values from both cubes. When I go to "Display SQl Query", I see 2 separare queries for each cube separately. I don't see a join between them.
    If I have to write the same query directly in ABAP, then how should I go about it?
    Also any idea what does the statement below means..I see this in every MultiProvider query
    STAR_TRANSFORMATION FACT( &TABLE& ) &SUBSTITUTE LITERALS&

    Hello:
    - You could never write a BI query in ABAP - that is not a real possibility, don't bother trying this, it's not reasonable (sorry).
    - MultiProvider is a Union operation, not a Join.  Queries against to a MultiProvider are split into sub-queries, where joins are performed on the tables of a cube, then the subqueries are merged in a Union operation.
    - You can see more information about the SQL in RSRT (including a MultiProvider explain)
    - STAR_TRANSFORMATION is a feature of the Oracle RDBMS, where the optimizer recognizes that the join operation against the tables in a star schema (InfoCube) can be more efficiently performed using a special technique, as opposed to ordinary join operations (like you might see in an OLTP system).  The optimizer automatically uses STAR_TRANSFORMATION to ensure that efficient joins are executed.
    Thanks for any points you choose to assign (the way of saying thanks in SDN).
    Best Regards -
    Ron Silberstein
    SAP

  • How to fetch the executed sql query in publisher

    hi.. like in obiee from manage session we can fetch the sql query similarly how can we fetch the query in BI publisher

    This may help you:
    http://gerardnico.com/wiki/bip/log
    Cheers
    Nico

  • How can i track the all sql/query executed from application

    How we can track all sql/query that has executed or being executing on oracle database server 10g r2.
    regards
    Prabhaker

    select s.sid,
           s.status,
           s.process,
           s.osuser,
           a.sql_text,
           p.program
    from v$session s,
         v$sqlarea a,
         v$process p
    where s.sql_hash_value = a.hash_value
      and s.sql_address    = a.address
      and s.paddr          = p.addr
      and s.schemaname     = '&1'
      and s.status         = 'ACTIVE'

  • How to compare result from sql query with data writen in html input tag?

    how to compare result
    from sql query with data
    writen in html input tag?
    I need to compare
    user and password in html form
    with all user and password in database
    how to do this?
    or put the resulr from sql query
    in array
    please help me?

    Hi dejani
    first get the user name and password enter by the user
    using
    String sUsername=request.getParameter("name of the textfield");
    String sPassword=request.getParameter("name of the textfield");
    after executeQuery() statement
    int exist=0;
    while(rs.next())
    String sUserId= rs.getString("username");
    String sPass_wd= rs.getString("password");
    if(sUserId.equals(sUsername) && sPass_wd.equals(sPassword))
    exist=1;
    if(exist==1)
    out.println("user exist");
    else
    out.println("not exist");

  • Re: How to converting from PL/SQL query to T-SQL query

    How to converting from PL/SQL query to T-SQL query... Its Urgent

    Download the
    SQL Server Migration Assistant for Oracle.  It will convert whole Oracle databases, or single queries or PL/SQL stored procedures.
    With caution that If your database is using Collation which is case sensitive SSMA will not work.SSMA doesnt guarantees 100% for conversion of Queries/stored proc /database if it fails to do so for some queries you will have to do it manually.
    But you can try
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Combine multiple web services with the same SQL query into one

    Hello,
    I would like to ask a question regarding combine multiple similar web services into one. Can you please tell me if it is possible to combine 4-5 web services into one since they built on the same SQL query with 5 different criterias or condition so that the user can enter any of the 5 criterias to populate the data on the form instead of having 5 different web services?
    e.g Query: Select appName, permit#, address, phone, description, type, section, from table where appName = can be 'appName, permit#, address, phone, or description' to populate the rest of the data to the form.
    Does any one have ever done some thing like this in Workbench ES? If so please assist. I know it can be easier to build it in Visual Basic, C#, or dot.net but the requirement is to build it in workbench ES.
    Thanks in advance,
    Han Dao

    If you are querying for Name, PhoneNumber, and SSN, and you queried for all people with a phone number that started with 867, you would have a potentially long list of people.  So to keep track of all of the people, we store each record in XML complex elements.  The root node is just any name you want, and the repeating element is the complex element name. 
    So using the example from above, I'm going to specify the following:
         Root Node: Result
         Repeating Element: Person
    So now when I do a query, my resultXML will look like:
    <Result>
          <Person>
                 <Name>Alex</Name>
                 <PhoneNumber>867-5309</PhoneNumber>
                 <SSN>111-11-1111</SSN>
          </Person>
    </Result>
    If your query returned multiple results (like ours would probably), it would look like:
    <Result>
          <Person>
                 <Name>Alex</Name>
                 <PhoneNumber>867-5309</PhoneNumber>
                 <SSN>111-11-1111</SSN>
          </Person>
          <Person>
                 <Name>Han</Name>
                 <PhoneNumber>867-2169</PhoneNumber>
                 <SSN>222-22-2222</SSN>
          </Person>
    </Result>
    So Result and Person is just to give a little bit of structure to the xml result (containers really).  So you can name them whatever is helpful for you.
    The column name mappings map the query columns (Name, PhoneNumber, SSN) to some node in the XML (Name, PhoneNumber, SSN).  So you don't need to specify which field maps to what in the form.  Just copy the column names to the element name so you have a 1-to-1 naming.  If you want to manipulate the XML a bit though, you could do:
    Column Name               Element
    Name                            YourName
    PhoneNumber                Phone
    SSN                              Secret
    which would then make your xml look like:
    <Result>
          <Person>
                 <YourName>Alex</YourName>
                 <Phone>867-5309</Phone>
                 <Secret>111-11-1111</Secret>
          </Person>
    </Result>
    It lets you change the XML element names to whatever you want. Otherwise by default they take on their column names.
    In your form, you could bind to the WSDL through the Data Connections pane and point it to your web service.  This will then create form elements that you can just drag and drop allowing you to have the information available when the service gets ran.  Once the service is called, you can modify the field's data to get whatever information you need in order to populate other form fields. 
    If that is too confusing, feel free to send me your form (e-mail is on profile page) and I'll add comments to it to show you how to set up the form for the web service call (and also give me the link to your webservice)

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • Extracting the Logical sql query for the specified report  in OBIEE 11g

    Hi ,
    I want to extract the logical SQL Query for the Particular report in OBIEE 11.1.1.5.
    Any pointers related to this will be very helpful.
    Thanks,
    Sonali

    for a try please add Logical sql view to ur report it will dispaly the Logical sql for that Report..
    Hope it will helps you.

  • Can we implement the custom sql query in CR for joining the two tables

    Hi All,
    Is there anyway to implement the custom sql query in CR for joining the two tables?
    My requirement here is I need to write sql logics for joining the two tables...
    Thanks,
    Gana

    In the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
    Log on to your data source if necessary.
    Under your data source, double-click the Add Command node.
    In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
    For example:
    SELECT
        Customer.`Customer ID`,
        Customer.`Customer Name`,
        Customer.`Last Year's Sales`,
        Customer.`Region`,
        Customer.`Country`,
        Orders.`Order Amount`,
        Orders.`Customer ID`,
        Orders.`Order Date`
    FROM
        Customer Customer INNER JOIN Orders Orders ON
            Customer.`Customer ID` = Orders.`Customer ID`
    WHERE
        (Customer.`Country` = 'USA' OR
        Customer.`Country` = 'Canada') AND
        Customer.`Last Year's Sales` < 10000.
    ORDER BY
        Customer.`Country` ASC,
        Customer.`Region` ASC
    Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
    Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
    For more information about creating parameters, see To create a parameter for a command object.
    Click OK.
    You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
    Note:
    To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
    By default, your command is called Command. You can change its alias by selecting it and pressing F2.

  • Changing the JCA SQL query in runtime

    Hi,
    Is it possible to change the predefined sql query in JCA during runtime in OSB.
    Regards,
    Abdul

    Abdul,
    It won't be possible as structure of request and response is tightly coupled with the SQL and any update in SQL may also require corresponding update in XSD.
    Regards,
    Anuj

  • How to shrink the MS SQL 2005 Databse.

    how to shrink the ms sql server 2005 databse on windows 2003 server?

    What's the filling level of the database?
    Markus

  • What Option Allows Permanent Change of Query in the Show SQL Query Window?

    I am trying to create a report in Crystal Reports v8.5 (or v10).  I would like to create the report by simply cutting and pasting an SQL query from SQL Designer into the appropriate place in Crystal Reports.  I can paste the query into the "Show SQL Query" window, but it reverts back to something else.  What Option do I change to allow me to do that, i.e, change the query in the "Show SQL Query" window?

    Hi Alan,
    In CR10 there is no option to past SQL qurety in Show Sql command option.  There is another option provided 'Add Commad' to execute customized SQL queries.  After connecting to your datasource before selecting tables you can choose Add Command option and past your SQL queries.
    Also you can modify the queries which you have pasted in add command.
    Thanks,
    Sastry

Maybe you are looking for