Performance issue in selecting data from a view because of not in condition

Hi experts,
I have a requirement to select data in a view which is not available in a fact with certain join conditions. but the fact table contains 2 crore rows of data. so this view is not working at all. it is running for long time. im pasting query here. please help me to tune it. whole query except prior to not in is executing in 15 minutes. but when i add not in condition it is running for so many hours as the second table has millions of records.
CREATE OR REPLACE FORCE VIEW EDWOWN.MEDW_V_GIEA_SERVICE_LEVEL11
   SYS_ENT_ID,
   SERVICE_LEVEL_NO,
   CUSTOMER_NO,
   BILL_TO_LOCATION,
   PART_NO,
   SRCE_SYS_ID,
   BUS_AREA_ID,
   CONTRACT,
   WAREHOUSE,
   ORDER_NO,
   LINE_NO,
   REL_NO,
   REVISED_DUE_DATE,
   REVISED_QTY_DUE,
   QTY_RESERVED,
   QTY_PICKED,
   QTY_SHIPPED,
   ABBREVIATION,
   ACCT_WEEK,
   ACCT_MONTH,
   ACCT_YEAR,
   UPDATED_FLAG,
   CREATE_DATE,
   RECORD_DATE,
   BASE_WAREHOUSE,
   EARLIEST_SHIP_DATE,
   LATEST_SHIP_DATE,
   SERVICE_DATE,
   SHIP_PCT,
   ALLOC_PCT,
   WHSE_PCT,
   ABC_CLASS,
   LOCATION_ID,
   RELEASE_COMP,
   WAREHOUSE_DESC,
   MAKE_TO_FLAG,
   SOURCE_CREATE_DATE,
   SOURCE_UPDATE_DATE,
   SOURCE_CREATED_BY,
   SOURCE_UPDATED_BY,
   ENTITY_CODE,
   RECORD_ID,
   SRC_SYS_ENT_ID,
   BSS_HIERARCHY_KEY,
   SERVICE_LVL_FLAG
AS
   SELECT SL.SYS_ENT_ID,
             SL.ENTITY_CODE
          || '-'
          || SL.order_no
          || '-'
          || SL.LINE_NO
          || '-'
          || SL.REL_NO
             SERVICE_LEVEL_NO,
          SL.CUSTOMER_NO,
          SL.BILL_TO_LOCATION,
          SL.PART_NO,
          SL.SRCE_SYS_ID,
          SL.BUS_AREA_ID,
          SL.CONTRACT,
          SL.WAREHOUSE,
          SL.ORDER_NO,
          SL.LINE_NO,
          SL.REL_NO,
          SL.REVISED_DUE_DATE,
          SL.REVISED_QTY_DUE,
          NULL QTY_RESERVED,
          NULL QTY_PICKED,
          SL.QTY_SHIPPED,
          SL.ABBREVIATION,
          NULL ACCT_WEEK,
          NULL ACCT_MONTH,
          NULL ACCT_YEAR,
          NULL UPDATED_FLAG,
          SL.CREATE_DATE,
          SL.RECORD_DATE,
          SL.BASE_WAREHOUSE,
          SL.EARLIEST_SHIP_DATE,
          SL.LATEST_SHIP_DATE,
          SL.SERVICE_DATE,
          SL.SHIP_PCT,
          0 ALLOC_PCT,
          0 WHSE_PCT,
          SL.ABC_CLASS,
          SL.LOCATION_ID,
          NULL RELEASE_COMP,
          SL.WAREHOUSE_DESC,
          SL.MAKE_TO_FLAG,
          SL.source_create_date,
          SL.source_update_date,
          SL.source_created_by,
          SL.source_updated_by,
          SL.ENTITY_CODE,
          SL.RECORD_ID,
          SL.SRC_SYS_ENT_ID,
          SL.BSS_HIERARCHY_KEY,
          'Y' SERVICE_LVL_FLAG
     FROM (  SELECT SL_INT.SYS_ENT_ID,
                    SL_INT.CUSTOMER_NO,
                    SL_INT.BILL_TO_LOCATION,
                    SL_INT.PART_NO,
                    SL_INT.SRCE_SYS_ID,
                    SL_INT.BUS_AREA_ID,
                    SL_INT.CONTRACT,
                    SL_INT.WAREHOUSE,
                    SL_INT.ORDER_NO,
                    SL_INT.LINE_NO,
                    MAX (SL_INT.REL_NO) REL_NO,
                    SL_INT.REVISED_DUE_DATE,
                    SUM (SL_INT.REVISED_QTY_DUE) REVISED_QTY_DUE,
                    SUM (SL_INT.QTY_SHIPPED) QTY_SHIPPED,
                    SL_INT.ABBREVIATION,
                    MAX (SL_INT.CREATE_DATE) CREATE_DATE,
                    MAX (SL_INT.RECORD_DATE) RECORD_DATE,
                    SL_INT.BASE_WAREHOUSE,
                    MAX (SL_INT.LAST_SHIPMENT_DATE) LAST_SHIPMENT_DATE,
                    MAX (SL_INT.EARLIEST_SHIP_DATE) EARLIEST_SHIP_DATE,
                    MAX (SL_INT.LATEST_SHIP_DATE) LATEST_SHIP_DATE,
                    MAX (
                       CASE
                          WHEN TRUNC (SL_INT.LAST_SHIPMENT_DATE) <=
                                  TRUNC (SL_INT.LATEST_SHIP_DATE)
                          THEN
                             TRUNC (SL_INT.LAST_SHIPMENT_DATE)
                          ELSE
                             TRUNC (SL_INT.LATEST_SHIP_DATE)
                       END)
                       SERVICE_DATE,
                    MIN (
                       CASE
                          WHEN TRUNC (SL_INT.LAST_SHIPMENT_DATE) >=
                                  TRUNC (SL_INT.EARLIEST_SHIP_DATE)
                               AND TRUNC (SL_INT.LAST_SHIPMENT_DATE) <=
                                      TRUNC (SL_INT.LATEST_SHIP_DATE)
                               AND SL_INT.QTY_SHIPPED = SL_INT.REVISED_QTY_DUE
                          THEN
                             100
                          ELSE
                             0
                       END)
                       SHIP_PCT,
                    SL_INT.ABC_CLASS,
                    SL_INT.LOCATION_ID,
                    SL_INT.WAREHOUSE_DESC,
                    SL_INT.MAKE_TO_FLAG,
                    MAX (SL_INT.source_create_date) source_create_date,
                    MAX (SL_INT.source_update_date) source_update_date,
                    SL_INT.source_created_by,
                    SL_INT.source_updated_by,
                    SL_INT.ENTITY_CODE,
                    SL_INT.RECORD_ID,
                    SL_INT.SRC_SYS_ENT_ID,
                    SL_INT.BSS_HIERARCHY_KEY
               FROM (SELECT SL_UNADJ.*,
                            DECODE (
                               TRIM (TIMA.DAY_DESC),
                               'saturday',   SL_UNADJ.REVISED_DUE_DATE
                                           - 1
                                           - early_ship_days,
                               'sunday',   SL_UNADJ.REVISED_DUE_DATE
                                         - 2
                                         - early_ship_days,
                               SL_UNADJ.REVISED_DUE_DATE - early_ship_days)
                               EARLIEST_SHIP_DATE,
                            DECODE (
                               TRIM (TIMB.DAY_DESC),
                               'saturday',   SL_UNADJ.REVISED_DUE_DATE
                                           + 2
                                           + LATE_SHIP_DAYS,
                               'sunday',   SL_UNADJ.REVISED_DUE_DATE
                                         + 1
                                         + LATE_SHIP_DAYS,
                               SL_UNADJ.REVISED_DUE_DATE + LATE_SHIP_DAYS)
                               LATEST_SHIP_DATE
                       FROM (SELECT NVL (s2.sys_ent_id, '00') SYS_ENT_ID,
                                    cust.customer_no CUSTOMER_NO,
                                    cust.bill_to_loc BILL_TO_LOCATION,
                                    cust.early_ship_days,
                                    CUST.LATE_SHIP_DAYS,
                                    ord.PART_NO,
                                    ord.SRCE_SYS_ID,
                                    ord.BUS_AREA_ID,
                                    ord.BUS_AREA_ID CONTRACT,
                                    NVL (WAREHOUSE, ord.entity_code) WAREHOUSE,
                                    ORDER_NO,
                                    ORDER_LINE_NO LINE_NO,
                                    ORDER_REL_NO REL_NO,
                                    TRUNC (REVISED_DUE_DATE) REVISED_DUE_DATE,
                                    REVISED_ORDER_QTY REVISED_QTY_DUE,
                                    --   NULL QTY_RESERVED,
                                    --    NULL QTY_PICKED,
                                    SHIPPED_QTY QTY_SHIPPED,
                                    sold_to_abbreviation ABBREVIATION,
                                    --        NULL ACCT_WEEK,
                                    --      NULL ACCT_MONTH,
                                    --    NULL ACCT_YEAR,
                                    --  NULL UPDATED_FLAG,
                                    ord.CREATE_DATE CREATE_DATE,
                                    ord.CREATE_DATE RECORD_DATE,
                                    NVL (WAREHOUSE, ord.entity_code)
                                       BASE_WAREHOUSE,
                                    LAST_SHIPMENT_DATE,
                                    TRUNC (REVISED_DUE_DATE)
                                    - cust.early_ship_days
                                       EARLIEST_SHIP_DATE_UnAdj,
                                    TRUNC (REVISED_DUE_DATE)
                                    + CUST.LATE_SHIP_DAYS
                                       LATEST_SHIP_DATE_UnAdj,
                                    --0 ALLOC_PCT,
                                    --0 WHSE_PCT,
                                    ABC_CLASS,
                                    NVL (LOCATION_ID, '000') LOCATION_ID,
                                    --NULL RELEASE_COMP,
                                    WAREHOUSE_DESC,
                                    NVL (
                                       DECODE (MAKE_TO_FLAG,
                                               'S', 0,
                                               'O', 1,
                                               '', -1),
                                       -1)
                                       MAKE_TO_FLAG,
                                    ord.CREATE_DATE source_create_date,
                                    ord.UPDATE_DATE source_update_date,
                                    ord.CREATED_BY source_created_by,
                                    ord.UPDATED_BY source_updated_by,
                                    ord.ENTITY_CODE,
                                    ord.RECORD_ID,
                                    src.SYS_ENT_ID SRC_SYS_ENT_ID,
                                    ord.BSS_HIERARCHY_KEY
                               FROM EDW_DTL_ORDER_FACT ord,
                                    edw_v_maxv_cust_dim cust,
                                    edw_v_maxv_part_dim part,
                                    EDW_WAREHOUSE_LKP war,
                                    EDW_SOURCE_LKP src,
                                    MEDW_PLANT_LKP s2,
                                    edw_v_incr_refresh_ctl incr
                              WHERE ord.BSS_HIERARCHY_KEY =
                                       cust.BSS_HIERARCHY_KEY(+)
                                    AND ord.record_id = part.record_id(+)
                                    AND ord.part_no = part.part_no(+)
                                    AND NVL (ord.WAREHOUSE, ord.entity_code) =
                                           war.WAREHOUSE_code(+)
                                    AND ord.entity_code = war.entity_code(+)
                                    AND ord.record_id = src.record_id
                                    AND src.calculate_back_order_flag = 'Y'
                                    AND NVL (cancel_order_flag, 'N') != 'Y'
                                    AND UPPER (part.source_plant) =
                                           UPPER (s2.location_code1(+))
                                    AND mapping_name = 'MEDW_MAP_GIEA_MTOS_STG'
                                  --  AND NVL (ord.UPDATE_DATE, SYSDATE) >=
                                  --         MAX_SOURCE_UPDATE_DATE
                                    AND UPPER (
                                           NVL (ord.order_status, 'BOOKED')) NOT IN
                                           ('ENTERED', 'CANCELLED')
                                    AND TRUNC (REVISED_DUE_DATE) <= SYSDATE) SL_UNADJ,
                            EDW_TIME_DIM TIMA,
                            EDW_TIME_DIM TIMB
                      WHERE TRUNC (SL_UNADJ.EARLIEST_SHIP_DATE_UnAdj) =
                               TIMA.ACCOUNT_DATE
                            AND TRUNC (SL_UNADJ.LATEST_SHIP_DATE_Unadj) =
                                   TIMB.ACCOUNT_DATE) SL_INT
              WHERE TRUNC (LATEST_SHIP_DATE) <= TRUNC (SYSDATE)
           GROUP BY SL_INT.SYS_ENT_ID,
                    SL_INT.CUSTOMER_NO,
                    SL_INT.BILL_TO_LOCATION,
                    SL_INT.PART_NO,
                    SL_INT.SRCE_SYS_ID,
                    SL_INT.BUS_AREA_ID,
                    SL_INT.CONTRACT,
                    SL_INT.WAREHOUSE,
                    SL_INT.ORDER_NO,
                    SL_INT.LINE_NO,
                    SL_INT.REVISED_DUE_DATE,
                    SL_INT.ABBREVIATION,
                    SL_INT.BASE_WAREHOUSE,
                    SL_INT.ABC_CLASS,
                    SL_INT.LOCATION_ID,
                    SL_INT.WAREHOUSE_DESC,
                    SL_INT.MAKE_TO_FLAG,
                    SL_INT.source_created_by,
                    SL_INT.source_updated_by,
                    SL_INT.ENTITY_CODE,
                    SL_INT.RECORD_ID,
                    SL_INT.SRC_SYS_ENT_ID,
                    SL_INT.BSS_HIERARCHY_KEY) SL
    WHERE (SL.BSS_HIERARCHY_KEY,
           SL.ORDER_NO,
           Sl.line_no,
           sl.Revised_due_date,
           SL.PART_NO,
           sl.sys_ent_id) NOT IN
             (SELECT BSS_HIERARCHY_KEY,
                     ORDER_NO,
                     line_no,
                     revised_due_date,
                     part_no,
                     src_sys_ent_id
                FROM MEDW_MTOS_DTL_FACT
               WHERE service_lvl_flag = 'Y');
               thanks
asn

Also 'NOT IN' + nullable columns can be an expensive combination - and may not give the expected results. For example, compare these:
with test1 as ( select 1 as key1 from dual )
   , test2 as ( select null as key2 from dual )
select * from test1
where  key1 not in
       ( select key2 from test2 );
no rows selected
with test1 as ( select 1 as key1 from dual )
   , test2 as ( select null as key2 from dual )
select * from test1
where  key1 not in
       ( select key2 from test2
         where  key2 is not null );
      KEY1
         1
1 row selected.Even if the columns do contain values, if they are nullable Oracle has to perform a resource-intensive filter operation in case they are null. An EXISTS construction is not concerned with null values and can therefore use a more efficient execution plan, leading people to think it is inherently faster in general.

Similar Messages

  • How to select data from Maintance View in Program

    Dear All ,
    How to select data from Maintance View V_T052 in abap Program.
    Regards,
    Archana

    TABLES: t179, t179t.
    DATA: v_t179_int TYPE TABLE OF v_t179.
    SELECT * FROM t179
      JOIN t179t ON
        t179prodh = t179tprodh
      INTO CORRESPONDING FIELDS OF TABLE v_t179_int.
    Reward points...

  • Performance Issue - Fetching latest date from a507 table

    Hi All,
    I am fetching data from A507 table for material and batch combination. I want to fetch the latest record based on the value of field DATBI. I have written the code as follows. But in the select query its taking more time. I dont want to write any condition in where claue for DATBI field because I have already tried with that option.
    SELECT kschl
               matnr
               charg
               datbi
               knumh
        FROM a507
        INTO TABLE it_a507
        FOR ALL ENTRIES IN lit_mch1
        WHERE kschl = 'ZMRP'
        AND   matnr = lit_mch1-matnr
        AND   charg = lit_mch1-charg.
    SORT it_a507 BY kschl matnr charg datbi DESCENDING.
      DELETE ADJACENT DUPLICATES FROM it_a507 COMPARING kschl matnr charg.

    Hi,
    These kind of tables will be storing large volumes of data. Thus while making a select on it, its important to use as many primary key fields as possible in the where condition. Here you can try mentioning KAPPL since its specific to a requirement. If its for purchasing use 'M' and try.
    if not lit_mch1[] is initial.
    SELECT kschl
    matnr
    charg
    datbi
    knumh
    FROM a507
    INTO TABLE it_a507
    FOR ALL ENTRIES IN lit_mch1
    WHERE kappl = 'M'
    AND kschl = 'ZMRP'
    AND matnr = lit_mch1-matnr
    AND charg = lit_mch1-charg.
    endif.
    SORT it_a507 BY kschl matnr charg datbi DESCENDING.
    DELETE ADJACENT DUPLICATES FROM it_a507 COMPARING kschl matnr charg.
    This should considerably increase the performance
    Regards,
    Vik

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

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

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

  • Performance issue while extracting data from non-APPS schema tables.

    Hi,
    I have developed an ODBC application to extract data from Oracle E-Business Suite 12 tables.
    e.g. I am trying to extract data from HZ_IMP_PARTIES_INT table of Receivables application(Table is in "AR" database schema) using this ODBC application.
    The performance of extraction (i.e. number of rows extracted per second) is very low if the table belongs to non-APPS schema. (e.g. HZ_IMP_PARTIES_INT belongs to "AR" database schema)
    Now if I create same table (HZ_IMP_PARTIES_INT) with same data in "APPS" schema, the performance of extraction improves a lot. (i.e. the number of rows extracted per second increases a lot) with the same ODBC application.
    The "APPS" user is used to connect to the database in both scenarios.
    Also note that my ODBC application creates multiple threads and each thread creates its own connection to the database. Each thread extract different data using SQL filter condition.
    So, my question is:
    Is APPS schema optimized for any data extraction?
    I will really appreciate any pointer on this.
    Thanks,
    Rohit.

    Hi,
    Is APPS schema optimized for any data extraction? I would say NO as data extraction performance should be the same for all schemas. Do you run "Gather Schema Statistics" concurrent program for ALL schemas on regular basis?
    Regards,
    Hussein

  • Performance issue while transferring data from one itab to another itab

    hi experts,
    i have stored all the general material details in one internal table and description, valuation details of the meterial is stored in another internal table which is of standard table. now i need to tranfer all the data from these two internal tables into one final internal table but it is taking lot of time as it has to transfer lacs of data.
    i have declared the output table as shown below
    DATA:
      t_output TYPE standard TABLE
               OF type_output
               INITIAL SIZE 0
               WITH HEADER LINE.
    (according to the standard i have to declare like this and the two internal tables are declared similar to the above one)
    could somebody suggest me how shall I procced through this...
    thanks in advance....
    ragerds,
    Deepu

    Have a look at the following article which you may find useful:
      <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40729734-3668-2910-deba-fa0e95e2c541">Improving performance in nested loops</a>
    good luck, damian

  • Select data from tab 1 that are not in tab 2

    hi,
    i want to select data (mnr, date) from tab1, which are not in tab2!
    what would be the best select-statement for this problem.
    select mnr, date from tab1 where ...???

    SELECT col1, col2 FROM tab1
    MINUS
    SELECT col1, col2 FROM tab2is one option. There are dozens of other approaches, some of which may perform better and some which may perform worse, but this is generally pretty efficient and pretty easy to understand.
    Justin

  • Performance problem in select data from data base

    hello all,
    could you please suggest me which select statement is good for fetch data form data base if data base contain more than 10 lac records.
    i am using SELECT PACKAGE SIZE n statement,  but it's taking lot of time .
    with best regards
    srinivas rathod

    Hi Srinivas,
    if you have huge data and selecting ,you could decrease little bit time if you use better techniques.
    I do not think SELECT PACKAGE SIZE  will give good performance
    see the below examples :
    ABAP Code Samples for Simple Performance Tuning Techniques
    1. Query including select and sorting functionality
    tables: mara, mast.
        data: begin of itab_new occurs 0,
                 matnr like mara-matnr,
                 ernam like mara-ernam,
                 mtart like mara-mtart,
                 matkl like mara-matkl,
                 werks like mast-werks,
               aenam like mast-aenam,
    stlal like mast-stlal,
         end of itab_new.
    select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
    into table itab_new from mara as f inner join mast as g on
    fmatnr = gmatnr where gstlal = '01' order by fernam.
    Code B
    tables: mara, mast.
    data: begin of itab_new occurs 0,
          matnr like mara-matnr,
          ernam like mara-ernam,
          mtart like mara-mtart,
          matkl like mara-matkl,
          werks like mast-werks,
          aenam like mast-aenam,
          stlal like mast-stlal,
    end of itab_new.
    select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
    into table itab_new from mara as f inner join mast as g on f~matnr =
    gmatnr where gstlal = '01'.
    sort itab_new by ernam.
    Both the above codes essentially do the same function, but the execution time for code B is considerably lesser than that of Code A. Reason: The Order by clause associated with a select statement increases the execution time of the statement, so it is profitable to sort the internal table once after selecting the data.
    2. Performance Improvement Due to Identical Statements – Execution Plan
    Consider the below queries and their levels of efficiencies is saving the execution
    tables: mara, mast.
    data: begin of itab_new occurs 0,
          matnr like mara-matnr,
          ernam like mara-ernam,
          mtart like mara-mtart,
          matkl like mara-matkl,
          werks like mast-werks,
          aenam like mast-aenam,
          stlal like mast-stlal,
    end of itab_new.
    select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
    into table itab_new from mara as f inner join mast as g on f~matnr =
    gmatnr where gstlal = '01' .
    sort itab_new.
    select fmatnr fernam
    fmtart fmatkl gwerks gaenam g~stlal
    into table itab_new from mara as
    f inner join mast as g on f~matnr =
    gmatnr where gstlal
    = '01' .
    Code D (Identical Select Statements)
    tables: mara, mast.
    data: begin of itab_new occurs 0,
          matnr like mara-matnr,
          ernam like mara-ernam,
          mtart like mara-mtart,
          matkl like mara-matkl,
          werks like mast-werks,
          aenam like mast-aenam,
          stlal like mast-stlal,
    end of itab_new.
    select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
    into table itab_new from mara as f inner join mast as g on f~matnr =
    gmatnr where gstlal = '01' .
    sort itab_new.
    select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
    into table itab_new from mara as f inner join mast as g on f~matnr =
    gmatnr where gstlal = '01' .
    Both the above codes essentially do the same function, but the execution time for code B is considerably lesser than that of Code A. Reason: Each SQL statement during the process of execution is converted into a series of database operation phases. In the second phase of conversion (Prepare phase) an “execution  plan” is determined for the current SQL statement and it is stored, if in the program any identical select statement is used, then the same execution plan is reused to save time. So retain the structure of the select statement as the same when it is used more than once in the program.
    3. Reducing Parse Time Using Aliasing
    A statement which does not have a cached execution plan should be parsed before execution; this parsing phase is a highly time and resource consuming, so parsing time for any sql query must include an alias name in it for the following reason.
    1.     Providing the alias name will enable the query engine to resolve the tables to which the specified fields belong to.
    2.     Providing a short alias name, (a single character alias name) is more efficient that providing a big alias name.
    Code E
    select jmatnr jernam jmtart jmatkl
    gwerks gaenam g~stlal into table itab_new from mara as
    j inner join mast as g on jmatnr = gmatnr where
                g~stlal = '01' .
    In the above code the alias name used is ‘ j ‘.
    4. Performance Tuning Using Order by Clause
    If in a SQL query you are going to  read a particular database record based on some key values mentioned in the select statement, then the read query can be very well optimized by ordering the fields in the same order in which we are going to read them in the read query.
    Code F
    tables: mara, mast.
    data: begin of itab_new occurs 0,
          matnr like mara-matnr,
          ernam like mara-ernam,
          mtart like mara-mtart,
          matkl like mara-matkl,
          end of itab_new.
    select MATNR ERNAM MTART MATKL from mara into table itab_new where
    MTART = 'HAWA' ORDER BY  MATNR ERNAM  MTART MATKL.
    read table itab_new with key MATNR = 'PAINT1'   ERNAM = 'RAMANUM'
    MTART = 'HAWA'   MATKL = 'OFFICE'.
    Code G
    tables: mara, mast.
    data: begin of itab_new occurs 0,
          matnr like mara-matnr,
          ernam like mara-ernam,
          mtart like mara-mtart,
          matkl like mara-matkl,
          end of itab_new.
    select MATNR ERNAM MTART MATKL from mara into table itab_new where
    MTART = 'HAWA' ORDER BY  ERNAM MATKL MATNR MTART.
    read table itab_new with key MATNR = 'PAINT1'   ERNAM = 'RAMANUM'
    MTART = 'HAWA'   MATKL = 'OFFICE'.
    In the above code F, the read statement following the select statement is having the order of the keys as MATNR, ERNAM, MTART, MATKL. So it is less time intensive if the internal table is ordered in the same order as that of the keys in the read statement.
    5. Performance Tuning Using Binary Search
    A very simple but useful method of fine tuning performance of a read statement is using ‘Binary search‘ addition to it. If the internal table consists of more than 20 entries then the traditional linear search method proves to be more time intensive.
    Code H
    select * from mara into corresponding fields of table intab.
    sort intab.     
    read table intab with key matnr = '11530' binary search.
    Code I
    select * from mara into corresponding fields of table intab.
    sort intab.     
    read table intab with key matnr = '11530'.
    Thanks
    Seshu

  • How to select data from a view (V_5UBI_B)

    The following SELECT won't compile.  The compiler gives the message "'V_5UBI_B" is not defined in the ABAP Dictionary as a table, projection view or database view".  I can run SE11 and enter it as the name of a view and pull it up so I'm obviously missing something.
    SELECT SINGLE ercst
        INTO (p_covered_rate_out)
        FROM V_5UBI_B
        WHERE barea = '01'
          AND bplan = p_bplan_in
          AND bcost = '0001'.

    hi,
    do this way ..
    SELECT  ercst up to 1 rows
        FROM T5UBI
        INTO (p_covered_rate_out)
        WHERE barea = '01'
          AND bplan = p_bplan_in
          AND bcost = '0001'.
    ENDSELECT.

  • Select data from  view ( V_T856 ).

    Hi All,
    i need to download transaction type and text from V_T856 ,  but the data is not selected from V_T856 view.
    how to select data from a view, is there any special conditions.
    i declared V_T856 in tables statement, even though select statement not exicuted.
    pls suggest me with relevant information..
    thank you
    Regards
    Ramesh.

    hi ramesh,
    using Select statement you cannot retrieve the data from view.
    use the FM - VIEW_GET_DATA.
    call function 'VIEW_GET_DATA'      " func. mod to get data from maintenance view.
        exporting
          view_name = view
        tables
          data      = gt_data.
    Regards,
    Sakthi.

  • Select data from table not in another table

    Hi,
    I want to select data from table A which is not in table B.
    Currently I am doing:
    select
    snoA,
    nameA,
    dobA
    from A
    where snoA not in
    (select snoB from A, B
    where snoA = snoB
    and nameA = nameB)
    But above is very slow.
    Can I do something like:
    select
    snoA,
    nameA,
    dobA
    from A, B
    where
    EXCLUDE ( snoA = snoB and nameA = nameB)
    Please note that I need the where condition on both the columns.
    any help will be appreciated.
    -- Harvey

    What are the approximate data volumes in A and B?
    What is "very slow"?
    What version of Oracle?
    What is the query plan?
    Without knowing anything about your system, my first thought would be to see if a NOT EXISTS happened to be faster for your data
    SELECT snoA,
           nameA,
           dobA
      FROM a
    WHERE NOT EXISTS (
        SELECT 1
          FROM b
         WHERE a.snoA = b.snoB
           AND a.nameA = b.nameB )Of course, I'm not sure why you are joining A & B in your NOT IN subquery. It would seem like you would just need a correlated subquery, i.e.
    SELECT snoA,
           nameA,
           dobA
      FROM a
    WHERE snoA NOT IN (
        SELECT snoB
          FROM b
         WHERE a.snoA = b.snoB
           AND a.nameA = b.nameB )That should be more efficient than the original query. The NOT EXISTS version may or may not be more efficient than the NOT IN depending on data volumes.
    Justin

  • Select data from database tables with high performance

    hi all,
    how to select data from different database tables with high performance.
    im using for all entries instead of inner joins, even though burden on data base tables is going very high ( 90 % in se30)
    hw to increase the performance.
    kindly, reply.
    thnks

    Also Check you are not using open sql much like distict order by group by , use abap techniques on internal table to acive the same.
    also Dont use select endselect.
    if possible use up to n rows claus....
    taht will limit the data base hits.
    also dont run select in siode any loops.
    i guess these are some of the trics oyu can use to avoid frequent DATA BASE HITS AND ABVOID THE DATA BASE LAOD.

  • Select data from all the table names in the view

    Hi,
    "I have some tables with names T_SRI_MMYYYY in my database.
    I created a view ,Say "Summary_View" for all the table names
    with "T_SRI_%".
    Now i want to select data from all the tables in the view
    Summary_View.
    How can i do that ? Please throw some light on the same?
    Thanks and Regards
    Srinivas Chebolu

    Srinivas,
    There are a couple of things that I am unsure of here.
    Firstly, does your view definition say something like ...
    Select ...
    From "T_SRI_%"
    If so, it is not valid. Oracle won't allow this.
    The second thing is that your naming convention for the
    tables suggests to me that each table is the same except
    that they store data for different time periods. This would be
    a very bad design methodology. You should have a single
    table with an extra column to state what period is referred to,
    although you can partition it into segments for each period if
    appropriate.
    Apologies if i am misinterpreting your question, but perhaps
    you could post your view definition and table definitions
    here.

  • Performance issue while selecting material documents MKPF & MSEG

    Hello,
    I'm facing performance issues in production while selecting Material documents for Sales order and item based on the Sales order Stock.
    Here is the query :
    I'm first selecting data from ebew table which is the Sales order Stock table then this query.
        IF ibew[] IS NOT INITIAL AND ignore_material_documents IS INITIAL.
    *     Select the Material documents created for the the sales orders.
          SELECT mkpf~mblnr mkpf~budat
                 mseg~matnr mseg~mat_kdauf mseg~mat_kdpos mseg~shkzg
                 mseg~dmbtr mseg~menge
           INTO  CORRESPONDING FIELDS OF TABLE i_mseg
           FROM  mkpf INNER JOIN mseg
           ON    mkpf~mandt = mseg~mandt
           AND   mkpf~mblnr = mseg~mblnr
           AND   mkpf~mjahr = mseg~mjahr
           FOR   ALL entries IN ibew
           WHERE mseg~matnr      = ibew-matnr
           AND   mseg~werks         = ibew-bwkey
           AND   mseg~mat_kdauf   = ibew-vbeln
           AND   mseg~mat_kdpos  = ibew-posnr.
          SORT i_mseg BY mat_kdauf ASCENDING
                         mat_kdpos ASCENDING
                         budat     DESCENDING.
        ENDIF.
    I need to select the material documents because the end users want to see the stock as on certain date for the sales orders and only material document lines can give this information. Also EBEW table gives Stock only for current date.
    For Example :
    If the report was run for Stock date 30th Sept 2008, but  on the 5th Oct 2008, then I need to consider the goods movements after 30th Sept and add if stock was issued or subtract if stock was added.
    I know there is an Index MSEG~M in database system on mseg, however I don't know the Storage location LGORT and Movement types BWART that should be considered, so I tried to use all the Storage locations and Movement types available in the system, but this caused the query to run even slower than before.
    I could create an index for the fields mentioned in where clause , but it would be an overhead anyways.
    Your help will be appreciated. Thanks in advance
    regards,
    Advait

    Hi Thomas,
    Thanks for your reply. the performance of the query has significantly improved than before after switching the join from mseg join mkpf.
    Actually, I even tried without join and looped using field symbols ,this is working slightly faster than the switched join.
    Here are the result ,  tried with 371 records as our sandbox doesn't have too many entries unfortunately ,
    Results before switching the join  146036 microseconds
    Results after swithing the join        38029 microseconds
    Results w/o join                           28068 microseconds for selection and 5725 microseconds for looping
    Thanks again.
    regards,
    Advait

  • How to select data from another schema in Oracle-Sqldeveloper?

    Hi,
    I open two schemas, assumed schema1 and schema2, in SQL-Developer. In the SQL-Edit Area of schema1 I want to select data from schema2. So I did followings:
    select * from schema2.table1;
    But I got error message: 00942. 00000 -  "table or view does not exist"
    What could be the problem?

    Correct place for your question is SQL Developer (Not for general SQL/PLSQL questions)
    Oh my bad.. Check previous post.. Its privilege issue.
    Message was edited by: Karthick_Arp

Maybe you are looking for