Query performance concerning count

Hi
I join three tables based on indexed fields.
Two tables have 25000 records, the third has only
a couple of records. The result of the join is
25000 records.
The query runs in 0.2 seconds. Very fast.
I try to count the records replacing the select ID
with count(ID) or with count(*) and it takes 2 seconds
to count the rows.
Any ideas ?
Thank you !!

COUNT(*) can most certainly make use of indexes, assuming you're using the cost-based optimizer and you have gathered statistics recently.
First, let's walk through what happens when there are no statistics on a table
scott@jcave > ANALYZE TABLE my_table DELETE STATISTICS;
scott@jcave > desc my_table;
Name                  Null?    Type
MYKEY                 NOT NULL NUMBER
VALUE                          VARCHAR2(100)
scott@jcave > set autotrace on;
scott@jcave > select count(*) from my_table;
  COUNT(*)
    227610
Elapsed: 00:00:03.03
Execution Plan
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   SORT (AGGREGATE)
   2    1     TABLE ACCESS (FULL) OF 'MY_TABLE'
Statistics
         36  recursive calls
          0  db block gets
       1145  consistent gets
       1126  physical reads
        480  redo size
        381  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processedSo, it took 3 seconds to full-scan the table when there were no statistics. Now, lets gather some statistics and try again. Note that I'll be using the ANALYZE command, but production databases should probably be gathering statistics with the dbms_stats package regularly.
scott@jcave > analyze table my_table compute statistics;
Table analyzed.
Elapsed: 00:00:09.07
scott@jcave > analyze table my_table compute statistics for all indexes;
Table analyzed.
Elapsed: 00:00:04.00
scott@jcave > select count(*) from my_table;
  COUNT(*)
    227610
Elapsed: 00:00:00.08
Execution Plan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=43 Card=1)
   1    0   SORT (AGGREGATE)
   2    1     INDEX (FAST FULL SCAN) OF 'SYS_C003704' (UNIQUE) (Cost=4
          3 Card=227610)
Statistics
         55  recursive calls
          2  db block gets
        517  consistent gets
        489  physical reads
        120  redo size
        381  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processedWe've gone down to a fraction of a second, now that the CBO knows that the index will be useful.
The moral of the story is that if you haven't gathered statistics recently, you may want to try doing so.
Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com/askDDBC

Similar Messages

  • SQL Query Performance Concern

    Hi All,
    I have a two type of query  below
     Query 1:
    Select  A.name, C.description  from  A   JOIN B   ON A.id=B.id
    LEFT JOIN C ON b.id=c.id 
    where B.status<>'PASS'
    Query 2:
    Select  A.name, C.description  from  A   JOIN  B   ON A.id=B.id  AND B.status<>'PASS'
    LEFT JOIN C ON b.id=c.id 
     which one will give the best performance in the above. Table A ,B And C have more than million records.
    Regards,
    Thiru 
    Thiru

    As its an INNER JOIN in the above case the queries are equivalent and so is the plan created by the optimizer.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Query performance concerning order by

    Hi
    The following query taks 0.2 seconds
    select * from messagerecipients order by messageid
    Also the following one takes same amount of time
    select * from messagerecipients order by groupid
    I want to order by both messageid and groupid so
    I try both the following ways :
    1)
    select * from messagerecipients order by messageid, groupid
    2)
    select * from
    ( select * from messagerecipients order by messageid)
    order by groupid
    Both ways take around 2 seconds (10 times slower than
    each query on each own).
    Any ideas ?
    Thanks !!

    I just noticed the following:
    messagerecipients has 39998 rows.
    The following runs in 0.2 secs
    select * from (
    select * from messagerecipients
    order by messageid, groupid
    ) where rownum < 38000
    While the following in 2.5 secs
    select * from (
    select * from messagerecipients
    order by messageid, groupid
    ) where rownum < 39000
    Very strange !!!
    Does that give you any ideas maybe ?
    Thank you once again !!

  • Query performance slow WHY

    Its 11G R2 version, and query is performing very slow
    SELECT OBJSTATE
    FROM
    SUB_CON_CALL_OFF WHERE SUB_CON_NO = :B2 AND CALL_OFF_SEQ = :B1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse      140      0.00       0.00          0          0          0           0
    Execute 798747      8.34      14.01          0          4          0           0
    Fetch   798747     22.22      35.54          0    7987470          0      798747
    total   1597634     30.56      49.56          0    7987474          0      798747
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 51     (recursive depth: 1)
    Rows     Row Source Operation
          5  FILTER  (cr=50 pr=0 pw=0 time=239 us)
          5   NESTED LOOPS  (cr=40 pr=0 pw=0 time=164 us)
          5    NESTED LOOPS  (cr=30 pr=0 pw=0 time=117 us)
          5     TABLE ACCESS BY INDEX ROWID SUB_CON_CALL_OFF_TAB (cr=15 pr=0 pw=0 time=69 us)
          5      INDEX UNIQUE SCAN SUB_CON_CALL_OFF_PK (cr=10 pr=0 pw=0 time=41 us)(object id 59706)
          5     TABLE ACCESS BY INDEX ROWID SUB_CONTRACT_TAB (cr=15 pr=0 pw=0 time=42 us)
          5      INDEX UNIQUE SCAN SUB_CONTRACT_PK (cr=10 pr=0 pw=0 time=26 us)(object id 59666)
          5    INDEX UNIQUE SCAN USER_PROFILE_ENTRY_SYS_PK (cr=10 pr=0 pw=0 time=41 us)(object id 60891)
          5   INDEX UNIQUE SCAN USER_ALLOWED_SITE_PK (cr=10 pr=0 pw=0 time=36 us)(object id 60866)
          5    FAST DUAL  (cr=0 pr=0 pw=0 time=4 us)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      library cache lock                              1        0.00          0.00
      gc cr block 2-way                               3        0.00          0.00
      gc current block 2-way                          1        0.00          0.00
      gc cr multi block request                       4        0.00          0.00 Edited by: 842638 on Feb 2, 2013 5:52 AM

    Hi Mark,
    Just have few basic doubts regarding the below query performance :
    call     count       cpu    elapsed       disk      query    current        rows
    Parse      140      0.00       0.00          0          0          0           0
    Execute 798747      8.34      14.01          0          4          0           0
    Fetch   798747     22.22      35.54          0    7987470          0      798747
    total   1597634     30.56      49.56          0    7987474          0      798747
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 51     (recursive depth: 1)
    Rows     Row Source Operation
           5  FILTER  (cr=50 pr=0 pw=0 time=239 us)
           5   NESTED LOOPS  (cr=40 pr=0 pw=0 time=164 us)
           5    NESTED LOOPS  (cr=30 pr=0 pw=0 time=117 us)
           5     TABLE ACCESS BY INDEX ROWID SUB_CON_CALL_OFF_TAB (cr=15 pr=0 pw=0 time=69 us)
           5      INDEX UNIQUE SCAN SUB_CON_CALL_OFF_PK (cr=10 pr=0 pw=0 time=41 us)(object id 59706)
           5     TABLE ACCESS BY INDEX ROWID SUB_CONTRACT_TAB (cr=15 pr=0 pw=0 time=42 us)
           5      INDEX UNIQUE SCAN SUB_CONTRACT_PK (cr=10 pr=0 pw=0 time=26 us)(object id 59666)
           5    INDEX UNIQUE SCAN USER_PROFILE_ENTRY_SYS_PK (cr=10 pr=0 pw=0 time=41 us)(object id 60891)
           5   INDEX UNIQUE SCAN USER_ALLOWED_SITE_PK (cr=10 pr=0 pw=0 time=36 us)(object id 60866)
           5    FAST DUAL  (cr=0 pr=0 pw=0 time=4 us)
    Elapsed times include waiting on following events:
       Event waited on                             Times   Max. Wait  Total Waited
       ----------------------------------------   Waited  ----------  ------------
       library cache lock                              1        0.00          0.00
       gc cr block 2-way                               3        0.00          0.00
       gc current block 2-way                          1        0.00          0.00
       gc cr multi block request                       4        0.00          0.00
    1] How do you determine that this query performance is +ok+ ?
    2] What is the actual need of checking the query performance this way?
    3] Is this the TKPROF output?
    4] How do you know that the query was +called+ 798747 times? the +execute+ shows 0
    Could you please help me with this?
    Thanks.
    Ranit B.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Performance concern

    Dear Experts,
    The below query is causing a lot of performance concern. Kindly go through and let me know about the suitable modifications i can make.
    select
              vbeln
              fkart
              vkorg
              vtweg
              fkdat
              sum( fkimg ) as fkimg
              matnr
              aubel
              vstel
              ktgrm
              matkl
              prctr
              spart
              SAKN1
              from ZV_BSEG_VBRP_RK
              into table it_sales
              where
              fkdat_i in s_fkdat and
              vtweg in s_vtweg and
              vkorg in s_vkorg and
              fkart in so_fkart and
              spart in s_spart and
              vstel in s_werks and
              matnr in s_matnr and
              vbeln in s_vbeln and
              fkimg ne '0' and
              ktgrm in ('01','02','03','04','05','06','07','08','09','10','11','12') and
              fksto ne 'X'
              group by vbeln fkart vkorg vtweg fkdat matnr aubel vstel ktgrm matkl prctr spart SAKN1.
        sort it_sales by vbeln matnr prctr.
        if it_sales[] is not initial.
    select vbeln fkdat GJAHR VKORG from vbrk into table it_vbeln for all entries in it_sales where vbeln = it_sales-vbeln.
        select
              belnr
              shkzg
              dmbtr
              hkont
              MATNR
              prctr
              from bsEG into table it_fin1
              for all entries in it_vbeln
              where belnr = it_vbeln-vbeln AND
              BUKRS EQ IT_VBELN-VKORG and
              hkont >= '0000400001' and hkont <= '0000400251'.
    *          hkont = it_sales-sakn1.
    *          group by belnr shkzg hkont prctr.
              SORT IT_FIN BY hkont.
    *delete it_fin where hkont >= '0000400001' and hkont <= '0000400251'.
              SORT IT_FIN BY BELNR MATNR PRCTR.
            IF it_fin1[] IS NOT INITIAL.
    loop at it_fin1.
    move-corresponding it_fin1 to it_fin.
    collect it_fin.
    append it_fin.
    endloop.
              loop at it_fin.
                it_data_1-vbeln = it_fin-belnr.
                it_data_1-matnr = it_fin-matnr.
                it_data_1-prctr = it_fin-prctr.
    *read table it_sales transporting no fields with key vbeln = it_data_1-vbeln matnr = it_Data_1-matnr prctr = it_data_1-prctr.
    *if sy-subrc = 0.
    *tabix = sy-tabix.
    *FOR SALES INVOICE
    read table it_sales with key vbeln = it_data_1-vbeln matnr = it_Data_1-matnr prctr = it_data_1-prctr.
                it_data_1-aubel = it_sales-aubel.
                it_data_1-vstel = it_sales-vstel.
                it_data_1-ktgrm = it_sales-ktgrm.
                it_data_1-matkl = it_sales-matkl.
                it_data_1-fkart = it_sales-fkart.
                it_data_1-vkorg = it_sales-vkorg.
                it_data_1-vtweg = it_sales-vtweg.
                it_data_1-fkdat = it_sales-fkdat.
                it_data_1-spart = it_sales-spart.
                if it_data_1-fkart = 'F2' or  it_data_1-fkart = 'IV' or  it_data_1-fkart = 'ZF2' or it_data_1-fkart = 'ZMIS' or  it_data_1-fkart = 'ZSF2' or it_data_1-fkart = 'ZMF2'.
                  it_data_1-fkimg = it_sales-fkimg.
                  it_data_1-shkzg = it_fin-shkzg.
                  if it_data_1-shkzg = 'H'.
                  it_data_1-dmbtr_1 = it_data_1-dmbtr_1 + it_fin-dmbtr.
                  endif.
                  if it_data_1-shkzg = 'S'.
                  it_data_1-dmbtr_2 = it_data_1-dmbtr_2 + it_fin-dmbtr.
                  endif.
                  endif.
    * H - Credit
    * S - Debit
                if it_data_1-fkart = 'G2' or  it_data_1-fkart = 'IG' or  it_data_1-fkart = 'RE' or  it_data_1-fkart = 'ZCRE'.
                  if it_data_1-fkart = 'G2'.
                    it_data_1-cr_qty = '0'.
                  else.
                    it_data_1-cr_qty = it_sales-fkimg.
                  endif.
                  it_data_1-shkzg = it_fin-shkzg.
                  if it_data_1-shkzg = 'H'.
                  it_data_1-dmbtr_cr_1 = it_data_1-dmbtr_cr_1 + it_fin-dmbtr.
                  endif.
                  if it_data_1-shkzg = 'S'.
                  it_data_1-dmbtr_cr_2 = it_data_1-dmbtr_cr_2 + it_fin-dmbtr.
                  endif.
                  endif.
                if it_data_1-fkart = 'L2'.
                  it_data_1-dr_qty = 0.
                  it_data_1-shkzg = it_fin-shkzg.
                  if it_data_1-shkzg = 'H'.
                  it_data_1-dmbtr_dr_1 = it_data_1-dmbtr_dr_1 + it_fin-dmbtr.
                  endif.
                  if it_data_1-shkzg = 'S'.
                  it_data_1-dmbtr_dr_2 = it_data_1-dmbtr_dr_2 + it_fin-dmbtr .
                  endif.
                endif.
                select single vtext into it_data_1-vtext from tvkmt where spras = 'EN' and ktgrm = it_data_1-ktgrm.
                select single txt20 into it_data_1-gltxt from skat where spras = 'EN' and saknr = it_data_1-hkont and ktopl = '1000'.
                select single maktg into it_data_1-maktg from makt where matnr = it_data_1-matnr.
                select single vtext into it_data_1-division from tspat where spart = it_data_1-spart and spras = 'EN'.
                append it_data_1.
                clear it_data_1.
                clear it_sales.
              endloop.
              sort it_data_1 by matnr vbeln.
    if p_check ne 'X'.
              loop at it_data_1.
                concatenate it_data_1-matnr ' ' it_data_1-matkl ' ' it_data_1-ktgrm into it_final_1-count.
                move: it_data_1-matnr to it_final_1-matnr,
                      it_data_1-matkl to it_final_1-matkl,
                      it_data_1-ktgrm to it_final_1-ktgrm,
                      it_data_1-vtext to it_final_1-vtext,
                      it_data_1-sakn1 to it_final_1-sakn1,
                      it_data_1-spart to it_final_1-spart,
                      it_data_1-gltxt to it_final_1-gltxt,
                      it_data_1-division to it_final_1-division,
                      it_data_1-prctr to it_final_1-prctr,
                      it_data_1-maktg to it_final_1-maktg,
                      it_data_1-fkimg to it_final_1-fkimg,
    *                  it_data_1-dmbtr to it_final_1-dmbtr,
    *                  it_data_1-dmbtr_cr to it_final_1-dmbtr_cr,
    *                  it_data_1-dmbtr_dr to it_final_1-dmbtr_dr,
                      it_data_1-dr_qty to it_final_1-dr_qty,
                      it_data_1-cr_qty to it_final_1-cr_qty,
                      it_data_1-dmbtr_1 TO it_final_1-dmbtr_1,
                      it_data_1-dmbtr_2 TO it_final_1-dmbtr_2,
                      it_data_1-dmbtr_dr_1 TO it_final_1-dmbtr_dr_1,
                      it_data_1-dmbtr_dr_2 TO it_final_1-dmbtr_dr_2,
                      it_data_1-dmbtr_cr_1 TO it_final_1-dmbtr_cr_1,
                      it_data_1-dmbtr_cr_2 TO it_final_1-dmbtr_cr_2.
                append it_final_1.
                clear it_data_1.
              endloop.
              data: wa_matnr_1 like mara-matnr,
                    wa_matkl_1 like vbrp-matkl,
                    wa_ktgrm_1 like vbrp-ktgrm,
                    wa_hkont like bsis-hkont,
                    wa_gltxt like skat-txt20,
                    wa_hkont_dr like bsis-hkont,
                    wa_hkont_cr like bsis-hkont,
                    wa_maktg_1 like makt-maktg,
                    wa_vtext_1 like tvkmt-vtext,
                    wa_vtext_2 like tspat-vtext,
                    wa_spart like vbrk-spart,
                    wa_prctr like vbrp-prctr.
              sort it_final_1 by matnr matkl ktgrm division prctr hkont.
              loop at it_final_1.
                wa_matnr_1 = it_final_1-matnr.
                wa_matkl_1 = it_final_1-matkl.
                wa_ktgrm_1 = it_final_1-ktgrm.
                wa_vtext_1 = it_final_1-vtext.
                wa_spart = it_final_1-spart.
                wa_hkont = it_final_1-sakn1.
                wa_gltxt = it_final_1-gltxt.
                wa_vtext_2 = it_final_1-division.
                wa_prctr = it_final_1-prctr.
                wa_maktg_1 = it_final_1-maktg.
    *        wa_hkont_cr = it_final_1-hkont_cr.
                at end of count.
                  sum.
    *          it_gl-hkont_dr = it_final_1-hkont_dr.
    *          it_gl-hkont_cr = it_final_1-hkont_cr.
                  it_gl-fkimg = it_final_1-fkimg.
                  it_gl-dr_qty = it_final_1-dr_qty.
                  it_gl-cr_qty = it_final_1-cr_qty.
                  it_gl-dmbtr_1 = it_final_1-dmbtr_1.
                  it_gl-dmbtr_2 = it_final_1-dmbtr_2.
                  it_gl-dmbtr = it_final_1-dmbtr_1 - it_final_1-dmbtr_2.
    *it_gl-dmbtr = it_final_1-dmbtr.
                  it_gl-dmbtr_dr_1 = it_final_1-dmbtr_dr_1.
                  it_gl-dmbtr_dr_2 = it_final_1-dmbtr_dr_2.
                  it_gl-dmbtr_dr = it_final_1-dmbtr_dr_1 - it_final_1-dmbtr_dr_2.
    *it_gl-dmbtr_dr = it_final_1-dmbtr_dr.
                  it_gl-dmbtr_cr_1 = it_final_1-dmbtr_cr_1.
                  it_gl-dmbtr_cr_2 = it_final_1-dmbtr_cr_2.
                  it_gl-dmbtr_cr = it_final_1-dmbtr_cr_1 - it_final_1-dmbtr_cr_2.
    *it_gl-dmbtr_cr = it_final_1-dmbtr_cr.
                  it_gl-gltxt = wa_gltxt.
                  it_gl-matnr = wa_matnr_1.
                  it_gl-matkl = wa_matkl_1.
                  it_gl-vtext = wa_vtext_1.
                  it_gl-spart = wa_spart.
                  it_gl-division = wa_vtext_2.
                  it_gl-prctr = wa_prctr.
                  it_gl-hkont = wa_hkont.
                  it_gl-maktg = wa_maktg_1.
                  it_gl-netqty = ( it_gl-fkimg + it_gl-dr_qty ) - ( it_gl-cr_qty ).
                  it_gl-netval = ( it_gl-dmbtr + it_gl-dmbtr_dr ) - ( it_gl-dmbtr_cr ).
                  append it_gl.
                  clear wa_matnr_1.
                  clear wa_vtext_1.
                  clear wa_matkl_1.
                  clear wa_ktgrm_1.
                  clear wa_hkont.
                  clear wa_hkont_dr.
                  clear wa_hkont_cr.
                endat.
                clear it_final_1.
                clear it_gl.
              endloop.
            endif.
          ENDIF.
      endif.
    Do provide your valuable suggestions
    Regards,
    Jitesh
    Use meaningful subject for your Future questions
    Edited by: Vijay Babu Dudla on Mar 23, 2009 6:20 AM

    Assuming you are using standard tables instead of sorted or hashed, your problem is likely here:
    loop at it_fin.
      read table it_sales with
        key vbeln = it_data_1-vbeln
        matnr = it_Data_1-matnr
        prctr = it_data_1-prctr.
    endloop.
    The read without the binary search option is in effect a nested loop. so have a look at:
    [Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]
    Rob

  • Query performance.

    Hi
    I have created a procedure that accepts two bind variables from a report. The user will select one or the other, both or neither of the variables. To return the appropriate results i have created a view with the entire result set and in the procedure are a number of if statements that determine what to place in the where clause selecting from the view, depending on what variables populated.
    My concern is that the query that generates the view includes several joins and in total outputs around 150,000 records and seems to be rather slow to run.
    Would you recommend another solution such as placing the query in the procedure itself repeated for every if statement?
    Or should I work on the query performance?
    What would be the most efficient solution for my problem?
    Any advice would be greatly appreciated.
    Thanks

    [url http://forums.oracle.com/forums/thread.jspa?threadID=501834&tstart=0]When your query takes too long

  • Query performance vs MySQL

    I have a table with about 500 million records in it stored within both Oracle and MySQL (MyISAM). I have a column (say phone_number) with a standard b-tree index on it in both places. Without data or indexes cached (not enough memory to fully cache the index), I run about 10,000 queries using randomly generated phone numbers as criteria in 10 concurrent threads. It seems that the average time to retrieve a record in MySQL is about 200 milliseconds whereas in Oracle it is about 400 milliseconds. I'm just wondering if MyISAM/MySQL is inherently faster for a basic index search than Oracle is, or should I be able to tune Oracle to get comparable performance.
    Of course the hardware configurations and storage configurations are the same. It's not the absolute time I'm concerned about here but the relative time. Twice as long to perform basically the same query seems concerning. I enabled tracing and it seems like some of the problem may be the recursive calls Oracle is making. Is there some way to optimize this a bit further?
    Realize, I just want to look at query performance right now...ignoring all of the issues (locking, transactional integrity, etc.)
    Thanks,
    Greg

    In Oracle, a standard table is heap-organized. A b-tree index then contains index keys and ROWIDs, so if you need to read a particular row in the table, you first do a few I/O's on the index to get the ROWIDs and then look up the ROWIDs in the table. For any given key, ROWIDs are likely to be scattered throughout the table, so this latter step generally involves multiple scattered I/O's.
    You can create an index-organized table or a hash cluster in Oracle in order to minimize the cost of this particular sort of lookup by clustering data with the same key physically near each other and, in the case of IOTs, potentially eliminating the need to store the index and table separately. Of course, there are costs to doing this in that inserts are now more expensive and secondary indexes are likely to be less useful. That probably gets you closer to what MySQL is doing if, as ajallen indicates, a MySQL table is generally stored more like an IOT than a heap-organized table.
    If you get really creative, you could even partition this single table to potentially improve performance further.
    Of course, if you're only storing one table, I'm not sure that you could really justify the cost of an Oracle license. This may well be the case where MySQL is more than sufficient for what this particular customer needs (knowing, nothing, of course, about the other requirements for the system).
    Justin

  • SQL query performance issues.

    Hi All,
    I worked on the query a month ago and the fix worked for me in test intance but failed in production. Following is the URL for the previous thread.
    SQL query performance issues.
    Following is the tkprof file.
    CURSOR_ID:76  LENGTH:2383  ADDRESS:f6b40ab0  HASH_VALUE:2459471753  OPTIMIZER_GOAL:ALL_ROWS  USER_ID:443 (APPS)
    insert into cos_temp(
    TRX_DATE, DEPT, PRODUCT_LINE, PART_NUMBER,
    CUSTOMER_NUMBER, QUANTITY_SOLD, ORDER_NUMBER,
    INVOICE_NUMBER, EXT_SALES, EXT_COS,
    GROSS_PROFIT, ACCT_DATE,
    SHIPMENT_TYPE,
    FROM_ORGANIZATION_ID,
    FROM_ORGANIZATION_CODE)
    select a.trx_date,
    g.segment5 dept,
    g.segment4 prd,
    m.segment1 part,
    d.customer_number customer,
    b.quantity_invoiced units,
    --       substr(a.sales_order,1,6) order#,
    substr(ltrim(b.interface_line_attribute1),1,10) order#,
    a.trx_number invoice,
    (b.quantity_invoiced * b.unit_selling_price) sales,
    (b.quantity_invoiced * nvl(price.operand,0)) cos,
    (b.quantity_invoiced * b.unit_selling_price) -
    (b.quantity_invoiced * nvl(price.operand,0)) profit,
    to_char(to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS'),'DD-MON-RR') acct_date,
    'DRP',
    l.ship_from_org_id,
    p.organization_code
    from   ra_customers d,
    gl_code_combinations g,
    mtl_system_items m,
    ra_cust_trx_line_gl_dist c,
    ra_customer_trx_lines b,
    ra_customer_trx_all a,
    apps.oe_order_lines l,
    apps.HR_ORGANIZATION_INFORMATION i,
    apps.MTL_INTERCOMPANY_PARAMETERS inter,
    apps.HZ_CUST_SITE_USES_ALL site,
    apps.qp_list_lines_v price,
    apps.mtl_parameters p
    where a.trx_date between to_date('2010/02/01 00:00:00','yyyy/mm/dd HH24:MI:SS')
    and to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS')+0.9999
    and   a.batch_source_id = 1001     -- Sales order shipped other OU
    and   a.complete_flag = 'Y'
    and   a.customer_trx_id = b.customer_trx_id
    and   b.customer_trx_line_id = c.customer_trx_line_id
    and   a.sold_to_customer_id = d.customer_id
    and   b.inventory_item_id = m.inventory_item_id
    and   m.organization_id
         = decode(substr(g.segment4,1,2),'01',5004,'03',5004,
         '02',5003,'00',5001,5002)
    and   nvl(m.item_type,'0') <> '111'
    and   c.code_combination_id = g.code_combination_id+0
    and   l.line_id = b.interface_line_attribute6
    and   i.organization_id = l.ship_from_org_id
    and   p.organization_id = l.ship_from_org_id
    and   i.org_information3 <> '5108'
    and   inter.ship_organization_id = i.org_information3
    and   inter.sell_organization_id = '5108'
    and   inter.customer_site_id = site.site_use_id
    and   site.price_list_id = price.list_header_id
    and   product_attr_value = to_char(m.inventory_item_id)
    call        count       cpu   elapsed         disk        query      current         rows    misses
    Parse           1      0.47      0.56           11          197            0            0         1
    Execute         1   3733.40   3739.40        34893    519962154           11          188         0
    total           2   3733.87   3739.97        34904    519962351           11          188         1
    |         Rows Row Source Operation
    | ------------ ---------------------------------------------------
    |          188 HASH JOIN (cr=519962149 pr=34889 pw=0 time=2607.35)
    |          741 .TABLE ACCESS BY INDEX ROWID QP_PRICING_ATTRIBUTES (cr=519939426 pr=34889 pw=0 time=2457.32)
    |    254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
    |    254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)
    |          741 ....NESTED LOOPS (cr=50042 pr=7230 pw=0 time=11.37)
    |          741 .....NESTED LOOPS (cr=48558 pr=7229 pw=0 time=11.35)
    |          741 ......NESTED LOOPS (cr=47815 pr=7223 pw=0 time=11.32)
    |         3237 .......NESTED LOOPS (cr=41339 pr=7223 pw=0 time=12.42)
    |         3237 ........NESTED LOOPS (cr=38100 pr=7223 pw=0 time=12.39)
    |         3237 .........NESTED LOOPS (cr=28296 pr=7139 pw=0 time=12.29)
    |         1027 ..........NESTED LOOPS (cr=17656 pr=4471 pw=0 time=3.81)
    |         1027 ...........NESTED LOOPS (cr=13537 pr=4404 pw=0 time=3.30)
    |          486 ............NESTED LOOPS (cr=10873 pr=4240 pw=0 time=0.04)
    |          486 .............NESTED LOOPS (cr=10385 pr=4240 pw=0 time=0.03)
    |          486 ..............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_ALL (cr=9411 pr=4240 pw=0 time=0.02)
    |        75253 ...............INDEX RANGE SCAN RA_CUSTOMER_TRX_N5 (cr=403 pr=285 pw=0 time=0.38)
    |          486 ..............TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=974 pr=0 pw=0 time=0.01)
    |          486 ...............INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=488 pr=0 pw=0 time=0.01)
    |          486 .............INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=488 pr=0 pw=0 time=0.01)
    |         1027 ............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_LINES_ALL (cr=2664 pr=164 pw=0 time=1.95)
    |         2063 .............INDEX RANGE SCAN RA_CUSTOMER_TRX_LINES_N2 (cr=1474 pr=28 pw=0 time=0.22)
    |         1027 ...........TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_LINE_GL_DIST_ALL (cr=4119 pr=67 pw=0 time=0.54)
    |         1027 ............INDEX RANGE SCAN RA_CUST_TRX_LINE_GL_DIST_N1 (cr=3092 pr=31 pw=0 time=0.20)
    |         3237 ..........TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=10640 pr=2668 pw=0 time=15.35)
    |         3237 ...........INDEX RANGE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2062 pr=40 pw=0 time=0.33)
    |         3237 .........TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=9804 pr=84 pw=0 time=0.77)
    |         3237 ..........INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=6476 pr=47 pw=0 time=0.43)
    |         3237 ........TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=3239 pr=0 pw=0 time=0.04)
    |         3237 .........INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=2 pr=0 pw=0 time=0.01)
    |          741 .......TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=6476 pr=0 pw=0 time=0.10)
    |         6474 ........INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=3239 pr=0 pw=0 time=0.03)Please help.
    Regards
    Ashish

    |    254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
    |    254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)There is no way the optimizer should choose to process that many rows using nested loops.
    Either the statistics are not up to date, the data values are skewed or you have some optimizer parameter set to none default to force index access.
    Please post explain plan and optimizer* parameter settings.

  • Forms - Query - Performance

    Hi,
    I am working on a application Developed in Forms10g and Oralce 10g.
    I have few very large transaction tables in db and most of the screens in my application based on these tables only.
    When user performs a query (with out any filter conditions) the whole table(s) loaded into memory and takes very long time. Further queries on the same screen perform better.
    How can I keep these tables in memory (buffer) always to reduce the initial query time?
    or
    Is there any way to share the session buffers with other sessions, sothat it does not take long time in each session?
    or
    Any query performance tuning suggestions will be appreciated.
    Thanks in advance

    Thanks a lot for your posts, very large means around
    12 million rows. Yep, that's a large table
    I have set the query all records to "No". Which is good. It means only enough records are fetched to fill the initial block. That's probably about 10 records. All the other records are not fetched from the database, so they're also not kept in memory at the Forms server.
    Even when I try the query in SQL PLUS it is taking
    long time. Sounds like a query performance problem, not a Forms issue. You're probably better of asking in the database or SQL forum. You could at least include the SELECT statement here if you want any help with it. We can't guess why a query is slow if we have no idea what the query is.
    My concern is, when I execute the same query again or
    in another session (some other user or same user),
    can I increase the performance because the tables are
    already in memory. any possibility for this? Can I
    set any database parameters to share the data between
    sessions like that... The database already does this. If data is retrieved from disk for one user it is cached in the SGA (Shared Global Area). Mind the word Shared. This caching information is shared by all sessions, so other users should benefit from it.
    Caching also has its limits. The most obvious one is the size of the SGA of the database server. If the table is 200 megabyte and the server only has 8 megabyte of cache available, than caching is of little use.
    Am I thinking in the right way? or I lost some where?Don't know.
    There's two approaches:
    - try to tune the query or database to have better performance. For starters, open SQL*Plus, execute "set timing on", then execute "set autotrace traceonly explain statistics", then execute your query and look at the results. it should give you an idea on how the database is executing the query and what improvements could be made. You could come back here with the SELECT statement and timing and trace results, but the database or SQL forum is probably better
    - MORE IMPORTANTLY: think if it is necessary for users to perform such time consuming (and perhaps complex) queries. Do users really need the ability to query all records. Are they ever going to browse through millions of records?
    >
    >
    Thanks

  • Create dynamic report or query for piece count

    Hi abaper's
    This is a very straight forward requirement. so please give me code
    First you have to get the corresponding plant from table T320 for the given warehouse numbers in the selection screen. 
    1.     Get the sum of order qty of sales orders from the sales order tables      for the given warehouse(Plant), distribution channel and the give date      range.
    2.     Get the confirmed transfer orders qty from the TO master table where      TO confirmation date is in the given date range and WH number.
    3.     Get the total PGIed qty from the delivery master table where PGI'ed      date in the given date range, shipping point is in the corresponding      plant of the WH and for the given distribution channel.
    As you are going to use the major tables please try to write the select commands effectively to avoid further performance issues.

    How to improve the performance fo this code.....this very urgent.
    & Issue Number          : 22199                                    &
    & Programmer            : Anjaneyulu.Pabba                         &
    & Transport Number      : D01K962471                               &
    & Date of Creation      : 19/03/2008                               &
    & Description           : Dynamic report or query for piece count  &
    & Requested By          : Parvati.Polisetty                        &
    REPORT  ZR_SD_PIECE_COUNT_ALV no standard page heading
                                  line-size 255
                                  line-count 65.
                          TABLES DECLARATION
    *TABLES: T320,   "Assignment IM Storage Location to WM Warehouse Number
          VBAK,   "Sales Document: Header Data
          VBAP,   "Sales Document: Item Data
          TVKOV,  "Org. Unit: Distribution Channels per Sales Organization
          LTAK,   "WM transfer order header
          LTAP,   "Transfer order item
          LIKP,   "SD Document: Delivery Header Data
          LIPS.   "SD document: Delivery: Item data
                          TYPE-POOLS DECLARATION
    TYPE-POOLS: SLIS .
         Internal Table Declaration
    DATA : BEGIN OF TY_T320,
            WERKS TYPE WERKS_D,
            LGNUM TYPE LGNUM,
           END OF TY_T320.
    DATA : BEGIN OF TY_VBAK,
            VBELN  TYPE VBELN_VA,
            VTWEG  TYPE VTWEG,
            WERKS  TYPE WERKS_D,
            KWMENG TYPE KWMENG,
            VSTEL  TYPE VSTEL,
           END OF TY_VBAK.
    DATA : BEGIN OF TY_LTAK,
            LGNUM TYPE LGNUM,
            TANUM TYPE TANUM,
            VISTA TYPE LTAP_VISTA,
           END OF TY_LTAK.
    DATA : BEGIN OF TY_LIKP,
            VBELN TYPE VBELN_VL,
            WERKS TYPE WERKS_D,
            LFIMG TYPE LFIMG,
           END OF TY_LIKP.
    DATA : BEGIN OF TY_ITAB ,
    LGNUM  TYPE LGNUM,    "Warehouse Number / Warehouse Complex
    WERKS  TYPE WERKS_D,  "Plant
    VBELN  TYPE VBELN_VA, "Sales Document
    VTWEG  TYPE VTWEG,   "Distribution Channel
    KWMENG TYPE KWMENG,  "Cumulative order quantity in sales units
    TANUM  TYPE TANUM ,     "Transfer Order Number
    VISTA  TYPE LTAP_VISTA, "Source actual quantity in alternative
                                                 unit of measure
    LFIMG  TYPE LFIMG,  "Actual quantity delivered (in sales units)
    END OF TY_ITAB .
    DATA: T_T320 LIKE STANDARD TABLE OF TY_T320 INITIAL SIZE 0 WITH HEADER
                                                                   LINE,
          T_VBAK LIKE STANDARD TABLE OF TY_VBAK INITIAL SIZE 0 .
    DATA: T_LTAK LIKE STANDARD TABLE OF TY_LTAK INITIAL SIZE 0 WITH HEADER
                                                                    LINE.
    DATA :T_LIKP LIKE STANDARD TABLE OF TY_LIKP INITIAL SIZE 0 WITH HEADER
                                                                    LINE.
    DATA:T_ITAB LIKE STANDARD TABLE OF TY_ITAB INITIAL SIZE 0 WITH HEADER
                                                                   LINE .
    *&      Fieldcatalog Declaration
    DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV,
           W_FCAT TYPE SLIS_FIELDCAT_ALV.
    DATA : W_LAYOUT TYPE SLIS_LAYOUT_ALV.
    ********Global Data Declaration***
    DATA :G_REPID        LIKE SY-REPID,
         G_EXIT(1)      TYPE C,
         GX_VARIANT     LIKE DISVARIANT,
         X_SAVE,                          "for Parameter I_SAVE
         GS_VARIANT TYPE DISVARIANT.      "for parameter IS_VARIANT
    data: g_lgnum type t320-lgnum,
          g_vtweg type vbak-vtweg,
          g_erdat type vbak-erdat.
    *&      Selection-Screen
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_LGNUM FOR  g_lgnum, "Warehouse Number
                    S_VTWEG FOR g_vtweg, "Distribution Channel
                    S_ERDAT FOR g_erdat ."Date on which the record was
    **********"created
    SELECTION-SCREEN END OF BLOCK B1 .
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
    PARAMETER: P_VARI LIKE DISVARIANT-VARIANT.  "Layout
    SELECTION-SCREEN END OF BLOCK B2.
    *&       INITIALIZATION EVENT
    INITIALIZATION.
      CLEAR GS_VARIANT.
    'gs_variant' must at least contain the report-id to allow
    saving a variant.
      G_REPID = SY-REPID.
    § 2.At least field REPORT of this structure has to be filled!
      GS_VARIANT-REPORT = G_REPID.
    § 3.Determine saving options.
      X_SAVE = 'A'.   "The user may save all types of variants
    *******Validating selection-screen values**********************
    getting F4 value for display variant field
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.
      PERFORM F4_FOR_VARIANT.
    ****validation of F4 value of display variant
    AT SELECTION-SCREEN.
      PERFORM PAI_OF_SELECTION_SCREEN.
    *&      Start-Of-Selection
    START-OF-SELECTION.
    *****Subroutine to  select Plant from T320
      PERFORM FIND_PLANT .
    *****Subroutine to select Order Quantity from VBAP
      PERFORM ORDER_QUANTITY .
    *****Subroutine to select Transfer Order Quantity from LTAK and LTAP
      PERFORM TRANSFER_ORDER_QUANTITY.
    *****Subroutine to select TDelivery Quantity from  LIKP and LIPS
      PERFORM DELIVERY_QUANTITY.
    *&      End-Of-Selection
    END-OF-SELECTION.
    *****Subroutine for Fieldcatalog
      PERFORM FIELDCATALOG .
    *****Subroutine for Final Output
      PERFORM DISPLAY_OUTPUT .
    *&     Subroutine Implementaion
    *&      Form  FIND_PLANT
          text
    -->  p1        text
    <--  p2        text
    FORM FIND_PLANT .
      SELECT  WERKS
              LGNUM
              FROM T320
              INTO  TABLE T_T320
              WHERE LGNUM IN S_LGNUM.
    ENDFORM.                    " FIND_PLANT
    *&      Form  order_quantity
          text
    -->  p1        text
    <--  p2        text
    FORM ORDER_QUANTITY .
      SELECT VK~VBELN
             VK~VTWEG
             VP~WERKS
             VP~KWMENG
             VP~VSTEL
             INTO TABLE T_VBAK FROM VBAK AS VK
             INNER JOIN  VBAP AS VP
             ON VKVBELN = VPVBELN
             FOR ALL ENTRIES IN T_T320
             WHERE VK~VTWEG IN S_VTWEG
             AND   VK~ERDAT IN S_ERDAT
             AND   VP~WERKS = T_T320-WERKS.
    ENDFORM.                    " order_quantity
    *&      Form  Transfer_order_quantity
          text
    -->  p1        text
    <--  p2        text
    FORM TRANSFER_ORDER_QUANTITY .
      SELECT LK~LGNUM
             LK~TANUM
             LP~VISTA
             INTO TABLE T_LTAK FROM LTAK AS LK
             INNER JOIN LTAP AS LP
             ON LKLGNUM = LPLGNUM
             WHERE LK~KQUIT = 'X'
             AND   LK~BDATU IN S_ERDAT
             AND   LK~LGNUM IN S_LGNUM.
    ENDFORM.                    " Transfer_order_quantity
    *&      Form  Delivery_QUANTITY
          text
    -->  p1        text
    <--  p2        text
    FORM DELIVERY_QUANTITY .
      SELECT  VBELN WERKS LFIMG FROM LIPS
              INTO TABLE T_LIKP
              FOR ALL ENTRIES IN T_T320
              WHERE WERKS = T_T320-WERKS
              AND ERDAT IN S_ERDAT
              AND VTWEG IN S_VTWEG.
    ENDFORM.                    " Delivery_QUANTITY
    *&      Form  fieldcatalog
          text
    -->  p1        text
    <--  p2        text
    FORM FIELDCATALOG .
      W_FCAT-COL_POS       = '1' .
      W_FCAT-FIELDNAME     = 'LGNUM' .
      W_FCAT-REF_TABNAME   = 'T320'.
      W_FCAT-REF_FIELDNAME = 'LGNUM' .
      APPEND W_FCAT TO T_FCAT.
      CLEAR W_FCAT.
      W_FCAT-COL_POS       = '2' .
      W_FCAT-FIELDNAME     = 'VTWEG' .
      W_FCAT-REF_TABNAME   = 'VBAK'.
      W_FCAT-REF_FIELDNAME = 'VTWEG' .
      APPEND W_FCAT TO T_FCAT.
      CLEAR W_FCAT.
      W_FCAT-COL_POS       = '3' .
      W_FCAT-FIELDNAME     = 'KWMENG' .
      W_FCAT-REF_TABNAME   = 'VBAP'.
      W_FCAT-REF_FIELDNAME = 'KWMENG' .
    *w_fcat-seltext_m     = '# of Orders'.
      APPEND W_FCAT TO T_FCAT.
      CLEAR W_FCAT.
      W_FCAT-COL_POS       = '4' .
      W_FCAT-FIELDNAME     = 'VISTA' .
      W_FCAT-REF_TABNAME   = 'LTAP'.
      W_FCAT-REF_FIELDNAME = 'VISTA' .
    *w_fcat-seltext_m     = '# of Pcs Picked'.
      APPEND W_FCAT TO T_FCAT.
      CLEAR W_FCAT.
      W_FCAT-COL_POS       = '5' .
      W_FCAT-FIELDNAME     = 'LFIMG' .
      W_FCAT-REF_TABNAME   = 'LIPS'.
      W_FCAT-REF_FIELDNAME = 'LFIMG' .
    *w_fcat-seltext_m     = '# of Pcs Shipped'.
      APPEND W_FCAT TO T_FCAT.
      CLEAR W_FCAT.
    W_FCAT-COL_POS       = '6' .
    W_FCAT-FIELDNAME     = 'TANUM' .
    W_FCAT-REF_TABNAME   = 'LTAK'.
    W_FCAT-REF_FIELDNAME = 'TANUM' .
    **w_fcat-seltext_m     = '# of Pcs Shipped'.
    APPEND W_FCAT TO T_FCAT.
    CLEAR W_FCAT.
    W_FCAT-COL_POS       = '7' .
    W_FCAT-FIELDNAME     = 'WERKS' .
    W_FCAT-REF_TABNAME   = 'T320'.
    W_FCAT-REF_FIELDNAME = 'WERKS' .
    **w_fcat-seltext_m     = '# of Pcs Shipped'.
    APPEND W_FCAT TO T_FCAT.
    CLEAR W_FCAT.
    ENDFORM.                    " fieldcatalog
    *&      Form  display_output
          text
    -->  p1        text
    <--  p2        text
    FORM DISPLAY_OUTPUT .
      LOOP AT T_T320 INTO TY_T320.
        TY_ITAB-WERKS = TY_T320-WERKS.
        TY_ITAB-LGNUM = TY_T320-LGNUM.
        READ TABLE T_VBAK INTO TY_VBAK WITH KEY WERKS = TY_T320-WERKS.
        IF SY-SUBRC = 0.
        TY_ITAB-VBELN  = TY_VBAK-VBELN.
        TY_ITAB-VTWEG  = TY_VBAK-VTWEG.
        TY_ITAB-KWMENG = TY_VBAK-KWMENG + ty_itab-kwmeng.
        ENDIF.
        READ TABLE T_LTAK INTO TY_LTAK WITH KEY LGNUM = TY_T320-LGNUM.
        IF SY-SUBRC = 0.
        TY_ITAB-TANUM = TY_LTAK-TANUM.
        TY_ITAB-VISTA = TY_LTAK-VISTA + ty_itab-vista.
        ENDIF.
        READ TABLE T_LIKP INTO TY_LIKP WITH KEY WERKS = TY_T320-WERKS.
        IF SY-SUBRC = 0.
        TY_ITAB-LFIMG = TY_LIKP-LFIMG + ty_itab-lfimg.
        ENDIF.
        APPEND TY_ITAB TO T_ITAB.
      ENDLOOP.
    Function Module for Displaying Final Output ********
      W_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM = SY-CPROG
          IS_LAYOUT          = W_LAYOUT
          IT_FIELDCAT        = T_FCAT[]
        TABLES
          T_OUTTAB           = T_ITAB.
    ENDFORM.                    " display_output
    *&      Form  f4_for_variant
          text
    -->  p1        text
    <--  p2        text
    FORM F4_FOR_VARIANT .
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          IS_VARIANT = GS_VARIANT
          I_SAVE     = X_SAVE
        IMPORTING
          E_EXIT     = G_EXIT
          ES_VARIANT = GX_VARIANT
        EXCEPTIONS
          NOT_FOUND  = 2.
      IF SY-SUBRC = 2.
        MESSAGE ID SY-MSGID TYPE 'S'      NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ELSE.
        IF G_EXIT = SPACE.
          P_VARI = GX_VARIANT-VARIANT.
        ENDIF.
      ENDIF.
    ENDFORM.                    " f4_for_variant
    *&      Form  pai_of_selection_screen
          text
    -->  p1        text
    <--  p2        text
    FORM PAI_OF_SELECTION_SCREEN .
      IF NOT P_VARI IS INITIAL.
        MOVE GS_VARIANT TO GX_VARIANT.
        MOVE P_VARI TO GX_VARIANT-VARIANT.
        CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
          EXPORTING
            I_SAVE     = X_SAVE
          CHANGING
            CS_VARIANT = GX_VARIANT.
        GS_VARIANT = GX_VARIANT.
      ELSE.
        PERFORM VARIANT_INIT.
      ENDIF.
    ENDFORM.                    " pai_of_selection_screen
    *&      Form  variant_init
          text
    -->  p1        text
    <--  p2        text
    FORM VARIANT_INIT .
      CLEAR GS_VARIANT.
      GS_VARIANT-REPORT = G_REPID.
    ENDFORM.                    " variant_init

  • How to improve the query performance

    ALTER PROCEDURE [SPNAME]
    @Portfolio INT,
    @Program INT,
    @Project INT
    AS
    BEGIN
    --DECLARE @StartDate DATETIME
    --DECLARE @EndDate DATETIME
    --SET @StartDate = '11/01/2013'
    --SET @EndDate = '02/28/2014'
    IF OBJECT_ID('tempdb..#Dates') IS NOT NULL
    DROP TABLE #Dates
    IF OBJECT_ID('tempdb..#DailyTasks') IS NOT NULL
    DROP TABLE #DailyTasks
    CREATE TABLE #Dates(WorkDate DATE)
    --CREATE INDEX IDX_Dates ON #Dates(WorkDate)
    ;WITH Dates AS
    SELECT (@StartDate) DateValue
    UNION ALL
    SELECT DateValue + 1
    FROM Dates
    WHERE DateValue + 1 <= @EndDate
    INSERT INTO #Dates
    SELECT DateValue
    FROM Dates D
    LEFT JOIN tb_Holidays H
    ON H.HolidayOn = D.DateValue
    AND H.OfficeID = 2
    WHERE DATEPART(dw,DateValue) NOT IN (1,7)
    AND H.UID IS NULL
    OPTION(MAXRECURSION 0)
    SELECT TSK.TaskID,
    TR.ResourceID,
    WC.WorkDayCount,
    (TSK.EstimateHrs/WC.WorkDayCount) EstimateHours,
    D.WorkDate,
    TSK.ProjectID,
    RES.ResourceName
    INTO #DailyTasks
    FROM Tasks TSK
    INNER JOIN TasksResource TR
    ON TSK.TaskID = TR.TaskID
    INNER JOIN tb_Resource RES
    ON TR.ResourceID=RES.UID
    OUTER APPLY (SELECT COUNT(*) WorkDayCount
    FROM #Dates
    WHERE WorkDate BETWEEN TSK.StartDate AND TSK.EndDate)WC
    INNER JOIN #Dates D
    ON WorkDate BETWEEN TSK.StartDate AND TSK.EndDate
    -------WHERE TSK.ProjectID = @Project-----
    SELECT D.ResourceID,
    D.WorkDayCount,
    SUM(D.EstimateHours/D.WorkDayCount) EstimateHours,
    D.WorkDate,
    T.TaskID,
    D.ResourceName
    FROM #DailyTasks D
    OUTER APPLY (SELECT (SELECT CAST(TaskID AS VARCHAR(255))+ ','
    FROM #DailyTasks DA
    WHERE D.WorkDate = DA.WorkDate
    AND D.ResourceID = DA.ResourceID
    FOR XML PATH('')) AS TaskID) T
    LEFT JOIN tb_Project PRJ
    ON D.ProjectID=PRJ.UID
    INNER JOIN tb_Program PR
    ON PRJ.ProgramID=PR.UID
    INNER JOIN tb_Portfolio PF
    ON PR.PortfolioID=PF.UID
    WHERE (@Portfolio = -1 or PF.UID = @Portfolio)
    AND (@Program = -1 or PR.UID = @Program)
    AND (@Project = -1 or PRJ.UID = @Project)
    GROUP BY D.ResourceID,
    D.WorkDate,
    T.TaskID,
    D.WorkDayCount,
    D.ResourceName
    HAVING SUM(D.EstimateHours/D.WorkDayCount) > 8
    hi..
    My SP is as above..
    I connected this SP to dataset in SSRS report..as per my logic..Portfolio contains many Programs and Program contains many Projects.
    When i selected the ALL value for parameters Program and Project..i'm unable to get output.
    but when i select values for all 3 parameters i'm getting output. i took default values for paramters also.
    so i commented the where condition in SP as shown above
    --------where TSK.ProjectID=@Project-------------
    now i'm getting output when selecting ALL value for parameters.
    but here the issue is performance..it takes 10sec to retrieve for single project when i'm executing the sp.
    how can i create index on temp table in this sp and how can i improve the query performance..
    please help.
    thanks in advance..
    lucky

    Didnt i provide you solution in other thread?
    ALTER PROCEDURE [SPNAME]
    @Portfolio INT,
    @Program INT,
    @Project INT
    AS
    BEGIN
    --DECLARE @StartDate DATETIME
    --DECLARE @EndDate DATETIME
    --SET @StartDate = '11/01/2013'
    --SET @EndDate = '02/28/2014'
    IF OBJECT_ID('tempdb..#Dates') IS NOT NULL
    DROP TABLE #Dates
    IF OBJECT_ID('tempdb..#DailyTasks') IS NOT NULL
    DROP TABLE #DailyTasks
    CREATE TABLE #Dates(WorkDate DATE)
    --CREATE INDEX IDX_Dates ON #Dates(WorkDate)
    ;WITH Dates AS
    SELECT (@StartDate) DateValue
    UNION ALL
    SELECT DateValue + 1
    FROM Dates
    WHERE DateValue + 1 <= @EndDate
    INSERT INTO #Dates
    SELECT DateValue
    FROM Dates D
    LEFT JOIN tb_Holidays H
    ON H.HolidayOn = D.DateValue
    AND H.OfficeID = 2
    WHERE DATEPART(dw,DateValue) NOT IN (1,7)
    AND H.UID IS NULL
    OPTION(MAXRECURSION 0)
    SELECT TSK.TaskID,
    TR.ResourceID,
    WC.WorkDayCount,
    (TSK.EstimateHrs/WC.WorkDayCount) EstimateHours,
    D.WorkDate,
    TSK.ProjectID,
    RES.ResourceName
    INTO #DailyTasks
    FROM Tasks TSK
    INNER JOIN TasksResource TR
    ON TSK.TaskID = TR.TaskID
    INNER JOIN tb_Resource RES
    ON TR.ResourceID=RES.UID
    OUTER APPLY (SELECT COUNT(*) WorkDayCount
    FROM #Dates
    WHERE WorkDate BETWEEN TSK.StartDate AND TSK.EndDate)WC
    INNER JOIN #Dates D
    ON WorkDate BETWEEN TSK.StartDate AND TSK.EndDate
    WHERE (TSK.ProjectID = @Project OR @Project = -1)
    SELECT D.ResourceID,
    D.WorkDayCount,
    SUM(D.EstimateHours/D.WorkDayCount) EstimateHours,
    D.WorkDate,
    T.TaskID,
    D.ResourceName
    FROM #DailyTasks D
    OUTER APPLY (SELECT (SELECT CAST(TaskID AS VARCHAR(255))+ ','
    FROM #DailyTasks DA
    WHERE D.WorkDate = DA.WorkDate
    AND D.ResourceID = DA.ResourceID
    FOR XML PATH('')) AS TaskID) T
    LEFT JOIN tb_Project PRJ
    ON D.ProjectID=PRJ.UID
    INNER JOIN tb_Program PR
    ON PRJ.ProgramID=PR.UID
    INNER JOIN tb_Portfolio PF
    ON PR.PortfolioID=PF.UID
    WHERE (@Portfolio = -1 or PF.UID = @Portfolio)
    AND (@Program = -1 or PR.UID = @Program)
    AND (@Project = -1 or PRJ.UID = @Project)
    GROUP BY D.ResourceID,
    D.WorkDate,
    T.TaskID,
    D.WorkDayCount,
    D.ResourceName
    HAVING SUM(D.EstimateHours/D.WorkDayCount) > 8
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Query performance data

    Hi,
    I have archived our dev database and reduced the table size from one million to 45000 records. The same table is having 1 million records in PROD. Before implementing the archival job in PROD I want to see the difference in query performance. When I ran
    the same query in DEV and PROD both are taking 1 sec for execution. On a basic terms, there is not much performance improvement. But I ran io statistics and statistics time on for the queries in DEV and PROD.
    DEV - Clustreredindex look up shows-88% and nonclustered index lookup is 2 %
    PROD- Clustreredindex look up shows-18% and nonclustered index lookup is 67 %
    I am not sure why this difference in query plan. But the logical read in DEV-1657 and CPU time = 12609 ms
    PROD-logical read19434 and CPU time = 13625
    Can any one help me in analysing the key differences to come to a conclusion that says there is some performance improvement?
    Thanks

    Hi
    The statistics on DEV:
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 20, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'AirlineGroupMaster'. Scan count 0, logical reads 158, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#2F8E53E2'. Scan count 1, logical reads 79, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'TimefenceSubGroup'. Scan count 1, logical reads 9, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#3082781B'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 16 ms,  elapsed time = 10 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 15 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
    (492 row(s) affected)
    Table 'AirlineGroupMaster'. Scan count 0, logical reads 1024, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#2F8E53E2'. Scan count 1, logical reads 512, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'FLIGHTDETAILS'. Scan count 5, logical reads 1607, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#3082781B'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 13000 ms,  elapsed time = 13373 ms.
     SQL Server Execution Times:
       CPU time = 13000 ms,  elapsed time = 13373 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 13031 ms,  elapsed time = 13392 ms.
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    IN PROD:
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 20, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'AirlineGroupMaster'. Scan count 0, logical reads 158, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#58010028'. Scan count 1, logical reads 79, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'TimefenceSubGroup'. Scan count 1, logical reads 9, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#58F52461'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 96 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'Worktable'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
    (518 row(s) affected)
    Table 'AirlineGroupMaster'. Scan count 0, logical reads 2196, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'FLIGHTDETAILS'. Scan count 20, logical reads 19445, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#58010028'. Scan count 5, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table '#58F52461'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    (1 row(s) affected)
     SQL Server Execution Times:
       CPU time = 13859 ms,  elapsed time = 16827 ms.
     SQL Server Execution Times:
       CPU time = 13859 ms,  elapsed time = 16827 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 13859 ms,  elapsed time = 16972 ms.
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
     SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.

  • Query performance decreases dramatically after adding 0AGE characteristic

    Hi gurus,
    I've added 0AGE as a free characteristic to a query based on 0PAPA_C02 cube and the query performance falls down dramatically.
    In transaction RSRT I have compared statistics for two identical queries, one with 0AGE, and one without it.
    Total DBTRANS changed from 1.528 to 284.342
    Total DBSEL didn't change.
    "OLAP: Data Selection" changed from 0,207267 to 232,879858
    There is also a new line: OLAP: USER_EXIT with long duration: 289,386668 and counter: 6.840.863
    And I am not using any user exit variable!!!! or anything...
    What may be wrong and how can I fix that?
    Regards,
    Dorota

    Found the answer.
    There is a BAPI for 0PAPA_C01 InfoCube which makes 0AGE a virtual characteristic.
    It needs to be deactivated.
    The BAPI name is RS_BCT_PA.

  • Improve query performance

    Hi,
    I am executing one query it takes 40-45 mins, can anybody tell me where is the issue because I have index on SUBSCRIPTION table.
    Query is taking time in Nested Loop. Can anyboduy please help to improve query performance.
    Select count(unique individual_id)
    from SUBSCRIPTION S ,SOURCE D WHERE S.ORDER_DOCUMENT_KEY_CD=D.FULFILLMENT_KEY_CD AND prod_abbr='TOH'
    and to_char(source_start_dt,'YYMM')>='1010' and mke_mag_source_type_cd='D';
    select count(*) from source; ----------3,425,131
    select count(*) from subscription;---------394,517,271
    Below is exlain Plan
    Plan
    SELECT STATEMENT CHOOSECost: 219 Bytes: 38 Cardinality: 1                                              
    13 SORT GROUP BY Bytes: 38 Cardinality: 1                                                   
    12 PX COORDINATOR                                              
         11 PX SEND QC (RANDOM) SYS.:TQ10001 Bytes: 38 Cardinality: 1                                         
         10 SORT GROUP BY Bytes: 38 Cardinality: 1                                    
         9 PX RECEIVE Bytes: 38 Cardinality: 1                               
              8 PX SEND HASH SYS.:TQ10000 Bytes: 38 Cardinality: 1                          
              7 SORT GROUP BY Bytes: 38 Cardinality: 1                     
              6 TABLE ACCESS BY LOCAL INDEX ROWID TABLE SUBSCRIPTION Cost: 21 Bytes: 3,976 Cardinality: 284                
                   5 NESTED LOOPS Cost: 219 Bytes: 604,276 Cardinality: 15,902           
              2 PX BLOCK ITERATOR      
                   1 TABLE ACCESS FULL TABLE SOURCE Cost: 72 Bytes: 1,344 Cardinality: 56
                   4 PARTITION HASH ALL Cost: 2 Cardinality: 284 Partition #: 12 Partitions accessed #1 - #16     
                   3 INDEX RANGE SCAN INDEX XAK1SUBSCRIPTION Cost: 2 Cardinality: 284 Partition #: 12 Partitions accessed #1 - #16
    Please suggest

    it eliminate hidden conversation from char to numberi dont know indexes/partition on TC table, and you?
    drop table test;
    create table test as select level id, sysdate + level/24/60/60 datum from dual connect by level < 10000;
    create index idx1 on test(datum);
    analyze table test compute statistics;
    explain plan for select count(*) from test where to_char(datum,'YYYYMMDD') > '20120516';   
    SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 3467505462                                                    
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |    
    |   0 | SELECT STATEMENT   |      |     1 |     7 |     7  (15)| 00:00:01 |    
    |   1 |  SORT AGGREGATE    |      |     1 |     7 |            |          |    
    |*  2 |   TABLE ACCESS FULL| TEST |   500 |  3500 |     7  (15)| 00:00:01 |    
    Predicate Information (identified by operation id):                            
       2 - filter(TO_CHAR(INTERNAL_FUNCTION("DATUM"),'YYYYMMDD')>'20120516')       
    explain plan for select count(*) from test where datum > trunc(sysdate);   
    SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 2330213601                                                    
    | Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     | 
    |   0 | SELECT STATEMENT      |      |     1 |     7 |     7  (15)| 00:00:01 | 
    |   1 |  SORT AGGREGATE       |      |     1 |     7 |            |          | 
    |*  2 |   INDEX FAST FULL SCAN| IDX1 |  9999 | 69993 |     7  (15)| 00:00:01 | 
    Predicate Information (identified by operation id):                            
       2 - filter("DATUM">TRUNC(SYSDATE@!))                                        
    drop index idx1;
    create index idx1 on test(to_number(to_char(datum,'YYYYMMDD')));
    analyze table test compute statistics;
    explain plan for select count(*) from test where to_number(to_char(datum,'YYYYMMDD')) > 20120516;   
    SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 227046122                                                     
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |     
    |   0 | SELECT STATEMENT  |      |     1 |     5 |     2   (0)| 00:00:01 |     
    |   1 |  SORT AGGREGATE   |      |     1 |     5 |            |          |     
    |*  2 |   INDEX RANGE SCAN| IDX1 |     1 |     5 |     2   (0)| 00:00:01 |     
    Predicate Information (identified by operation id):                            
       2 - access(TO_NUMBER(TO_CHAR(INTERNAL_FUNCTION("DATUM"),'YYYYMMDD'))>       
                  20120516)                                                        
    explain plan for select count(*) from test where datum > trunc(sysdate);   
    SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 3467505462                                                    
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |    
    |   0 | SELECT STATEMENT   |      |     1 |     7 |     7  (15)| 00:00:01 |    
    |   1 |  SORT AGGREGATE    |      |     1 |     7 |            |          |    
    |*  2 |   TABLE ACCESS FULL| TEST |  9999 | 69993 |     7  (15)| 00:00:01 |    
    Predicate Information (identified by operation id):                            
       2 - filter("DATUM">TRUNC(SYSDATE@!))                                        

  • Physical partitioning query performance wore than without

    Hello experts,
    I have copied InfoCube 0COPC_C04 to ZCPOC_C06 with a test-query and took over data from 0COPC_C04 to test the functionality of Repartitioning (~ 4 million records)
    I did Repartitioning following instructions from note 1008833 for 0FISCPER (I used se38 RSDU_SET_FV_TO_FIX_VALUE  to set 0FISCVARNT to constant) - starting-point is 001.2000 - end-point is 016.2010
    Indexes and Statistcs are re-created.
    We have Oracle 10.2.0.2.0 and SAPKW70022 on BW 700
    So - from my point of view everything is fine - BUT: Queryperformance is worst than before - shown in rsrv.
    Variable in Query is over 0FISCYEAR and 0FISCPER3 and NOT over 0FISCPER (a querytest with 0FISCPER brought the same bad performance result).
    Even I read, that with physical partitioning the query reads PARALLEL --- I can not see any parallel things in sm50 / sm66 - I have excpected to see parallel readings due to my query - I asked for results from 001.2006 - 12.2010 - and 13 partions were created (related to se14 ).
    What might be the problem?
    Thanks for your answer,
    Thomas
    Edited by: Thomas Liebschner on Jan 4, 2011 3:28 PM

    #1171650 is already implemented (since 14.12.2010) --- I asked my collegaue from Basis-Team to send me the report.
    > I read parallel-queryexcution in the SAP Press Galileo Press Book "SAP BW Peformanceoptimierung" written by Thomas Schröder (ISBN: 3-89842-718-8), Page 376. If you like, I can send this page as pdf to your mail stored in your business card.
    Would be interesting to see that excerpt, yes.
    > What I missed was to compress the F-Table.
    >
    > I'm wondering, that:
    > 1. After Compressing 0COPC_C04 with 8 million records gave a dramatically improvement of query-performance. No partitioning.
    Sure, usually a lot less data needs to be read now.
    > 2. After a new Full-load from 0COPC_C04 to ZCOPC_C06 with rebuilding indices and statistics I got similar query-performance compared to 1
    Also easy to understand.
    The F-Facttable contains data per load. So data concerning the same business items will be in that table multiple times and need to be aggregated on-the-fly during query execution.
    The E-Facttable in contrast just contains one entry per business item. Which is the same situation you'll find when you just have one single data load request.
    > 3. If I compress ZCOPC_C06, then query-performance drops dramatically down (needs double time, if I use 0FISCPER, needs 8 times more in query with 0FISCYEAR and 0FISCPER3)
    >
    > additional information: I have merged partitions from ZCOPC_C06 to one partition --> checked by se14 /BIC/FZCOPC_C06 -- storage parameters
    Hmm... ok, here we would really need to see what Oracle does with your Query and the partitioning scheme then.
    What seems obvious is that as soon as you have just one partition, then there is no way for Oracle to split up work and leave uninteresting data aside (partition-pruning),
    > Conclusion: it seems for me, that compression is enough - partitioning has no advantage in that dedicated scenario.
    > Do I think right?
    I think that compression is a must-do in 99% of all cases for SAP BI and that the partitioning of the E-Facttable should be reviewed on your system.
    Up to here there is too little information available to tell whether or not it could benefit your query execution time.
    Another aspect you might consider with partitioning the E-facttable is your data retention policy.
    If you're about to throw away your data on, say, a yearly basis, then having the table partitioned that way can provide huge benefits.
    My personal view to this is: you already payed for the most expensive and feature-rich database engine available for SAP BI - so why not go and exploit these features where possible?
    best regards
    Lars

Maybe you are looking for