Query Optimization help

hi all,
Below are the two queries that can be optimized further as specified below:
Select MAXSUBSCRIBER,GROUPNAME,GROUPTYPE from DG.GROUPINFO_011851 where GROUPID = '011851857541'
Select MAXSUBSCRIBER,GROUPNAME,GROUPTYPE from DG.GROUPINFO_011851 where GROUPID = '011851709212'
Optimized Query
==============
Select MAXSUBSCRIBER,GROUPNAME,GROUPTYPE from DG.GROUPINFO_011851 where GROUPID IN ('011851857541','011851709212') ;
Can anyone please suggest whether the optimized query makes any difference in performance?
Regards
Pratheej

Pratheej,
When you run two similar queries that match word to word and in similar case an additional parsing is avoided by oracle.
What you should understand is what is important to you is it throughput or response time. This is where you make use of the optimizer in assisting you.
If your database optimizer is set in "CHOOSE" mode it will use the cost based optimizer and determine the cost based on the statistics generated on the tables involved else it resorts to a RULE based mode. The CBO always picks the execution path with the lowest cost.
You can make use of hints to further optmize your cost. Always ensure big tables are analyzed periodically. Also ensure that proper indexes are created for your tables.
Hope this helps you sir.
Regards,
Sumita Chand

Similar Messages

  • Reg Query Optimization - doubts..

    Hi Experts,
    This is related to Blog by Mr Prakash Darji regarding "Query Optimization" posted on Jan 26 2006.In this to optimize query Generation of Report is suggested.
    I tried this, but I am not sure I am analyzing this correctly.
    I collected Stats data before and after Generation of Report.But how to be sure that this is helping me? Did any one has tried this?
    What to look for in Stats Data - duration?
    But duration would not be absolute parameter as there is factor of "Wait Time, User", so duration may depend on this.
    Please help me in this.
    Thanks
    Gaurav
    Message was edited by: Gaurav

    Any ideas Experts?

  • SQL Server 2008R2 SP2 Query optimizer memory leak ?

    It looks like we are facing a SQL Server 2008R2 queery optimizer memory leak.
    We have below version of SQL Server
    Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
     Jun 28 2012 08:36:30
     Copyright (c) Microsoft Corporation
     Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
    The instance is set MAximum memory tro 20 GB.
    After executing a huge query (2277 kB generated by IBM SPSS Clementine) with tons of CASE and a lot of AND/OR statements in the WHERE and CASE statements and muliple subqueries the server stops responding on Out of memory in the internal pool
    and the query optimizer has allocated all the memory.
    From Management Data Warehouse we can find that the query was executed at
    7.11.2014 22:40:57
    Then at 1:22:48 we recieve FAIL_PACE_ALLOCATION 1
    2014-11-08 01:22:48.70 spid75       Failed allocate pages: FAIL_PAGE_ALLOCATION 1
    And then tons of below errors
    2014-11-08 01:24:02.22 spid87      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:02.22 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:02.22 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:02.30 Server      Error: 17312, Severity: 16, State: 1.
    2014-11-08 01:24:02.30 Server      SQL Server is terminating a system or background task Fulltext Host Controller Timer Task due to errors in starting up the task (setup state 1).
    2014-11-08 01:24:02.22 spid74      Error: 701, Severity: 17, State: 123.
    2014-11-08 01:24:02.22 spid74      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:13.22 Server      Error: 17312, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:13.22 spid87      Error: 701, Severity: 17, State: 123.
    2014-11-08 01:24:13.22 spid87      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:13.22 spid63      Error: 701, Severity: 17, State: 130.
    2014-11-08 01:24:13.22 spid63      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:13.22 spid57      Error: 701, Severity: 17, State: 123.
    2014-11-08 01:24:13.22 spid57      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:13.22 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:18.26 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:24.43 spid81      Error: 701, Severity: 17, State: 123.
    2014-11-08 01:24:24.43 spid81      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:18.25 Server      Error: 18052, Severity: -1, State: 0. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:18.25 Server      BRKR TASK: Operating system error Exception 0x1 encountered.
    2014-11-08 01:24:30.11 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:30.11 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:35.18 spid57      Error: 701, Severity: 17, State: 131.
    2014-11-08 01:24:35.18 spid57      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:35.18 spid71      Error: 701, Severity: 17, State: 193.
    2014-11-08 01:24:35.18 spid71      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:35.18 Server      Error: 17312, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:35.41 Server      Error: 17312, Severity: 16, State: 1.
    2014-11-08 01:24:35.41 Server      SQL Server is terminating a system or background task SSB Task due to errors in starting up the task (setup state 1).
    2014-11-08 01:24:35.71 Server      Error: 17053, Severity: 16, State: 1.
    2014-11-08 01:24:35.71 Server      BRKR TASK: Operating system error Exception 0x1 encountered.
    2014-11-08 01:24:35.71 spid73      Error: 701, Severity: 17, State: 123.
    2014-11-08 01:24:35.71 spid73      There is insufficient system memory in resource pool 'internal' to run this query.
    2014-11-08 01:24:46.30 Server      Error: 17312, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:51.31 Server      Error: 17053, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:51.31 Server      Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    2014-11-08 01:24:51.31 Logon       Error: 18052, Severity: -1, State: 0. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped.
    Last error message is half an hour after the inital Out of memory at 2014-11-08 01:52:54.03. Then the Instance is completely shut down
    From the memory information in the error log we can see that all the memory is consumed by the QUERY_OPTIMIZER
    Buffer Pool                                   Value
    Committed                                   2621440
    Target                                      2621440
    Database                                     130726
    Dirty                                          3682
    In IO                                            
    0
    Latched                                          
    1
    Free                                           
    346
    Stolen                                      2490368
    Reserved                                          0
    Visible                                     2621440
    Stolen Potential                                  0
    Limiting Factor                                  17
    Last OOM Factor                                   0
    Last OS Error                                     0
    Page Life Expectancy                             28
    2014-11-08 01:22:48.90 spid75     
    Process/System Counts                         Value
    Available Physical Memory                29361627136
    Available Virtual Memory                 8691842715648
    Available Paging File                    51593969664
    Working Set                               628932608
    Percent of Committed Memory in WS               100
    Page Faults                                48955000
    System physical memory high                       1
    System physical memory low                        0
    Process physical memory low                       1
    Process virtual memory low                        0
    MEMORYCLERK_SQLOPTIMIZER (node 1)                KB
    VM Reserved                                       0
    VM Committed                                      0
    Locked Pages Allocated                            0
    SM Reserved                                       0
    SM Committed                                      0
    SinglePage Allocator                       19419712
    MultiPage Allocator                             128
    Memory Manager                                   KB
    VM Reserved                               100960236
    VM Committed                                 277664
    Locked Pages Allocated                     21483904
    Reserved Memory                                1024
    Reserved Memory In Use                            0
    On the other side MDW reports that the MEMORYCLERK_SQLOPTIMIZER increases since the execution of the query up to the point of OUTOF MEMORY, but the Average value is 54.7 MB during that period as can be seen on attached graph.
    We have encountered this issue already two times (every time the critical query is executed).

    Hi,
    This does seems to me kind of memory Leak and actually it is from SQL Optimizer which leaked memory from buffer pool so much that it did not had any memory to be allocated for new page.
    MEMORYCLERK_SQLOPTIMIZER (node 1)                KB
    VM Reserved                                       0
    VM Committed                                      0
    Locked Pages Allocated                            0
    SM Reserved                                       0
    SM Committed                                      0
    SinglePage Allocator                       19419712
    MultiPage Allocator                             128
    Can you post complete DBCC MEMORYSTATUS output which was generated in errorlog. Is this the only message in errorlog or there are some more messages before and after it.
    select (SUM(single_pages_kb)*1024)/8192 as total_stolen_pages, type
    from sys.dm_os_memory_clerks
    group by typeorder by total_stolen_pages desc
    and
    select sum(pages_allocated_count * page_size_in_bytes)/1024,type from sys.dm_os_memory_objects
    group by type
    If you can post the output of above two queries with dbcc memorystaus output on some shared drive and share location with us here. I would try to find out what is leaking memory.
    You can very well apply SQL Server 2008 r2 SP3 and see if this issue subsides but I am not sure whether this is fixed or actually it is a bug.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • Reg : Query Optimization

    Hi Experts,
    I wrote this query but it takes around 7 mins to execute & fetch results.
    SELECT a.generic_part_number gpn,
           XMLAGG (XMLELEMENT (e, b.orderable_part_number || ', ')).EXTRACT ( '//text()').EXTRACT ('//text()') opn,
           a.device_description,
           LOWER (a.generic_part_number) datasheets
    FROM emsg_v2.emsg_generic_part a, emsg_v2.emsg_orderable_part b
    WHERE EXISTS (SELECT 1 FROM emsg_v2.emsg_quasi_generic_part c
           WHERE a.generic_part_id = c.generic_part_id
           AND b.quasi_generic_id = c.quasi_generic_id)
    GROUP BY a.generic_part_number,
             b.orderable_part_number,
             a.device_description,
             a.generic_part_number
    Explain Plan -
    Cost = 2K
    Bytes = 9M
    Cardinality = 97K
    Also, i can see FULL TABLE SCAN for all the 3 tables used.
    Can anybody please give me some pointers how to optimize this query?
    Help really appreciated.
    Thanks & Regards,
    Ranit B.

    You do not have an join conditions between emsg_v2.emsg_generic_part and emsg_v2.emsg_orderable_part, which is likely a big part of your problem. Without knowing your data model it looks to me like like it could be a three table join like:
    SELECT a.generic_part_number gpn,
           XMLAGG (XMLELEMENT (e, b.orderable_part_number || ', ')).EXTRACT ( '//text()').EXTRACT ('//text()') opn,
           a.device_description,
           LOWER (a.generic_part_number) datasheets
    FROM emsg_v2.emsg_generic_part a,
       JOIN emsg_v2.emsg_quasi_generic_part c
          ON a.generic_part_id = c.generic_part_id
       JOIN emsg_v2.emsg_orderable_part b
          ON b.quasi_generic_id = c.quasi_generic_id
    GROUP BY a.generic_part_number,
             b.orderable_part_number,
             a.device_description,
             a.generic_part_numberJohn

  • Any software for Query Optimization?

    Hi,
    Is there any software to be used for query Optimization
    Please help me

    3rd party tools suck (if they did not Oracle would incorporate them in its optimizer long ago). The best tools are:
    1. Gather table and index statistics
    2. Use CBO (FIRST_ROWS, ALL_ROWS)
    3. SQL*Plus AUTOTRACE
    4. EXPLAIN PLAN
    5. SET SQL_TRACE = TRUE + TKPROF
    6. Statspack
    7. Enterprise manager (new Ora10g, did not try it)
    All from Oracle...

  • The query processor ran out of stack space during query optimization. Please simplify the query

    Can you suggest me that what should i do in this case.
    Actually i am having one table that is a MasterTable.I am referring this table in more than 300 tables that means i am having foreign key of this primary key in 300+ tables.
    due to this i am getting following error during deleting any row,
    doesn't matter that data is existing in reference table or not.
    Error that i am getting is 
    "The query processor ran out of stack space during query optimization. Please simplify the query"
    Can you suggest me that what should i do to avoid this error,because i am unable to delete this entry.
    Apart from it,i am getting performance problem too,so is it due to such huge FK on it.
    Please suggest me on following points
    1. Is it worst way to handle it,if yes then please suggest me solution for it.
    2. If it is a correct way then what should i do if getting error during deleting any record.
    3. Is it right to create Foreign key on each table where i am saving data of this master. if no then how to manage integrity.
    4. What people do in huge database when they wants to create foreign key for any primary key.
    5. Can you suggest me that how DBA's are handling this in big database,where they are having huge no. of tables.

    The most common reason of getting such error is having more than 253 foreign key constraints on a table. 
    The max limit is documented here:
    http://msdn.microsoft.com/en-us/library/ms143432(SQL.90).aspx 
    Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional foreign key constraints may be expensive for the query
    optimizer to process. If you are on 32 bit, then you might want to move to 64 bit to get little bigger stack space but eventually having 300 FK is not something which would work in long run.
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • HFR - Data Query Optimization Settings

    hi
    In HFR, in a grid there are Data Query Optimization Settings, can you please help me on the settings property.
    Our report fetches data using lot of attributes. When we don't use MDX setting, it fetches very fast, but the alias doesn't come.
    However, when we use MDX setting, the alias comes, but the report takes lot of time to run(approx 1 min / row of data fetched)
    Can you please guide on the same.
    Thanks

    pm wrote:
    Hi ,
    I am working on below query optimization/Tuning.
    SELECT
    c_date,
    c1,
    c2,
    c3,
    c4,
    c5,
    c6
    FROM tab1
    WHERE
    ROWNUM <= &param
    AND ( c_date BETWEEN &date1 AND &date2 )
    AND c3 in (
    select c3
    from tab2
    where xxx='abc')
    ORDER BY c1, c_date;
    Note : &param,&date1 ,&date2 are parameters runtime getting from UI code .
    tab1 having huge data around 10lacs to crores. and it has range partition on c_date column and subpartiotion on c1 column.
    To get best throughput in less time, what i need to do ?
    Please do let me know steps to tune/optimize the sql query.Also which hint we can use on sql query to better results.
    Thanks in advanced.
    PMBefore you start worrying about performance tuning you should worry about the query being incorrect.
             WHERE
                 ROWNUM <= &param
                 AND   ( c_date BETWEEN &date1 AND &date2 )
                 AND c3 in (
                                             select c3
                                             from tab2
                                             where xxx='abc')
             ORDER BY c1, c_date;Presumably you want to limit the number of rows with the ROWNUM predicate AFTER the ORDER BY clause is applied.
    Please read this and learn how queries are actually processed, I can almost guarantee you this query is not doing what you think it is doing at present.
    http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html
    Cheers,

  • Query optimization..yet again...

    Guys,
    I need some advice yet again for tuning my query.
    The query below takes hell lots of time for execution(earlier ther performance was very much appreciable).
    SELECT 'B'||','||FD.GEO_ID||','||FD.PROD_ID||','||','||','||','||','||','||SUM(FACT_AMT_18-FACT_AMT_16)||','||NVL(FD.ISO_CRNCY_CODE_CHAR, 'USD')||','||FD.DUE_PERD||','||FD.MEASR_ID content
    FROM AGG_FACT_605 FD
    WHERE DUE_PERD = TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-3))) + 1
    AND FACT_TYPE_CODE='A8'
    AND FD.PROD_ID IN (SELECT DISTINCT DSEND_ID FROM PROD_ASSOC_DNORM WHERE CTRL_PERD='20-SEP-06' AND STRCT_CODE='722' AND PARNT_ID='000000011' AND DSEND_LVL=8 )
    AND FD.GEO_ID IN
    (SELECT DISTINCT DSEND_ID FROM GEO_ASSOC_DNORM WHERE STRCT_CODE='705' AND CTRL_PERD='02-OCT-06' AND DSEND_LVL=6
    MINUS
    SELECT DISTINCT DSEND_ID FROM GEO_ASSOC_DNORM WHERE STRCT_CODE='705' AND CTRL_PERD='02-OCT-06' AND DSEND_LVL=6 AND PARNT_ID='948')
    AND FD.MEASR_ID IN
    ('900005','900015','720000','770000','900038','900039','900031','900030')
    GROUP BY FD.GEO_ID,FD.PROD_ID,FD.ISO_CRNCY_CODE_CHAR,FD.DUE_PERD,FD.MEASR_ID
    ORDER BY FD.GEO_ID,FD.PROD_ID,FD.ISO_CRNCY_CODE_CHAR,FD.DUE_PERD,FD.MEASR_ID;
    | Id  | Operation                   |  Name                  | Rows  | Bytes | Cost  | Pstart| Pstop |
    |   0 | SELECT STATEMENT            |                        | 10546 |   628K|   377K|       |       |
    |   1 |  SORT GROUP BY              |                        | 10546 |   628K|   377K|       |       |
    |   2 |   HASH JOIN                 |                        |  9558K|   556M|   284K|       |       |
    |   3 |    VIEW                     | VW_NSO_2               |    89 |   801 |    28 |       |       |
    |   4 |     MINUS                   |                        |       |       |       |       |       |
    |   5 |      SORT UNIQUE            |                        |    89 |  1869 |       |       |       |
    |   6 |       PARTITION RANGE SINGLE|                        |       |       |       |   KEY |   KEY |
    |   7 |        INDEX FAST FULL SCAN | GEO_ASSOC_DNORM_IDX2   |    90 |  1890 |     1 |   KEY |   KEY |
    |   8 |      SORT UNIQUE            |                        |     1 |    26 |       |       |       |
    |   9 |       PARTITION RANGE SINGLE|                        |       |       |       |   KEY |   KEY |
    |  10 |        INDEX FAST FULL SCAN | GEO_ASSOC_DNORM_IDX3   |     1 |    26 |     1 |   KEY |   KEY |
    |  11 |    HASH JOIN                |                        |  6766K|   335M|   284K|       |       |
    |  12 |     VIEW                    | VW_NSO_1               |  5273 | 52730 |   235 |       |       |
    |  13 |      SORT UNIQUE            |                        |  5273 |   190K|   235 |       |       |
    |  14 |       PARTITION RANGE SINGLE|                        |       |       |       |   KEY |   KEY |
    |  15 |        INDEX FAST FULL SCAN | PROD_ASSOC_DNORM_IDX3  |  5297 |   191K|   189 |   KEY |   KEY |
    |  16 |     PARTITION RANGE ITERATOR|                        |       |       |       |     1 |     2 |
    |  17 |      TABLE ACCESS FULL      | AGG_FACT_605           |    23M|   936M|   284K|     1 |     2 |
    [\pre]
    I beleive the problem is due to full table scan on 'AGG_FACT_605' table which contains about 1395678439 records.
    If I create a partitioned table and then make use of the above query on the partioned table, what would be the best bet of column to have the partition on?
    Can I've partition on combination of column values?
    Any other advice to tune my query?
    Help me out...
    Bhagat
    Message was edited by:
            Bugs                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    First off you must have current stats gathered -- as has already been noted.
    Beyond that there are a couple of simple things that you can do.
    1) You don't need the DISTINCT clause in your sub-queries -- and it may be getting in the way of the optimizer making a bit better guesses.
    2) You don't need the MINUS in your 2nd sub-query, you can use (parnt_id IS NULL OR parnt_id='948') instead.
    Now if you're still seeing a full table scan on your fact table you need to ask what approach would be better than a full table scan. How selective is (i.e. what proportion of the data corresponds to) each of your predicates? In particular, how much of the data corresponds to:
    1) DUE_PERD = TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-3))) + 1
    2) FACT_TYPE_CODE='A8'
    3) FD.PROD_ID IN (blah)
    4) FD.GEO_ID IN (stuff)
    Hopefully at least one of those eliminates a significant proportion of your data such that an index can be used to retrieve only the relevant rows.

  • Need Query Optimization Info

    Hi Everyone:
    I have a user on my site who's trying to find information on database query optimization. She's willing to pay $3 to someone who will give her some very basic information. I figured those of you who read this forum would have something handy you could just provide to her. It's not the information she's paying for, but the service of someone retrieving it for her. Would someone take a look? You can find her request here:
    http://www.yepic.com/index.php?module=ContReq&hdnRequestID=8
    The one problem is you have to register on the site before you can post your response. You just need to give create a username, email and password, though. It's very easy. I'd appreciate someone helping one of my users out.

    . . . she's trying to avoid the
    search taxSearch tax... never heard it put that way. I guess you are trying to avoid the "search engine" tax by advertising your site here? Maybe some one will help you out by answering the request from Corey for Search Engine Optimization.

  • Oracle 11g on Linux : Query Optimization issue

    Hi guru,
    I am facing one query optimization related problem in group by query
    Table (10 million Records)
    Product(ProductId number,ProductName varchar(100),CategoryId VARCHAR2(38),SubCategoryId VARCHAR2(38))
    Index
    create index idxCategory on Product (CategoryId,SubCategoryId)
    Query1:To find product count for all CategoryId and SubCategoryId
    select CategoryId,SubCategoryId,count(*) from Product group by CategoryId,SubCategoryId
    Above query is not using index idxCategory and doing table scan which is very costly.
    When I fire Query2: select count(*) from Product group by CategoryId,SubCategoryId
    then it is properly using index idxCategory and very fast.
    Even I specified hint in Query1 but it is not using hint.
    Can anybody suggest why oracle is not using index in Query1 and what should I do so that Query1 will use Index.
    Thanks in advance.

    user644199 wrote:
    I am facing one query optimization related problem in group by query
    Query1:To find product count for all CategoryId and SubCategoryId
    select CategoryId,SubCategoryId,count(*) from Product group by CategoryId,SubCategoryId
    Above query is not using index idxCategory and doing table scan which is very costly.
    When I fire Query2: select count(*) from Product group by CategoryId,SubCategoryId
    then it is properly using index idxCategory and very fast.
    Even I specified hint in Query1 but it is not using hint.
    Can anybody suggest why oracle is not using index in Query1 and what should I do so that Query1 will use Index.The most obvious reason that the table needs to be visited would be that the columns "CategoryId" / "SubCategoryId" can be NULL but then this should apply to both queries. You could try the following to check the NULL issue:
    select CategoryId,SubCategoryId,count(*) from Product where CategoryId is not null and SubCategoryId is not null group by CategoryId,SubCategoryId
    Does this query use the index?
    Can you show us the hint you've used to force the index usage and the EXPLAIN PLAN output of the two queries including the "Predicate Information" section? Use DBMS_XPLAN.DISPLAY to get a proper output, and use the \ tag before and after when posting here to format it using fixed font. Use the "Quote" button in the message editor to see how I used the \ tag here.
    Are above queries representing the actual queries used or did you omit some predicates etc. for simplicity?
    By the way, VARCHAR2(38) and ...ID as name, are these columns storing number values?
    Regards,
    Randolf
    Oracle related stuff blog:
    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/

  • What is query optimization and how to do it.

    Hi
    What is query optimization?
    Any link can any one provide me so that i can read and learn the techniques.
    Thanks
    Elias Maliackal

    THis is an excellent place to start: When your query takes too long ...

  • How to improve the performance of the attached query, Please help

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description                    Object_owner          Object_name     Cost     Cardinality     Bytes     
    SELECT STATEMENT, GOAL = ALL_ROWS                              14     1     13
    SORT AGGREGATE                                                  1     13
    VIEW                         GEMINI_REPORTING               14     1     13
    HASH GROUP BY                                        14     1     103
    NESTED LOOPS                                        13     1     103
    HASH JOIN                                             12     1     85
    TABLE ACCESS BY INDEX ROWID     GEMINI_REPORTING     RCAMSIT          2     4     100
    NESTED LOOPS                                        9     5     325
    HASH JOIN                                        7     1     40
    SORT UNIQUE                                        2     1     18
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          SITE          2     1     18
    INDEX RANGE SCAN          GEMINI_PRIMARY          SITE_I0          1     1     
    TABLE ACCESS FULL          GEMINI_PRIMARY          SITE          3     27     594
    INDEX RANGE SCAN          GEMINI_REPORTING     RCAMSIT_I     1     1     5     
    TABLE ACCESS FULL     GEMINI_PRIMARY     CAMPAIGN                    3     127     2540
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          CAMBILLING     1     1     18
    INDEX UNIQUE SCAN     GEMINI_PRIMARY     CAMBILLING_U1                    0     1

    Hello,
    This has really nothing to do with the Oracle Forms product.
    Please, send the SQL or/and PL/SQL questions in the corresponding forums.
    Francois

  • OBIEE 11.1.1.7-Ago Function Error-[nQSError: 46008] Internal error: File server\Query\Optimizer\SmartScheduler\PhysicalRequestGenerator\Src\SQOSPMarkMultiTargetSupport.cpp

    Hi All,
    I was performing the steps mentioned in Oracle Tutorial"http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/bi/bi11115/biadmin11g_02/biadmin11g.htm#t10"-BI RPD creation.
    After Using the AGO function data in the Time series metric(Month Ago Revenue) was null always. I updated the DB features in RPD physical layers by selecting support for time series functions.
    After that report started to fail with below error. Please let me know if its a bug and any option to fix it.
    Thanks,
    Sreekanth
    Error
    View Display Error
    Odbc driver returned an error (SQLExecDirectW). 
      Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P 
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 46008] Internal error: File server\Query\Optimizer\SmartScheduler\PhysicalRequestGenerator\Src\SQOSPMarkMultiTargetSupport.cpp, line 1680. (HY000) 
    SQL Issued: SELECT 0 s_0, "Sample Sales"."Time"."Year-L1" s_1, "Sample Sales"."Revenue"."Ago-Year Revenue" s_2, "Sample Sales"."Revenue"."Revenue" s_3 FROM "Sample Sales" FETCH FIRST 65001 ROWS ONLY
      Refresh

    I know that there is no relation between "SampleApp Lite"."D3 Orders (Facts Attributes)"."Order Date", "SampleApp Lite"."D0 Time"."Calendar Date", it's also the same thing in my own RPD.
    But as it's working with the 11.1.1.6.2 BP1 version I don't understand why it's not working with 11.1.1.6.9.
    Implicit fact column is not set on my repository, but I don't have any request with only dimensional column, so if my understanding is correct I don't need to use it. Also, the problem appears during the check of the repository not in answers.
    thanks anyway

  • How to do query Optimization ,plz share any documents with real examples

    Hi All,
    could any one please provide me some informations, how can i do query optimization in oracle using Third party tool sql developer .
    i am working oracle 10g version,please share with me if any documents or ppt like that.
    Thanks
    Krupa

    879534 wrote:
    Hi All,
    could any one please provide me some informations, how can i do query optimization in oracle using Third party tool sql developer .SQL Developer is Oracle's development tool, not a third party tool.
    Questions about using SQL Developer should go in the SQL Developer forum:
    SQL Developer
    I'll move the question there for you.

  • Regarding Query Optimization

    Hi Gurus,
    I am preparing for an interview. I need to know about Query Optimization, explain plan, Cost analysis.
    Can anyone please give me some reference link or site where i can get step by step details for the above..
    It would be really helpfull.
    Thanks in advance..
    Ameya.

    RTFM [url http://oraclesvca2.oracle.com/docs/cd/B10501_01/server.920/a96533/toc.htm]Performance Tuning Guide and Reference

Maybe you are looking for

  • File sender adapter not reading

    Hi experts, We're getting an issue with the File sender channels in our system. None of the files we place in the source directory is read by our channels. These channels are NFS. We've already gave all permissions to SO user <sysid>ADM. The CC monit

  • System upgrade agetty issue

    I executed a complete system upgrade yesterday.  Now when I attempt to login in (through the terminal, not graphically) it allows me to enter my username and then instead of prompting for a password it immediately reports "incorrect password" about f

  • Speller for estonian language

    Hei When will ms release speller, dictionary and swipe keyboard for all languages for example estonian. We have localised os and office for years. How hard can it be?

  • Auto Increment Sequence Custom Field

    Hi All, I was wondering if it is possible to have a custom field defined as an auto incrementing sequence number?  E.g. Let's say I go in and create a project for the first time, this field will show the value 1.  The next project I go to create, the

  • Inconsistent Adobe Dynamic Link clip corruption in Premiere Pro (All CS5)

    So I'm working towards having seventeen AE compositions in a video I'm cutting with Premiere. I was chugging along just fine until most, but not all, of my clips started showing this strange diagonal line business. When I drag the timeline over the c