Select query taking long time (more then 6 min)

Dear experts,
DATA:IT_CHEQ2 TYPE TABLE OF TY_BSAS,
     WA_CHEQ2 LIKE LINE OF IT_CHEQ2.
DATA : IT_CHEQ3 TYPE STANDARD TABLE OF TY_BSAS WITH HEADER LINE.
TYPES:BEGIN OF TY_BSAS,
       BUKRS TYPE BSAS-BUKRS,
       HKONT TYPE BSAS-HKONT,
       AUGDT TYPE BSAS-AUGDT,
       AUGBL TYPE BSAK-AUGBL,
       ZUONR TYPE BSAK-ZUONR,
       GJAHR TYPE BSAK-GJAHR,
       BELNR TYPE BSAK-BELNR,
       BUZEI TYPE BSAK-BUZEI,
       BUDAT TYPE BSAK-BUDAT,
       XBLNR TYPE BSAK-XBLNR,
       BLART TYPE BSAK-BLART,
       SHKZG TYPE BSAK-SHKZG,
       DMBTR TYPE BSAK-DMBTR,
       WMWST TYPE BSAK-WMWST,
      AUGGJ TYPE BSAK-AUGGJ, " CLEARING FYSICAL YEAR
       OT_TAX TYPE BSAK-DMBTR,
       TDS   TYPE BSAK-DMBTR,
       VAT    TYPE BSAK-DMBTR, "Vat amount
       WCT   TYPE BSAK-DMBTR,
       ADV    TYPE BSAK-DMBTR,  "Advance
       CHAMT TYPE BSAK-DMBTR,
       CHNO  TYPE PAYR-CHECT,
       CHDATE TYPE PAYR-ZALDT,
       DBIT_NOTE TYPE BSAK-DMBTR,
       PAY_ADJ   TYPE BSAK-DMBTR,
       PEND_SES TYPE BSAK-DMBTR, "PENDING SES
       CR_PARTY(50)  TYPE C,
      END OF TY_BSAS.
SELECT BUKRS HKONT AUGDT AUGBL ZUONR GJAHR BELNR BUZEI BUDAT XBLNR BLART SHKZG
                  DMBTR WMWST
                  FROM BSAS INTO " APPENDING
           CORRESPONDING FIELDS OF TABLE IT_CHEQ3
                  FOR ALL ENTRIES IN IT_CHEQ2
                  WHERE AUGBL = IT_CHEQ2-AUGBL and
                    BUKRS = IT_CHEQ2-BUKRS   AND
*                  AUGBL = IT_CHEQ2-AUGBL
                      GJAHR = IT_CHEQ2-GJAHR
                  AND  XBLNR = IT_CHEQ2-XBLNR.
line company code  hkont       augdt               augbl               zuonr              gjahr        belnr                 buzei  budat
1     1018     0012100030     20110831     2100009710     20110831     2011     2100009710     005     20110831
xblnr       blart        shkzg
RA03     KZ         H            37067.00         0.00     2011     0.00     0.00
2     1018     0012100030     20110831     2100009710     20110831     2011     2100009710     006     20110831
     RA03     KZ     H     393850.00     0.00     2011     0.00     0.00
3     1018     0012100030     20110831     2100009710     20110831     2011     2100009710     004     20110831     RA03     KZ     S     723589.13     0.00     2011     0.00     0.00
4     1018     0012100030     20110831     2100009710     20110823     2011     3900001250     001     20110823     RA03     RS     H     712921.13     0.00     2011     0.00     0.00
5     1018     0023200000     20110831     2100009710     20110831     2011     2100009710     008     20110831     RA03     KZ     H     21788.00     0.00     2011     0.00     0.00
6     1018     0023200000     20110831     2100009710     20110831     2011     2100009710     007     20110831     RA03     KZ     H     1162821.00     0.00     2011     0.00     0.00
if i put same entry in se11 for bsas it takes 7 second
and in query takes  more then 6 min ,kindly tell why
help me gurus
regards
victor

Tested point 2.
There is no difference.
REPORT  Z_YZ_SELECT_ORDER.
types: begin of t_orderadm,
         description type CRMT_PROCESS_DESCRIPTION,
         created_at type COMT_CREATED_AT_USR,
         LOGICAL_SYSTEM type CRMT_LOGSYS,
         TEMPLATE_TYPE type CRMT_TEMPLATE_TYPE_DB,
         VERIFY_DATE type CRMT_VERIFY_DATE,
         GUID type CRMT_OBJECT_GUID,
       end of t_orderadm.
types: begin of t_orderadm_1,
         GUID type CRMT_OBJECT_GUID,
         description type CRMT_PROCESS_DESCRIPTION,
         LOGICAL_SYSTEM type CRMT_LOGSYS,
         TEMPLATE_TYPE type CRMT_TEMPLATE_TYPE_DB,
         created_at type COMT_CREATED_AT_USR,
         VERIFY_DATE type CRMT_VERIFY_DATE,
       end of t_orderadm_1.
data: lt_orders type table of t_orderadm,
      lt_orders_1 type table of t_orderadm_1.
select description created_at logical_system template_type verify_date guid
  into table lt_orders
  from crmd_orderadm_h.
select guid description logical_system template_type created_at verify_date
  into table lt_orders_1
  from crmd_orderadm_h.
write 'done'.
First select - mixed order of fields. Response time: 82.155 microseconds for 39380 records selected.
Second select - fields in the order of the table. Response time: 81.061 microseconds for the same 39380 records selected.
Then I changed the order of SELECT statements. I have put first the select with ordered fields, and second - select with mixed order of fields. The runtimes were the following:
Ordered fields - 82.649 microseconds
Mixed order of fields - 80.270 microseconds.
So I'm going to change the Wiki page in order to avoid  in future advices that make no sense.

Similar Messages

  • Select Query taking long time to run second time

    Hi All,
    I have Oracle 11gR1 in windows server 2008 R2 .
    I have some tables with 10 million records . When i run the select query for those tables first time it gives me result in 15 seconds but if i am running the same script second time from the same session I am getting the result in 15 minutes to complete ..
    Why it is happening? What may be the solution for this ?
    Thanks & Regards,
    Vikash jain(Junior DBA)

    Hi Mohamed,
    I just saw that both the times for the same query execution plan is different ..
    here are the details :
    First time Second Time
    g84m3qqjv2p3q g84m3qqjv2p3q
    2733045235 1310485984
    So plz tell me how should i force database to use the first execution plan ?
    I got this script for forcing the Db to use the same execution plan
    accept sql_id -
    prompt 'Enter value for sql_id: ' -
    default 'X0X0X0X0'
    accept plan_hash_value -
    prompt 'Enter value for plan_hash_value: ' -
    default 'X0X0X0X0'
    accept fixed -
    prompt 'Enter value for fixed (NO): ' -
    default 'NO'
    accept enabled -
    prompt 'Enter value for enabled (YES): ' -
    default 'YES'
    accept plan_name -
    prompt 'Enter value for plan_name (ID_sqlid_planhashvalue): ' -
    default 'X0X0X0X0'
    set feedback off
    set sqlblanklines on
    set serveroutput on
    declare
    l_plan_name varchar2(40);
    l_old_plan_name varchar2(40);
    l_sql_handle varchar2(40);
    ret binary_integer;
    l_sql_id varchar2(13);
    l_plan_hash_value number;
    l_fixed varchar2(3);
    l_enabled varchar2(3);
    major_release varchar2(3);
    minor_release varchar2(3);
    begin
    select regexp_replace(version,'\..*'), regexp_substr(version,'[0-9]+',1,2) into major_release, minor_release from v$instance;
    minor_release := 2;
    l_sql_id := '&&sql_id';
    l_plan_hash_value := to_number('&&plan_hash_value');
    l_fixed := '&&fixed';
    l_enabled := '&&enabled';
    ret := dbms_spm.load_plans_from_cursor_cache(
    sql_id=>l_sql_id,
    plan_hash_value=>l_plan_hash_value,
    fixed=>l_fixed,
    enabled=>l_enabled);
    if minor_release = '1' then
    -- 11gR1 has a bug that prevents renaming Baselines
    dbms_output.put_line(' ');
    dbms_output.put_line('Baseline created.');
    dbms_output.put_line(' ');
    else
    -- This statements looks for Baselines create in the last 4 seconds
    select sql_handle, plan_name,
    decode('&&plan_name','X0X0X0X0','SQLID_'||'&&sql_id'||'_'||'&&plan_hash_value','&&plan_name')
    into l_sql_handle, l_old_plan_name, l_plan_name
    from dba_sql_plan_baselines spb
    where created > sysdate-(1/24/60/15);
    ret := dbms_spm.alter_sql_plan_baseline(
    sql_handle=>l_sql_handle,
    plan_name=>l_old_plan_name,
    attribute_name=>'PLAN_NAME',
    attribute_value=>l_plan_name);
    dbms_output.put_line(' ');
    dbms_output.put_line('Baseline '||upper(l_plan_name)||' created.');
    dbms_output.put_line(' ');
    end if;
    end;
    undef sql_id
    undef plan_hash_value
    undef plan_name
    undef fixed
    set feedback on
    Output:
    Enter value for sql_id: g84m3qqjv2p3q
    Enter value for plan_hash_value: 2733045235
    Enter value for fixed (NO):
    Enter value for enabled (YES):
    Enter value for plan_name (ID_sqlid_planhashvalue): g84m3qqjv2p3q
    old 16: l_sql_id := '&&sql_id';
    new 16: l_sql_id := 'g84m3qqjv2p3q';
    old 17: l_plan_hash_value := to_number('&&plan_hash_value');
    new 17: l_plan_hash_value := to_number('2733045235');
    old 18: l_fixed := '&&fixed';
    new 18: l_fixed := 'NO';
    old 19: l_enabled := '&&enabled';
    new 19: l_enabled := 'YES';
    old 40: decode('&&plan_name','X0X0X0X0','SQLID_'||'&&sql_id'||'_'||'&&plan_hash_value','&&plan_name')
    new 40: decode('g84m3qqjv2p3q','X0X0X0X0','SQLID_'||'g84m3qqjv2p3q'||'_'||'2733045235','g84m3qqjv2p3q')
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 39
    Kindly help me to resolve the issue ..
    Thanks & Regards,
    Vikash Jain(Junior DBA)

  • SELECT query taking long time

    Hi All,
    I am trying to run one SELECT statement which uses 6 tables. That query generally take 25-30 minutes to generate output.
    Today it is running from more than 2 hours. I have checked there are no locks on those tables and no other process is using them.
    What else I should check in order to figure out why my SELECT statement is taking time?
    Any help will be much appreciated.
    Thanks!

    Please let me know if you still want me to provide all the information mentioned in the link.Yes, please.
    Before you can even start optimizing, it should be clear what parts of the query are running slow.
    The links contains the steps to take regarding how to identify the things that make the query run slow.
    Ideally you post a trace/tkprof report with wait events, it'll show on what time is being spent, give an execution plan and a database version all in once...
    Today it is running from more than 2 hours. I have checked there are no locks on those tables and no other process is using them.Well, something must have changed.
    And you must indentify what exactly has changed, but it's a broad range you have to check:
    - it could be outdated table statistics
    - it could be data growth or skewness that makes Optimizer choose a wrong plan all of a sudden
    - it could be a table that got modified with some bad index
    - it could be ...
    So, by posting the information in the link, you'll leave less room for guesses from us, so you'll get an explanation that makes sense faster or, while investigating by following the steps in the link, you'll get the explanation yourself.

  • Query taking long time for EXTRACTING the data more than 24 hours

    Hi ,
    Query taking long time for EXTRACTING the data more than 24 hours please find the query and explain plan details below even indexes avilable on table's goe's to FULL TABLE SCAN. please suggest me.......
    SQL> explain plan for select a.account_id,round(a.account_balance,2) account_balance,
    2 nvl(ah.invoice_id,ah.adjustment_id) transaction_id,
    to_char(ah.effective_start_date,'DD-MON-YYYY') transaction_date,
    to_char(nvl(i.payment_due_date,
    to_date('30-12-9999','dd-mm-yyyy')),'DD-MON-YYYY')
    due_date, ah.current_balance-ah.previous_balance amount,
    decode(ah.invoice_id,null,'A','I') transaction_type
    3 4 5 6 7 8 from account a,account_history ah,invoice i_+
    where a.account_id=ah.account_id
    and a.account_type_id=1000002
    and round(a.account_balance,2) > 0
    and (ah.invoice_id is not null or ah.adjustment_id is not null)
    and ah.CURRENT_BALANCE > ah.previous_balance
    and ah.invoice_id=i.invoice_id(+)
    AND a.account_balance > 0
    order by a.account_id,ah.effective_start_date desc; 9 10 11 12 13 14 15 16
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 544K| 30M| | 693K (20)|
    | 1 | SORT ORDER BY | | 544K| 30M| 75M| 693K (20)|
    |* 2 | HASH JOIN | | 544K| 30M| | 689K (20)|
    |* 3 | TABLE ACCESS FULL | ACCOUNT | 20080 | 294K| | 6220 (18)|
    |* 4 | HASH JOIN OUTER | | 131M| 5532M| 5155M| 678K (20)|
    |* 5 | TABLE ACCESS FULL| ACCOUNT_HISTORY | 131M| 3646M| | 197K (25)|
    | 6 | TABLE ACCESS FULL| INVOICE | 262M| 3758M| | 306K (18)|
    Predicate Information (identified by operation id):
    2 - access("A"."ACCOUNT_ID"="AH"."ACCOUNT_ID")
    3 - filter("A"."ACCOUNT_TYPE_ID"=1000002 AND "A"."ACCOUNT_BALANCE">0 AND
    ROUND("A"."ACCOUNT_BALANCE",2)>0)
    4 - access("AH"."INVOICE_ID"="I"."INVOICE_ID"(+))
    5 - filter("AH"."CURRENT_BALANCE">"AH"."PREVIOUS_BALANCE" AND ("AH"."INVOICE_ID"
    IS NOT NULL OR "AH"."ADJUSTMENT_ID" IS NOT NULL))
    22 rows selected.
    Index Details:+_
    SQL> select INDEX_OWNER,INDEX_NAME,COLUMN_NAME,TABLE_NAME from dba_ind_columns where
    2 table_name in ('INVOICE','ACCOUNT','ACCOUNT_HISTORY') order by 4;
    INDEX_OWNER INDEX_NAME COLUMN_NAME TABLE_NAME
    OPS$SVM_SRV4 P_ACCOUNT ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME ACCOUNT_NAME ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT CUSTOMER_NODE_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT ACCOUNT_TYPE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_ACCOUNT_TYPE ACCOUNT_TYPE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_INVOICE INVOICE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_PREVIOUS_INVOICE PREVIOUS_INVOICE_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME_ID ACCOUNT_NAME ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME_ID ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 I_LAST_MODIFIED_ACCOUNT LAST_MODIFIED ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_INVOICE_ACCOUNT INVOICE_ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ACCOUNT ACCOUNT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ACCOUNT SEQNR ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_INVOICE INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADINV INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA CURRENT_BALANCE ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA ACCOUNT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_LMOD LAST_MODIFIED ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADINV ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_PAYMENT PAYMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADJUSTMENT ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_APPLIED_DT APPLIED_DATE ACCOUNT_HISTORY
    OPS$SVM_SRV4 P_INVOICE INVOICE_ID INVOICE
    OPS$SVM_SRV4 U_INVOICE CUSTOMER_INVOICE_STR INVOICE
    OPS$SVM_SRV4 I_LAST_MODIFIED_INVOICE LAST_MODIFIED INVOICE
    OPS$SVM_SRV4 U_INVOICE_ACCOUNT ACCOUNT_ID INVOICE
    OPS$SVM_SRV4 U_INVOICE_ACCOUNT BILL_RUN_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_BILL_RUN BILL_RUN_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_INVOICE_TYPE INVOICE_TYPE_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_CUSTOMER_NODE CUSTOMER_NODE_ID INVOICE
    32 rows selected.
    Regards,
    Bathula
    Oracle-DBA

    I have some suggestions. But first, you realize that you have some redundant indexes, right? You have an index on account(account_name) and also account(account_name, account_id), and also account_history(invoice_id) and account_history(invoice_id, adjustment_id). No matter, I will suggest some new composite indexes.
    Also, you do not need two lines for these conditions:
    and round(a.account_balance, 2) > 0
    AND a.account_balance > 0
    You can just use: and a.account_balance >= 0.005
    So the formatted query isselect a.account_id,
           round(a.account_balance, 2) account_balance,
           nvl(ah.invoice_id, ah.adjustment_id) transaction_id,
           to_char(ah.effective_start_date, 'DD-MON-YYYY') transaction_date,
           to_char(nvl(i.payment_due_date, to_date('30-12-9999', 'dd-mm-yyyy')),
                   'DD-MON-YYYY') due_date,
           ah.current_balance - ah.previous_balance amount,
           decode(ah.invoice_id, null, 'A', 'I') transaction_type
      from account a, account_history ah, invoice i
    where a.account_id = ah.account_id
       and a.account_type_id = 1000002
       and (ah.invoice_id is not null or ah.adjustment_id is not null)
       and ah.CURRENT_BALANCE > ah.previous_balance
       and ah.invoice_id = i.invoice_id(+)
       AND a.account_balance >= .005
    order by a.account_id, ah.effective_start_date desc;You will probably want to select:
    1. From ACCOUNT first (your smaller table), for which you supply a literal on account_type_id. That should limit the accounts retrieved from ACCOUNT_HISTORY
    2. From ACCOUNT_HISTORY. We want to limit the records as much as possible on this table because of the outer join.
    3. INVOICE we want to access last because it seems to be least restricted, it is the biggest, and it has the outer join condition so it will manufacture rows to match as many rows as come back from account_history.
    Try the query above after creating the following composite indexes. The order of the columns is important:create index account_composite_i on account(account_type_id, account_balance, account_id);
    create index acct_history_comp_i on account_history(account_id, invoice_id, adjustment_id, current_balance, previous_balance, effective_start_date);
    create index invoice_composite_i on invoice(invoice_id, payment_due_date);All the columns used in the where clause will be indexed, in a logical order suited to the needs of the query. Plus each selected column is indexed as well so that we should not need to touch the tables at all to satisfy the query.
    Try the query after creating these indexes.
    A final suggestion is to try larger sort and hash area sizes and a manual workarea policy.alter session set workarea_size_policy = manual;
    alter session set sort_area_size = 2147483647;
    alter session set hash_area_size = 2147483647;

  • Select query running long time

    Hi,
    DB version : 10g
    platform : sunos
    My select sql query running long time (more than 20hrs) .Still running .
    Is there any way to find sql query completion time approximately. (Pending time)
    Also is there any possibilities to increase the speed of sql query (already running) like adding hints.
    Please help me on this .
    Thanks

    Hi Sathish thanks for your reply,
    I have already checked in V$SESSION_LONGOPS .But it's showing TIME_REMAINING -->0
    select TOTALWORK,SOFAR,START_TIME,TIME_REMAINING from V$SESSION_LONGOPS where SID='10'
    TOTALWORK      SOFAR START_TIME      TIME_REMAINING
         1099759    1099759 27-JAN-11                    0Any idea ?
    Thanks.

  • Select query takes long time....

    Hi Experts,
    I am using a select query in which inspection lot is in another table and order no. is in another table. this select query taking very long time, what is the problem in this query ? Pl. guide us.
    select bPRUEFLOS bMBLNR bCPUDT aAUFNR amatnr aLGORT a~bwart
    amenge aummat asgtxt axauto
    into corresponding fields of table itab
    *into table itab
    from mseg as a inner join qamb as b
    on amblnr = bmblnr
    and azeile = bzeile
    where b~PRUEFLOS in insp
    and  b~cpudt in date1
    and b~typ = '3'
    and a~bwart = '321'
    and a~aufnr in aufnr1.
    Yusuf

    hi
    instead of using 'move to corresponding of itab'  fields use  'into table itab'.....
    coz......if u use move to corresponding it will search for all the appropriate fields then it will place u r data........instead of that declare apprpiate internal table and use 'into table itab'.
    and one more thing dont use joins ......coz joins will decrease u r performance .....so instead of that use 'for all entries' ....and mention all the key fields in where condition ........
    ok
    reward points for helpful answers

  • Query taking long time to run.

    The following query is taking long time to run, is there anything can be done to make it run faster by changing the sql etc.
    select distinct
    A.DEPTID,
    A.POSITION_NBR,
    A.EMPLID,
    A.EMPL_RCD_NBR,
    A.EFFDT,
    B.NAME,
    A.EMPL_STATUS,
    A.JOBCODE,
    A.ANNUAL_RT,
    A.STD_HOURS,
    A.PRIMARY_JOB,
    C.POSN_STATUS,
    case when A.POSITION_NBR = ' ' then 0 else C.STD_HOURS end,
    case when A.POSITION_NBR = ' ' then ' ' else C.DEPTID end
    from PS_JOB A,
    PS_PERSONAL_DATA B,
    PS_POSITION_DATA C
    where A.EMPLID = B.EMPLID
    and
    ((A.POSITION_NBR = C.POSITION_NBR
    and A.EFFSEQ = (select max(D.EFFSEQ)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT = A.EFFDT)
    and C.POSN_STATUS <> 'G'
    and C.EFFDT = (select max(E.EFFDT)
    from PS_POSITION_DATA E
    where E.POSITION_NBR = A.POSITION_NBR
    and E.EFFDT <= A.EFFDT)
    and C.EFFSEQ = (select max(F.EFFSEQ)
    from PS_POSITION_DATA F
    where F.POSITION_NBR = A.POSITION_NBR
    and F.EFFDT = C.EFFDT))
    or
    (A.POSITION_NBR = C.POSITION_NBR
    and A.EFFDT = (select max(D.EFFDT)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT <= C.EFFDT)
    and A.EFFSEQ = (select max(E.EFFSEQ)
    from PS_JOB E
    where E.EMPLID = A.EMPLID
    and E.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and E.EFFDT = A.EFFDT)
    and C.POSN_STATUS <> 'G'
    and C.EFFSEQ = (select max(F.EFFSEQ)
    from PS_POSITION_DATA F
    where F.POSITION_NBR = A.POSITION_NBR
    and F.EFFDT = C.EFFDT)))
    or
    (A.POSITION_NBR = ' '
    and A.EFFSEQ = (select max(E.EFFSEQ)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and E.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT = A.EFFDT)))

    Using distributive law A and (B or C) = (A and B) or (A and C) from right to left we can have:
    select distinct A.DEPTID,A.POSITION_NBR,A.EMPLID,A.EMPL_RCD_NBR,A.EFFDT,B.NAME,A.EMPL_STATUS,
                    A.JOBCODE,A.ANNUAL_RT,A.STD_HOURS,A.PRIMARY_JOB,C.POSN_STATUS,
                    case when A.POSITION_NBR = ' ' then 0 else C.STD_HOURS end,
                    case when A.POSITION_NBR = ' ' then ' ' else C.DEPTID end
      from PS_JOB A,PS_PERSONAL_DATA B,PS_POSITION_DATA C
    where A.EMPLID = B.EMPLID
       and (
             A.POSITION_NBR = C.POSITION_NBR
         and A.EFFSEQ = (select max(D.EFFSEQ)
                           from PS_JOB D
                          where D.EMPLID = A.EMPLID
                            and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
                            and D.EFFDT = A.EFFDT
         and C.EFFSEQ = (select max(F.EFFSEQ)
                           from PS_POSITION_DATA E
                          where E.POSITION_NBR = A.POSITION_NBR
                            and E.EFFDT = C.EFFDT
         and C.POSN_STATUS != 'G'
         and (
               C.EFFDT = (select max(E.EFFDT) 
                            from PS_POSITION_DATA E
                           where E.POSITION_NBR = A.POSITION_NBR
                             and E.EFFDT <= A.EFFDT
           or
               A.EFFDT = (select max(D.EFFDT) 
                            from PS_JOB D
                           where D.EMPLID = A.EMPLID
                             and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
                             and D.EFFDT <= C.EFFDT
         or
             A.POSITION_NBR = ' '
               and A.EFFSEQ = (select max(E.EFFSEQ)
                                 from PS_JOB D
                                where D.EMPLID = A.EMPLID
                                  and E.EMPL_RCD_NBR = A.EMPL_RCD_NBR
                                  and D.EFFDT = A.EFFDT
           )may not help much as the optimizer might have guessed it already
    Regards
    Etbin

  • CDHDR table query taking long time

    Hi all,
    Select query from CDHDR table is taking long time,in where condition i am giving OBJECTCLASS = 'MAT_FULL' udate = sy-datum and langu = 'EN'.
    any suggestion to improve the performance.i want to select all the article which got changed on current date
    regards
    shibu

    This will always be slow for large data volumes, since CDHDR is designed for quick access by object ID (in this case material number), not by date.
    I'm afraid you would need to introduce a secondary index on OBJECTCLAS and UDATE, if that query is crucial enough to warrant the additional disk space and processing time taken by the new index.
    Greetings
    Thomas

  • Sap bi--query taking long time to exexute

    Hi
    When i try  run the bex query ,its taking long time,please suggest
    Thanks
    sreedhar

    Hi
    When i try  run the bex query ,its taking long time,please suggest
    Thanks
    sreedhar

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Select query taking Much time

    Dear all ,
    I am fetching data from pool table a006.  The select query is mentioned below.
    select * from a005 into table i_a005 for all wntries in it_table
                 where  kappl  = 'V'
                 and      kschl   IN  s_kschl
                 and     vkorg   in   s_vkorg
                 and     vtweg  in   s_vtgew
                 and     matnr   in s_matnr
                 and    knumh  =  it_table-knumh .
    here every fields are primary key fields except one field knumh which is comparing with table it_table. Because of these field this query is taking too much time as KNUMH is not primary key. And a005 is pool table . So , i cant create index for same. If there is alternate solutions , than please let me know..
    Thank You ,
    And in technical setting of table ITS Metioned as Fully buffered and size category is 0 .. But data are around 9000000. Is it issue or What ?  Can somebody tell some genual reason ? Or improvement in my select query.........
    Edited by: TVC6784 on Jun 30, 2011 3:31 PM

    TVC6784 wrote:
    Hi Yuri ,
    >
    > Thanks for your reply....I will check as per your comment...
    > bUT if i remove field KNUMH  From selection condition and also for all entries in it_itab ,  than data fetch very fast As KNUMH is not primary key..
    > .  the example is below
    >
    > select * from a005 into table i_a005
    > where kappl = 'V'
    > and kschl IN s_kschl
    > and vkorg in s_vkorg
    > and vtweg in s_vtgew
    > and matnr in s_matnr.
    >
    > Can you comment anything about it ?
    >
    > And can you please say how can i check its size as you mention that is  2-3 Mb More   ?
    >
    > Edited by: TVC6784 on Jun 30, 2011 7:37 PM
    I cannot see the trace and other information about the table so I cannot judge why the select w/o KNUMH is faster.
    Basically, if the table is buffered and it's contents is in the SAP application server memory, the access should be really fast. Does not really matter if it is with KNUMH or without.
    I would really like to see at least ST05 trace of your report that is doing this select. This would clarify many things.
    You can check the size by multiplying the entries in A005 table by 138. This is (in my test system) the ABAP width of the structure.
    If you have 9.000.000 records in A005, then it would take 1,24 Gb in the buffer (which is a clear sign to unbuffer).

  • Calculations in query taking long time and to load target table

    Hi,
    I am pulling approx 45 Million records using the below query in a ssis package which pulls from one DB on one server and loading the results to another target table on the another server. In the select query I have a calculation for 6 columns. The target
    table is trunctaed and loaded every day. Also most of the columns in the source which I used for the calculations is having 0 and it took approximately 1 hour 45 min to load the target table. Is there any way to reduce the load time? Also can I do the calcultions
    after once all the 47 M records loaded during query running and then calculate for the non zero records alone?
    SELECT T1.Col1,
    T1.Col2,
    T1.Col3,
    T2.Col1,
    T2.Col2,
    T3.Col1,
    convert( numeric(8,5), (convert( numeric,T3.COl2) / 1000000)) AS Colu2,
    convert( numeric(8,5), (convert( numeric,T3.COl3) / 1000000)) AS Colu3,
    convert( numeric(8,5), (convert( numeric,T3.COl4) / 1000000)) AS Colu4,
    convert( numeric(8,5),(convert( numeric, T3.COl5) / 1000000)) AS Colu5,
    convert( numeric(8,5), (convert( numeric,T3.COl6) / 1000000)) AS Colu6,
    convert( numeric(8,5), (convert( numeric,T3.COl7) / 1000000)) AS Colu7,
    FROM Tab1 T1 
    JOIN Tab2 T2
    ON (T1.Col1 = T2.Col1)
    JOIN Tab3 T3
    ON (Tab3.Col9 =Tab3.Col9)
    Anand

    So 45 or 47? Nevertheless ...
    This is hardly a heavy calculation, the savings will be dismal. Also anything numeric is very easy on CPU in general.
    But
    convert( numeric(8,5), (convert( numeric,T3.COl7) / 1000000))
    is not optimal.
    CONVERT( NUMERIC(8,5),300 / 1000000.00000 )
    Is
    Now it boils to how to make load faster: do it in parallel. Find how many sockets the machine have and split the table into as many chunks. Also profile to find out where it spends most of the time. I saw sometimes the network is not letting me thru so you
    may want to play with buffers, and packet sizes, for example if OLEDB used increase the packet size two times see if works faster, then x2 more and so forth.
    To help you further you need to tell more e.g. what is this source, destination, how you configured the load.
    Please understand that there is no Silver Bullet anywhere, or a blanket solution, and you need to tell me your desired load time. E.g. if you tell me it needs to load in 5 min I will give your ask a pass.
    Arthur
    MyBlog
    Twitter

  • Query taking long time

    Hi
    I have a query in which, its a 3 table join but takes a long time to execute. I had checked with plan table.. it shows one of the table is FULL ACCESS.
    I have 2 clarifications.
    1. Will the status checking as NULL - (it shouldn't use index)
    2. Is the case statements are recommended for queries.
    Query
    Select .........
    FROM CLIENT LEFT OUTER JOIN INTERNET_LOGIN ON INTERNET_LOGIN.NUM_CLIENT_ID=CLIENT.NUM_CLIENT_ID,
    POLI_MOT.
    WHERE
    POLI_MOT.NUM_CLIENT_ID=CLIENT.NUM_CLIENT_ID
    AND
    (POLI_MOT.CHR_CANCEL_STATUS='N'
    OR
    POLI_MOT.CHR_CANCEL_STATUS IS NULL)
    AND
    CLIENT.NUM_CONTACT_TYPE_ID IN (1,3)
    AND
    (NVL(POLI_MOT.VCH_NEW_IC_NO,'A') =
    CASE WHEN (NVL(null,NULL) IS NULL) THEN
    NVL(POLI_MOT.VCH_NEW_IC_NO,'A')
    ELSE
    NVL(null,NULL)
    END
    OR
    POLI_MOT.VCH_OLD_IC_NO =
    CASE WHEN nvl(null,null) IS NULL THEN
    POLI_MOT.VCH_OLD_IC_NO
    ELSE
    NVL(null,NULL)
    END )
    AND POLI_MOT.VCH_POLICY_NO =
    CASE WHEN UPPER(nvl(NULL,null)) IS NULL THEN
    POLI_MOT.VCH_POLICY_NO
    ELSE
    NVL(NULL,NULL)
    END
    AND POLI_MOT.VCH_VEHICLE_NO =
    CASE WHEN UPPER(NVL('123',NULL)) IS NULL THEN
    POLI_MOT.VCH_VEHICLE_NO
    ELSE
    NVL('123',NULL)
    END

    Hi,
    There is nothing wrong in having a full table access. When you do the explain plan please check for which table costs you the maximun. try to work on that table.
    To tune the performance of your query you can try either indexing or parallel access.
    the syntax for parallel index is
    /*+ PARALLEL("TBL_NM",100) */(any number)...
    for index please use the index name of the table you want to index..
    regards
    Bharath

  • Query taking long time To Fectch the Results

    Hi!
    when I run the query,it takes too long time for fetching the resultsets.
    Please find the query below for the same.
    SELECT
    A.BUSINESS_UNIT,
    A.JOURNAL_ID,
    TO_CHAR(A.JOURNAL_DATE,'YYYY-MM-DD'),
    A.UNPOST_SEQ,
    A.FISCAL_YEAR,
    A.ACCOUNTING_PERIOD,
    A.JRNL_HDR_STATUS,
    C.INVOICE,
    C.ACCT_ENTRY_TYPE,
    C.LINE_DST_SEQ_NUM,
    C.TAX_AUTHORITY_CD,
    C.ACCOUNT,
    C.MONETARY_AMOUNT,
    D.BILL_SOURCE_ID,
    D.IDENTIFIER,
    D.VAT_AMT_BSE,
    D.VAT_TRANS_AMT_BSE,
    D.VAT_TXN_TYPE_CD,
    D.TAX_CD_VAT,
    D.TAX_CD_VAT_PCT,
    D.VAT_APPLICABILITY,
    E.BILL_TO_CUST_ID,
    E.BILL_STATUS,
    E.BILL_CYCLE_ID,
    TO_CHAR(E.INVOICE_DT,'YYYY-MM-DD'),
    TO_CHAR(E.ACCOUNTING_DT,'YYYY-MM-DD'),
    TO_CHAR(E.DT_INVOICED,'YYYY-MM-DD'),
    E.ENTRY_TYPE,
    E.ENTRY_REASON,
    E.AR_LVL,
    E.AR_DST_OPT,
    E.AR_ENTRY_CREATED,
    E.GEN_AR_ITEM_FLG,
    E.GL_LVL, E.GL_ENTRY_CREATED,
    (Case when c.account in ('30120000','30180050','30190000','30290000','30490000',
    '30690000','30900040','30990000','35100000','35120000','35150000','35160000',
    '39100050','90100000')
    and D.TAX_CD_VAT_PCT <> 0 then 'Ej_Momskonto_med_moms'
    When c.account not in ('30120000','30180050','30190000','30290000',
    '30490000','30690000','30900040','30990000','35100000','35120000','35150000',
    '35160000','39100050','90100000')
    and D.TAX_CD_VAT_PCT <> 25 then 'Momskonto_utan_moms' end)
    FROM
    sysadm.PS_JRNL_HEADER A,
    sysadm.PS_JRNL_LN B,
    sysadm.PS_BI_ACCT_ENTRY C,
    sysadm.PS_BI_LINE D,
    sysadm.PS_BI_HDR E
    WHERE A.BUSINESS_UNIT = '&BU'
    AND A.JOURNAL_DATE BETWEEN TO_DATE('&From_date','YYYY-MM-DD')
    AND TO_DATE('&To_date','YYYY-MM-DD')
    AND A.SOURCE      = 'BI'
    AND A.BUSINESS_UNIT = B.BUSINESS_UNIT
    AND A.JOURNAL_ID      = B.JOURNAL_ID
    AND A.JOURNAL_DATE = B.JOURNAL_DATE
    AND A.UNPOST_SEQ      = B.UNPOST_SEQ
    AND B.BUSINESS_UNIT = C.BUSINESS_UNIT
    AND B.JOURNAL_ID = C.JOURNAL_ID
    AND B.JOURNAL_DATE = C.JOURNAL_DATE
    AND B.JOURNAL_LINE = C.JOURNAL_LINE
    AND C.ACCT_ENTRY_TYPE = 'RR'
    AND C.BUSINESS_UNIT = '&BU'
    AND C.BUSINESS_UNIT = D.BUSINESS_UNIT
    AND C.INVOICE = D.INVOICE
    AND C.LINE_SEQ_NUM = D.LINE_SEQ_NUM
    AND D.BUSINESS_UNIT = '&BU'
    AND D.BUSINESS_UNIT = E.BUSINESS_UNIT
    AND D.INVOICE = E.INVOICE
    AND E.BUSINESS_UNIT = '&BU'
    AND
    ((c.account in ('30120000','30180050','30190000','30290000','30490000',
    '30690000','30900040','30990000','35100000','35120000','35150000','35160000',
    '39100050','90100000')
    and D.TAX_CD_VAT_PCT <> 0)
    OR
    (c.account not in ('30120000','30180050','30190000','30290000','30490000',
    '30690000','30900040','30990000','35100000','35120000','35150000','35160000',
    '39100050','z')
    and D.TAX_CD_VAT_PCT <> 25)
    GROUP BY
    A.BUSINESS_UNIT,
    A.JOURNAL_ID,
    TO_CHAR(A.JOURNAL_DATE,'YYYY-MM-DD'),
    A.UNPOST_SEQ, A.FISCAL_YEAR,
    A.ACCOUNTING_PERIOD,
    A.JRNL_HDR_STATUS,
    C.INVOICE,
    C.ACCT_ENTRY_TYPE,
    C.LINE_DST_SEQ_NUM,
    C.TAX_AUTHORITY_CD,
    C.ACCOUNT,
    D.BILL_SOURCE_ID,
    D.IDENTIFIER,
    D.VAT_TXN_TYPE_CD,
    D.TAX_CD_VAT,
    D.TAX_CD_VAT_PCT,
    D.VAT_APPLICABILITY,
    E.BILL_TO_CUST_ID,
    E.BILL_STATUS,
    E.BILL_CYCLE_ID,
    TO_CHAR(E.INVOICE_DT,'YYYY-MM-DD'),
    TO_CHAR(E.ACCOUNTING_DT,'YYYY-MM-DD'),
    TO_CHAR(E.DT_INVOICED,'YYYY-MM-DD'),
    E.ENTRY_TYPE, E.ENTRY_REASON,
    E.AR_LVL, E.AR_DST_OPT,
    E.AR_ENTRY_CREATED,
    E.GEN_AR_ITEM_FLG,
    E.GL_LVL,
    E.GL_ENTRY_CREATED,
    C.MONETARY_AMOUNT,
    D.VAT_AMT_BSE,
    D.VAT_TRANS_AMT_BSE
    having
    (Case when c.account in ('30120000','30180050','30190000','30290000',
    '30490000','30690000','30900040','30990000','35100000','35120000','35150000',
    '35160000','39100050','90100000')
    and D.TAX_CD_VAT_PCT <> 0 then 'Ej_Momskonto_med_moms'
    When c.account not in ('30120000','30180050','30190000','30290000','30490000',
    '30690000','30900040','30990000','35100000','35120000','35150000','35160000',
    '39100050','90100000')
    and D.TAX_CD_VAT_PCT <> 25 then 'Momskonto_utan_moms' end) is not null
    So Could you provide the solution to fix this issue?
    Thanks
    senthil

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

  • Sql query taking long time

    the below query is taking very long time.
    select /*+ PARALLEL(a,8) PARALLEL(b,8) */ a.personid,a.winning_id, b.questionid from
    winning_id_cleanup a , rm_personquestion b
    where a.personid = b.personid and (a.winning_id,b.questionid) not in
    (select /*+ PARALLEL(c,8) */ c.personid,c.questionid from rm_personquestion c where c.personid=a.winning_id);
    where the rm_personquestion table is having 45 million rows and winning_id_cleanup is having 1 million rows.
    please tell me how to tune this query?

    Please post u'r query at PL/SQL
    It's not for SQL and PL/SQL

Maybe you are looking for

  • Creating a step type "launcher" that would insert the appropriate built-in or custom step type at edit time

    Hi everybody, I'm looking for tips, pointers,directions... to be able to perform this operation in TS 4.0 sequence Editor, if it's even possible... I'm managing a test system with a "home-made" virtual instruments abstraction Layer complementary to I

  • How do I sync iPod calendar with iCal?

    Hello everyone, I have just been bought a new iPod touch as a birthday present.  Since I have never had a device that operates like a smart phone before (I know it's not exactly a smart phone), I thought I would begin to use it as a diary, note-taker

  • Velocity / XML response

    Hi everyone, I'd be grateful if someone could help me out here. I use apache velocity to generate an xml request to send to a gateway which processes the request and sends an xml response. At the moment, the response (xmlString) is outputted to the b

  • 802.1x + ACS + AD

    I am wondering is it possible to accomplish following scenario. I want to authenticate users connecting to my network using 802.1x based on Active Directory, but to be able to put users from external database (AD) to different Vlans based on some spe

  • Payable status is being set as SP and the TL_PYBL_REASON_CD is being set as Payroll not Processed (PNP)

    Hi All, Have you come across any scenarios where the Payable status is being set as SP and the TL_PYBL_REASON_CD is being set as Payroll not Processed (PNP) in Peoplesoft Time and Labor 9.0 application? Thanks & Regards, Allen