Performance issue on query. Help needed.

This is mainly a performance issue. I hope someone can help me on this.
Basically I have four tables Master (150000 records), Child1 (100000+ records), Child2 (50 million records !), Child 3 (10000+ records)
(please pardon the aliases).
Now every record in master has more than one corresponding record in each of the child tables (one to many).
Also there may not be any record in any or all of the tables for a particular master record.
Now, I need to fetch the max of last_updated_date for every master record in each of the 3 child tables and then find the maximum of
the three last_active_dates obtained from the 3 tables.
eg: for Master ID 100, I need to query Child1 for all the records of Master ID 100 and get the max last_updated_date.
Same for the other 2 tables and then get the maximum of these three values.
(I also need to take care of cases where no record may be found in a child table for a Master ID)
Writing a procedure that uses cursors that fetches the value from each of the child table hits performance
badly. And thing is I need to find out the last_updated_date for every Master record (all 150000 of them). It'll probably take days to do this.
SELECT MAX (C1.LAST_UPDATED_DATE)
,MAX (C2.LAST_UPDATED_DATE)
,MAX (C3.LAST_UPDATED_DATE)
FROM CHILD1 C1
,CHILD2 C2
,CHILD3 C3
WHERE C1.MASTER_ID = 100
OR C2.MASTER_ID = 100
OR C3.MASTER_ID = 100
I tried the above but I got a temp tablespace error. I don't think the query is good enough at all.
(The OR clause is to take care of no records in any child table. If there's an AND, then the join and hence select will
fail even if there is no record in one child table but valid values in the other 2 tables).
Thanks a lot.
Edited by: user773489 on Dec 16, 2008 11:49 AM

Not sure I understand the problem. The max you are getting from the above is already the greatest out of the three - that's why we do the UNION ALL.
Here's sample code without output, maybe this will clear it up:
with a as (
select 10 MASTER_ID, to_date('12/15/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 20 MASTER_ID, to_date('12/01/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 30 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual
b as (
select 10 MASTER_ID, to_date('12/14/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 20 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 40 MASTER_ID, to_date('11/15/2008', 'MM/DD/YYYY') LAST_DTE from dual
c as (
select 10 MASTER_ID, to_date('12/07/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 30 MASTER_ID, to_date('11/29/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
select 40 MASTER_ID, to_date('12/13/2008', 'MM/DD/YYYY') LAST_DTE from dual
select MASTER_ID, MAX(LAST_DTE)
FROM
(select MASTER_ID, LAST_DTE from a UNION ALL
select MASTER_ID, LAST_DTE from b UNION ALL
select MASTER_ID, LAST_DTE from c)
group by MASTER_ID;
MASTER_ID              MAX(LAST_DTE)            
30                     02-DEC-08                
40                     13-DEC-08                
20                     02-DEC-08                
10                     15-DEC-08                
4 rows selectedEdited by: tk-7381344 on Dec 16, 2008 12:38 PM

Similar Messages

  • Performance Issue in Query using = and =

    Hi,
    I have a performance issue in using condition like:
    SELECT * FROM A WHERE ITEM_NO>='M-1130' AND ITEM_NO<='M-9999'.
    Item_No is a varchar2 field and the field contains Numberical as well as string values.
    Can anyone help to solve the issue.
    Thanks and Regards

    How can you say it is a performance issue with the condition? Do you have execution plan? If yes, post it between [pre] and [/pre] tags. Like this.
    [pre]SQL> explain plan for
      2  select sysdate
      3  from dual
      4  /
    Explained.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 1546270724
    | Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     1 |     2   (0)| 00:00:01 |
    |   1 |  FAST DUAL       |      |     1 |     2   (0)| 00:00:01 |
    8 rows selected.
    SQL>
    [/pre]

  • Performance issues while query data from a table having large records

    Hi all,
    I have a performance issues on the queries on mtl_transaction_accounts table which has around 48,000,000 rows. One of the query is as below
    SQL ID: 98pqcjwuhf0y6 Plan Hash: 3227911261
    SELECT SUM (B.BASE_TRANSACTION_VALUE)
    FROM
    MTL_TRANSACTION_ACCOUNTS B , MTL_PARAMETERS A  
    WHERE A.ORGANIZATION_ID =    B.ORGANIZATION_ID 
    AND A.ORGANIZATION_ID =  :b1 
    AND B.REFERENCE_ACCOUNT =    A.MATERIAL_ACCOUNT 
    AND B.TRANSACTION_DATE <=  LAST_DAY (TO_DATE (:b2 ,   'MON-YY' )  )  
    AND B.ACCOUNTING_LINE_TYPE !=  15  
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      3      0.02       0.05          0          0          0           0
    Fetch        3    134.74     722.82     847951    1003824          0           2
    total        7    134.76     722.87     847951    1003824          0           2
    Misses in library cache during parse: 1
    Misses in library cache during execute: 2
    Optimizer mode: ALL_ROWS
    Parsing user id: 193  (APPS)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  SORT AGGREGATE (cr=469496 pr=397503 pw=0 time=237575841 us)
        788242     788242     788242   NESTED LOOPS  (cr=469496 pr=397503 pw=0 time=337519154 us cost=644 size=5920 card=160)
             1          1          1    TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=59 us cost=1 size=10 card=1)
             1          1          1     INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=40 us cost=0 size=0 card=1)(object id 181399)
        788242     788242     788242    TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=469494 pr=397503 pw=0 time=336447304 us cost=643 size=4320 card=160)
       8704356    8704356    8704356     INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N3 (cr=28826 pr=28826 pw=0 time=27109752 us cost=28 size=0 card=7316)(object id 181802)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   SORT (AGGREGATE)
    788242    NESTED LOOPS
          1     TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                    'MTL_PARAMETERS' (TABLE)
          1      INDEX   MODE: ANALYZED (UNIQUE SCAN) OF
                     'MTL_PARAMETERS_U1' (INDEX (UNIQUE))
    788242     TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                    'MTL_TRANSACTION_ACCOUNTS' (TABLE)
    8704356      INDEX   MODE: ANALYZED (RANGE SCAN) OF
                     'MTL_TRANSACTION_ACCOUNTS_N3' (INDEX)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      row cache lock                                 29        0.00          0.02
      SQL*Net message to client                       2        0.00          0.00
      db file sequential read                    847951        0.40        581.90
      latch: object queue header operation            3        0.00          0.00
      latch: gc element                              14        0.00          0.00
      gc cr grant 2-way                               3        0.00          0.00
      latch: gcs resource hash                        1        0.00          0.00
      SQL*Net message from client                     2        0.00          0.00
      gc current block 3-way                          1        0.00          0.00
    ********************************************************************************On a 5 node rac environment the program completes in 15 hours whereas on a single node environemnt the program completes in 2 hours.
    Is there any way I can improve the performance of this query?
    Regards
    Edited by: mhosur on Dec 10, 2012 2:41 AM
    Edited by: mhosur on Dec 10, 2012 2:59 AM
    Edited by: mhosur on Dec 11, 2012 10:32 PM

    CREATE INDEX mtl_transaction_accounts_n0
      ON mtl_transaction_accounts (
                                   transaction_date
                                 , organization_id
                                 , reference_account
                                 , accounting_line_type
    /:p

  • Performance issue with query when generated from an ODS

    I am generating a query from an ODS. The run time is very high. How do I improve the performance of the query ?

    Hi Baruah,
    Steps:
    1. Build the Secondary Index.
    2. divide the data in to 2 ODS where Historical and Present data ODS's and then build a Multiprovider and build the query on multiprovider.
    3.  Build the Indexing on the Table level (ODS table level).
    We cannot make much faster performance for the ODS's that too with huge data...
    The above are very few of them...
    Hope you understood ..
    Regards,
    Ravi Kanth

  • Anyone using a 12 Core Mac Pro? I have HORRIBLE performance issues .. Help!

    After the latest 10.7.4 Mac OS X update I have extremely horrible performance issues with AE ... and they were not so great before the update.
    It is still stabilizing ... but an 1:19 clip in SD is taking 12 HOURS TO analyze and stabilize. !!!
    The 12 cores are barely being used and this problem has been an issue since I purchased the suite over a year ago.
    Does anyone else have problems using AE on their 12 CORE MAC PRO?
    REPLY ONLY IF YOU HAVE A 12 CORE MAC PRO PLEASE.
    There must be a problem because since the update ... Adobe Encore is PERFECT .. and ALL 12 CORES MAX OUT and the encoding is quick!!
    I also have major problems between PP and AE using Dynamic link .. and slow renders in PP.
    Everything else works fine .. other apps / other vendors.
    I am calling Adobe today.

    Thank you for your time.
    I am using a 12 Core 2.93 GHZ with 32 GB RAAM and a NVidia GTX 285.
    I also have a Areca 1212 PCI RAID Card. ( NOTE: I HAVE A SERIOUS RAID DRIVER PROBLEM NOW. THE RAID IS DISCONNECTED )
    Mac OS X 10.7.4
    Adobe Master Suite 5.5
    The Apple "Console" app logs a whole lot of these three Adobe related errors:
    1. 5/18/12 2:10:16.260 AM aeselflink: CFURLCreateWithString was passed this invalid URL string: '/System/Library/Frameworks/System.framework' (a file system path instead of an URL string). The URL created will not work with most file URL functions. CFURLCreateWithFileSystemPath or CFURLCreateWithFileSystemPathRelativeToBase should be used instead.
    2.) 5/18/12 2:10:16.331 AM aeselflink: -[NSMenu menuID]: unrecognized selector sent to instance 0x1183100e0
    5/18/12 2:10:17.333 AM aeselflink: -[NSMenu menuID]: unrecognized selector sent to instance 0x115625740
    3.) 5/18/12 2:11:18.596 AM [0x0-0x9b09b].com.adobe.aerendercore: You have at least one output module template that refers to a missing output plug-in.  Please check your Output Module Templates.
    Only half of my hyperthreaded processors are active when using AE "Warp Stabilizer". This issue was addressed before in the Forums. There was no solution. I dont' know if it is any better in CS 6.
    Also the automatic saving of all linked compositions while using the dynamic link feature bewteen PP and AE causes huge inoperatable waiting times .. unbearable. My guess is that the new "Global Performance Cache " fixes this ... which I consider update to a terrible problem .. but they sell it as a feature ( Ill go into that later.
    Question:
    What RAID card are you using?
    Do you use the Warp Stabilizer?

  • XML QUERY HELP NEEDED

    Hi,
    Need help in writing a query.
    SQL> SELECT xmlelement("P",xmlforest(P.process_id AS Ppid),
      2   xmlagg(xmlelement("PI",XMLFOREST( PI.question_id AS PIqid,
      3   PI.process_id AS PIpid,
      4   PI.innertext AS PItext),
      5   xmlagg(Xmlelement("PO",xmlforest( PO.option_id AS POoid,
      6   PO.question_id AS POqid,
      7   PO.process_id AS popid
      8   ))
      9  ORDER BY PO.option_id))
    10     ORDER BY PI.question_id ) )
    11     FROM liveProcess_ec P
    12  INNER JOIN vw_liveProcessItem_Sim_v6 PI
    13       ON P.process_id = PI.process_id
    14  LEFT OUTER JOIN vw_liveProcessOption_Sim_v6 PO
    15       ON PI.question_id = PO.question_id
    16  AND PI.process_id      = PO.process_id
    17    WHERE p.process_id   =450
    18  GROUP BY p.process_id,PI.question_id,PI.process_id,PI.innertext
    19    ORDER BY p.process_id;
    SELECT xmlelement("P",xmlforest(P.process_id AS Ppid),
    ERROR at line 1:
    ORA-00937: not a single-group group functionThanks in advance

    Hi,
    Here below are the create table scripts along with sample data and expected output.
    CREATE TABLE VW_LIVEPROCESSOPTION_SIM_v6
    ( "OPTION_ID" NUMBER,
    "QUESTION_ID" NUMBER(10,0),
    "PROCESS_ID" NUMBER(10,0),
    "OPT_INNERTEXT" VARCHAR2(200 CHAR),
    "OPT_LINKFROM" VARCHAR2(20 CHAR),
    "OPT_LINKTO" VARCHAR2(20 CHAR),
    "LIBQUESTION_IDFK" NUMBER,
    "LIBOPTION_IDFK" NUMBER
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,2,450,'Yes',null,'5',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,3,450,'Yes',null,'5',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,5,450,'Yes',null,'6',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,6,450,'Yes',null,'7',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,8,450,'Block All',null,'9',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,9,450,'Yes',null,'10',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,11,450,'Yes',null,'12',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,12,450,'Yes',null,'13',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,14,450,'Yes',null,'16',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,2,450,'No',null,'3',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,3,450,'No',null,'4',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,5,450,'No',null,'8',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,6,450,'No',null,'8',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,8,450,'Standard',null,'11',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,9,450,'No',null,'11',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,11,450,'No',null,'14',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,12,450,'No',null,'14',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,14,450,'No',null,'15',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (3,8,450,'Disabled',null,'12',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (4,8,450,'User Defined',null,'12',null,null);
    REATE TABLE "VW_LIVEPROCESSITEM_SIM_v6"
    ( "QUESTION_ID" NUMBER(10,0),
    "PROCESS_ID" NUMBER(10,0),
    "INNERTEXT" VARCHAR2(200 CHAR),
    "ITEMTYPE" VARCHAR2(50 CHAR),
    "LINKFROM" VARCHAR2(500 CHAR),
    "LINKTO" VARCHAR2(500 CHAR),
    "ASSOCIATED" VARCHAR2(200 CHAR),
    "CONTENT_ID" NUMBER,
    "EXITPOINT1_ID" NUMBER(10,0),
    "EXITPOINT2_ID" NUMBER(10,0),
    "EXITPOINT3_ID" NUMBER(10,0),
    "RESOLVEIDENTIFIER" VARCHAR2(40 CHAR),
    "LIBQUESTION_IDFK" NUMBER(10,0),
    "FOLLOWONCALL" NUMBER(1,0),
    "USERINPUT" VARCHAR2(200 CHAR),
    "ISLOCKED" NUMBER(1,0),
    "PREVIOUSANSWER" NUMBER(1,0),
    "VISIBLETOAGENT" NUMBER(1,0),
    "RETRYATTEMPT" NUMBER(10,0),
    "TAGS" VARCHAR2(50 BYTE)
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (1,450,'CBB1015 - Router Firewall Settinngs Process','Title',null,'2',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (2,450,'Is the customers PC Firewall turned off?','Question','1','2.2,2.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (3,450,'Advise the customer to turn off the PC Firewall in order to continue. Has this been done?','Question','2.2','3.2,3.1',null,278,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (4,450,'Advise the customer the PC Firewall must be switched off before this process????','ExitPoint','3.2',null,null,null,14,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (5,450,'Is the customer able to access the internet now?','Question','3.1,2.1','5.2,5.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (6,450,'Is the customer having a problem with a specific website?','Question','5.1','6.2,6.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (7,450,'1536: CBB1008 - Browser Setup and Daignostics','SubProcess','6.1',null,'1536-1-0',null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (8,450,'What is the security level on the CPE Management page?','Question','6.2,5.2','8.4,8.3,8.2,8.1',null,279,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (9,450,'Change the security level to Standard. Does this resolve the customers issue?','Question','8.1','9.2,9.1',null,280,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (10,450,'Issue Resolved','ExitPoint','9.1',null,null,null,1,6,122,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (11,450,'Change the security level to Disabled. Is the customer able to browse the internet?','Question','9.2,8.2','11.2,11.1',null,281,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (12,450,'Change the security level to Standard. Is the customer able to browse the internet now?','Question','11.1,8.3,8.4','12.2,12.1',null,283,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (13,450,'Issue Resolved','ExitPoint','12.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (14,450,'Ask the customer to perform a master reset. Does this resolve their issue?','Question','12.2,11.2','14.2,14.1',null,282,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (15,450,'Faulty CPE','ExitPoint','14.2',null,null,null,1,6,124,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (16,450,'Issue Resolved','ExitPoint','14.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
    CREATE TABLE "LIVEPROCESS_EC_V"
    ( "PROCESS_ID" NUMBER(10,0),
    "USER_ID" NUMBER(10,0),
    "CREATED" TIMESTAMP (6)
    Insert into LIVEPROCESS_EC (PROCESS_ID,USER_ID,CREATED) values (450,7460,to_timestamp('21-APR-08 09.34.41.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'));Expected Output
    <P>
      <Ppid>450</Ppid>
      <Pn>CBB1015 - Router Firewall Settinngs Process</Pn>
      <Pg>9</Pg>
      <Pl>0</Pl>
      <Pb>5</Pb>
      <qcount>100</qcount>
      <ocount>200</ocount>
      <PI>
        <PIqid>1</PIqid>
        <PIpid>450</PIpid>
        <PIpx>366</PIpx>
        <PIpy>-516</PIpy>
        <PItext>CBB1015 - Router Firewall Settinngs Process</PItext>
        <PItype>Title</PItype>
        <PIto>2</PIto>
        <PO />
      </PI>
      <PI>
        <PIqid>2</PIqid>
        <PIpid>450</PIpid>
        <PIpx>366</PIpx>
        <PIpy>-437</PIpy>
        <PItext>Is the customers PC Firewall turned off?</PItext>
        <PItype>Question</PItype>
        <PIfrom>1</PIfrom>
        <PIto>2.2,2.1</PIto>
        <PO>
          <POoid>1</POoid>
          <POqid>2</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>5</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>2</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>3</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>3</PIqid>
        <PIpid>450</PIpid>
        <PIpx>468</PIpx>
        <PIpy>-344</PIpy>
        <PItext>Advise the customer to turn off the PC Firewall in order to continue. Has this been done?</PItext>
        <PItype>Question</PItype>
        <PIfrom>2.2</PIfrom>
        <PIto>3.2,3.1</PIto>
        <PIc>278</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>3</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>5</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>3</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>4</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>4</PIqid>
        <PIpid>450</PIpid>
        <PIpx>571</PIpx>
        <PIpy>-250</PIpy>
        <PItext>Advise the customer the PC Firewall must be switched off before this process????</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>3.2</PIfrom>
        <PIe1>14</PIe1>
        <PO />
      </PI>
      <PI>
        <PIqid>5</PIqid>
        <PIpid>450</PIpid>
        <PIpx>374</PIpx>
        <PIpy>-240</PIpy>
        <PItext>Is the customer able to access the internet now?</PItext>
        <PItype>Question</PItype>
        <PIfrom>3.1,2.1</PIfrom>
        <PIto>5.2,5.1</PIto>
        <PO>
          <POoid>1</POoid>
          <POqid>5</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>6</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>5</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>8</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>6</PIqid>
        <PIpid>450</PIpid>
        <PIpx>322</PIpx>
        <PIpy>-141</PIpy>
        <PItext>Is the customer having a problem with a specific website?</PItext>
        <PItype>Question</PItype>
        <PIfrom>5.1</PIfrom>
        <PIto>6.2,6.1</PIto>
        <PO>
          <POoid>1</POoid>
          <POqid>6</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>7</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>6</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>8</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>7</PIqid>
        <PIpid>450</PIpid>
        <PIpx>128</PIpx>
        <PIpy>-36</PIpy>
        <PItext>1536: CBB1008 - Browser Setup and Daignostics</PItext>
        <PItype>SubProcess</PItype>
        <PIfrom>6.1</PIfrom>
        <PIas>1536-1-0</PIas>
        <PO />
      </PI>
      <PI>
        <PIqid>8</PIqid>
        <PIpid>450</PIpid>
        <PIpx>461</PIpx>
        <PIpy>-43</PIpy>
        <PItext>What is the security level on the CPE Management page?</PItext>
        <PItype>Question</PItype>
        <PIfrom>6.2,5.2</PIfrom>
        <PIto>8.4,8.3,8.2,8.1</PIto>
        <PIc>279</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>-112</POpx>
          <POpy>89</POpy>
          <POtext>Block All</POtext>
          <POto>9</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>Standard</POtext>
          <POto>11</POto>
        </PO>
        <PO>
          <POoid>3</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>83</POpx>
          <POpy>116</POpy>
          <POtext>Disabled</POtext>
          <POto>12</POto>
        </PO>
        <PO>
          <POoid>4</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>-14</POpx>
          <POpy>94</POpy>
          <POtext>User Defined</POtext>
          <POto>12</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>9</PIqid>
        <PIpid>450</PIpid>
        <PIpx>237</PIpx>
        <PIpy>76</PIpy>
        <PItext>Change the security level to Standard. Does this resolve the customers issue?</PItext>
        <PItype>Question</PItype>
        <PIfrom>8.1</PIfrom>
        <PIto>9.2,9.1</PIto>
        <PIc>280</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>9</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>10</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>9</POqid>
          <popid>450</popid>
          <POpx>69</POpx>
          <POpy>73</POpy>
          <POtext>No</POtext>
          <POto>11</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>10</PIqid>
        <PIpid>450</PIpid>
        <PIpx>158</PIpx>
        <PIpy>185</PIpy>
        <PItext>Issue Resolved</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>9.1</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>122</PIe3>
        <PO />
      </PI>
      <PI>
        <PIqid>11</PIqid>
        <PIpid>450</PIpid>
        <PIpx>821</PIpx>
        <PIpy>144</PIpy>
        <PItext>Change the security level to Disabled. Is the customer able to browse the internet?</PItext>
        <PItype>Question</PItype>
        <PIfrom>9.2,8.2</PIfrom>
        <PIto>11.2,11.1</PIto>
        <PIc>281</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>11</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>12</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>11</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>14</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>12</PIqid>
        <PIpid>450</PIpid>
        <PIpx>474</PIpx>
        <PIpy>186</PIpy>
        <PItext>Change the security level to Standard. Is the customer able to browse the internet now?</PItext>
        <PItype>Question</PItype>
        <PIfrom>11.1,8.3,8.4</PIfrom>
        <PIto>12.2,12.1</PIto>
        <PIc>283</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>12</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>13</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>12</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>14</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>13</PIqid>
        <PIpid>450</PIpid>
        <PIpx>322</PIpx>
        <PIpy>278</PIpy>
        <PItext>Issue Resolved</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>12.1</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>123</PIe3>
        <PO />
      </PI>
      <PI>
        <PIqid>14</PIqid>
        <PIpid>450</PIpid>
        <PIpx>645</PIpx>
        <PIpy>327</PIpy>
        <PItext>Ask the customer to perform a master reset. Does this resolve their issue?</PItext>
        <PItype>Question</PItype>
        <PIfrom>12.2,11.2</PIfrom>
        <PIto>14.2,14.1</PIto>
        <PIc>282</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>14</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>16</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>14</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>15</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>15</PIqid>
        <PIpid>450</PIpid>
        <PIpx>768</PIpx>
        <PIpy>435</PIpy>
        <PItext>Faulty CPE</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>14.2</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>124</PIe3>
        <PO />
      </PI>
      <PI>
        <PIqid>16</PIqid>
        <PIpid>450</PIpid>
        <PIpx>479</PIpx>
        <PIpy>420</PIpy>
        <PItext>Issue Resolved</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>14.1</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>123</PIe3>
        <PO />
      </PI>
    </P>Thanks in advance.

  • Pagination query help needed for large table - force a different index

    I'm using a slight modification of the pagination query from over at Ask Tom's: [http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html]
    Mine looks like this when fetching the first 100 rows of all members with last name Smith, ordered by join date:
    SELECT members.*
    FROM members,
        SELECT RID, rownum rnum
        FROM
            SELECT rowid as RID
            FROM members
            WHERE last_name = 'Smith'
            ORDER BY joindate
        WHERE rownum <= 100
    WHERE rnum >= 1
             and RID = members.rowidThe difference between this and the one at Ask Tom's is that my innermost query just returns the ROWID. Then in the outermost query we join the ROWIDs returned to the members table, after we have pruned the ROWIDs down to only the chunk of 100 we want. This makes it MUCH faster (verifiably) on our large tables, as it is able to use the index on the innermost query (well... read on).
    The problem I have is this:
    SELECT rowid as RID
    FROM members
    WHERE last_name = 'Smith'
    ORDER BY joindateThis will use the index for the predicate column (last_name) instead of the unique index I have defined for the joindate column (joindate, sequence). (Verifiable with explain plan). It is much slower this way on a large table. So I can hint it using either of the following methods:
    SELECT /*+ index(members, joindate_idx) */ rowid as RID
    FROM members
    WHERE last_name = 'Smith'
    ORDER BY joindate
    SELECT /*+ first_rows(100) */ rowid as RID
    FROM members
    WHERE last_name = 'Smith'
    ORDER BY joindateEither way, it now uses the index of the ORDER BY column (joindate_idx), so now it is much faster as it does not have to do a sort (remember, VERY large table, millions of records). So that seems good. But now, on my outermost query, I join the rowid with the meaningful columns of data from the members table, as commented below:
    SELECT members.*      -- Select all data from members table
    FROM members,           -- members table added to FROM clause
        SELECT RID, rownum rnum
        FROM
            SELECT /*+ index(members, joindate_idx) */ rowid as RID   -- Hint is ignored now that I am joining in the outer query
            FROM members
            WHERE last_name = 'Smith'
            ORDER BY joindate
        WHERE rownum <= 100
    WHERE rnum >= 1
            and RID = members.rowid           -- Merge the members table on the rowid we pulled from the inner queriesOnce I do this join, it goes back to using the predicate index (last_name) and has to perform the sort once it finds all matching values (which can be a lot in this table, there is high cardinality on some columns).
    So my question is, in the full query above, is there any way I can get it to use the ORDER BY column for indexing to prevent it from having to do a sort? The join is what causes it to revert back to using the predicate index, even with hints. Remove the join and just return the ROWIDs for those 100 records and it flies, even on 10 million records.
    It'd be great if there was some generic hint that could accomplish this, such that if we change the table/columns/indexes, we don't need to change the hint (the FIRST_ROWS hint is a good example of this, while the INDEX hint is the opposite), but any help would be appreciated. I can provide explain plans for any of the above if needed.
    Thanks!

    Lakmal Rajapakse wrote:
    OK here is an example to illustrate the advantage:
    SQL> set autot traceonly
    SQL> select * from (
    2  select a.*, rownum x  from
    3  (
    4  select a.* from aoswf.events a
    5  order by EVENT_DATETIME
    6  ) a
    7  where rownum <= 1200
    8  )
    9  where x >= 1100
    10  /
    101 rows selected.
    Execution Plan
    Plan hash value: 3711662397
    | Id  | Operation                      | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT               |            |  1200 |   521K|   192   (0)| 00:00:03 |
    |*  1 |  VIEW                          |            |  1200 |   521K|   192   (0)| 00:00:03 |
    |*  2 |   COUNT STOPKEY                |            |       |       |            |          |
    |   3 |    VIEW                        |            |  1200 |   506K|   192   (0)| 00:00:03 |
    |   4 |     TABLE ACCESS BY INDEX ROWID| EVENTS     |   253M|    34G|   192   (0)| 00:00:03 |
    |   5 |      INDEX FULL SCAN           | EVEN_IDX02 |  1200 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - filter("X">=1100)
    2 - filter(ROWNUM<=1200)
    Statistics
    0  recursive calls
    0  db block gets
    443  consistent gets
    0  physical reads
    0  redo size
    25203  bytes sent via SQL*Net to client
    281  bytes received via SQL*Net from client
    8  SQL*Net roundtrips to/from client
    0  sorts (memory)
    0  sorts (disk)
    101  rows processed
    SQL>
    SQL>
    SQL> select * from aoswf.events a, (
    2  select rid, rownum x  from
    3  (
    4  select rowid rid from aoswf.events a
    5  order by EVENT_DATETIME
    6  ) a
    7  where rownum <= 1200
    8  ) b
    9  where x >= 1100
    10  and a.rowid = rid
    11  /
    101 rows selected.
    Execution Plan
    Plan hash value: 2308864810
    | Id  | Operation                   | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |            |  1200 |   201K|   261K  (1)| 00:52:21 |
    |   1 |  NESTED LOOPS               |            |  1200 |   201K|   261K  (1)| 00:52:21 |
    |*  2 |   VIEW                      |            |  1200 | 30000 |   260K  (1)| 00:52:06 |
    |*  3 |    COUNT STOPKEY            |            |       |       |            |          |
    |   4 |     VIEW                    |            |   253M|  2895M|   260K  (1)| 00:52:06 |
    |   5 |      INDEX FULL SCAN        | EVEN_IDX02 |   253M|  4826M|   260K  (1)| 00:52:06 |
    |   6 |   TABLE ACCESS BY USER ROWID| EVENTS     |     1 |   147 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("X">=1100)
    3 - filter(ROWNUM<=1200)
    Statistics
    8  recursive calls
    0  db block gets
    117  consistent gets
    0  physical reads
    0  redo size
    27539  bytes sent via SQL*Net to client
    281  bytes received via SQL*Net from client
    8  SQL*Net roundtrips to/from client
    0  sorts (memory)
    0  sorts (disk)
    101  rows processed
    Lakmal (and OP),
    Not sure what advantage you are trying to show here. But considering that we are talking about pagination query here and order of records is important, your 2 queries will not always generate output in same order. Here is the test case:
    SQL> select * from v$version ;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    SQL> show parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.1
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    SQL> show parameter pga
    NAME                                 TYPE        VALUE
    pga_aggregate_target                 big integer 103M
    SQL> create table t nologging as select * from all_objects where 1 = 2 ;
    Table created.
    SQL> create index t_idx on t(last_ddl_time) nologging ;
    Index created.
    SQL> insert /*+ APPEND */ into t (owner, object_name, object_id, created, last_ddl_time) select owner, object_name, object_id, created, sysdate - dbms_random.value(1, 100) from all_objects order by dbms_random.random;
    40617 rows created.
    SQL> commit ;
    Commit complete.
    SQL> exec dbms_stats.gather_table_stats(user, 'T', cascade=>true);
    PL/SQL procedure successfully completed.
    SQL> select object_id, object_name, created from t, (select rid, rownum rn from (select rowid rid from t order by created desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
    OBJECT_ID OBJECT_NAME                    CREATED
         47686 ALL$OLAP2_JOIN_KEY_COLUMN_USES 28-JUL-2009 08:08:39
         47672 ALL$OLAP2_CUBE_DIM_USES        28-JUL-2009 08:08:39
         47681 ALL$OLAP2_CUBE_MEASURE_MAPS    28-JUL-2009 08:08:39
         47682 ALL$OLAP2_FACT_LEVEL_USES      28-JUL-2009 08:08:39
         47685 ALL$OLAP2_AGGREGATION_USES     28-JUL-2009 08:08:39
         47692 ALL$OLAP2_CATALOGS             28-JUL-2009 08:08:39
         47665 ALL$OLAPMR_FACTTBLKEYMAPS      28-JUL-2009 08:08:39
         47688 ALL$OLAP2_DIM_LEVEL_ATTR_MAPS  28-JUL-2009 08:08:39
         47689 ALL$OLAP2_DIM_LEVELS_KEYMAPS   28-JUL-2009 08:08:39
         47669 ALL$OLAP9I2_HIER_DIMENSIONS    28-JUL-2009 08:08:39
         47666 ALL$OLAP9I1_HIER_DIMENSIONS    28-JUL-2009 08:08:39
    11 rows selected.
    SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
    OBJECT_ID OBJECT_NAME                    LAST_DDL_TIME
         11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
         13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
         37534 com/sun/mail/smtp/SMTPMessage  06-FEB-2010 03:46:14
         36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
         26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
         16695 /2940a364_RepIdDelegator_1_3   06-FEB-2010 03:38:17
         36539 sun/io/ByteToCharMacHebrew     06-FEB-2010 03:28:57
         14044 /d29b81e1_OldHeaders           06-FEB-2010 03:12:12
         12920 /25f8f3a5_BasicSplitPaneUI     06-FEB-2010 03:11:06
         42266 SI_GETCLRHSTGRFTR              06-FEB-2010 03:40:20
         15752 /2f494dce_JDWPThreadReference  06-FEB-2010 03:09:31
    11 rows selected.
    SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
    OBJECT_ID OBJECT_NAME                    LAST_DDL_TIME
         37534 com/sun/mail/smtp/SMTPMessage  06-FEB-2010 03:46:14
         13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
         11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
         42266 SI_GETCLRHSTGRFTR              06-FEB-2010 03:40:20
         16695 /2940a364_RepIdDelegator_1_3   06-FEB-2010 03:38:17
         36539 sun/io/ByteToCharMacHebrew     06-FEB-2010 03:28:57
         26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
         14044 /d29b81e1_OldHeaders           06-FEB-2010 03:12:12
         36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
         12920 /25f8f3a5_BasicSplitPaneUI     06-FEB-2010 03:11:06
         15752 /2f494dce_JDWPThreadReference  06-FEB-2010 03:09:31
    11 rows selected.
    SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc ;
    OBJECT_ID OBJECT_NAME                    LAST_DDL_TIME
         37534 com/sun/mail/smtp/SMTPMessage  06-FEB-2010 03:46:14
         13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
         11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
         42266 SI_GETCLRHSTGRFTR              06-FEB-2010 03:40:20
         16695 /2940a364_RepIdDelegator_1_3   06-FEB-2010 03:38:17
         36539 sun/io/ByteToCharMacHebrew     06-FEB-2010 03:28:57
         26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
         14044 /d29b81e1_OldHeaders           06-FEB-2010 03:12:12
         36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
         12920 /25f8f3a5_BasicSplitPaneUI     06-FEB-2010 03:11:06
         15752 /2f494dce_JDWPThreadReference  06-FEB-2010 03:09:31
    11 rows selected.
    SQL> set autotrace traceonly
    SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc
      2  ;
    11 rows selected.
    Execution Plan
    Plan hash value: 44968669
    | Id  | Operation                       | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |       |  1200 | 91200 |   180   (2)| 00:00:03 |
    |   1 |  SORT ORDER BY                  |       |  1200 | 91200 |   180   (2)| 00:00:03 |
    |*  2 |   HASH JOIN                     |       |  1200 | 91200 |   179   (2)| 00:00:03 |
    |*  3 |    VIEW                         |       |  1200 | 30000 |    98   (0)| 00:00:02 |
    |*  4 |     COUNT STOPKEY               |       |       |       |            |          |
    |   5 |      VIEW                       |       | 40617 |   475K|    98   (0)| 00:00:02 |
    |   6 |       INDEX FULL SCAN DESCENDING| T_IDX | 40617 |   793K|    98   (0)| 00:00:02 |
    |   7 |    TABLE ACCESS FULL            | T     | 40617 |  2022K|    80   (2)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("T".ROWID="T1"."RID")
       3 - filter("RN">=1190)
       4 - filter(ROWNUM<=1200)
    Statistics
              1  recursive calls
              0  db block gets
            348  consistent gets
              0  physical reads
              0  redo size
           1063  bytes sent via SQL*Net to client
            385  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
             11  rows processed
    SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
    11 rows selected.
    Execution Plan
    Plan hash value: 882605040
    | Id  | Operation                | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT         |      |  1200 | 62400 |    80   (2)| 00:00:01 |
    |*  1 |  VIEW                    |      |  1200 | 62400 |    80   (2)| 00:00:01 |
    |*  2 |   COUNT STOPKEY          |      |       |       |            |          |
    |   3 |    VIEW                  |      | 40617 |  1546K|    80   (2)| 00:00:01 |
    |*  4 |     SORT ORDER BY STOPKEY|      | 40617 |  2062K|    80   (2)| 00:00:01 |
    |   5 |      TABLE ACCESS FULL   | T    | 40617 |  2062K|    80   (2)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("RN">=1190)
       2 - filter(ROWNUM<=1200)
       4 - filter(ROWNUM<=1200)
    Statistics
              0  recursive calls
              0  db block gets
            343  consistent gets
              0  physical reads
              0  redo size
           1063  bytes sent via SQL*Net to client
            385  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
             11  rows processed
    SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
    11 rows selected.
    Execution Plan
    Plan hash value: 168880862
    | Id  | Operation                      | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT               |       |  1200 | 91200 |   179   (2)| 00:00:03 |
    |*  1 |  HASH JOIN                     |       |  1200 | 91200 |   179   (2)| 00:00:03 |
    |*  2 |   VIEW                         |       |  1200 | 30000 |    98   (0)| 00:00:02 |
    |*  3 |    COUNT STOPKEY               |       |       |       |            |          |
    |   4 |     VIEW                       |       | 40617 |   475K|    98   (0)| 00:00:02 |
    |   5 |      INDEX FULL SCAN DESCENDING| T_IDX | 40617 |   793K|    98   (0)| 00:00:02 |
    |   6 |   TABLE ACCESS FULL            | T     | 40617 |  2022K|    80   (2)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("T".ROWID="T1"."RID")
       2 - filter("RN">=1190)
       3 - filter(ROWNUM<=1200)
    Statistics
              0  recursive calls
              0  db block gets
            349  consistent gets
              0  physical reads
              0  redo size
           1063  bytes sent via SQL*Net to client
            385  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
             11  rows processed
    SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 order by last_ddl_time desc ;
    11 rows selected.
    Execution Plan
    Plan hash value: 882605040
    | Id  | Operation           | Name | Rows     | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |     |  1200 | 62400 |    80   (2)| 00:00:01 |
    |*  1 |  VIEW                |     |  1200 | 62400 |    80   (2)| 00:00:01 |
    |*  2 |   COUNT STOPKEY       |     |     |     |          |          |
    |   3 |    VIEW            |     | 40617 |  1546K|    80   (2)| 00:00:01 |
    |*  4 |     SORT ORDER BY STOPKEY|     | 40617 |  2062K|    80   (2)| 00:00:01 |
    |   5 |      TABLE ACCESS FULL      | T     | 40617 |  2062K|    80   (2)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("RN">=1190)
       2 - filter(ROWNUM<=1200)
       4 - filter(ROWNUM<=1200)
    Statistics
         175  recursive calls
           0  db block gets
         388  consistent gets
           0  physical reads
           0  redo size
           1063  bytes sent via SQL*Net to client
         385  bytes received via SQL*Net from client
           2  SQL*Net roundtrips to/from client
           4  sorts (memory)
           0  sorts (disk)
          11  rows processed
    SQL> set autotrace off
    SQL> spool offAs you will see, the join query here has to have an ORDER BY clause at the end to ensure that records are correctly sorted. You can not rely on optimizer choosing NESTED LOOP join method and, as above example shows, when optimizer chooses HASH JOIN, oracle is free to return rows in no particular order.
    The query that does not involve join always returns rows in the desired order. Adding an ORDER BY does add a step in the plan for the query using join but does not affect the other query.

  • Performance issues with query input variable selection in ODS

    Hi everyone
    We've upgraded from BW 3.0B to NW04s BI using SP12.
    There is a problem encountered with input variable selection. This happens regardless of using BEx (new or old 3.x) or using RSRT. When using the F4 search help (or "Select from list" in BEx context) to list possible values, this takes forever for large ODS (containing millions of records).
    Using ST01 and SM50 to trace the code in the same query, we see a difference here:
    <u>NW04s BI SQL command</u>
    SELECT                                                                               
    "P0000"."COMP_CODE" AS "0000000032" ,"T0000"."TXTMD" AS "0000000032_TXTMD"                             
    FROM                                                                               
    ( "/BI0/PCOMP_CODE" "P0000" ) LEFT OUTER JOIN "/BI0/TCOMP_CODE" "T0000" ON  "P0000"."COMP_CODE" = "T0000
      "."COMP_CODE"                                                                               
    WHERE                                                                               
    "P0000"."OBJVERS" = 'A' AND "P0000"."COMP_CODE" IN ( SELECT "O"."COMP_CODE" AS "KEY" FROM              
      "/BI0/APY_PP_C100" "O" )                                                                               
    ORDER BY                                                                               
    "P0000"."COMP_CODE" ASC#                                                                               
    <u>BW 3.0B SQL command:</u>
    SELECT ROWNUM < 500 ....
    In 3.0B, rownum is limited to 500 and this results in a speedy, though limited query. In the new NW04s BI, this renders the selection screen unusable as ABAP dumps for timing out will occur first due to the large data volume searched using sequential read.
    It will not be feasible to create indexes for every single query selection parameter (issues with oerformance when loading, space required etc.). Is there a reason why SAP seems have fallen back on a less effective code for this?
    I have tried to change the number of selected rows to <500 in BEx settings but one must reach a responsive screen in order to get to that setting and it is not always possible or saved for the next run.
    Anyone with similar experience or can provide help on this?

    here is a reason why the F4 help on ODS was faster in BW 3.x.
    In BW 3.x the ODS did not support the read mode "Only values in
    InfoProvider". So If I compare the different SQL statements I propose
    to change the F4 mode in the InfoProvider specific properties to
    "About master data". This is the fastest F4 mode.
    As an alternative you can define indexes on your ODS to speed up F4.
    So would need a non-unique index on InfoObject 0COMP_CODE in your ODS
    Check below for insights
    https://forums.sdn.sap.com/click.jspa?searchID=6224682&messageID=2841493
    Hope it Helps
    Chetan
    @CP..

  • Query help needed

    Hi
    I need help in writing a sql query for the data given below
    Market Description Revenue
    LARGE CORPORATE 0.0
    LARGE CORPORATE 0.0
    OTHERS 0.0
    OTHERS 1.98
    LARGE CORPORATE 5.1299999999999999
    LARGE CORPORATE 6.8500000000000005
    LARGE CORPORATE 10.98
    LARGE CORPORATE 16.490000000000002
    LARGE CORPORATE 21.129999999999999
    LARGE CORPORATE 28.66
    LARGE CORPORATE 38.579999999999998
    OTHERS 68.420000000000002
    OTHERS 87.590000000000003
    LARGE CORPORATE 90.040000000000006
    LARGE CORPORATE 511.94
    LARGE CORPORATE 625.01999999999998
    LARGE CORPORATE 662.75999999999999
    LARGE CORPORATE 700.68000000000006
    LARGE CORPORATE 2898.6799999999998
    LARGE CORPORATE 3273.96
    OTHERS 3285.4400000000001
    LARGE CORPORATE 3580.0799999999999
    LARGE CORPORATE 4089.1900000000001
    LARGE CORPORATE 4373.5200000000004
    LARGE CORPORATE 16207.550000000001
    LARGE CORPORATE 19862.740000000002
    LARGE CORPORATE 33186.150000000001
    LARGE CORPORATE 107642.79000000001
    The output of query should be in the following format
    Market Description 1st 10%(revenue) 2nd 10%(revenue) 3rd 10%(revenue) 4th 10%(revenue) 5th 10%(revenue) rest 50%(revenue)
    Would appreciate any help on this query.

    Hi,
    What does 1st 10%, 2nd 10% etc. mean?
    Is it 0-10%, 11-20%, 21-30%....
    If so, combination of floor,decode and division should help to
    achieve the result.
    For example for the followint table,
    NAME SALE
    SALES_GROUP1 .2
    SALES_GROUP1 1
    SALES_GROUP1 9
    SALES_GROUP2 2.1
    SALES_GROUP2 12.2
    SALES_GROUP2 19.9
    SALES_GROUP3 22.2
    write,
    select name,decode(floor(sale/10),0,sale,null) "1st10%",
    decode(floor(sale/10),1,sale,null)"11to20%",
    decode(floor(sale/10),2,sale,null) "21to30%"
    from revenue;
    I mean, using floor and division, your rounding all values b/w 0 to 10 as 0
    Similarly, 11 to 20 has be rounded to 1 etc...then apply decode function it
    to achive the result.
    I hope this helps.
    Regards,
    Suresh
    8i OCP.

  • Query help needed for querybuilder to use with lcm cli

    Hi,
    I had set up several queries to run with the lcm cli in order to back up personal folders, inboxes, etc. to lcmbiar files to use as backups.  I have seen a few posts that are similar, but I have a specific question/concern.
    I just recently had to reference one of these back ups only to find it was incomplete.  Does the query used by the lcm cli also only pull the first 1000 rows? Is there a way to change this limit somwhere?
    Also, since when importing this lcmbiar file for something 'generic' like 'all personal folders', pulls in WAY too much stuff, is there a better way to limit this? I am open to suggestions, but it would almost be better if I could create individual lcmbiar output files on a per user basis.  This way, when/if I need to restore someone's personal folder contents, for example, I could find them by username and import just that lcmbiar file, as opposed to all 3000 of our users.  I am not quite sure how to accomplish this...
    Currently, with my limited windows scripting knowledge, I have set up a bat script to run each morning, that creates a 'runtime' properties file from a template, such that the lcmbiar file gets named uniquely for that day and its content.  Then I call the lcm_cli using the proper command.  The query within the properties file is currently very straightforward - select * from CI_INFOOBJECTS WHERE SI_ANCESTOR = 18.
    To do what I want to do...
    1) I'd first need a current list of usernames in a text file, that could be read (?) in and parsed to single out each user (remember we are talking about 3000) - not sure the best way to get this.
    2) Then instead of just updating the the lcmbiar file name with a unique name as I do currently, I would also update the query (which would be different altogether):  SELECT * from CI_INFOOBJECTS where SI_OWNER = '<username>' AND SI_ANCESTOR = 18.
    In theory, that would grab everything owned by that user in their personal folder - right? and write it to its own lcmbiar file to a location I specify.
    I just think chunking something like this is more effective and BO has no built in back up capability that already does this.  We are on BO 4.0 SP7 right now, move to 4.1 SP4 over the summer.
    Any thoughts on this would be much appreciated.
    thanks,
    Missy

    Just wanted to pass along that SAP Support pointed me to KBA 1969259 which had some good example queries in it (they were helping me with a concern I had over the lcmbiar file output, not with query design).  I was able to tweak one of the sample queries in this KBA to give me more of what I was after...
    SELECT TOP 10000 static, relationships, SI_PARENT_FOLDER_CUID, SI_OWNER, SI_PATH FROM CI_INFOOBJECTS,CI_APPOBJECTS,CI_SYSTEMOBJECTS WHERE (DESCENDENTS ("si_name='Folder Hierarchy'","si_name='<username>'"))
    This exports inboxes, personal folders, categories, and roles, which is more than I was after, but still necessary to back up.. so in a way, it is actually better because I have one lcmbiar file per user - contains all their 'personal' objects.
    So between narrowing down my set of users to only those who actually have saved things to their personal folder and now having a query that actually returns what I expect it to return, along with the help below for a job to clean up these excessive amounts of promotion jobs I am now creating... I am all set!
    Hopefully this can help someone else too!
    Thanks,
    missy

  • Another query help needed...

    I have a tale as follows:
    -- INSERTING into TABLE_EXPORT
    Insert into TABLE_EXPORT (ACCOUNT_ID,TRANSACTION_AMOUNT,TRANSACTION_TYPE,DRAWEE_ACCOUNT_ID,BENEFICIARY_ACCOUNT_ID) values ('112010026758',6000,'Withdrawal','112010026758',null);
    Insert into TABLE_EXPORT (ACCOUNT_ID,TRANSACTION_AMOUNT,TRANSACTION_TYPE,DRAWEE_ACCOUNT_ID,BENEFICIARY_ACCOUNT_ID) values ('112010026758',21664,'Deposit','147010001002','112010026758');
    Insert into TABLE_EXPORT (ACCOUNT_ID,TRANSACTION_AMOUNT,TRANSACTION_TYPE,DRAWEE_ACCOUNT_ID,BENEFICIARY_ACCOUNT_ID) values ('112010026758',23000,'Withdrawal','112010026758','147010001000');
    Insert into TABLE_EXPORT (ACCOUNT_ID,TRANSACTION_AMOUNT,TRANSACTION_TYPE,DRAWEE_ACCOUNT_ID,BENEFICIARY_ACCOUNT_ID) values ('112010026758',5000,'Withdrawal','112010026758','147010001000');
    Insert into TABLE_EXPORT (ACCOUNT_ID,TRANSACTION_AMOUNT,TRANSACTION_TYPE,DRAWEE_ACCOUNT_ID,BENEFICIARY_ACCOUNT_ID) values ('112010026758',15000,'Deposit',null,'112010026758');I need to get the Counterparties and the number of txns with the counterparty and the amount transacted with the counterparties. Here counterparty is decided based on the transaction type i.e., if transaction_type is 'Deposit' then the counterparty is Drawee_Account_id. If transaction_type is 'Withdrawal' then the counterparty is Beneficiary_Account_id.
    So in this data for the Account_id 112010026758, there are 2 counterparties - 147010001000 and 147010001002.
    I am able to get the count of counterparties and the count of transactions with the counterparty using the following query
    Select Account_id,
    count(decode(Beneficiary_Account_id,Account_id,Drawee_Account_id,Beneficiary_Account_id)) NoofTransactions,
    count(distinct(decode(Beneficiary_Account_id,Account_id,Drawee_Account_id,Beneficiary_Account_id))) Counterparties
    from ENTTEST.TABLE_EXPORT
    where Account_id = '112010026758'
    group by Account_idBut how do i find the sum of transaction amount of the transactions with the counterparty. i.e., for the data above, number of transactions involved with the counterparties is 3 and the sum is 49664.. How can i get that sum??
    Can anybody please help me with the query for getting this result...Please.. I am struck at this point..

    Does this answer your question?
    SQL &gt; WITH TABLE_EXPORT AS
      2  (
      3     SELECT '112010026758' AS ACCOUNT_ID, 6000 AS TRANSACTION_AMOUNT, 'Withdrawal' AS TRANSACTION_TYPE, '112010026758' AS DRAWEE_ACCOUNT_ID, null AS BENEFICI
    ARY_ACCOUNT_ID FROM DUAL UNION ALL
      4     SELECT '112010026758' AS ACCOUNT_ID, 21664 AS TRANSACTION_AMOUNT, 'Deposit' AS TRANSACTION_TYPE, '147010001002' AS DRAWEE_ACCOUNT_ID, '112010026758' AS
    BENEFICIARY_ACCOUNT_ID FROM DUAL UNION ALL
      5     SELECT '112010026758' AS ACCOUNT_ID, 23000 AS TRANSACTION_AMOUNT, 'Withdrawal' AS TRANSACTION_TYPE, '112010026758' AS DRAWEE_ACCOUNT_ID, '147010001002'
    AS BENEFICIARY_ACCOUNT_ID FROM DUAL UNION ALL
      6     SELECT '112010026758' AS ACCOUNT_ID, 5000 AS TRANSACTION_AMOUNT, 'Withdrawal' AS TRANSACTION_TYPE, '112010026758' AS DRAWEE_ACCOUNT_ID, '147010001002' A
    S BENEFICIARY_ACCOUNT_ID FROM DUAL UNION ALL
      7     SELECT '112010026758' AS ACCOUNT_ID, 15000 AS TRANSACTION_AMOUNT, 'Deposit' AS TRANSACTION_TYPE, null AS DRAWEE_ACCOUNT_ID, '112010026758' AS BENEFICIAR
    Y_ACCOUNT_ID FROM DUAL
      8  )
      9  SELECT ACCOUNT_ID,SUM(TRANSACTION_AMOUNT)
    10  FROM TABLE_EXPORT
    11  WHERE DRAWEE_ACCOUNT_ID IS NOT NULL
    12  AND BENEFICIARY_ACCOUNT_ID IS NOT NULL
    13  GROUP BY ACCOUNT_ID
    14  /
    ACCOUNT_ID   SUM(TRANSACTION_AMOUNT)
    112010026758                   49664This is a modified version of your query:
    SQL &gt; WITH TABLE_EXPORT AS
      2  (
      3     SELECT '112010026758' AS ACCOUNT_ID, 6000 AS TRANSACTION_AMOUNT, 'Withdrawal' AS TRANSACTION_TYPE, '112010026758' AS DRAWEE_ACCOUNT_ID, null AS BENEFICI
    ARY_ACCOUNT_ID FROM DUAL UNION ALL
      4     SELECT '112010026758' AS ACCOUNT_ID, 21664 AS TRANSACTION_AMOUNT, 'Deposit' AS TRANSACTION_TYPE, '147010001002' AS DRAWEE_ACCOUNT_ID, '112010026758' AS
    BENEFICIARY_ACCOUNT_ID FROM DUAL UNION ALL
      5     SELECT '112010026758' AS ACCOUNT_ID, 23000 AS TRANSACTION_AMOUNT, 'Withdrawal' AS TRANSACTION_TYPE, '112010026758' AS DRAWEE_ACCOUNT_ID, '147010001002'
    AS BENEFICIARY_ACCOUNT_ID FROM DUAL UNION ALL
      6     SELECT '112010026758' AS ACCOUNT_ID, 5000 AS TRANSACTION_AMOUNT, 'Withdrawal' AS TRANSACTION_TYPE, '112010026758' AS DRAWEE_ACCOUNT_ID, '147010001002' A
    S BENEFICIARY_ACCOUNT_ID FROM DUAL UNION ALL
      7     SELECT '112010026758' AS ACCOUNT_ID, 15000 AS TRANSACTION_AMOUNT, 'Deposit' AS TRANSACTION_TYPE, null AS DRAWEE_ACCOUNT_ID, '112010026758' AS BENEFICIAR
    Y_ACCOUNT_ID FROM DUAL
      8  )
      9  SELECT Account_id,
    10     COUNT(DECODE(Beneficiary_Account_id,Account_id,Drawee_Account_id,Beneficiary_Account_id)) NoofTransactions,
    11     COUNT(DISTINCT(DECODE(Beneficiary_Account_id,Account_id,Drawee_Account_id,Beneficiary_Account_id))) Counterparties,
    12     SUM(CASE WHEN BENEFICIARY_ACCOUNT_ID IS NOT NULL AND DRAWEE_ACCOUNT_ID IS NOT NULL THEN TRANSACTION_AMOUNT ELSE NULL END) AS TRANSACTION_AMOUNT
    13  FROM TABLE_EXPORT
    14  WHERE Account_id = '112010026758'
    15  GROUP BY Account_id
    16  /
    ACCOUNT_ID   NOOFTRANSACTIONS COUNTERPARTIES TRANSACTION_AMOUNT
    112010026758                3              1              49664Hope this helps!

  • Performance issue in query on reguh

    Hi,
    The following query on table REGUH is taking a lot of time..
        SELECT laufd laufi xvorl
               zbukr lifnr kunnr
               empfg vblnr znme1
               znme2 rbetr
            FROM reguh
              INTO TABLE i_reguh_vendor
                 FOR ALL ENTRIES IN i_lfa1
                   WHERE laufd IN s_laufd AND
                         zbukr EQ i_lfa1-bukrs AND
                         lifnr EQ i_lfa1-lifnr AND
                         rzawe IN s_rzawe AND
                         uzawe IN s_uzawe AND
                         xvorl IN s_xvorl.
    The company code is available on the selection screen as select-option.

    Check out the OSS Note numbers # 597984 ( Create Index )
    and 145647
    597984 ( Create Index )
    Solution
    Solve the performance problem by importing Support Packages for Release 4.6C and 4.70. You can implement an advance correction. For this purpose implement the attached program corrections and create the following index in table REGUH:
    Transaction SE11
    Display Database table REGUH
    Goto -> Indexes...
    In the standard system no indexes have been defined yet, so answer the displayed question "Do you want to create an index? " with "Yes". If customer-specific indexes have already been created, click on "Create" (F5) for the creation of a new index in the dialog box.
    Index Name:     PMW
    Short description: Logical database FPMF of Payment Medium Workbench
    Index flds:       MANDT
                     FPM_KEY
                     GRPNO
                     SRTF1
    Index -> Activate
    Consequently, the index exists in the ABAP Dictionary. Finally, the index must be activated in the database.
    If you cannot activate the index via "Utilities -> Database utility -> Create database index", let your database administrator create the index.
    Note that follow-up actions can be required depending on the database, so that the new index is used.
    For example, with DB2/390 a RUNSTATS must be carried out on table REGUH using Transaction DB13.
    Hope this`ll help you .
    Good Luck !
    Thanks
    Message was edited by: Saquib Khan

  • Performance issue with Query

    11g
    Hi there experts,
      I have an issue with performance with a simple SQL which I thought cannot be tuned but just wanted to check with the experts here. We are running a query to get a persons ID based on his logged in email address from a Parties table which is huge (Millions of records). The query takes about 30 seconds to return a value. Was wondering is there a way to optimize this
    The query is
    {code}
    select par.party_id
    from parties party, users users
    where
    lower(party.email_address) = lower(:USER_EMAIL)
    and party.system_reference = to_char(users.person_id)
    and users.active_flag ='Yes';
    {code}
    The emails are stored in upper and lower, hence the lower functions
    IS creating a function based index the only way?
    Thanks,
    Ryan

    Hi Everyone.
    Thanks and apologies, first post on tuning as such. Here is the explain plan generated through SQL DEVELOPER. IT showed the output in XML
    By the way, looks like the {code} tag does not work?
    {code}
      SELECT STATEMENT
      84903
         HASH JOIN
      84903
         Access Predicates
         PARTY.ORIG_SYSTEM_REFERENCE=TO_CHAR(PERSON_ID)
         TABLE ACCESS
         PER_USERS
      STORAGE FULL
      1059
         Access Predicates
         AND
         ACTIVE_FLAG='Y'
         OR
         OR
         BUSINESS_GROUP_ID=0
         BUSINESS_GROUP_ID=1
         BUSINESS_GROUP_ID=DECODE(SYS_CONTEXT('FND_VPD_CTX','FND_ENTERPRISE_ID'),NULL,BUSINESS_GROUP_ID,TO_NUMBER(SYS_CONTEXT('FND_VPD_CTX','FND_ENTERPRISE_ID')))
         Filter Predicates
         AND
         ACTIVE_FLAG='Y'
         OR
         OR
         BUSINESS_GROUP_ID=0
         BUSINESS_GROUP_ID=1
         BUSINESS_GROUP_ID=DECODE(SYS_CONTEXT('FND_VPD_CTX','FND_ENTERPRISE_ID'),NULL,BUSINESS_GROUP_ID,TO_NUMBER(SYS_CONTEXT('FND_VPD_CTX','FND_ENTERPRISE_ID')))
         TABLE ACCESS
         HZ_PARTIES
      STORAGE FULL
      83843
         Access Predicates
         LOWER(PARTY.EMAIL_ADDRESS)='[email protected]'
         Filter Predicates
         LOWER(PARTY.EMAIL_ADDRESS)='[email protected]'
    {code}
    Purvesh, around 50% are 'Yes'
    Thanks!

  • IPS event query ** Help needed badly**

    Greetings all. Apologies for the dramatic headline but I'm in a bit of a time crunch.
    I have a 4215 running 6.0(3)E1. The device is inline. Below is an event which triggered,
    ========================
    evIdsAlert: eventId=1184881408377311643 severity=low vendor=Cisco
    originator:
    hostId: xyz
    appName: sensorApp
    appInstanceId: 380
    time: 2007/09/24 15:11:25 2007/09/24 15:11:25 UTC
    signature: description=Recognized content type id=12673 version=S149
    subsigId: 0
    sigDetails: Recognized content type
    marsCategory: Info/Misc
    interfaceGroup: vs0
    vlan: 0
    participants:
    attacker:
    addr: locality=any a.a.a.a
    port: 80
    target:
    addr: locality=any b.b.b.b
    port: 51095
    os: idSource=unknown relevance=relevant type=unknown
    actions:
    deniedFlow: true
    context:
    fromAttacker: <stuff>
    riskRatingValue: attackRelevanceRating=relevant targetValueRating=medium 50
    threatRatingValue: 15
    interface: fe2_1
    protocol: tcp
    ========================
    I have an external application which pull this same event from the sensor using a query *like* the following,
    wget --user foo --password hoo http://a.b.c.d/cgi-bin/event-server?events=evAlert
    I'm able to pull most of the event information but not all. What I can't seem to get from query is the " deniedFlow: true" value. I'm seeing something like,
    ></attack></participants><actions></actions></evAlert>
    Notice the "deniedFlow: true" information missing between action.
    Is my wget-ish query missing some arguments which is preventing me from pulling all the same information I can see from the CLI?
    Thanks in advance.

    The problem is that you are using the 5.x-style event-server and so you do not see all of the event fields. You need to change the app to pull from the "sdee-server" and then you will see all of the event fields:
    http://a.b.c.d/cgi-bin/sdee-server?events=evAlert

  • Simple Query Help Needed

    I must not be in the right mode today, because this is giving
    me a hard time...
    I have a SQL Server database with 250,000 records. Each
    record represents a medical visit.
    Each record has 25 fields that contain patient diagnosis. A
    visit may show one diagnosis, or it may show as many as 25. Any
    specific diagnosis (250.00 for example) may appear in a field
    called Code1, or a field called Code2.... Code25.
    There are a total of about 500 patients that make up the
    250,000 visits.
    What I need is a report that shows each DISTINCT diagnosis,
    and a listing (and count) of people that have been assigned that
    diagnosis.
    My thought is to first query the table to arrive at the
    unique list of diagnosis codes. Then, in a nested loop, query the
    database to see who has been assigned that code, and how many
    times.
    This strikes me as an incredibly database intensive query,
    however.
    What is teh correct way to do this?

    The correct way to do this is to normalize your database.
    Rather than having 25 separate colums that essentially
    contain the same data (different codes), break that out into a
    separate table.
    Patient
    patientid
    Visit
    patientid (foreign key referencing Patient)
    visitid
    Diagnosis
    visitid (foreign key referencing visitid in Visit)
    diagnosiscode
    order (if the 1-25 ordering of diagnosis codes is important)
    Once you correct your datamodel, what you're trying to do
    becomes simple.
    -- get all diagnosis codes
    select distinct(diagnosiscode) from diagnosis
    -- get a breakdown of diagnosis codes, patients, and counts
    for that diagnosis
    select diagnosiscode, patient.name, count(diagnosiscode) from
    patient left join visit on (patient.patientid =
    visit.patientid)
    left join diagnosis on (visit.visitid = diagnosis.visitid)
    group by diagnosiscode, patient.name

Maybe you are looking for

  • I am getting error 1001 on my ipad 2 while upgrading updates

    When click to upgrade updates on my ipad 2 i get error 1001 and says please try again later.

  • Problems with Hints in abap code to use an index in a Select statement

    Hi, I want to use an especific index in a select statement but I can´t get it. I use de next statement: SELECT ltaklgnum ltaktanum ltakvbeln ltaptapos ltapnltyp ltappvqui        FROM ltak AS ltak INNER JOIN ltap AS ltap                         ON  lt

  • Reversal of sales invoice : isssue

    Hi experts, My user wants to reverse the sale invoice which was posted earlier.The he will post new invoice.My question is,what effect will come in FI , CO  and SD module,if he does it. Pl advise. Regards, Samar

  • Content.load("directory path");

    Hi..I have a flash file using a textarea component that brings in XML data. I'm running into an issue that involves my XML and CSS file residing on a different server. The ".load" command seems to only read a directory path. I think I need a command

  • Will I be able to keep my unlimited data?

    I have been on a family plan for over 10 years and we have unlimited data. Last year I decided to upgrade to the galaxy note 2 even though the rep said I was going to lose my data and be downgraded to 2GB per month. They said that even though my data