Improving a simple select query, which uses all rows.

Hi All,
Please excuse me if the question is too silly. Below is my code
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 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.07
SQL> show parameter optim
NAME                                 TYPE        VALUE
object_cache_optimal_size            integer     102400
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
plsql_optimize_level                 integer     2
SQL> explain plan for select SUM(decode(transaction_type,'D',txn_amount,0)) payments_reversals,
  2          SUM(decode(transaction_type,'C',txn_amount,0)) payments,primary_card_no,statement_date
  3             from credit_card_pymt_dtls  group by primary_card_no,statement_date;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 2801218574
| Id  | Operation          | Name                  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT   |                       |  1912K|    56M|       | 21466   (3)| 00:04:18 |
|   1 |  SORT GROUP BY     |                       |  1912K|    56M|   161M| 21466   (3)| 00:04:18 |
|   2 |   TABLE ACCESS FULL| CREDIT_CARD_PYMT_DTLS |  1912K|    56M|       |  4863   (3)| 00:00:59 |
9 rows selected.
SQL> select index_name,index_type
  2  from all_indexes
  3  where table_name = 'CREDIT_CARD_PYMT_DTLS';
INDEX_NAME                     INDEX_TYPE
INDX_TRANTYPE                  BITMAP
INDX_PCARD                     NORMAL
INDX_PSTATEMENT_DATE           NORMALThe query is using all the records in the CREDIT_CARD_PYMT_DTLS table. Transaction type will be either 'C' or 'D'.
CREDIT_CARD_PYMT_DTLS has 2 million rows and the qury will output 1.5 million rows. Table statisticas are upto date.
The query now is taking almost 5 minutes. Is thaere any way to reduce the time ?
Our DB server has 8 CPUs and 8 GB memory. Is the timing genuine ?
Thanks in Advance.
Edited by: user11115924 on Apr 29, 2009 2:43 AM
All the columns used in the query are already indexed. ( Ofcourse, not only for this query.)

Hi All,
Thanks for the helps provided. Expecting it once more..
My actual query is as below
select     primary_card_no,base_segment_number,atab.previous_balance,current_balance,intrest_amt_due_this_cycle,total_min_amt_due,total_credit_limit,
          total_purchase_this_cycle,total_cash_trns_this_cycle,available_credit_limit,payments,utilization,payment_ratio,payments_reversals,cash_limit,
          available_cash_limit, description
from
       select primary_card_no,DECODE(base_segment_number,NULL,primary_card_no,base_segment_number) base_segment_number,
               SUM(previous_balance) previous_balance,SUM(current_balance) current_balance ,SUM(intrest_amt_due_this_cycle) intrest_amt_due_this_cycle,
               SUM(total_min_amt_due) total_min_amt_due,SUM(total_credit_limit_all) total_credit_limit,
               SUM(total_purchase_this_cycle) total_purchase_this_cycle,SUM(total_cash_trns_this_cycle) total_cash_trns_this_cycle,
               SUM(available_credit_limit) available_credit_limit,SUM(payments) payments,
               (SUM(NVL(current_balance,0)) / SUM(total_credit_limit_all)) * 100 utilization,
               (SUM(NVL(payments,0)) / DECODE(SUM(previous_balance),0,NULL,SUM(previous_balance))) * 100 payment_ratio,
               SUM(payments_reversals) payments_reversals,SUM(cash_limit) cash_limit,SUM(available_cash_limit) available_cash_limit
      from
        ( select a.*,NVL(payments_reversals,0)payments_reversals ,NVL(payments,0) payments
          from
                (  select primary_card_no,previous_balance,current_balance,intrest_amt_due_this_cycle,total_min_amt_due,total_purchase_this_cycle,
                          total_cash_trns_this_cycle,statement_date,available_credit_limit,cash_limit,available_cash_limit,
                       (case when statement_date <= TO_DATE('301108','ddmmyy') then NULLIF(total_credit_limit,0)
                                  else NULLIF((select credit_limit
                                            from ccm_dbf_chtxn_v0 t1
                                               where t1.batch_id = '011208'
                                               and SUBSTR(t1.card_number,4) = a.primary_card_no),0)
                         end) total_credit_limit_all
                 from
                    ( select primary_card_no,previous_balance,current_balance,INTREST_AMT_DUE_THIS_CYCLE,
                                TOTAL_MIN_AMT_DUE,TOTAL_PURCHASE_THIS_CYCLE,TOTAL_CASH_TRNS_THIS_CYCLE,statement_date,
                               AVAILABLE_CREDIT_LIMIT,cash_limit,available_cash_limit,total_credit_limit
                      from credit_card_master_all@FGBAPPL_LINK
                    ) a
                 where statement_date between ADD_MONTHS(TRUNC(SYSDATE,'mm'),-6) and  TRUNC(SYSDATE,'mm')-1
             ) a,
             ( select SUM(decode(transaction_type,'D',txn_amount,0)) payments_reversals,
                           SUM(decode(transaction_type,'C',txn_amount,0)) payments,primary_card_no,TO_CHAR(statement_date,'MON-RRRR') sdate
                from credit_card_pymt_dtls 
                group by primary_card_no,TO_CHAR(statement_date,'MON-RRRR')
             ) b
         where TO_CHAR(a.statement_date,'MON-RRRR')= b.sdate(+)
           and a.primary_card_no= b.primary_card_no(+)
        ) a,
        (  select SUBSTR(a.card_number,4) card_number,base_segment_number,TO_DATE(account_creation_date,'DDMMYYYY') account_creation_date,
                       a.batch_id, credit_limit credit_limit_current
            from
                   (  select *
                       from ccm_dbf_phtxn_v0
                       where batch_id=  (SELECT to_char(MAX(TO_DATE(SUBSTR(BATCH_ID,1,6),'DDMMRR')),'DDMMRR') FROM CCM_MST_V0)
                    ) a,
                    ( select *
                      from ccm_dbf_chtxn_v0
                      where batch_id=(SELECT to_char(MAX(TO_DATE(SUBSTR(BATCH_ID,1,6),'DDMMRR')),'DDMMRR') FROM CCM_MST_V0)
                    ) b
            where a.card_number=b.card_number
            and TO_NUMBER(ROUND(MONTHS_BETWEEN(SYSDATE,TO_DATE(account_creation_date,'DDMMYYYY')),2)) >=6
            and a.company ='BNK'
        ) b
   where a.primary_card_no = b.card_number
   group by primary_card_no,base_segment_number) atab, card_summary_param btab
where utilization between utilization_low and utilization_high
and payment_ratio between  payment_ratio_low and payment_ratio_high
and SIGN(atab.previous_balance) =btab.previous_balanceWhere I have to put the PARALLEL hint for maximum performance?
Sorry for asking blindly without doing any R&D. Time is not permitting that...
Edited by: user11115924 on Apr 29, 2009 5:09 AM
Sorry for the kiddy aliases.. Query is not written by me..

Similar Messages

  • A simple select query taking forever

    Hi All
    I am not able to execute a simple select query, I traced my session and here is TKPROF of that Trace.
    Solaris 8 , Oracle 10.2.0.4.0
    TKPROF: Release 10.2.0.4.0 -
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: 502_ora_28260.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select OBJECT_ID , ORACLE_USERNAME , SESSION_ID
    from
      v$locked_object
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.03      32.86          0          0          6           0
    total        3      0.03      32.86          0          0          6           0
    Misses in library cache during parse: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS
    Rows     Row Source Operation
          0  MERGE JOIN  (cr=0 pr=0 pw=0 time=60 us)
          0   SORT JOIN (cr=0 pr=0 pw=0 time=58 us)
          0    MERGE JOIN  (cr=0 pr=0 pw=0 time=42 us)
          1     SORT JOIN (cr=0 pr=0 pw=0 time=2443 us)
       1105      FIXED TABLE FULL X$KSUSE (cr=0 pr=0 pw=0 time=1204 us)
          0     SORT JOIN (cr=0 pr=0 pw=0 time=41 us)
       1001      FIXED TABLE FULL X$KTCXB (cr=0 pr=0 pw=0 time=16132 us)
          0   SORT JOIN (cr=0 pr=0 pw=0 time=0 us)
          0    FIXED TABLE FULL X$KTADM (cr=0 pr=0 pw=0 time=0 us)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
      buffer busy waits                              34        0.97         32.83
      SQL*Net break/reset to client                   1        0.00          0.00
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.03      32.86          0          0          6           0
    total        3      0.03      32.86          0          0          6           0
    Misses in library cache during parse: 1
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       2        0.00          0.00
      SQL*Net message from client                     1       19.00         19.00
      buffer busy waits                              34        0.97         32.83
      SQL*Net break/reset to client                   1        0.00          0.00
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        1  user  SQL statements in session.
        0  internal SQL statements in session.
        1  SQL statements in session.
    Trace file: 502_ora_28260.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           0  session in tracefile.
           1  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           1  SQL statements in trace file.
           1  unique SQL statements in trace file.
          64  lines in trace file.
          32  elapsed seconds in trace file. There is nothing fishy in alert logs... Please guide
    Thanks

    There it is TOP
    $ RUMPSHAKER>top
    load averages:  6.63,  7.45,  7.88;                    up 33+12:02:33           
    3631 processes: 3616 sleeping, 5 zombie, 1 stopped, 9 on cpu
    CPU states: 58.6% idle, 18.2% user, 23.2% kernel,  0.0% iowait,  0.0% swap
    Memory: 192G phys mem, 92G free mem, 96G swap, 96G free swap
       PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
    13752 ora0005    1  19    0 4243M 4219M sleep    5:21 62.78% oracle
    17758 ora0005    1  25    0 1174M 1156M cpu      1:05 37.12% oracle
    17923 root       1  57    0   18M   14M sleep  689:07 13.59% ecap_monitor
    20777 root      12  58    0   14M   13M sleep  864:33 11.55% OracleAgent
    18884 ora0004    1   1    0  830M  813M sleep    0:01  9.54% oracle
    12070 ora0004   61  58    0  320M  315M sleep   28.5H  8.29% emagent
    20347 root      16  59    0   33M   25M sleep   26.0H  6.34% caiUxsA2
    17949 ist0005    1  53    0 7984K 4984K cpu      0:00  3.93% top
         1 root       1  59    0 2912K 1288K sleep   32.2H  3.75% init
    15035 ora0001    1  46    0   32M   22M sleep  166:43  2.98% tnslsnr
      5748 ora0004   11  54    0  516M  496M sleep  389:37  2.78% oracle
    20567 ora0004    1  55    0   27M   22M sleep    0:00  2.69% sqlplus
      6730 ora0001    1  33    0  632M  616M sleep    0:06  2.67% oracle
    20557 ora0004    1  56    0   27M   23M sleep    0:00  2.53% sqlplus
      5355 ora0005    1  59    0 1154M 1137M sleep    0:04  2.46% oracleand VMSTAT 2 5
    $ RUMPSHAKER> vmstat 2 5
    kthr      memory            page            disk          faults      cpu
    r b w   swap  free  re  mf pi po fr de sr s0 s1 s2 sd   in   sy   cs us sy id
    6 8 0 143125576 74272080 4628 24012 488 150 149 0 0 4 4 -2 0 25037 192698 65249 38 26 36
    1 3 0 162803992 95246464 1989 6989 0 4 4 0 0 6 6 0  0 9170 57822 26434 8 13 79
    1 7 0 162801352 95240296 3043 15633 4 9737 9682 0 0 0 0 0 0 11277 73516 38200 16 16 68
    3 10 0 162801560 95227920 3326 12729 16 16862 16774 0 0 1 1 0 0 11377 86054 44758 16 17 68
    1 10 0 162784520 95186488 9638 48359 24 11682 11626 0 0 13 13 0 0 13484 149366 44205 23 29 47

  • SQL query  which return all the NET SERVICES which are avaiable in tnsname

    hi all
    how to write a sql query which return all the net services which are avaiable in tnsname.ora
    Regards
    s

    Also, tnsnames.ora is stored on the client, and not necessarily on the server; it's possible (and quite likely) that the name I use for a database in my tnsnames.ora could be different from the name you use for the same database; conversely we might use the same name for two different databases.
    Regards Nigel

  • How to reduce functions with simple select query?

    I have a function to identify the root parent of a particular id. I use this in function in select query,which invokes function for every row in table.I need to merge the function inside the query itself.Please suggest  me.
    Function
    CREATE OR REPLACE FUNCTION fnroot(v_id int ) return int as
    v_left int;
    v_right int;
    v-result int;
    begin
    select left,right into v_left,v_right from sam where id=v_id;
    select id into v_result from sam
    where id in (select id from mst m where m.depth=2 )
    and left < v_left and right > v_right;
    return v_result;
    end
    query:
    select fnroot(s.id) from master s;

    Hi,
    Ramin's idea is very good. You must use joins in function as below
    CREATE OR REPLACE FUNCTION fnroot(v_id int ) return int as
        v_result int;
    Begin
    select  s.id into v_result
      from sam s on s.id = v_id
               left join sam s2 on (s2.id in (select id from mst m where m.depth = 2) and s2.left < s.left and s2.right > s.right)
    return v_result;
    End;
    Regards
    Mahir M. Quluzade

  • HT1933 My 10 yr. old went behind me and downloaded some music which used all my money on my account. Is it any way that I can delete it and get my money back on my account.

    My 10 yr. old went behind me and downloaded some music which used all my money on my account. Is it any way that I can delete it and get my money back on my account.

    You can try contacting iTunes support via this page and see if they will refund or credit you : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Simple SELECT query to generate  INSERT for a table

    Hi,
    I am looking for a SELECT query which generates INSERT statements for a table.Please guide.
    Thanks
    PG.

    Like this?
    SQL> SELECT * from kons;
         COL1      COL2
            1         1
            2         2
    SQL> SELECT 'INSERT INTO kons VALUES('||col1||','||col2||');' statement FROM kons;
    STATEMENT
    INSERT INTO kons VALUES(1,1);
    INSERT INTO kons VALUES(2,2);
    SQL> If you have character and / or date columns you will have to change my example,
    but you might get the idea from it.
    You can spool the result to a file.
    Regards,
    Guido
    Edit: ';' added to end of statement...

  • Bex Query which uses Dynamic columns to display actuals

    Hi Bex experts,
    I have a query issue/question.
    I currently have a Bex query which shows me the the planned values for each period, spanning 6 years into the future. My Key figure columns are defined as follows:
    Value type  = '020'
    Version  = mandatory variable, entered at execution.
    Posting period (FISCPER3)  = These columns are fixed values using periods 1 to 12 for each column.
    Fiscal year (0FISCYEAR) = Each column contains SAP exit for current year, and using the offset +1, +2, +3, +4 etc, when I define the future years coulmns.
    Currency = fixed 'USD'.
    Fiscal year variant = fixed 'Z4'
    The above works fine for plan data.
    I want to now include is:
    Seperate 'Dynamic columns' to show only actuals for period ranges from period one to the previous period (or current period minus 1). Each period should have it's own column for actuals.
    The dynamic actuals columns should be grouped together to the left of the plan columns.
    Actuals are only for current year, so I will still use the SAP EXIT for current year in the column definition.
    Example: If I am currently in period 10, the query should show me actuals from period 1 to period 9 in seperate columns, then continue to show me my plan values columns that I have in place already.
    How can I construct these actuals columns in to my existing query. If you have possible screens shots.
    Thanks, and maximum points will be alotted.

    The way I have approached this you may not like as it involves quite a bit of coding
    12 CKFs
    each CKF adds up 2 RKFs
    So 24 RKFs
    example Column 6 CKF
    Adds Column 6 RKF Actual and Column 6 RKF Plan
    Column 6 RKF Actual contains Actual version + key figure + Period variable column 6 Actual
    Column 6 RKF Plan contains Plan version + key figure + Period Variable column 6 Plan
    Period variable column 6 Actual
    is a cmod variable which reads the entered date
    if the period of entered date is LE 6
    then return period 6 into "Period variable column 6 Actual"
    else put 0 into "Period variable column 6 Actual"
    Period variable column 6 Plan
    is a cmod variable which reads the entered date
    if the period of entered date is LE 6
    then return period 0 into "Period variable column 6 Plan"
    else put 6 into "Period variable column 6 Plan"
    Now what happens is that if you enter period 6 in your selection screen all the Actuals of columns greater than 6 all have period 0 put into their selection so return 0 and all the columns less than or equal to 6 return the values for the fiscal period (ie column 1 gets period 1)
    And in addition all the Plans columns return the value of their column ie for their period for those greater than 6 and for those less than 6 they all return 0
    It's convulted - but you get the idea - and yes it works
    There may be a better way to do it - and I am open to suggestions
    (this does assume that NOTHING is posted to period 0 otherwise it won't work)

  • Simple Select on VBPA using index running very slow

    Hello,
    We have a very simple selection on the table VBPA:
    data:
    begin of it_vbeln occurs 100,
      vbeln like vbpa-vbeln,
    end of it_vbeln.
    select vbeln from vbpa
    into table it_vbeln
    where
    kunnr = '##########'
    and parvw = 'AG'.
    All we're trying to accomplish is to find orders for a given customer number and type.
    We have two indices "Z1" and "Z2" which respectively declare: KUNNR, and MANDT, KUNNR, PARVW.
    In looking at a sql trace, it says it's using the VBPA~Z2 index, which is expected, and that its estimated costs are very low on the index:
    SELECT STATEMENT ( Estimated Costs = 71 , Estimated #Rows = 63 )
           2 TABLE ACCESS BY INDEX ROWID VBPA
             ( Estim. Costs = 71 , Estim. #Rows = 63 )
             Estim. CPU-Costs = 553,782 Estim. IO-Costs = 71
               1 INDEX RANGE SCAN VBPA~Z2
                 ( Estim. Costs = 3 , Estim. #Rows = 111 )
                 Search Columns: 3
                 Estim. CPU-Costs = 43,764 Estim. IO-Costs = 3
    Despite declaring that it will do an index range scan, in SM51 it shows as Sequential Read (Table Scan?) and takes a VERY long time to return, about 60 - 120 seconds.
    Since this is needed for a user exit that will be run during order creation, it needs to occur MUCH faster. Our entries in VBPA number above 10 million records currently.
    Can anyone suggest either why the index does not appear to be helping (it takes just as long without the index), or perhaps another method for finding the orders for a given customer number.
    Thank you,
    Randy

    Hi Randy,
    I suggest you skip the attempts to speed up selecting on VBPA, but rather look into using table VAKPA for finding sales documents for a given partner number.
    Greetings
    Thomas

  • Simple Select query with 'where', 'and', 'between' clauses takes time

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

  • Simple select query is taking a lot of time

    hi gems...
    my table has 7267563 rows...and i am doing a simple select * from table;
    but it is taking a lot of time nearly 25minutes but not completed...
    when i did select count(1) from table then it gave the result instantly also select * from table where rownum < 10 is also fine...even when i am selecting all the records using rownum i.e. select * from table where rownum < 7267563 is also giving result instantly...
    but the entire table is not getting result i.e. select * from table...also there is no lock in the table(though i know that select is nothing to do with lock)..
    what may be the issue..please suggest...thanks in advance...
    Edited by: user12780416 on Dec 12, 2011 11:08 PM

    Hi;
    Please see below thread
    query takes too long ...
    help in solving long run query
    HOW TO: Post a SQL statement tuning request - template posting
    Hope it helps
    Regard
    Helios

  • How to improve performance of select query when primary key is not referred

    Hi,
    There is a select query where we are unable to refrence primary key of the tables:
    Since, the the below code is refrensing to vgbel and vgpos fields instead of vbeln and posnr..... the performance is very  slow.
    select vbeln posnr into (wa-vbeln1, wa-posnr1)             
           from lips                                            
           where ( pstyv ne 'ZBAT'    
               and pstyv ne 'ZNLN' )  
               and vgbel = i_vbap-vbeln                         
               and vgpos = i_vbap-posnr.                        
    endselect.                                                 
    Please le t me know if you have some tips..

    hi,
    I hope you are using the select statement inside a loop ...endloop get that outside to improve the performance ..
    if not i_vbap[] is initial.
    select vbeln posnr into table it_lips
    from lips
    for all entries in  i_vbap
    where ( pstyv ne 'ZBAT'
    and pstyv ne 'ZNLN' )
    and vgbel = i_vbap-vbeln
    and vgpos = i_vbap-posnr.
    endif.

  • Simple Select Query Taking 5-10s

    We have a web server on the same lan as the DB server.
    A simple select * from tablename (~100 entries) is taking
    anywhere from 30ms to 10 seconds lan. ASP code on the web server
    provides instant (30ms) queries. Ping is never <1ms. If I point
    to a remote DB server, the same query is never more than 300ms
    (which is great for over the internet).
    I enabled logging in CFAdmin -> Datasources and shortly
    after my select * from tablename I see this:
    spy(2009/02/28 16:39:00.539)>>
    Connection[2].setReadOnly(boolean readOnly)
    spy(2009/02/28 16:39:00.539)>> readOnly = false
    spy(2009/02/28 16:39:00.539)>> OK
    spy(2009/02/28 16:39:05.726)>> OK (true)
    We need to get this up and running ASAP. Please help!!

    > I'm connecting to SQL Server 2000 on a Win2k3 box.
    > The default CF8 Installation.
    > Every table this happens for.
    OK. I think CF8 runs the most recent JDBC drivers too. It
    might pay to
    check that though.
    > Select * is needed, because we have existing sites we
    are migrating a lot of
    > which use select *.
    Sure. But just for the purposes of experimentation, change
    your test code
    to specify columns to see if it makes any difference.
    It might pay to get hold of FusionReactor to check what CF is
    doing with
    the queries, under the hood.
    Adam

  • Performance issue with select query and for all entries.

    hi,
    i have a report to be performance tuned.
    the database table has around 20 million entries and 25 fields.
    so, the report fetches the distinct values of two fields using one select query.
    so, the first select query fetches around 150 entries from the table for 2 fields.
    then it applies some logic and eliminates some entries and makes entries around 80-90...
    and then it again applies the select query on the same table using for all entries applied on the internal table with 80-90 entries...
    in short,
    it accesses the same database table twice.
    so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    is around 80-90 entries too much for using "for all entries"?
    the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    i really cant find the way out...
    please help.

    chinmay kulkarni wrote:Chinmay,
    Even though you tried to ask the question with detailed explanation, unfortunately it is still not clear.
    It is perfectly fine to access the same database twice. If that is working for you, I don't think there is any need to change the logic. As Rob mentioned, 80 or 8000 records is not a problem in "for all entries" clause.
    >
    > so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    >
    It is not clear what you tried to do here. Did you try to bring all 20 million records into an internal table? That will certainly cause the program to short dump with memory shortage.
    > the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    >
    That is fine. Actually, it is better (performance wise) to do much of the work in ABAP than writing a complex WHERE clause that might bog down the database.

  • Select query like For all Entries

    Hi,
    I have a requirement like:
    I need to extract data (BKTXT) from table BKPF based on some criteria, into one internal table and I need to query on REGUP table for the above data, the selection criteria on REGUP as follows:
    BKTXT(Document Header Text with 25 Char) is a combination of DATE and character string.
    Ex: bkpf-bktxt = 20060710-PL02 (YYYYMMDD)
    it is like LAUFD + LAUFI (of table REGUP)
    i.e: LAUFD (REGUP) = 07/10/2006 (MM/DD/YYYY) and LAUFI(REGUP) = PL02
    here I am thinking to use a select query on REGUP using FOR ALL ENTRIES of table i_bkpf..
    How can I change the date format YYYYMMDD to MM/DD/YYYY for my requirement?
    ((    Run-on Date (REGUP-LAUFD) = the first 8 characters in the Document Header Text (BKPF- BKTXT) in MM/DD/YYYY date format (e.g. 07/10/2006)
       Run ID (REGUP-LAUFI) = the 10th character through the 15th character in the Document Header Text (BKPF- BKTXT)

    It is not possible to do in the way you are thinking of doing. "For all entries" requires you to have the itab table field and the database table field to have the same type and length. So something like below <u>will not work</u>.
    TABLES: regup.
    DATA: BEGIN OF itab OCCURS 0,
            text LIKE bkpf-bktxt.
    DATA: END OF itab.
    DATA: BEGIN OF itab_regup OCCURS 0.
            INCLUDE STRUCTURE regup.
    DATA: END OF itab_regup.
    SELECT * INTO TABLE itab_regup
             FROM regup FOR ALL ENTRIES IN itab
            WHERE laufd = itab-text+0(8).
    If you run this code, you will get an error as follows:
    <i>"When using the addition "FOR ALL ENTRIES IN itab", the fields "LAUFD" and "ITAB-TEXT+0(8)" must have the same type and length."</i>

  • Problem with SImple Select Query

    Hi
    I am trying to write a simple Select SQL to a table and find out whether certain data exist or not. I have done this before but now for some reason this one is not working.
    I started like this
    select single * from ANLH where ANLN1 = rec-Asset
                                                 and BUKRS = Comp_Cd.
    * Error Handler for non-existent empno in the database
      if sy-subrc = 0 or rec-asset = ''.
         rec_failed = 'T'.
         concatenate 'Asset does not exist' rec-asset into asst_err.
      endif.
    when i debugged the code i found out that sy-subrc  is returning 4 all the time. (i have passes some numbers in rec-Asset which i know doesn't exist in that table.
    So i have modified the code to see if its pulling anything.
    like this
    select single ANLN1 into v_Asset from ANLH where ANLN1 = rec-Asset
                                                 and BUKRS = Comp_Cd.
    * Error Handler for non-existent empno in the database
      if sy-subrc = 0 or rec-asset = ''.
         rec_failed = 'T'.
         concatenate 'Asset does not exist' rec-asset into asst_err.
      endif.
    in debug v_asset is always empty (for real number and for the madeup number)
    Please help.
    Thanks
    Edited by: Anwarul Kabir on Apr 3, 2008 9:27 PM
    Edited by: Anwarul Kabir on Apr 3, 2008 9:29 PM
    Edited by: Anwarul Kabir on Apr 3, 2008 9:30 PM

    Thanks for the answer. But i thought i was doing the same. Anyway I replaced my code with yours but result is the same. I also did this
    select single
    ANLN1 into v_Asset
    from ANLH where
    ANLN1 = '20000544'
    and BUKRS = '3000'.
    I did SE11 and entered the table name and i can see that data.
    but on my code i get sy-subrc=4 and v_Asset is blank
    again i tried with this madeup number which i know its not in the table
    select single
    ANLN1 into v_Asset
    from ANLH where
    ANLN1 = '2056555433544'
    and BUKRS = '3000'.
    Get sy-subrc=4 and v_Asset is blank...
    Is there anything special about the Table?

Maybe you are looking for