Query taking ages...seem simple enough

10.2.0.3.0 Standard ed.
RHEL
1 table, short query with 1 predicate.
1 index : TRANSACTION_IX9 which is a functional index on the column with the function in the where clause. Index is used in the plan see below.
Table has 100+ million rows. stats on table and index up to date.
Takes hours to come back. Plan shows this.
SQL> explain plan for
  2  select
  3        x1.session_id
  4        x1.received_date
  5  from transaction_tb x1
where trunc(x1.received_date) < '01-OCT-11';  -- for some reason the date I put in here isnt coming out in the code display on the forum, probably single quotes, anyway its just 01-oct-2011
  6
Explained.
set linesize 132
set pagesize 999
SQL> SQL>  SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY);
PLAN_TABLE_OUTPUT
Plan hash value: 2633564245
| Id  | Operation                   | Name                       | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT            |                            |    17M|  1572M|  1599K  (1)| 05:19:51 |
|   1 |  TABLE ACCESS BY INDEX ROWID| TRANSACTION_TB  |    17M|  1572M|  1599K  (1)| 05:19:51 |
|*  2 |   INDEX RANGE SCAN          | TRANSACTION_IX9 |    17M|       | 48162   (1)| 00:09:38 |
Predicate Information (identified by operation id):
   2 - access(TRUNC(INTERNAL_FUNCTION("RECEIVED_DATE"))<'01-OCT-11')
14 rows selected.
SQL>Yes I know there are millions of rows returned which is probably (defintely!!) not helping the query, but playing with rows returned via the date range if I shorten the time span to reduce to say 20k rows returned, Im still looking at 15 minues to get them out with the index range scan in the plan staying the same. This shouldnt be to my mind. Any thoughts?
Edited by: deebee_eh on 26-Mar-2012 15:47

deebee_eh wrote:
10.2.0.3.0 Standard ed.
RHEL
SQL> explain plan for
2  select
3        x1.session_id
4        x1.received_date
5  from transaction_tb x1
where trunc(x1.received_date) < '01-OCT-11';  -- for some reason the date I put in here isnt coming out in the code display on the forum, probably single quotes, anyway its just 01-oct-2011
Before going to much further, you need to check that the actual execution plan matches the predicted plan.
set serveroutput off
select .... -- your query
select * from table(dbms_xplan.display_cursor);
{code]
You may find that Oracle handles the run-time situation differently.  (The appearance of the internal_function() suggests this as a possibility).
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
Author:  <b><em><a href="http://www.apress.com/9781430239543">Oracle Core</a></em></b>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Seems simple enough right? Wrong!

    Okay hopefully someone on here can help me. I am using Illustrator CS5 and I am working on a document. I'm trying to put a logo on top of another item created by the pen tool. seems simple enough right? Wrong, the software will not let me use object>arrange>bring to front or Cmd ] and cmd [ is there something that i'm doing wrong? I've redrawn the shape and it still won't let me, I've brought in the logo again, it won't let me, i've done a host of other things and it still won't let me put that stupid logo on top of the cloud (what i drew with the pen tool)
    Thanks!

    Not sure what you mean. Why is there more than one layer?
    It could be that you intentionally created additional layers. It could be that you unintentionally created additional layers. It could be that you hit Cmd L some day. It could be that you pasted objects while Paste Remembers Layers was turned on. Or something else.

  • HT201270 I want to sync my iPhone 4S with my MacBook Air, seems simple enough...

    I am having trouble syncing my iPhone 4S with my MacBook Air. I thought all I had to do was connect my USB cable to the iPhone and to my lapatop and voila, it wound sync, but I guess not. Any ideas?

    I didn't get any message, that was what surprised me. However I went to turn off my computer and I received a message saying it was syncing and that it would stop if I turned off my computer. I had lauched iTunes, shouldn't I have seen some messge? I thought I would see the iPhone on the desktop too. Thanks for your help.

  • Insert select statement is taking ages

    Sybase version: Adaptive Server Enterprise/12.5.4/EBF 15432 ESD#8/P/Sun_svr4/OS 5.8/ase1254/2105/64-bit/FBO/Sat Mar 22 14:38:37 2008
    Hi guyz,
    I have a question about the performance of a statement that is very slow and I'd like to have you input.
    I have the SQL statement below that is taking ages to execute and I can't find out how to imporve it
    insert SST_TMP_M_TYPE select M_TYPE from MKT_OP_DBF M join TRN_HDR_DBF T on M.M_ORIGIN_NB=T.M_NB where T.M_LTI_NB=@Nson_lti
    @Nson_lti is the same datatype as T.M_LTI_NB
    M.M_ORIGIN_NB=T.M_NB have the same datatype
    TRN_HDR_DBF has 1424951 rows and indexes on M_LTI_NB and M_NB
    table MKT_OP_DBF has 870305 rows
    table MKT_OP_DBF has an index on M_ORIGIN_NB column
    Statistics for index:                   "MKT_OP_ND7" (nonclustered)
    Index column list:                      "M_ORIGIN_NB"
         Leaf count:                        3087
         Empty leaf page count:             0
         Data page CR count:                410256.0000000000000000
         Index page CR count:               566.0000000000000000
         Data row CR count:                 467979.0000000000000000
         First extent leaf pages:           0
         Leaf row size:                     12.1161512343373872
         Index height:                      2
    The representaion of M_ORIGIN_NB is
    Statistics for column:                  "M_ORIGIN_NB"
    Last update of column statistics:       Mar  9 2015 10:48:57:420AM
         Range cell density:                0.0000034460903826
         Total density:                     0.0053334921767125
         Range selectivity:                 default used (0.33)
         In between selectivity:            default used (0.25)
    Histogram for column:                   "M_ORIGIN_NB"
    Column datatype:                        numeric(10,0)
    Requested step count:                   20
    Actual step count:                      20
         Step     Weight                    Value
            1     0.00000000        <       0
            2     0.07300889        =       0
            3     0.05263098       <=       5025190
            4     0.05263098       <=       9202496
            5     0.05263098       <=       12664456
            6     0.05263098       <=       13129478
            7     0.05263098       <=       13698564
            8     0.05263098       <=       14735554
            9     0.05263098       <=       15168461
           10     0.05263098       <=       15562067
           11     0.05263098       <=       16452862
           12     0.05263098       <=       16909265
           13     0.05263212       <=       17251573
           14     0.05263098       <=       18009609
           15     0.05263098       <=       18207523
           16     0.05263098       <=       18404113
           17     0.05263098       <=       18588398
           18     0.05263098       <=       18793585
           19     0.05263098       <=       18998992
           20     0.03226340       <=       19574408
    If I look at the showplan, I can see indexes on TRN_HDR_DBF are used but now the one on MKT_OP_DBF
    QUERY PLAN FOR STATEMENT 16 (at line 35).
        STEP 1
            The type of query is INSERT.
            The update mode is direct.
            FROM TABLE
                MKT_OP_DBF
                M
            Nested iteration.
            Table Scan.
            Forward scan.
            Positioning at start of table.
            Using I/O Size 32 Kbytes for data pages.
            With LRU Buffer Replacement Strategy for data pages.
            FROM TABLE
                TRN_HDR_DBF
                T
            Nested iteration.
            Index : TRN_HDR_NDX_NB
            Forward scan.
            Positioning by key.
            Keys are:
                M_NB  ASC
            Using I/O Size 4 Kbytes for index leaf pages.
            With LRU Buffer Replacement Strategy for index leaf pages.
            Using I/O Size 4 Kbytes for data pages.
            With LRU Buffer Replacement Strategy for data pages.
            TO TABLE
                SST_TMP_M_TYPE
            Using I/O Size 4 Kbytes for data pages.
    I was expecting the query to use the index also on MKT_OP_DBF
    Thanks for your advices
    Simon

    The total density number for the MKT_OP_DBF.M_ORIGIN_NB column don't look very good:
         Range cell density:           0.0000034460903826
         Total density:                0.0053334921767125
    Notice the total density value is 3 magnitudes larger than the range density ... which can indicate a largish number of duplicates.  (NOTE: This wide difference between range cell and total density can be referred to as 'skew' - more on this later.)
    Do some M_ORIGIN_NB values have a large number of duplicates?  What does the following query return:
    =====================
    select top 30 M_ORIGIN_NB, count(*)
    from   MKT_OP_DBF
    group by M_ORIGIN_NB
    order by 2 desc, 1
    =====================
    The total density can be used to estimate the number of rows expected for a join (eg, TRN_HDR_DBF --> MKT_OP_DBF).  The largish total density number, when thrown into the optimizer's calculations, may be causing the optimizer to think that the volume of *possible* joins will be more expensive than a join in the opposite direction (MKT_OP_DBF --> TRN_HDR_DBF) which in turn means (as Jeff's pointed out) that you end up table scanning MKT_OP_DBF (as the outer table) because of no SARGs.
    From your description it sounds like you've got the necessary indexes to support a TRN_HDR_DBF --> MKT_OP_DBF join order. (Though it wouldn't hurt to see the complete output from sp_helpindex for both tables just to make sure we're on the same sheet of music.)
    Without more details (eg, complete stats for both tables, sp_help for both tables - if you decide to post these I'd recommend posting them as a *.txt attachment).
    I'm assuming you *know* that a join from TRN_NDR_DBF --> MKT_OP_DBF should be much quicker than what you're currently seeing.  If this is the case, I'd probably want to start with:
    =====================
    exec sp_modifystats MKT_OP_DBF, M_ORIGIN_NB, REMOVE_SKEW_FROM_DENSITY
    go
    exec sp_recompile MKT_OP_DBF
    go
    -- run your query again
    =====================
    By removing the skew from the total density (ie, set total density = range cell density = 0.00000344...) you're telling the optimizer that it can expect a much smaller number of joins for the join order of TRN_HDR_DBF --> MKT_OP_DBF ... and that may be enough for the optimizer to use TRN_HDR_DBF to drive the query.
    NOTE: If sp_modifystats/REMOVE_SKEW_FROM_DENSITY provides the desired join order, keep in mind that you'll need to re-issue this command after each update stats command that modifies the stats on the M_ORIGIN_NB column.  For example, modify your update stats maintenance job to issue sp_modifystats/REMOVE_SKEW_FROM_DENSITY for those special cases where you know it helps query performance.

  • Wine is taking ages to load

    Wine is taking ages to load in my machine. When i run winecfg, for exemple, it takes about 10min to show me a window.
    $ winecfg
    wine: creating configuration directory '~/.wine'...
    Failed to open the service control manager.
    -> hangs here for about 10min
    I already enabled (and disabled) the DRI module in xorg.conf, but it didint helped anything. Delete the .wine folder is not the solution either because im having this problem since i instaled wine (but i erased the folder, anyway).
    $ wine --version
    wine-0.9.30
    So ... any tips?
    Last edited by nozey (2007-02-06 22:42:57)

    I have the same problem as you. I installed wine through pacman and when I do 'winecfg' , I have to wait a really long time until it loads. I don't understand why this is so. In all of the other linux distributions that I tried, wine started up quite fast (gentoo, ubuntu, zenwalk, fedora core, etc) Could someone please tell us why it takes a long time for wine to open. Thank you.
    My WINE version is wine-0.9.33
    PS: I am not sure if this would be the cause, although I don't know why it would do anything but, I am running the 32 bit Arch Linux on a 64 bit machine, and this is because I need to use wine for a certain something that I have to do for my school, so I don't want to use Arch64. I know that it is possible to get wine to work in 64 bit Arch, but I have no clue how to update the package along with the rest of the system, and I can't seem to get a chroot environment to work.

  • 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;

  • Performance optimization : query taking 7mints

    Hi All ,
    Requirement : I need to improve the performance of  custom program ( Program taking more than 7 mints +dump).I checked in runtime analysis and below mention query taking more time .
    Please let me know the approach to minimize the  query time  .
    TYPES: BEGIN OF lty_dberchz1,
               belnr    TYPE dberchz1-belnr,
               belzeile TYPE dberchz1-belzeile,
               belzart  TYPE dberchz1-belzart,
               buchrel  TYPE dberchz1-buchrel,
               tariftyp TYPE dberchz1-tariftyp,
               tarifnr  TYPE dberchz1-tarifnr,
               v_zahl1  TYPE dberchz1-v_zahl1,
               n_zahl1  TYPE dberchz1-n_zahl1,
               v_zahl3  TYPE dberchz1-v_zahl3,
               n_zahl3  TYPE dberchz1-n_zahl3,
               nettobtr TYPE dberchz3-nettobtr,
               twaers   TYPE dberchz3-twaers,
             END   OF lty_dberchz1.
      DATA: lt_dberchz1 TYPE SORTED TABLE OF lty_dberchz1
            WITH NON-UNIQUE KEY belnr belzeile
            INITIAL SIZE 0 WITH HEADER LINE.
    DATA: lt_dberchz1a LIKE TABLE OF lt_dberchz1 WITH HEADER LINE.
    *** ***********************************Taking more time*************************************************
    *Individual line items
        SELECT dberchz1~belnr dberchz1~belzeile
               belzart buchrel tariftyp tarifnr
               v_zahl1 n_zahl1 v_zahl3 n_zahl3
               nettobtr twaers
          INTO TABLE lt_dberchz1
          FROM dberchz1 JOIN dberchz3
          ON dberchz1~belnr = dberchz3~belnr
          AND dberchz1~belzeile = dberchz3~belzeile
          WHERE buchrel  EQ 'X'.
        DELETE lt_dberchz1 WHERE belzart NOT IN r_belzart.     
        LOOP AT lt_dberchz1.
          READ TABLE lt_dberdlb BINARY SEARCH
          WITH KEY billdoc = lt_dberchz1-belnr.
          IF sy-subrc NE 0.
            DELETE lt_dberchz1.
          ENDIF.
        ENDLOOP.
        lt_dberchz1a[] = lt_dberchz1[].
        DELETE lt_dberchz1 WHERE belzart EQ 'ZUTAX1'
                              OR belzart EQ 'ZUTAX2'
                              OR belzart EQ 'ZUTAX3'.
        DELETE lt_dberchz1a WHERE belzart NE 'ZUTAX1'
                              AND belzart NE 'ZUTAX2'
                              AND belzart NE 'ZUTAX3'.
    ***************************second query************************************
    *  SELECT opbel budat vkont partner sto_opbel
        INTO CORRESPONDING FIELDS OF TABLE lt_erdk
        FROM erdk
        WHERE budat IN r_budat
          AND druckdat   NE '00000000'
          AND stokz      EQ space
          AND intopbel   EQ space
          AND total_amnt GT 40000.
    **************************taking more time*********************************
      SORT lt_erdk BY opbel.
      IF lt_erdk[] IS NOT INITIAL.
        SELECT DISTINCT printdoc billdoc vertrag
          INTO CORRESPONDING FIELDS OF TABLE lt_dberdlb
          FROM dberdlb
    * begin of code change by vishal
          FOR ALL ENTRIES IN lt_erdk
          WHERE printdoc = lt_erdk-opbel.
        IF lt_dberdlb[] IS NOT INITIAL.
          SELECT belnr belzart ab bis aus01
                 v_zahl1 n_zahl1 v_zahl3 n_zahl3
            INTO CORRESPONDING FIELDS OF TABLE lt_dberchz1
            FROM dberchz1
            FOR ALL ENTRIES IN lt_dberdlb
            WHERE belnr   EQ lt_dberdlb-billdoc
              AND belzart IN ('ZUTAX1', 'ZUTAX2', 'ZUTAX3').
        ENDIF. "lt_dberdlb
       endif.
    Regards
    Rahul
    Edited by: Matt on Mar 17, 2009 4:17 PM - Added  tags and moved to correct forum

    Run the SQL Trace and tell us where the time is spent,
    see here how to use it:
    SELECT dberchz1~belnr dberchz1~belzeile
               belzart buchrel tariftyp tarifnr
               v_zahl1 n_zahl1 v_zahl3 n_zahl3
               nettobtr twaers
          INTO TABLE lt_dberchz1
          FROM dberchz1 JOIN dberchz3
          ON dberchz1~belnr = dberchz3~belnr
          AND dberchz1~belzeile = dberchz3~belzeile
          WHERE buchrel  EQ 'X'.
    I assume that is this select, but without data is quite useless
    How large are the two tables  dberchz1 JOIN dberchz3
    What are the key fields?
    Is there an index on buchrel
    Please use aliases  dberchz1 as a
                                 INNER JOIN dberchz3 as b
    to which table does buchrel belong?
    I don't know you tables, but buchrel  EQ 'X' seems not selective, so a lot of data
    might be selected.
    lt_dberchz1 TYPE SORTED TABLE OF lty_dberchz1
            WITH NON-UNIQUE KEY belnr belzeile
            INITIAL SIZE 0 WITH HEADER LINE.
        DELETE lt_dberchz1 WHERE belzart NOT IN r_belzart.     
        LOOP AT lt_dberchz1.
          READ TABLE lt_dberdlb BINARY SEARCH
          WITH KEY billdoc = lt_dberchz1-belnr.
          IF sy-subrc NE 0.
            DELETE lt_dberchz1.
          ENDIF.
        ENDLOOP.
        lt_dberchz1a[] = lt_dberchz1[].
        DELETE lt_dberchz1 WHERE belzart EQ 'ZUTAX1'
                              OR belzart EQ 'ZUTAX2'
                              OR belzart EQ 'ZUTAX3'.
        DELETE lt_dberchz1a WHERE belzart NE 'ZUTAX1'
                              AND belzart NE 'ZUTAX2'
                              AND belzart NE 'ZUTAX3'.
    This is really poor coding, there is sorted table ... nice a compelelty different key is
    needed and used .... useless.
    Then there is a loop which is anywy a full processing no sort necessary.
    Where is the read if you use binary search on TABLE lt_dberdlb ?
    Then the tables are again process completely ...
        DELETE lt_dberchz1a WHERE belzart NE 'ZUTAX1'
                              AND belzart NE 'ZUTAX2'
                              AND belzart NE 'ZUTAX3'.
    What is that ???? Are you sure that anything can survive this delete???
    Siegfried

  • Making a join seems simple but I can't get it to work

    Hi All,
    I have 2 tables LUGallery and LUSubGallery, the tables are related by the GalleyID field
    LUGallery
    Gallery ID
    ClientID
    GalleryName
    5
    50
    Australia
    8
    50
    Weddings
    12
    33
    Portraits
    4
    33
    Landscapes
    LUSubGallery
    SubGalleryID
    GalleryID
    GalleryName
    67
    5
    NSW
    68
    5
    QLD
    69
    8
    Reception
    70
    8
    Location
    87
    8
    Ceromony
    97
    4
    Rain Forest
    What I am try to do seems simple but I can't get it to work the way I want it.
    I am trying to write a query to display Galleries from the LUGallery tbl that have a Sub Gallery attached to them (ie. It's GalleryID appears in the LUSubGallery tbl)
    So the query for the above example would list Australia, Weddings & Landscapes
    I have tried to write code both with inner joins and nested queries but just can't get it right,
    Any help would be greatly appreciated.
    Thanks in advance
    Kris

    I just want to
    display the GalleryNames from the LUGallery tbl once
    Then you probably do not want include all the extra columns from the LUSubGallery table.
    It returns all of the records from both tables that Have
    the same GalleryID
    That is the way this type of JOIN works. It will return one record for each matched GalleryID. If you only want to display the unique gallery names you can either:
    1) Use an EXISTS clause.  It will return the distinct records from the main gallery table IF a matching record exists in the LUSubGallery table
    --- Not tested ---
    SELECT  LUGallery.GalleryID,
    LUGallery.GalleryName
    FROM    LUGallery
    WHERE   EXISTS (
            SELECT  *
            FROM LUSubGallery
            WHERE LUGallery.GalleryID = LUSubGallery.GalleryID
    http://www.techonthenet.com/sql/exists.php
    ... OR ....
    2) Use the DISTINCT operator to return only the unique combinations of the selected columns. Note: DISTINCT considers all columns in the SELECT list . So if you only want unique galleries, do not include the LUSubGallery columns in the SELECT list.
    http://www.w3schools.com/SQl/sql_distinct.asp
    Message was edited by: -==cfSearching==-

  • My ipod touch is taking ages to back up, I dont know weather it is because I havent had my ipod plugged into my computer for a while or not... I dont know what to do... And i really need it to sinc so i can put new music on. Can anyone help?

    I really need your help. I'm 14.
    I really need to put new music on my iPod and I have plugged it into my computer and its taking ages to back-up and it wont let me do anything until its done. It will take over 3 hours if it keeps on going like this. Please help me. I don't know what's wrong with it.
    It might be because I haven't backed it up in a while but the reason I haven't is cause it takes this long! Anyone know what to do?
    Meg x <This is how I feel. (Confused and really upset)

    You can redownload most itunes purchase by the following. What you can redownload depends upon where you are located.
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • Query taking so long to execute.

    I have one table with 211 rows, When i am executing Delete from TEHSIL_TBL; its taking too long time to delete 211 rows. I execute explain plan then i am getting the following results.
    SQL> explain plan for delete from TEHSIL_TBL;
    Explained.
    SQL> @C:\oracle\product\10.2.0\db_1\RDBMS\ADMIN\utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 3350021484
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | DELETE STATEMENT | | 205 | 1435 | 1 (0)| 00:00:01 |
    | 1 | DELETE | TEHSIL_TBL | | | | |
    | 2 | INDEX FULL SCAN| PK_TEH_ID | 205 | 1435 | 1 (0)| 00:00:01 |
    Please suggest why that query taking so long tome to execute.
    Thanks in Advance...
    Asmit

    966523 wrote:
    I have one table with 211 rows, When i am executing Delete from TEHSIL_TBL; its taking too long time to delete 211 rows. I execute explain plan then i am getting the following results.
    SQL> explain plan for delete from TEHSIL_TBL;
    Explained.
    SQL> @C:\oracle\product\10.2.0\db_1\RDBMS\ADMIN\utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 3350021484
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | DELETE STATEMENT | | 205 | 1435 | 1 (0)| 00:00:01 |
    | 1 | DELETE | TEHSIL_TBL | | | | |
    | 2 | INDEX FULL SCAN| PK_TEH_ID | 205 | 1435 | 1 (0)| 00:00:01 |
    Please suggest why that query taking so long tome to execute.Please quantify "long time".
    >
    >
    Thanks in Advance...
    AsmitEXPLAIN PLAN shows time of 1 SECOND!
    How must faster should it be?

  • Simple enough but... calling a method from another class

    Hi all,
    I know it's simple enough, although I can't see where I'm going wrong for some reason. Basically I've got a class which extends JPanel but when I try to call one of its methods from my main class I get an error. The relevant code (I hope) is:
    Main.java
    import java.awt.BorderLayout;
    import javax.swing.UIManager;
    public class Main extends JFrame implements ActionListener {
         JFrame frame;
         public static JPanel statusBar;
         public Main() {
              // Add a status bar
              statusBar = new StatusBar();
              mainPanel.add( statusBar, BorderLayout.SOUTH );
              setContentPane( mainPanel );
         public static void setStatusBarText( String s ) {
              statusBar.setStatusText("Test");
    StatusBar.java
    import java.awt.Color;
    import javax.swing.SwingConstants;
    public class StatusBar extends JPanel {
         private int barWidth;
         private static JLabel status;
         public StatusBar() {
              super();
              //barWidth = Main.getProgramWidth();
              //setPreferredSize( new Dimension(barWidth,22) );
              setLayout( new FlowLayout( FlowLayout.LEADING ) );
              setBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(160,160,160) ) );
              status = new JLabel("Test", SwingConstants.LEFT);
              //status.setVerticalAlignment( SwingConstants.CENTER );
              add( status );
         protected void setStatusText( String s ) {
              status.setText( s );
              revalidate();
    }The "statusBar.setStatusText("Test");" call in the main class file doesn't work and I get the error:
    >
    cannot find symbol
    symbol : method setStatusText(java.lang.String)
    location: class javax.swing.JPanel
    statusBar.setStatusText("Test");
    >
    Any ideas what I'm doing wrong? I created an instance of the StatusBar class called statusBar, then I use this to call the setStatusText() method (via statusBar.setStatusText()) which I thought was all correct, then it doesn't work? Even if there's an easier way to do what I want to achieve (i.e. update a JLabel from the 'central' main class file instead of setting the JLabel to static and having every class call it directly), I'd appreciate knowing where I'm going wrong here nonetheless.
    Many thanks,
    Tristan

         public static JPanel statusBar;
         public static void setStatusBarText( String s ) {
              statusBar.setStatusText("Test");
    >
    cannot find symbol
    symbol : method setStatusText(java.lang.String)
    location: class javax.swing.JPanel
    statusBar.setStatusText("Test");
    >The type of variable statusBar is JPanel. That's all the compiler takes into account. It's irrelevant that at some point in the program the type of the object pointed to by this variable is a subclass of JPanel (because at another point it might be an instance of another subclass, or of JPanel itself.

  • Query taking more time

    Iam having nearly 2 crores records at present in my table..
    I want to get the avg of price from my table..
    i put the query like
    select avg(sum(price)) from table group by product_id
    The query taking more than 5 mins to execute...
    is that any other way i can simplify my query?

    Warren:
    Your first query gives:
    SQL> SELECT AVG(SUM(price)) sum_price
      2  FROM t;
    SELECT AVG(SUM(price)) sum_price
    ERROR at line 1:
    ORA-00978: nested group function without GROUP BYand your second gives:
    SQL> SELECT product_id, AVG(SUM(price))
      2  FROM t
      3  GROUP BY product_id;
    SELECT product_id, AVG(SUM(price))
    ERROR at line 1:
    ORA-00937: not a single-group group functionSymon:
    What exactly are you ttrying to accomplish. Your query as posted will calculate the average of the sums of the prices for all product_id values. That is, it is equivalent to:
    SELECT AVG(sum_price)
    FROM (SELECT SUM(price) sum_price
          FROM t
          GROUP BY product_id)So given:
    SQL> SELECT * FROM t;
    PRODUCT_ID      PRICE
    PROD1               5
    PROD1               7
    PROD1              10
    PROD2               3
    PROD2               4
    PROD2               5The sum of the prices per product_id is:
    SQL> SELECT SUM(price) sum_price
      2  FROM t
      3  GROUP BY product_id;
    SUM_PRICE
            22
            12 and the average of that is (22 + 12) / 2 = 17. Is that what you are looking for? If so, then the equivalent query I posted above is at least clearer, but may not be any faster. If this is not what you are looking for, then some sample data and expected results may help. Although, it appears that you need to full scan the table in either case, so that may be as good as it gets.
    John

  • Query taking much time Orace 9i

    Hi,
    **How can we tune the sql query in oracle 9i.**
    The select query taking more than 1 and 30 min to throw the result.
    Due to this,
    We have created materialsed view on the select query and also we submitted a job to get Materilazed view refreshed daily in dba_jobs.
    When we tried to retrive the data from Materilased view getting result very quickly.
    But the job which we has been assisgned in Dbajobs taking equal  time to complete, as the query use to take.
    We feel since the job taking much time in the test Database and it may cause load if we move the same scripts in Production Environment.
    Please suggest how to resolvethe issue and also how to tune the sql
    With Regards,
    Srinivas
    Edited by: Srinivas.. on Dec 17, 2009 6:29 AM

    Hi Srinivas;
    Please follow this search and see its helpful
    Regard
    Helios

  • Sql Query taking very long time to complete

    Hi All,
    DB:oracle 9i R2
    OS:sun solaris 8
    Below is the Sql Query taking very long time to complete
    Could any one help me out regarding this.
    SELECT MAX (md1.ID) ID, md1.request_id, md1.jlpp_transaction_id,
    md1.transaction_version
    FROM transaction_data_arc md1
    WHERE md1.transaction_name = :b2
    AND md1.transaction_type = 'REQUEST'
    AND md1.message_type_code = :b1
    AND NOT EXISTS (
    SELECT NULL
    FROM transaction_data_arc tdar2
    WHERE tdar2.request_id = md1.request_id
    AND tdar2.jlpp_transaction_id != md1.jlpp_transaction_id
    AND tdar2.ID > md1.ID)
    GROUP BY md1.request_id,
    md1.jlpp_transaction_id,
    md1.transaction_version
    Any alternate query to get the same results?
    kindly let me know if any one knows.
    regards,
    kk.
    Edited by: kk001 on Apr 27, 2011 11:23 AM

    Dear
    /* Formatted on 2011/04/27 08:32 (Formatter Plus v4.8.8) */
    SELECT   MAX (md1.ID) ID, md1.request_id, md1.jlpp_transaction_id,
             md1.transaction_version
        FROM transaction_data_arc md1
       WHERE md1.transaction_name = :b2
         AND md1.transaction_type = 'REQUEST'
         AND md1.message_type_code = :b1
         AND NOT EXISTS (
                SELECT NULL
                  FROM transaction_data_arc tdar2
                 WHERE tdar2.request_id = md1.request_id
                   AND tdar2.jlpp_transaction_id != md1.jlpp_transaction_id
                   AND tdar2.ID > md1.ID)
    GROUP BY md1.request_id
            ,md1.jlpp_transaction_id
            ,md1.transaction_versionCould you please post here :
    (a) the available indexes on transaction_data_arc table
    (b) the description of transaction_data_arc table
    (c) and the formatted explain plan you will get after executing the query and issuing:
    select * from table (dbms_xplan.display_cursor);Hope this helps
    Mohamed Houri

  • JDO Query does not seem to be executed at all

    I have the following JDO query and it returns empty collection but it
    should return some records. I set "SQL=TRACE" in kodo.properties file and
    traced the log file. This query does not seem to generate SQL statement
    at all. Other JDO method generates SQL statements.
    Kodo version: 3.1.2
    J2SE: 1.4.1_05
    Database: MS SQL Server 2000
    // Get endorsement rule type
    String ruleType = getEndorsementRuleType();
    Query qry = pm.newQuery(EndorsementRule.class);
    try {
    qry.declareParameters("String ruleType");
    qry.setFilter("this.ruleType == ruleType");
    log.info("*** EXECUTE RULE QUERY ***");
    Collection c = (Collection)qry.execute(ruleType);
    log.info("*** qrysize=" + c.size());
    finally {
    qry.closeAll();
    Log file: There is not SQL statement generated for the JDO query.
    [junit] INFO: Get endorsement rule type
    [junit] Jun 7, 2004 12:39:01 PM EndorsementRuleEngine
    getEndorsementRuleType
    [junit] INFO: *** JDO EXECUTE BEGIN ***
    [junit] 16366 TRACE [main] kodo.jdbc.SQL - <t 3969559, conn 18096534> [0
    m
    s] executing prepstmnt 20731151 SELECT t0.EndtType, t0.EndtId FROM EndtHe
    aderItem t0 WHERE t0.EndtId = ? [params=(int) 6137330] [reused=0]
    [junit] Jun 7, 2004 12:39:01 PM EndorsementRuleEngine
    getEndorsementRuleType
    [junit] INFO: *** JDO EXECUTE END ***
    [junit] Jun 7, 2004 12:39:02 PM EndorsementRuleEngine getRules
    [junit] INFO: *** EXECUTE RULE QUERY ***
    +++ WHERE IS SQL statement for JDO Query ? +++
    [junit] Jun 7, 2004 12:39:02 PM EndorsementRuleEngine getRules
    [junit] INFO: *** qrysize=0
    [junit] Jun 7, 2004 12:39:02 PM mytest.EndtRuleTestCase setComplete
    Thanks,
    Andy

    Please ignore this post. The error was caused by the file merge done by
    StarTeam.

Maybe you are looking for