Help with slow running query

Hi,
I am having some performance problems on OBIEE dashboards so I am trying to figure out what is going wrong by looking at the query being generated.
I have spent time simplifying the query down to a very basic select statement, and trying to see why it still takes about ~5 seconds to run. See the following explain plan:
SQL> explain plan for
  2  select count(distinct CASES_FACT.CASE_KEY) as CASE_COUNT
  3    from
  4         COMPSTAT_CASES_DIM CASES_DIM /* Dim - COMPSTAT_CASES_DIM */ ,
  5         COMPSTAT_CASES_FACT CASES_FACT /* Fact - COMPSTAT_CASES_FACT */
  6   where (    CASES_FACT.CASE_KEY = CASES_DIM.CASE_KEY  );
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 372393383
| Id  | Operation              | Name            | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT       |                 |     1 |    12 |       |  2741   (3)| 00:00:33 |
|   1 |  SORT GROUP BY         |                 |     1 |    12 |       |            |          |
|*  2 |   HASH JOIN            |                 |   925K|    10M|    15M|  2741   (3)| 00:00:33 |
|   3 |    INDEX FAST FULL SCAN| CASE_KEY        |   909K|  5327K|       |   674   (3)| 00:00:09 |
|   4 |    INDEX FAST FULL SCAN| CASES_FACT_IDX4 |   925K|  5421K|       |   466   (4)| 00:00:06 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
   2 - access("CASES_FACT"."CASE_KEY"="CASES_DIM"."CASE_KEY")
16 rows selected.We have the indexes on the columns being joined on, and it appears to use a fast full scan on that index, but still the query takes about 5 seconds to run, just for this very simple query. When I add the rest of the joins and conditions that are in the actual OBIEE query, it's more like a 15 second query. It needs to be much faster.
Any ideas? Btw I am not a DBA or tuning expert, simply an OBIEE developer that was tasked with fixing this performance.
Thanks.

both tables have ~1M rows so no much choice. Assuming the dim table has unique index, nest loop join is usually faster. try the two sql below to see any improvement
select /*+ use_nl(a b) */ count(distinct a.CASE_KEY)
from COMPSTAT_CASES_FACT a,
inner join COMPSTAT_CASES_DIM b on b.CASE_KEY = a.CASE_KEY
select /*+ use_nl(a b) */ count(*)
from (select distinct CASE_KEY from COMPSTAT_CASES_FACT) a
inner join COMPSTAT_CASES_DIM b on b.CASE_KEY = a.CASE_KEY
;

Similar Messages

  • Need help tuning slow running query

    Need help tuning below two Oracle queries:
    Query #1:
    ======================
    SELECT "WORK_ORDER_FACT_ALL_YESTERDAY"."WORK_ORDER_HISTORY_ID",
    "WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_NUMBER",
    "ACCOUNT_DIM"."ACCOUNT_NUMBER", "ACCOUNT_DIM"."ACCOUNT_WS_DISC_DATE"
    FROM "CDWD"."WORK_ORDER_FACT_ALL_YESTERDAY" "WORK_ORDER_FACT_ALL_YESTERDAY",
    "CDWD"."ACCOUNT_DIM" "ACCOUNT_DIM"
    WHERE (SUBSTR ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_FIRST_NAME", 1, 1) =
    SUBSTR ("ACCOUNT_DIM"."ACCOUNT_FIRST_NAME", 1, 1)
    AND (SUBSTR ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_LAST_NAME", 1, 4) =
    SUBSTR ("ACCOUNT_DIM"."ACCOUNT_LAST_NAME", 1, 4)
    AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_DL_NUMBER" =
    "ACCOUNT_DIM"."ACCOUNT_DL_NUMBER"
    AND "WORK_ORDER_FACT_ALL_YESTERDAY"."WO_TYPE_CODE" IN ('25', '27')
    AND ("ACCOUNT_DIM"."REVENUE_TYPE_ID" = 1)
    AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."TRANSFER_COUNT" = 0)
    AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."WINBACK_ADD_COUNT" = 0)
    AND ("ACCOUNT_DIM"."ACCOUNT_WS_ENTRY_DATE" <
    (TO_DATE ('2006.05.02', 'yyyy.mm.dd') - 11
    AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."IS_DERIVED" = 0)
    AND ("ACCOUNT_DIM"."EXPIRATION_DATE" IS NULL)
    AND ("WORK_ORDER_FACT_ALL_YESTERDAY"."ACT_ACCOUNT_TYPE_CD" <> '50');
    Query #2
    ==================
    UPDATE work_order_fact_all_yesterday g
    SET returns_count = 1
    WHERE EXISTS (SELECT 1
    FROM (SELECT a.phone_dim_key AS transactional_phone_dim_key,
    b.mdn_number AS transactional_mdn_number,
    b.account_number AS transactional_account_number
    FROM work_order_fact_all_yesterday a INNER JOIN phone_dim b ON a.phone_dim_key = b.phone_dim_key
    WHERE a.gross_deactivations_count = 1) e
    INNER JOIN (SELECT c.phone_dim_key AS historical_phone_dim_key,
    d.mdn_number AS historical_mdn_number,
    d.account_number AS historical_account_number
    FROM (SELECT phone_dim_key
    FROM work_order_activity_fact
    WHERE gross_adds_count = 1
    AND report_date >= :b1 - 66
    AND NVL (is_derived, 0 ) = 0
    UNION
    SELECT phone_dim_key
    FROM work_order_fact_all_yesterday
    WHERE gross_adds_count = 1
    AND is_derived = 0) c
    INNER JOIN phone_dim d ON c.phone_dim_key = d.phone_dim_key ) f
    ON e.transactional_mdn_number = f.historical_mdn_number
    AND e.transactional_account_number = f.historical_account_number
    WHERE e.transactional_phone_dim_key = g.phone_dim_key)
    AND g.gross_deactivations_count = 1
    AND g.account_revenue_type_id = 1;
    I ran the DBMS_SQLTUNE on it for 10g and did not get any advice. How can I tune the above queries? Thanks!

    Tune the SQL? Looking at the join criteria of SUBSTR("WORK_ORDER_FACT_ALL_YESTERDAY"."ACCOUNT_FIRST_NAME", 1, 1) = SUBSTR ("ACCOUNT_DIM"."ACCOUNT_FIRST_NAME", 1, 1) and other substrings, it seems to me that you have basic flaws in your relation design.
    Column must be atomic values. Having to extract a sub-set value from a column to create the intelligence needed to join to another table - that is just plain wrong in relation design. Never mind the performance impact and overheads it causes in the database.

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • [8i] Need help with SLOW query

    First, I'm working in 8i.
    Here's some sample data:
    -- this table actually has ~175 cols and ~40K rows
    CREATE TABLE     PART_1
    (     part_nbr     CHAR(25)     NOT NULL
    ,     lead_time     NUMBER(3)
    INSERT INTO     PART_1
    VALUES     ('ABC-100',2);
    INSERT INTO     PART_1
    VALUES     ('ABC-105G',4);
    INSERT INTO     PART_1
    VALUES     ('11-205-32',6);
    INSERT INTO     PART_1
    VALUES     ('RMS1109',8);
    INSERT INTO     PART_1
    VALUES     ('ABC-1',10);
    -- this table actually has ~40 cols and ~700K rows (SELECT COUNT(*) FROM REQS takes a good 30 sec to a min to run)
    CREATE TABLE     REQS_1
    (     comp_part_nbr     CHAR(25)
    ,     ord_nbr          CHAR(10)
    ,     sub_nbr          CHAR(3)
    ,     qty_reqd     NUMBER(13,4)
    ,     qty_issued     NUMBER(13,4)
    ,     date_reqd     DATE
    INSERT INTO     REQS_1
    VALUES     ('ABC-100','0000000110','001',10,0,TO_DATE('08/24/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('ABC-100','0000000200','001',10,0,TO_DATE('08/31/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('ABC-105G','0000000110','001',5,0,TO_DATE('08/24/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('ABC-105G','0000000200','001',5,0,TO_DATE('08/31/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('11-205-32','0000000110','001',10,0,TO_DATE('08/24/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('11-205-32','0000000200','001',10,0,TO_DATE('08/31/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('RMS1109','0000000110','001',30,0,TO_DATE('08/24/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('RMS1109','0000000200','001',30,0,TO_DATE('08/31/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('ABC-1','S000000025','001',1,0,TO_DATE('09/09/2010','mm/dd/yyyy'));
    INSERT INTO     REQS_1
    VALUES     ('ABC-1','S000000025','002',1,0,TO_DATE('09/16/2010','mm/dd/yyyy'));
    -- these are all the columns in the table, though there are many more rows
    CREATE TABLE     CALT
    (     clndr_dt     DATE     NOT NULL
    ,     clndr_yr     NUMBER(4)
    ,     work_day     NUMBER(3)
    ,     work_dt          DATE
    ,     work_wk          NUMBER(2)
    ,     work_yr          NUMBER(4)
    ,     work_days     NUMBER(5)
    ,     clndr_days     NUMBER(6)
    INSERT INTO CALT VALUES (TO_DATE('08/01/2010','mm/dd/yyyy'),2010,0, TO_DATE('07/30/2010','mm/dd/yyyy'),31,2010,1729,5121);
    INSERT INTO CALT VALUES (TO_DATE('08/02/2010','mm/dd/yyyy'),2010,149, TO_DATE('08/02/2010','mm/dd/yyyy'),31,2010,1730,5122);
    INSERT INTO CALT VALUES (TO_DATE('08/03/2010','mm/dd/yyyy'),2010,150, TO_DATE('08/03/2010','mm/dd/yyyy'),31,2010,1731,5123);
    INSERT INTO CALT VALUES (TO_DATE('08/04/2010','mm/dd/yyyy'),2010,151, TO_DATE('08/04/2010','mm/dd/yyyy'),31,2010,1732,5124);
    INSERT INTO CALT VALUES (TO_DATE('08/05/2010','mm/dd/yyyy'),2010,152, TO_DATE('08/05/2010','mm/dd/yyyy'),31,2010,1733,5125);
    INSERT INTO CALT VALUES (TO_DATE('08/06/2010','mm/dd/yyyy'),2010,153, TO_DATE('08/06/2010','mm/dd/yyyy'),31,2010,1734,5126);
    INSERT INTO CALT VALUES (TO_DATE('08/07/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/06/2010','mm/dd/yyyy'),31,2010,1734,5127);
    INSERT INTO CALT VALUES (TO_DATE('08/08/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/06/2010','mm/dd/yyyy'),32,2010,1734,5128);
    INSERT INTO CALT VALUES (TO_DATE('08/09/2010','mm/dd/yyyy'),2010,154, TO_DATE('08/09/2010','mm/dd/yyyy'),32,2010,1735,5129);
    INSERT INTO CALT VALUES (TO_DATE('08/10/2010','mm/dd/yyyy'),2010,155, TO_DATE('08/10/2010','mm/dd/yyyy'),32,2010,1736,5130);
    INSERT INTO CALT VALUES (TO_DATE('08/11/2010','mm/dd/yyyy'),2010,156, TO_DATE('08/11/2010','mm/dd/yyyy'),32,2010,1737,5131);
    INSERT INTO CALT VALUES (TO_DATE('08/12/2010','mm/dd/yyyy'),2010,157, TO_DATE('08/12/2010','mm/dd/yyyy'),32,2010,1738,5132);
    INSERT INTO CALT VALUES (TO_DATE('08/13/2010','mm/dd/yyyy'),2010,158, TO_DATE('08/13/2010','mm/dd/yyyy'),32,2010,1739,5133);
    INSERT INTO CALT VALUES (TO_DATE('08/14/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/13/2010','mm/dd/yyyy'),32,2010,1739,5134);
    INSERT INTO CALT VALUES (TO_DATE('08/15/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/13/2010','mm/dd/yyyy'),33,2010,1739,5135);
    INSERT INTO CALT VALUES (TO_DATE('08/16/2010','mm/dd/yyyy'),2010,159, TO_DATE('08/16/2010','mm/dd/yyyy'),33,2010,1740,5136);
    INSERT INTO CALT VALUES (TO_DATE('08/17/2010','mm/dd/yyyy'),2010,160, TO_DATE('08/17/2010','mm/dd/yyyy'),33,2010,1741,5137);
    INSERT INTO CALT VALUES (TO_DATE('08/18/2010','mm/dd/yyyy'),2010,161, TO_DATE('08/18/2010','mm/dd/yyyy'),33,2010,1742,5138);
    INSERT INTO CALT VALUES (TO_DATE('08/19/2010','mm/dd/yyyy'),2010,162, TO_DATE('08/19/2010','mm/dd/yyyy'),33,2010,1743,5139);
    INSERT INTO CALT VALUES (TO_DATE('08/20/2010','mm/dd/yyyy'),2010,163, TO_DATE('08/20/2010','mm/dd/yyyy'),33,2010,1744,5140);
    INSERT INTO CALT VALUES (TO_DATE('08/21/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/20/2010','mm/dd/yyyy'),33,2010,1744,5141);
    INSERT INTO CALT VALUES (TO_DATE('08/22/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/20/2010','mm/dd/yyyy'),34,2010,1744,5142);
    INSERT INTO CALT VALUES (TO_DATE('08/23/2010','mm/dd/yyyy'),2010,164, TO_DATE('08/23/2010','mm/dd/yyyy'),34,2010,1745,5143);
    INSERT INTO CALT VALUES (TO_DATE('08/24/2010','mm/dd/yyyy'),2010,165, TO_DATE('08/24/2010','mm/dd/yyyy'),34,2010,1746,5144);
    INSERT INTO CALT VALUES (TO_DATE('08/25/2010','mm/dd/yyyy'),2010,166, TO_DATE('08/25/2010','mm/dd/yyyy'),34,2010,1747,5145);
    INSERT INTO CALT VALUES (TO_DATE('08/26/2010','mm/dd/yyyy'),2010,167, TO_DATE('08/26/2010','mm/dd/yyyy'),34,2010,1748,5146);
    INSERT INTO CALT VALUES (TO_DATE('08/27/2010','mm/dd/yyyy'),2010,168, TO_DATE('08/27/2010','mm/dd/yyyy'),34,2010,1749,5147);
    INSERT INTO CALT VALUES (TO_DATE('08/28/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/27/2010','mm/dd/yyyy'),34,2010,1749,5148);
    INSERT INTO CALT VALUES (TO_DATE('08/29/2010','mm/dd/yyyy'),2010,0, TO_DATE('08/27/2010','mm/dd/yyyy'),35,2010,1749,5149);
    INSERT INTO CALT VALUES (TO_DATE('08/30/2010','mm/dd/yyyy'),2010,169, TO_DATE('08/30/2010','mm/dd/yyyy'),35,2010,1750,5150);
    INSERT INTO CALT VALUES (TO_DATE('08/31/2010','mm/dd/yyyy'),2010,170, TO_DATE('08/31/2010','mm/dd/yyyy'),35,2010,1751,5151);
    INSERT INTO CALT VALUES (TO_DATE('09/01/2010','mm/dd/yyyy'),2010,171, TO_DATE('09/01/2010','mm/dd/yyyy'),35,2010,1752,5152);
    INSERT INTO CALT VALUES (TO_DATE('09/02/2010','mm/dd/yyyy'),2010,172, TO_DATE('09/02/2010','mm/dd/yyyy'),35,2010,1753,5153);
    INSERT INTO CALT VALUES (TO_DATE('09/03/2010','mm/dd/yyyy'),2010,173, TO_DATE('09/03/2010','mm/dd/yyyy'),35,2010,1754,5154);
    INSERT INTO CALT VALUES (TO_DATE('09/04/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/03/2010','mm/dd/yyyy'),35,2010,1754,5155);
    INSERT INTO CALT VALUES (TO_DATE('09/05/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/03/2010','mm/dd/yyyy'),36,2010,1754,5156);
    INSERT INTO CALT VALUES (TO_DATE('09/06/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/03/2010','mm/dd/yyyy'),36,2010,1754,5157);
    INSERT INTO CALT VALUES (TO_DATE('09/07/2010','mm/dd/yyyy'),2010,174, TO_DATE('09/07/2010','mm/dd/yyyy'),36,2010,1755,5158);
    INSERT INTO CALT VALUES (TO_DATE('09/08/2010','mm/dd/yyyy'),2010,175, TO_DATE('09/08/2010','mm/dd/yyyy'),36,2010,1756,5159);
    INSERT INTO CALT VALUES (TO_DATE('09/09/2010','mm/dd/yyyy'),2010,176, TO_DATE('09/09/2010','mm/dd/yyyy'),36,2010,1757,5160);
    INSERT INTO CALT VALUES (TO_DATE('09/10/2010','mm/dd/yyyy'),2010,177, TO_DATE('09/10/2010','mm/dd/yyyy'),36,2010,1758,5161);
    INSERT INTO CALT VALUES (TO_DATE('09/11/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/10/2010','mm/dd/yyyy'),36,2010,1758,5162);
    INSERT INTO CALT VALUES (TO_DATE('09/12/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/10/2010','mm/dd/yyyy'),37,2010,1758,5163);
    INSERT INTO CALT VALUES (TO_DATE('09/13/2010','mm/dd/yyyy'),2010,178, TO_DATE('09/13/2010','mm/dd/yyyy'),37,2010,1759,5164);
    INSERT INTO CALT VALUES (TO_DATE('09/14/2010','mm/dd/yyyy'),2010,179, TO_DATE('09/14/2010','mm/dd/yyyy'),37,2010,1760,5165);
    INSERT INTO CALT VALUES (TO_DATE('09/15/2010','mm/dd/yyyy'),2010,180, TO_DATE('09/15/2010','mm/dd/yyyy'),37,2010,1761,5166);
    INSERT INTO CALT VALUES (TO_DATE('09/16/2010','mm/dd/yyyy'),2010,181, TO_DATE('09/16/2010','mm/dd/yyyy'),37,2010,1762,5167);
    INSERT INTO CALT VALUES (TO_DATE('09/17/2010','mm/dd/yyyy'),2010,182, TO_DATE('09/17/2010','mm/dd/yyyy'),37,2010,1763,5168);
    INSERT INTO CALT VALUES (TO_DATE('09/18/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/17/2010','mm/dd/yyyy'),37,2010,1763,5169);
    INSERT INTO CALT VALUES (TO_DATE('09/19/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/17/2010','mm/dd/yyyy'),38,2010,1763,5170);
    INSERT INTO CALT VALUES (TO_DATE('09/20/2010','mm/dd/yyyy'),2010,183, TO_DATE('09/20/2010','mm/dd/yyyy'),38,2010,1764,5171);
    INSERT INTO CALT VALUES (TO_DATE('09/21/2010','mm/dd/yyyy'),2010,184, TO_DATE('09/21/2010','mm/dd/yyyy'),38,2010,1765,5172);
    INSERT INTO CALT VALUES (TO_DATE('09/22/2010','mm/dd/yyyy'),2010,185, TO_DATE('09/22/2010','mm/dd/yyyy'),38,2010,1766,5173);
    INSERT INTO CALT VALUES (TO_DATE('09/23/2010','mm/dd/yyyy'),2010,186, TO_DATE('09/23/2010','mm/dd/yyyy'),38,2010,1767,5174);
    INSERT INTO CALT VALUES (TO_DATE('09/24/2010','mm/dd/yyyy'),2010,187, TO_DATE('09/24/2010','mm/dd/yyyy'),38,2010,1768,5175);
    INSERT INTO CALT VALUES (TO_DATE('09/25/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/24/2010','mm/dd/yyyy'),38,2010,1768,5176);
    INSERT INTO CALT VALUES (TO_DATE('09/26/2010','mm/dd/yyyy'),2010,0, TO_DATE('09/24/2010','mm/dd/yyyy'),39,2010,1768,5177);
    INSERT INTO CALT VALUES (TO_DATE('09/27/2010','mm/dd/yyyy'),2010,188, TO_DATE('09/27/2010','mm/dd/yyyy'),39,2010,1769,5178);
    INSERT INTO CALT VALUES (TO_DATE('09/28/2010','mm/dd/yyyy'),2010,189, TO_DATE('09/28/2010','mm/dd/yyyy'),39,2010,1770,5179);
    INSERT INTO CALT VALUES (TO_DATE('09/29/2010','mm/dd/yyyy'),2010,190, TO_DATE('09/29/2010','mm/dd/yyyy'),39,2010,1771,5180);
    INSERT INTO CALT VALUES (TO_DATE('09/30/2010','mm/dd/yyyy'),2010,191, TO_DATE('09/30/2010','mm/dd/yyyy'),39,2010,1772,5181);First, if I run
    DEFINE     days_out = 10
         SELECT     p.part_nbr
         ,     p.lead_time
         ,     r.date_reqd     
         ,     c2.clndr_dt               AS order_by
         FROM     REQS_1 r
         ,     PART_1 p
         ,     CALT c
         ,     CALT c2
         WHERE     p.part_nbr                    = r.comp_part_nbr
         AND     TRUNC(r.date_reqd)               = TRUNC(c.clndr_dt)
         AND     c2.work_days                    = c.work_days     - p.lead_time
         AND     c2.work_day                    <> 0
    --     AND     c2.clndr_dt                    <= SYSDATE + &days_outagainst my real data, I get:
    117969 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=RULE
       1    0   NESTED LOOPS
       2    1     NESTED LOOPS
       3    2       MERGE JOIN
       4    3         SORT (JOIN)
       5    4           TABLE ACCESS (FULL) OF 'CALT'
       6    3         SORT (JOIN)
       7    6           TABLE ACCESS (FULL) OF 'REQS_1'
       8    2       TABLE ACCESS (BY INDEX ROWID) OF 'PART_1'
       9    8         INDEX (RANGE SCAN) OF 'PART_1_PK' (UNIQUE)
      10    1     TABLE ACCESS (BY INDEX ROWID) OF 'CALT'
      11   10       INDEX (RANGE SCAN) OF 'CALT_IX4' (NON-UNIQUE)
    Statistics
              0  recursive calls
            323  db block gets
         997239  consistent gets
          34095  physical reads
              0  redo size
        9858097  bytes sent via SQL*Net to client
         550791  bytes received via SQL*Net from client
           7866  SQL*Net roundtrips to/from client
              0  sorts (memory)
              2  sorts (disk)
         117969  rows processed
    timing for: query_timer
    Elapsed: 00:00:58.69The problem is, if I un-comment out the last line of the query, it basically doesn't run. With my full query, I've gotten 'no more room in the temp space' type errors, or else it takes hours to run. My big problem is that I can't seem to get just the explain plan for the query (with that last line not commented out). In order for me to successfully be able to view an explain plan, I have to just set autotrace on, which means the query has to run first before I get the explain plan. That doesn't work so well when the query takes hours to run (if at all)....
    Does anyone have any suggestions for me?

    And, I took out the TRUNC() on both sides after I verified that the real data was always midnight for both, and it worked fine. I'm honestly not sure why I put it there in the first place (I started working on this query quite some time ago).
    Here's the new results (against my real data):
    117968 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=RULE
       1    0   NESTED LOOPS
       2    1     NESTED LOOPS
       3    2       NESTED LOOPS
       4    3         TABLE ACCESS (FULL) OF 'REQS_1'
       5    3         TABLE ACCESS (BY INDEX ROWID) OF 'CALT'
       6    5           INDEX (RANGE SCAN) OF 'CALT_IX3' (NON-UNIQUE)
       7    2       TABLE ACCESS (BY INDEX ROWID) OF 'PART_1'
       8    7         INDEX (RANGE SCAN) OF 'PART_1_PK' (UNIQUE)
       9    1     TABLE ACCESS (BY INDEX ROWID) OF 'CALT'
      10    9       INDEX (RANGE SCAN) OF 'CALT_IX4' (NON-UNIQUE)
    Statistics
              0  recursive calls
              4  db block gets
        1489048  consistent gets
          26244  physical reads
              0  redo size
        9936605  bytes sent via SQL*Net to client
         550791  bytes received via SQL*Net from client
           7866  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         117968  rows processed
    timing for: query_timer
    Elapsed: 00:01:58.30It took longer. But, I don't see a merge join anymore...

  • Slow running query after upgrading to Oracle 10.2.0.4

    Hello
    I had posted a query in Database Upgrade section , but all in vian as i have had no replies . So i am posing this in general section as i can now confirm with the exact query issue .
    1. I upgraded my oracle instance windows 64 bit from 10.2.0.1 to 10.2.0.4
    2. All is good except when i use SUM or MAX in queries i get a very slow performance below is the complete example
    Your help is much appreciated .
    Regards
    Harshad
    =====================================================================================================
    Example.
    =====================================================================================================The query runs on a single table of 275,000,000 records, partitioned by Feed_Id in 53 partitions:-
    SELECT *
    FROM Fact_Life
    WHERE Life_Id = 11555269
    AND Feed_Id = 2;
    This returns 18 rows in sub-second response time.
    Explain Plan for it:-
    SELECT *
    FROM Fact_Life
    WHERE Life_Id = 11555269
    AND Feed_Id = 2;
    Statement Id=3 Type=INDEX
    Cost=938 TimeStamp=11-06-09::11::25:55
    (1) SELECT STATEMENT ALL_ROWS
    Est. Rows: 66 Cost: 940
    (4) PARTITION RANGE SINGLE
    Est. Rows: 66 Cost: 940
    (3) TABLE TABLE ACCESS BY GLOBAL INDEX ROWID RDS.FACT_LIFE [Analyzed]
    Blocks: 2,765,931 Est. Rows: 66 of 275,979,985 Cost: 940
    (2) INDEX INDEX SKIP SCAN RDS.PIX_FTLE_1 [Analyzed]
    Est. Rows: 3 Cost: 938
    However, when the query employs an aggregate function:-
    SELECT MAX(Cap_Period_Id)
    FROM Fact_Life
    WHERE Life_Id = 11555269
    AND Feed_Id = 2;
    This takes anything from 200-400 seconds to return.
    Explain plan for it:-
    SELECT MAX(CAP_Period_Id)
    FROM Fact_Life
    WHERE Life_Id = 11555269
    AND Feed_Id = 2;
    Statement Id=3 Type=PARTITION RANGE
    Cost=7 TimeStamp=11-06-09::11::26:50
    (1) SELECT STATEMENT ALL_ROWS
    Est. Rows: 1 Cost: 7
    (5) SORT AGGREGATE
    Est. Rows: 1
    (4) FIRST ROW
    Est. Rows: 66 Cost: 7
    (3) PARTITION RANGE SINGLE
    Est. Rows: 66 Cost: 7
    (2) INDEX INDEX RANGE SCAN (MIN/MAX) RDS.PIX_FTLE_1 [Analyzed]
    Est. Rows: 66 Cost: 7
    However when the query is run with a different Life_Id for the same partition:-
    SELECT MAX(Cap_Period_Id)
    FROM Fact_Life
    WHERE Life_Id = 11555275
    AND Feed_Id = 2;
    Returns sub-second.
    Explain plan for it:-
    SELECT MAX(CAP_Period_Id)
    FROM Fact_Life
    WHERE Life_Id = 11555275
    AND Feed_Id = 2;
    Statement Id=3 Type=PARTITION RANGE
    Cost=7 TimeStamp=11-06-09::11::29:29
    (1) SELECT STATEMENT ALL_ROWS
    Est. Rows: 1 Cost: 7
    (5) SORT AGGREGATE
    Est. Rows: 1
    (4) FIRST ROW
    Est. Rows: 66 Cost: 7
    (3) PARTITION RANGE SINGLE
    Est. Rows: 66 Cost: 7
    (2) INDEX INDEX RANGE SCAN (MIN/MAX) RDS.PIX_FTLE_1 [Analyzed]
    Est. Rows: 66 Cost: 7
    Is this a problem with b-tree indexes? The Life_Id is allocated from a sequence and there are 67,535,682 rows in the partition. The stats are up to date.
    =====================================================================================================
    =====================================================================================================

    Hello Randolf,
    Sorry for the late reply was down with flue and could not mail , as mentioned i below is the DDL for PIX_FTLE_1 & PIX_FTLE_2 . I have used TOAD to extract the script.
    As i cant send the both the DDL in single post i will send it in 2 post , There is a limit of 30000 characters in sigle post .
    Thanks once again for your help .
    Regards
    Harshad
    CREATE INDEX RDS.PIX_FTLE_1 ON RDS.FACT_LIFE
    (FEED_ID, CAP_PERIOD_ID, LIFE_ID, ISO_CURRENCY_ID, LIFE_SCD_ID)
    TABLESPACE RDS_TABLESPACE01
    INITRANS 2
    MAXTRANS 255
    LOGGING
    GLOBAL PARTITION BY RANGE (FEED_ID) (
    PARTITION HA1 VALUES LESS THAN (2)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 1225M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION NU6 VALUES LESS THAN (3)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 2761M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION FP1 VALUES LESS THAN (4)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 971M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION PRU VALUES LESS THAN (5)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 993M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION GAC VALUES LESS THAN (6)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 622M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION NU3 VALUES LESS THAN (7)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 2136M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION LEG VALUES LESS THAN (8)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 847M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RSC VALUES LESS THAN (9)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 144M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SW1 VALUES LESS THAN (10)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 80M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION PRI VALUES LESS THAN (11)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 34M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION BAL VALUES LESS THAN (12)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION NA1 VALUES LESS THAN (13)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION MID VALUES LESS THAN (14)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION EGS VALUES LESS THAN (15)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION ARK VALUES LESS THAN (16)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 1088M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SKA VALUES LESS THAN (17)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 136M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION NU1 VALUES LESS THAN (18)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 196M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SK2 VALUES LESS THAN (19)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 9M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION CU1 VALUES LESS THAN (20)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 11M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION DLI VALUES LESS THAN (21)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION AEG VALUES LESS THAN (22)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION COM VALUES LESS THAN (23)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION CU2 VALUES LESS THAN (24)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION CUL VALUES LESS THAN (25)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION EAG VALUES LESS THAN (26)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION FP2 VALUES LESS THAN (27)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION HAG VALUES LESS THAN (28)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION HAL VALUES LESS THAN (29)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION JRA VALUES LESS THAN (30)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION LEL VALUES LESS THAN (31)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION MGA VALUES LESS THAN (32)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION MGM VALUES LESS THAN (33)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION NU2 VALUES LESS THAN (34)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION PEG VALUES LESS THAN (35)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RLM VALUES LESS THAN (36)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RL2 VALUES LESS THAN (37)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RL3 VALUES LESS THAN (38)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RL4 VALUES LESS THAN (39)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RL5 VALUES LESS THAN (40)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION BG4 VALUES LESS THAN (41)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION BG5 VALUES LESS THAN (42)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RS2 VALUES LESS THAN (43)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RS3 VALUES LESS THAN (44)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION RS4 VALUES LESS THAN (45)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SA1 VALUES LESS THAN (46)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SAF VALUES LESS THAN (47)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SCA VALUES LESS THAN (48)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SL1 VALUES LESS THAN (49)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SL2 VALUES LESS THAN (50)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SPI VALUES LESS THAN (51)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION SWP VALUES LESS THAN (52)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION VDL VALUES LESS THAN (53)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 240M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION ZUR VALUES LESS THAN (54)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION AR3 VALUES LESS THAN (55)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 360M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION ZZZ VALUES LESS THAN (MAXVALUE)
    NOLOGGING
    NOCOMPRESS
    TABLESPACE RDS_TABLESPACE01
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    NOPARALLEL;

  • Help with the problem query

    Hi,
    I have another query running slow when executed from cognos. It is also not returning any output continues to execute,
    with "Union15" as (
    select distinct CASE WHEN(substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end  IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 1, 4)||case substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END "QUARTER", "EES_ENERGY_MASTER"."PAT_KEY" "Cases_Using_Energy", 0 "Total_Cases"
    from "MDM_DBA"."EES_ENERGY_MASTER" "EES_ENERGY_MASTER", "MDM_DBA"."EES_CONS_PROV" "EES_CONS_PROV"
    where "EES_ENERGY_MASTER"."DISC_MON">=2006101 and "EES_ENERGY_MASTER"."PDCT_CAT"='Energy' and substr("EES_ENERGY_MASTER"."ICD_CODE", 1, 2)='68-gyn' and "EES_ENERGY_MASTER"."MANUFACTURER"='EES' and "EES_CONS_PROV"."CONS_06_09_YN" in ('N', 'Y') and "EES_ENERGY_MASTER"."PROV_ID"="EES_CONS_PROV"."PROV_ID" union 
    select CASE WHEN(substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end  IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4)||case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END "QUARTER", 0 "Cases_Using_Energy", count("MVW_EES_ICD_STATS"."CASES") "Total_Cases"
    from "MDM_DBA"."MVW_EES_ICD_STATS" "MVW_EES_ICD_STATS", "MDM_DBA"."EES_CONS_PROV" "EES_CONS_PROV", "MDM_DBA"."EES_HOSP_CHG_PROV" "EES_HOSP_CHG_PROV"
    where "MVW_EES_ICD_STATS"."DISC_QTR">=20061 and "MVW_EES_ICD_STATS"."ICD_GROUP"='68-gyn' and "EES_CONS_PROV"."CONS_06_09_YN" in ('N', 'Y') and "EES_HOSP_CHG_PROV"."PDCT_CAT"='Energy' and "EES_HOSP_CHG_PROV"."MANUFACTURER"='EES' and "MVW_EES_ICD_STATS"."PROV_ID"="EES_CONS_PROV"."PROV_ID" and "MVW_EES_ICD_STATS"."PROV_ID"="EES_HOSP_CHG_PROV"."PROV_ID"
    group by CASE WHEN(substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end  IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4)||case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END)
    select "T1"."C0" "levelkey", "T1"."C1" "Cases_Using_Energy", "T0"."C0" "Cases_Using_Energy1", "T1"."C2" "Total_Cases"
    from (
    select count(distinct "Union15"."Cases_Using_Energy") "C0"
    from "Union15") "T0", (
    select "Union15"."QUARTER" "C0", count(distinct "Union15"."Cases_Using_Energy") "C1", sum("Union15"."Total_Cases") "C2"
    from "Union15"
    group by "Union15"."QUARTER") "T1"The explain plan is as follows,
    PLAN_TABLE_OUTPUT
    | Id  | Operation                             |  Name                        | Rows  | Bytes |TempSpc| Cost  |
    |   0 | SELECT STATEMENT                      |                              |     1 |    50 |       |    22 |
    |   2 |  TEMP TABLE TRANSFORMATION            |                              |       |       |       |       |
    |   1 |   RECURSIVE EXECUTION                 | SYS_LE_2_0                   |       |       |       |       |
    |   0 |    INSERT STATEMENT                   |                              |  3053 |   128K|       |  1372 |
    |   1 |     LOAD AS SELECT                    |                              |       |       |       |       |
    |   2 |      SORT UNIQUE                      |                              |  3053 |   128K|   376K|  1372 |
    |   3 |       UNION-ALL                       |                              |       |       |       |       |
    |*  4 |        HASH JOIN                      |                              |  3052 |   128K|       |   185 |
    |*  5 |         TABLE ACCESS FULL             | EES_CONS_PROV                |   622 |  3732 |       |     2 |
    |*  6 |         TABLE ACCESS BY INDEX ROWID   | EES_ENERGY_MASTER            |  3055 |   110K|       |   182 |
    |*  7 |          INDEX RANGE SCAN             | IDX_ENERGY_PDCT_CAT          |  1978 |       |       |  2478 |
    |   8 |        SORT GROUP BY                  |                              |     1 |    40 |       |  1160 |
    |*  9 |         TABLE ACCESS BY INDEX ROWID   | EES_HOSP_CHG_PROV            |     4 |    72 |       |     1 |
    |  10 |          NESTED LOOPS                 |                              |     1 |    40 |       |  1157 |
    |  11 |           NESTED LOOPS                |                              |     1 |    22 |       |  1156 |
    |* 12 |            TABLE ACCESS BY INDEX ROWID| MVW_EES_ICD_STATS            |     1 |    16 |       |  1155 |
    |* 13 |             INDEX RANGE SCAN          | MVWICDSTATS_DISCQTR_IDX      |    13M|       |       | 26068 |
    |* 14 |            TABLE ACCESS BY INDEX ROWID| EES_CONS_PROV                |     1 |     6 |       |     1 |
    |* 15 |             INDEX UNIQUE SCAN         | EES_CONS_PROV_PK             |     1 |       |       |       |
    |* 16 |           INDEX RANGE SCAN            | PROV_ID_IDX_2                |    65 |       |       |     1 |
    |   3 |   MERGE JOIN CARTESIAN                |                              |     1 |    50 |       |    22 |
    |   4 |    VIEW                               |                              |     1 |    13 |       |     3 |
    |   5 |     SORT GROUP BY                     |                              |     1 |    13 |       |       |
    |   6 |      VIEW                             |                              |  3053 | 39689 |       |     3 |
    |   7 |       TABLE ACCESS FULL               | SYS_TEMP_0FD9D68B3_C112F95D  |  3053 |   110K|       |     3 |
    |   8 |    VIEW                               |                              |     1 |    37 |       |    19 |
    |   9 |     SORT GROUP BY                     |                              |     1 |    37 |       |    19 |
    |  10 |      VIEW                             |                              |  3053 |   110K|       |     3 |
    |  11 |       TABLE ACCESS FULL               | SYS_TEMP_0FD9D68B3_C112F95D  |  3053 |   110K|       |     3 |
    Predicate Information (identified by operation id):
       4 - access("EES_ENERGY_MASTER"."PROV_ID"="EES_CONS_PROV"."PROV_ID")
       5 - filter("EES_CONS_PROV"."CONS_06_09_YN"='N' OR "EES_CONS_PROV"."CONS_06_09_YN"='Y')
       6 - filter("EES_ENERGY_MASTER"."DISC_MON">=2006101 AND SUBSTR("EES_ENERGY_MASTER"."ICD_CODE",1,2)='68-gyn'
                  AND "EES_ENERGY_MASTER"."MANUFACTURER"='EES')
       7 - access("EES_ENERGY_MASTER"."PDCT_CAT"='Energy')
       9 - filter("EES_HOSP_CHG_PROV"."PDCT_CAT"='Energy' AND "EES_HOSP_CHG_PROV"."MANUFACTURER"='EES')
      12 - filter("MVW_EES_ICD_STATS"."ICD_GROUP"='68-gyn')
      13 - access("MVW_EES_ICD_STATS"."DISC_QTR">=20061 AND "MVW_EES_ICD_STATS"."DISC_QTR" IS NOT NULL)
      14 - filter("EES_CONS_PROV"."CONS_06_09_YN"='N' OR "EES_CONS_PROV"."CONS_06_09_YN"='Y')
      15 - access("MVW_EES_ICD_STATS"."PROV_ID"="EES_CONS_PROV"."PROV_ID")
      16 - access("MVW_EES_ICD_STATS"."PROV_ID"="EES_HOSP_CHG_PROV"."PROV_ID")
    Please help with some solution.

    OK: the third parameter of the SUBSTR function indicates the (maximum) length of the returnd string.
    Therefore SUBSTR("EES_ENERGY_MASTER"."ICD_CODE",1,2) could possibly be '68' , but never '68-gyn'.
    '68-gyn' is just 4 characters too long.
    Urs

  • Help with a group query

    I have the following table
    EX_ID
    EX_NAME
    EX_SURNAME
    EX_FLAG
    1
    TOM
    JONES
    Y
    1
    JIM
    SLIM
    N
    1
    BO
    SELECTA
    Y
    2
    AIRES
    BEARS
    N
    2
    JIM
    DAVIES
    Y
    3
    PAUL
    BALL
    N
    3
    YOU
    KNOW
    N
    I need to create a query that only displays one of the ex_id’s, it doesn’t matter which one.  When the query has been run it will look like below:
    EX_ID
    EX_NAME
    EX_SURNAME
    EX_FLAG
    1
    TOM
    JONES
    Y
    2
    AIRES
    BEARS
    N
    3
    YOU
    KNOW
    N
    Can anyone help with this query?

    SELECT * FROM
    SELECT *,ROW_NUMBER () OVER (PARTITION BY ex_id ORDER BY (SELECT 0))
    FROM tbl
    ) AS Der WHERE rn=1
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • Problem trying to diagnose slow running query

    Hi, Group.
    I have two versions of the same query. sql1 contains an inner select, sql2 contains the hard-coded values that the inner select returns. Other than that the queries look the exact same.
    sql1 takes over 8 minutes to complete.
    sql2 takes about 250ms to complete.
    I tried running explain plan on both queries and sql1 appears to be the better query based on the plan_table cost columns. I even ran a query that shows the plan hash value for the currently running query. Both times, the slower query appears to be quicker.
    So my problem is that all the diagnosis indicates that sql1 is faster than sql2 but in reality, sql2 is waaaaaaaaaaaaaaaaaaaaay faster than sql1. Does anyone have any other suggestions for tools that I can use that show why the supposedly fast query is actually the slower query?
    Thanks, Max
    EDIT: here is an example of sql1 and sql2 to help you visualize the problem.
    SELECT <column list>
    FROM <table list>
    WHERE column IN (SELECT column FROM table)
    AND <some more predicates>
    SELECT <column list>
    FROM <table list>
    WHERE column IN (value1, value2, value3)
    AND <some more predicates>

    The slow query is listed first.
    PLAN_TABLE_OUTPUT
    Plan hash value: 2494202055
    | Id  | Operation                          | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                   |                                |     1 |   869 |    10  (20)| 00:00:01 |
    |   1 |  SORT UNIQUE                       |                                |     1 |   869 |     9  (12)| 00:00:01 |
    |   2 |   NESTED LOOPS OUTER               |                                |     1 |   869 |     8   (0)| 00:00:01 |
    |   3 |    NESTED LOOPS                    |                                |     1 |   749 |     7   (0)| 00:00:01 |
    |   4 |     NESTED LOOPS                   |                                |     1 |   725 |     6   (0)| 00:00:01 |
    |   5 |      NESTED LOOPS                  |                                |     1 |   701 |     6   (0)| 00:00:01 |
    |   6 |       NESTED LOOPS                 |                                |     1 |   685 |     3   (0)| 00:00:01 |
    |   7 |        NESTED LOOPS                |                                |     1 |   645 |     1   (0)| 00:00:01 |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MASTERDATA_ATTRIBUTE           |     1 |   387 |     1   (0)| 00:00:01 |
    |*  9 |          INDEX RANGE SCAN          | I_MSTRRBT_M_VALUE              |     1 |       |     1   (0)| 00:00:01 |
    |* 10 |         TABLE ACCESS BY INDEX ROWID| MASTERDATA_ELEMENT             |     1 |   258 |     0   (0)| 00:00:01 |
    |* 11 |          INDEX UNIQUE SCAN         | I_MSTRMNT_M_VOCABULARYELEMENTI |     1 |       |     0   (0)| 00:00:01 |
    |  12 |        TABLE ACCESS BY INDEX ROWID | EPCIS_EVENT                    |     1 |    40 |     2   (0)| 00:00:01 |
    |* 13 |         INDEX RANGE SCAN           | I_PCS_VNT_M_BUSINESSLOCATIONUR | 65659 |       |     2   (0)| 00:00:01 |
    |* 14 |       TABLE ACCESS BY INDEX ROWID  | EPCIS_EVENT_EPC                |     2 |    32 |     3   (0)| 00:00:01
    |* 15 |        INDEX RANGE SCAN            | I_PCS__PC_EVENT_ID             |     2 |       |     2   (0)| 00:00:01 |
    |  16 |      TABLE ACCESS BY INDEX ROWID   | EPCIS_EVENT_EPC                |     2 |    48 |     0   (0)| 00:00:01
    |* 17 |       INDEX RANGE SCAN             | I_PCS__PC_EVENT_ID             |     2 |       |     2   (0)| 00:00:01 |
    |* 18 |     TABLE ACCESS BY INDEX ROWID    | EPC                            |     1 |    24 |     1   (0)| 00:00:01 |
    |* 19 |      INDEX UNIQUE SCAN             | SYS_C0012080                   |     1 |       |     0   (0)| 00:00:01 |
    |  20 |    TABLE ACCESS BY INDEX ROWID     | EPC                            |     1 |   120 |     1   (0)| 00:00:01 |
    |* 21 |     INDEX UNIQUE SCAN              | SYS_C0012080                   |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       8 - filter("T4"."MD_ATTRIBUTE_META_ID"='urn:epcglobal:epcis:mda:coun
                                try')
       9 - access("T4"."VALUE"='USA')
      10 - filter("T3"."MD_ELEMENT_META_ID"='urn:epcglobal:epcis:vtype:BusinessLo
                              cation')
      11 - access("T3"."MD_ELEMENT_ID"="T4"."PARENT_MD_ELEMENT_ID")
      13 - access("T0"."BUSINESS_LOCATION_URI"="T3"."MD_ELEMENT_ID")
      14 - filter(("T0"."EVENT_TYPE"='AGGREGATION' OR "T0"."EVENT_TYPE"='TRANSACTION') AND
                  "T1"."PARENT_EVENT_EPC_ID" IS NOT NULL OR "T0"."EVENT_TYPE"='OBJECT')
      15 - access("T0"."EVENT_ID"="T1"."EVENT_ID")
      17 - access("T0"."EVENT_ID"="T5"."EVENT_ID")
      18 - filter("T2"."COMPANY_PREFIX"='1' AND "T2"."REFERENCE"='1' AND "T2"."SCHEME"='gid')
      19 - access("T1"."EPC_ID"="T2"."EPC_ID")
      21 - access("T5"."EPC_ID"="T6"."EPC_ID"(+))
    46 rows selected.
    Explained.
    PLAN_TABLE_OUTPUT
    Plan hash value: 3062511058
    | Id  | Operation                        | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                 |                       |     7 |  1568 |    38   (6)| 00:00:01 |
    |   1 |  SORT UNIQUE                     |                       |     7 |  1568 |    37   (3)| 00:00:01 |
    |   2 |   NESTED LOOPS OUTER             |                       |     7 |  1568 |    36   (0)| 00:00:01 |
    |   3 |    NESTED LOOPS                  |                       |     7 |   728 |    29   (0)| 00:00:01 |
    |   4 |     NESTED LOOPS                 |                       |     4 |   320 |    17   (0)| 00:00:01 |
    |   5 |      NESTED LOOPS                |                       |     4 |   160 |    13   (0)| 00:00:01 |
    |*  6 |       TABLE ACCESS BY INDEX ROWID| EPC                   |     1 |    24 |    10   (0)| 00:00:01 |
    |*  7 |        INDEX RANGE SCAN          | I_EPC_M_COMPANYPREFIX |   220 |       |     3   (0)| 00:00:01 |
    |   8 |       TABLE ACCESS BY INDEX ROWID| EPCIS_EVENT_EPC       |     6 |    96 |     3   (0)| 00:00:01
    |*  9 |        INDEX RANGE SCAN          | I_PCS__PC_EPC_ID      |     7 |       |     2   (0)| 00:00:01 |
    |* 10 |      TABLE ACCESS BY INDEX ROWID | EPCIS_EVENT           |     1 |    40 |     1   (0)| 00:00:01 |
    |* 11 |       INDEX UNIQUE SCAN          | SYS_C0012082          |     1 |       |     0   (0)| 00:00:01 |
    |  12 |     TABLE ACCESS BY INDEX ROWID  | EPCIS_EVENT_EPC       |     2 |    48 |     3   (0)| 00:00:01
    |* 13 |      INDEX RANGE SCAN            | I_PCS__PC_EVENT_ID    |     2 |       |     2   (0)| 00:00:01 |
    |  14 |    TABLE ACCESS BY INDEX ROWID   | EPC                   |     1 |   120 |     1   (0)| 00:00:01 |
    |* 15 |     INDEX UNIQUE SCAN            | SYS_C0012080          |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       6 - filter("T2"."REFERENCE"='1' AND "T2"."SCHEME"='gid')
       7 - access("T2"."COMPANY_PREFIX"='1')
       9 - access("T1"."EPC_ID"="T2"."EPC_ID")
      10 - filter(("T0"."BUSINESS_LOCATION_URI"='businesslocation_ADD' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_DELETE' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE1' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE10' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE11' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE12' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE2' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE3' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE4' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE5' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE6' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE7' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE8' OR
                  "T0"."BUSINESS_LOCATION_URI"='businesslocation_OBSERVE9') AND (("T0"."EVENT_TYPE"='AGGREGATIO
                  OR "T0"."EVENT_TYPE"='TRANSACTION') AND "T1"."PARENT_EVENT_EPC_ID" IS NOT NULL OR
                  "T0"."EVENT_TYPE"='OBJECT'))
      11 - access("T0"."EVENT_ID"="T1"."EVENT_ID")
      13 - access("T0"."EVENT_ID"="T5"."EVENT_ID")
      15 - access("T5"."EPC_ID"="T6"."EPC_ID"(+))

  • Help with Inner Join query in SQL

    Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
    My table structure is :
    table_packages
    packageID
    package
    packageDetails
    etc
    table_destinations
    destinationID
    destination
    destinationDetails
    etc
    table_packagedestinations
    packageID
    destinationID
    ..so nothing that complicated.
    So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
    So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
    This is the PHP from the header, including my INNER JOIN query....
    PHP Code:
    <?php
    $ParampackageID_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    $ParamSessionpackageID_WADApackages = "-1";
    if (isset($_SESSION['WADA_Insert_packages'])) {
      $ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
    $ParampackageID2_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    mysql_select_db($database_connPackages, $connPackages);
    $query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
    $WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
    $row_WADApackages = mysql_fetch_assoc($WADApackages);
    $totalRows_WADApackages = mysql_num_rows($WADApackages);
    $colname_educationalDestinations = "1";
    if (isset($_GET['PackageID'])) {
      $colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
    mysql_select_db($database_connPackages, $connPackages);
    $query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
    $educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
    $row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
    $totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
    ?>
    And where I'm trying to display the destinations themselves, I have : 
    <table>
            <tr>
                     <td>Destinations :</td>
                </tr>
               <?php do { ?>
            <tr>
                 <td><?php echo $row_educationalDestinations['destination']; ?></td>
            </tr>
            <?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
    </table>
    If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working. 
    Thanks.

    First off, you need to get the database tables so that there is a relationship between them.
    In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
    table_packages
    packageID
    package
    packageDetails
    destination
    destinationDetails
    etc
    If there is a one to many relationship, then the following would be true
    packages
    packageID
    package
    packageDetails
    etc
    destinations
    destinationID
    packageID
    destination
    destinationDetails
    etc
    The above assumes that there are many destinations to one package with the relationship coloured orange.
    Once you have the above correct you can apply your query as follows
    SELECT *
    FROM packages
    INNER JOIN destinations
    ON packages.packageID = destinations.packageID
    WHERE packages.packageID = %s
    ORDER BY destination ASC
    The above query will show all packages with relevant destinations

  • Need help with LikeFilter for querying the keyset instead of value

    Hi,
    I'm looking for help with the LikeFilter.
    I need to query the cache to get all entries with key starting with a particular string.
    I could see samples using LikeFilter for querying the values in the cache but not the keyset.
    Can someone help?
    E.g:
    Cache Entries:
    abc123 - value1
    abc234 - value2
    bcd123 - value3
    I want to get all entries with key starting with 'abc'.
    thanks,
    rama.

    NJ, thanks for the quick reply.
    I tried something similar (as below) but this code gives me 'java.lang.NoClassDefFoundError: com/tangosol/util/ValueExtractor'.
    KeyExtractor extractor = new KeyExtractor("getKey");
    Filter filter = new LikeFilter(extractor, id+":%",'-',false);
    -rama.
    Edited by: 911950 on Feb 2, 2012 1:18 PM

  • Help with a PowerPivot query

    Hi,
    I've got a server audit log in PowerPivot (114,000 rows) which I provide some basic reporting from (PowerPivot is not my specialist subject so go easy).  What I now need to perform a Distinct filter, but can't get the logic right. Basically the log
    as two bits of information, 1) is the source of the job and 2) if it was a success or failure.    What I need to do is to find all of the Source items that have never completed sucessfully.  Any ideas on what formula is best to use, or
    do I need to split in to multiple sheets and create a table relationship?
    Source,Status
    ======,======
    Source1,Fail
    Source1,Fail
    Source1,Success
    Source2,Fail
    Source3,Fail
    Source3,Success
    So in the above example, I would only expect the filter to show me Source2
    Thanks
    Alex

    Hi Alex,
    using Power Query instead, it would work like this:
    Once you've pushed your table to PQ, add a column "helper" with value=1.
    Then pivot on "Status", taking "helper"-column into "values column"
    (hope translation is understandable, as I'm using localized Version & translation via "Quick info" isn't working in the PQ menu)
    Then filter on column "Success" = blank.
    Imke

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • Help with a update query from a subquery

    Hello All,
    I wanted to see if someone can help me with an update query.
    I need to grab a latitude & longitude from a the same user that is in two accounts. therefore i am trying to update lat/long in a users table for one account based off of the same user in another account. I am matching the users up by phone number and last name. I tried a subquery but am having difficulty.
    I was thinking of something like the following:
    update users
    set lat = getlat, long = getlong
    inner join (select lat as getlat, long as get long from users where account_id = '1')
    on phone = phone and last name = lastname
    where account_id = '2' and lat IS NULL and long IS NULL
    Am I going in the right direction???
    Thanks in advance for any assistance!!!!

    What difficulty are you having? Have you tried what you posted and get an error?
    Although someone may be able to give you sql advice here, I would try posting this over at Stack Overflow as its not really related to Coldfusion.

Maybe you are looking for