Query taking 6mins to execute wityh order by clause, 3secs without orderby

Dear All,
The below query is taking nearly 6minutes time to execute (as i have order by clause in the query)
/* Formatted on 2007/09/26 10:03 (Formatter Plus v4.8.0) */
SELECT (SELECT DISTINCT grndate
FROM fs_lg_grnhdr
WHERE grnid = pl.grnid AND custwhid = pl.custwhid)
grndate,
pl.grnid,
(SELECT DISTINCT vi.orderno
FROM fs_lg_vendorinvoicehdr vi, fs_lg_grndtl gd
WHERE gd.vendorinvoiceid = vi.vendorinvoiceid
AND gd.custwhid = vi.custwhid
AND gd.custwhid = pl.custwhid
AND gd.grnid = pl.grnid
AND gd.partid = pl.partid) orderno,
pl.expirydate, pl.batchno, pl.packuom,
NVL (pl.receiptqty, 0) receiptqty, pl.putawayid, pl.lineno,
(SELECT customscontrolno
FROM fs_lg_putawaydtl
WHERE custwhid = pl.custwhid
AND putawayid = pl.putawayid
AND partid = pl.partid
AND locationto = pl.locationid) cctrlno,
(SELECT customspermitno
FROM fs_lg_putawayhdr
WHERE custwhid = pl.custwhid
AND putawayid = pl.putawayid) cpermitno,
(SELECT SUM (pdtl.pickqty)
FROM fs_lg_pickticketdtl pdtl,
fs_lg_picktickethdr phdr
WHERE pdtl.custwhid = pl.custwhid
AND pdtl.putawayid = pl.putawayid
AND pdtl.putawaylineno = pl.lineno
AND phdr.custwhid = pdtl.custwhid
AND phdr.pickticketid = pdtl.pickticketid
AND phdr.pickdate < '01-SEP-2007'
AND pdtl.status = 'CM') previousoutqty,
(SELECT SUM (pdtl.pickqty)
FROM fs_lg_pickticketdtl pdtl,
fs_lg_picktickethdr phdr
WHERE pdtl.custwhid = pl.custwhid
AND pdtl.putawayid = pl.putawayid
AND pdtl.putawaylineno = pl.lineno
AND phdr.custwhid = pdtl.custwhid
AND phdr.pickticketid = pdtl.pickticketid
AND phdr.pickdate BETWEEN '01-SEP-2007'
AND '25-SEP-2007'
AND pdtl.status = 'CM') presentoutqty,
NVL ((SELECT SUM (qty)
FROM fs_lg_internaltransdtl
WHERE putawayid = pl.putawayid
AND fromputawaylineno = pl.lineno
AND custwhid = pl.custwhid),
0
) toistqty,
NVL ((SELECT SUM (qty)
FROM fs_lg_internaltransdtl
WHERE custwhid = pl.custwhid
AND putawayid = pl.putawayid
AND slno = pl.lineno),
0
) fromistqty
FROM fs_lg_partloads pl
WHERE pl.partid = '2ERCH-2022'
AND pl.custwhid = 'RNH-CSM'
AND inventoryflag IN ('AVAIL','')
AND pl.status = 'CM'
AND pl.grndate <= '25-SEP-2007'
ORDER BY grndate, pl.grnid, pl.putawayid, pl.lineno;
But when i don't use the order by clause it is executing within 3 seconds. But i need to get the output in the sorted order as shown in the order by clause.
Is there any way to avoid order by clause and to get the same output as with order by clasue, and i need to execute the query with less time.
Please help me in this.
Thanks in advance
Mahi

Dear Alok Kumar,
When i execute sql>set autotrace traceonly statistics ;
I am getting the below errors...
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report
What could be the problem, how to resolve this to get the statistics?
But when i use sql>set autotrace traceonly explain; i got the below output for the above query..
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_GRNHDR'
2 1 INDEX (UNIQUE SCAN) OF 'SYS_C00293078' (UNIQUE)
3 0 SORT (UNIQUE)
4 3 NESTED LOOPS
5 4 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_GRNDTL'
6 5 INDEX (RANGE SCAN) OF 'SYS_C00293075' (UNIQUE)
7 4 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_VENDORINVOICEH
DR'
8 7 INDEX (UNIQUE SCAN) OF 'PK_VENDORINVOICE' (UNIQUE)
9 0 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PUTAWAYDTL'
10 9 INDEX (UNIQUE SCAN) OF 'SYS_C00293260' (UNIQUE)
11 0 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PUTAWAYHDR'
12 11 INDEX (UNIQUE SCAN) OF 'SYS_C00293263' (UNIQUE)
13 0 SORT (AGGREGATE)
14 13 NESTED LOOPS
15 14 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETDTL'
16 15 INDEX (RANGE SCAN) OF 'F_L_P_CWI_IND1' (NON-UNIQUE)
17 14 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETHDR'
18 17 INDEX (UNIQUE SCAN) OF 'SYS_C00293202' (UNIQUE)
19 0 SORT (AGGREGATE)
20 19 NESTED LOOPS
21 20 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETDTL'
22 21 INDEX (RANGE SCAN) OF 'F_L_P_CWI_IND1' (NON-UNIQUE)
23 20 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETHDR'
24 23 INDEX (UNIQUE SCAN) OF 'SYS_C00293202' (UNIQUE)
25 0 SORT (AGGREGATE)
26 25 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_INTERNALTRANSDTL
27 26 INDEX (RANGE SCAN) OF 'PK_INTERNALTRANSDTL' (UNIQUE)
28 0 SORT (AGGREGATE)
29 28 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_INTERNALTRANSDTL
30 29 INDEX (RANGE SCAN) OF 'PK_INTERNALTRANSDTL' (UNIQUE)
31 0 SORT (ORDER BY)
32 31 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PARTLOADS'
33 32 INDEX (RANGE SCAN) OF 'PK_PARTLOADS' (UNIQUE)
Please advice me regarding this...
Thanks in advance
Mahi

Similar Messages

  • Query taking long to execute

    Hello
    One of my report taking long to execute. i have range base partition on table and indexes by month. following are the details
    SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 7 13:41:04 2011
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Enter user-name: sys as sysdba
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> show parameter optimizer;
    NAME                                 TYPE        VALUE
    optimizer_capture_sql_plan_baselines boolean     FALSE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      11.2.0.1
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     10
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    optimizer_use_invisible_indexes      boolean     FALSE
    optimizer_use_pending_statistics     boolean     FALSE
    optimizer_use_sql_plan_baselines     boolean     TRUE
    SQL> show parameter db_file_multi
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     64
    SQL> show parameter db_block_size
    NAME                                 TYPE        VALUE
    db_block_size                        integer     16384
    SQL> show parameter cursor_sharing
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    SQL>
    SNAME                          PNAME                          PVAL1                  PVAL2                                                                                                                                                                                                                                                          
    SYSSTATS_INFO                  STATUS                                                AUTOGATHERING                                                                                                                                                                                                                                                  
    SYSSTATS_INFO                  DSTART                                                10-07-2011 14:12                                                                                                                                                                                                                                               
    SYSSTATS_INFO                  DSTOP                                                 10-07-2011 14:42                                                                                                                                                                                                                                               
    SYSSTATS_INFO                  FLAGS                          0                                                                                                                                                                                                                                                                                     
    SYSSTATS_MAIN                  CPUSPEEDNW                     2526.08695652174                                                                                                                                                                                                                                                                      
    SYSSTATS_MAIN                  IOSEEKTIM                      10                                                                                                                                                                                                                                                                                    
    SYSSTATS_MAIN                  IOTFRSPEED                     4096                                                                                                                                                                                                                                                                                  
    SYSSTATS_MAIN                  SREADTIM                                                                                                                                                                                                                                                                                                             
    SYSSTATS_MAIN                  MREADTIM                                                                                                                                                                                                                                                                                                             
    SYSSTATS_MAIN                  CPUSPEED                                                                                                                                                                                                                                                                                                             
    SYSSTATS_MAIN                  MBRC                                                                                                                                                                                                                                                                                                                 
    SYSSTATS_MAIN                  MAXTHR                                                                                                                                                                                                                                                                                                               
    SYSSTATS_MAIN                  SLAVETHR                                                                                                                                                                                                                                                                                                             
    SYSSTATS_TEMP                  SBLKRDS                        640991392                                                                                                                                                                                                                                                                             
    SYSSTATS_TEMP                  SBLKRDTIM                      23353628654370                                                                                                                                                                                                                                                                        
    SYSSTATS_TEMP                  MBLKRDS                        128258266                                                                                                                                                                                                                                                                             
    SYSSTATS_TEMP                  MBLKRDTIM                      6812382430610                                                                                                                                                                                                                                                                         
    SYSSTATS_TEMP                  CPUCYCLES                      75032664                                                                                                                                                                                                                                                                              
    SYSSTATS_TEMP                  CPUTIM                         29682662                                                                                                                                                                                                                                                                              
    SYSSTATS_TEMP                  JOB                            12769                                                                                                                                                                                                                                                                                 
    SYSSTATS_TEMP                  CACHE_JOB                      12770                                                                                                                                                                                                                                                                                 
    SYSSTATS_TEMP                  MBRTOTAL                       3373935275                                                                                                                                                                                                                                                                            
    22 rows selected Any help or suggestion to improve its performance ?

    Execution plan is
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 2727856908                                                                                                                                                                                                                                                                                 
    | Id  | Operation                                                    | Name                  | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |                                                                                                                         
    |   0 | SELECT STATEMENT                                             |                       |     1 |  1183 |   138K  (1)| 00:32:21 |       |       |        |      |            |                                                                                                                         
    |*  1 |  COUNT STOPKEY                                               |                       |       |       |            |          |       |       |        |      |            |                                                                                                                         
    |   2 |   PX COORDINATOR                                             |                       |       |       |            |          |       |       |        |      |            |                                                                                                                         
    |   3 |    PX SEND QC (ORDER)                                        | :TQ10008              |     1 |  1183 |   138K  (1)| 00:32:21 |       |       |  Q1,08 | P->S | QC (ORDER) |                                                                                                                         
    |   4 |     VIEW                                                     |                       |     1 |  1183 |   138K  (1)| 00:32:21 |       |       |  Q1,08 | PCWP |            |                                                                                                                         
    |*  5 |      SORT ORDER BY STOPKEY                                   |                       |     1 |   400 |   138K  (1)| 00:32:21 |       |       |  Q1,08 | PCWP |            |                                                                                                                         
    |   6 |       PX RECEIVE                                             |                       |     1 |  1183 |            |          |       |       |  Q1,08 | PCWP |            |                                                                                                                         
    |   7 |        PX SEND RANGE                                         | :TQ10007              |     1 |  1183 |            |          |       |       |  Q1,07 | P->P | RANGE      |                                                                                                                         
    |*  8 |         SORT ORDER BY STOPKEY                                |                       |     1 |  1183 |            |          |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |   9 |          NESTED LOOPS                                        |                       |       |       |            |          |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |  10 |           NESTED LOOPS                                       |                       |     1 |   400 |   138K  (1)| 00:32:21 |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |  11 |            NESTED LOOPS                                      |                       |     1 |   377 |   138K  (1)| 00:32:21 |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |  12 |             NESTED LOOPS                                     |                       |     1 |   341 |   138K  (1)| 00:32:21 |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |* 13 |              HASH JOIN                                       |                       |     1 |   324 |   138K  (1)| 00:32:21 |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |  14 |               PX RECEIVE                                     |                       |     1 |   289 |   123K  (1)| 00:28:53 |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |  15 |                PX SEND BROADCAST                             | :TQ10006              |     1 |   289 |   123K  (1)| 00:28:53 |       |       |  Q1,06 | P->P | BROADCAST  |                                                                                                                         
    |* 16 |                 HASH JOIN                                    |                       |     1 |   289 |   123K  (1)| 00:28:53 |       |       |  Q1,06 | PCWP |            |                                                                                                                         
    |  17 |                  PX RECEIVE                                  |                       |     4 |  1016 |   123K  (1)| 00:28:51 |       |       |  Q1,06 | PCWP |            |                                                                                                                         
    |  18 |                   PX SEND BROADCAST                          | :TQ10005              |     4 |  1016 |   123K  (1)| 00:28:51 |       |       |  Q1,05 | P->P | BROADCAST  |                                                                                                                         
    |* 19 |                    HASH JOIN OUTER BUFFERED                  |                       |     4 |  1016 |   123K  (1)| 00:28:51 |       |       |  Q1,05 | PCWP |            |                                                                                                                         
    |  20 |                     PX RECEIVE                               |                       |       |       |            |          |       |       |  Q1,05 | PCWP |            |                                                                                                                         
    |  21 |                      PX SEND HASH                            | :TQ10003              |       |       |            |          |       |       |  Q1,03 | P->P | HASH       |                                                                                                                         
    |  22 |                       NESTED LOOPS                           |                       |       |       |            |          |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  23 |                        NESTED LOOPS                          |                       |     4 |   892 |   123K  (1)| 00:28:51 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  24 |                         NESTED LOOPS                         |                       |     6 |   948 |   123K  (1)| 00:28:51 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  25 |                          NESTED LOOPS                        |                       |     7 |  1043 |   123K  (1)| 00:28:51 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |* 26 |                           HASH JOIN                          |                       |  5784 |   728K|   118K  (1)| 00:27:45 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  27 |                            PX RECEIVE                        |                       |   667K|    26M| 11597   (1)| 00:02:43 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  28 |                             PX SEND BROADCAST                | :TQ10000              |   667K|    26M| 11597   (1)| 00:02:43 |       |       |  Q1,00 | P->P | BROADCAST  |                                                                                                                         
    |  29 |                              PX PARTITION RANGE ALL          |                       |   667K|    26M| 11597   (1)| 00:02:43 |     1 |    14 |  Q1,00 | PCWC |            |                                                                                                                         
    |  30 | WID                           TABLE ACCESS BY LOCAL INDEX RO | PAH01V1_DG1           |   667K|    26M| 11597   (1)| 00:02:43 |     1 |    14 |  Q1,00 | PCWP |            |                                                                                                                         
    |  31 |                                BITMAP CONVERSION TO ROWIDS   |                       |       |       |            |          |       |       |  Q1,00 | PCWP |            |                                                                                                                         
    |* 32 |                                 BITMAP INDEX SINGLE VALUE    | MINDX_PAH01V1_DG1_14  |       |       |            |          |     1 |    14 |  Q1,00 | PCWP |            |                                                                                                                         
    |* 33 |                            HASH JOIN                         |                       |  1826K|   151M|   107K  (1)| 00:25:03 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  34 |                             PX RECEIVE                       |                       |  2682 | 18774 |    58   (0)| 00:00:01 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  35 |                              PX SEND BROADCAST               | :TQ10001              |  2682 | 18774 |    58   (0)| 00:00:01 |       |       |  Q1,01 | P->P | BROADCAST  |                                                                                                                         
    |  36 |                               PX BLOCK ITERATOR              |                       |  2682 | 18774 |    58   (0)| 00:00:01 |     1 |    14 |  Q1,01 | PCWC |            |                                                                                                                         
    |  37 |                                TABLE ACCESS FULL             | PAH01V1_DG3           |  2682 | 18774 |    58   (0)| 00:00:01 |     1 |    14 |  Q1,01 | PCWP |            |                                                                                                                         
    |* 38 |                             HASH JOIN                        |                       |  2409K|   183M|   107K  (1)| 00:25:02 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  39 |                              PX RECEIVE                      |                       |   476K|    19M|  5904   (1)| 00:01:23 |       |       |  Q1,03 | PCWP |            |                                                                                                                         
    |  40 |                               PX SEND BROADCAST              | :TQ10002              |   476K|    19M|  5904   (1)| 00:01:23 |       |       |  Q1,02 | P->P | BROADCAST  |                                                                                                                         
    |  41 |                                PX PARTITION RANGE ALL        |                       |   476K|    19M|  5904   (1)| 00:01:23 |     1 |    14 |  Q1,02 | PCWC |            |                                                                                                                         
    |  42 | ROWID                           TABLE ACCESS BY LOCAL INDEX  | PAH01V1_DG5           |   476K|    19M|  5904   (1)| 00:01:23 |     1 |    14 |  Q1,02 | PCWP |            |                                                                                                                         
    |  43 |                                  BITMAP CONVERSION TO ROWIDS |                       |       |       |            |          |       |       |  Q1,02 | PCWP |            |                                                                                                                         
    |  44 |                                   BITMAP MINUS               |                       |       |       |            |          |       |       |  Q1,02 | PCWP |            |                                                                                                                         
    |  45 |                                    BITMAP MINUS              |                       |       |       |            |          |       |       |  Q1,02 | PCWP |            |                                                                                                                         
    |  46 |                                     BITMAP MERGE             |                       |       |       |            |          |       |       |  Q1,02 | PCWP |            |                                                                                                                         
    |  47 |                                      BITMAP INDEX FULL SCAN  | MINDX_PAH01V1_DG517   |       |       |            |          |     1 |    14 |  Q1,02 | PCWP |            |                                                                                                                         
    |* 48 | E                                   BITMAP INDEX SINGLE VALU | MINDX_PAH01V1_DG5_3   |       |       |            |          |     1 |    14 |  Q1,02 | PCWP |            |                                                                                                                         
    |* 49 |                                    BITMAP INDEX SINGLE VALUE | MINDX_PAH01V1_DG5_3   |       |       |            |          |     1 |    14 |  Q1,02 | PCWP |            |                                                                                                                         
    |  50 |                              PX BLOCK ITERATOR               |                       |   275M|     9G|   101K  (1)| 00:23:37 |     1 |    14 |  Q1,03 | PCWC |            |                                                                                                                         
    |* 51 |                               TABLE ACCESS FULL              | PAH01V1_JT            |   275M|     9G|   101K  (1)| 00:23:37 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |  52 |                           PARTITION RANGE ALL                |                       |     1 |    20 |     1   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |* 53 |                            TABLE ACCESS BY LOCAL INDEX ROWID | PAH01V1_DG2           |     1 |    20 |     1   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |* 54 |                             INDEX RANGE SCAN                 | PKINDX_PAH01V1_DG2_28 |     1 |       |     1   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |  55 |                          PARTITION RANGE ALL                 |                       |     1 |     9 |     0   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |  56 |                           TABLE ACCESS BY LOCAL INDEX ROWID  | PAH01V1_DG4           |     1 |     9 |     0   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |* 57 |                            INDEX RANGE SCAN                  | PKINDX_PAH01V1_DG4    |     1 |       |     0   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |  58 |                         PARTITION RANGE ALL                  |                       |     1 |       |     1   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |* 59 |                          INDEX RANGE SCAN                    | PKINDX_PAH01V1_DG0    |     1 |       |     1   (0)| 00:00:01 |     1 |    14 |  Q1,03 | PCWP |            |                                                                                                                         
    |  60 |                        TABLE ACCESS BY LOCAL INDEX ROWID     | PAH01V1_DG0           |     1 |    65 |     1   (0)| 00:00:01 |     1 |     1 |  Q1,03 | PCWP |            |                                                                                                                         
    |  61 |                     PX RECEIVE                               |                       |   296 |  9176 |     2   (0)| 00:00:01 |       |       |  Q1,05 | PCWP |            |                                                                                                                         
    |  62 |                      PX SEND HASH                            | :TQ10004              |   296 |  9176 |     2   (0)| 00:00:01 |       |       |  Q1,04 | P->P | HASH       |                                                                                                                         
    |  63 |                       PX BLOCK ITERATOR                      |                       |   296 |  9176 |     2   (0)| 00:00:01 |       |       |  Q1,04 | PCWC |            |                                                                                                                         
    |  64 |                        TABLE ACCESS FULL                     | PAH01V1_STORE_LKP     |   296 |  9176 |     2   (0)| 00:00:01 |       |       |  Q1,04 | PCWP |            |                                                                                                                         
    |  65 |                  PX PARTITION RANGE ITERATOR                 |                       |  1571K|    52M|   167   (1)| 00:00:03 |   KEY |    14 |  Q1,06 | PCWC |            |                                                                                                                         
    |  66 |                   TABLE ACCESS BY LOCAL INDEX ROWID          | PAH01V1_DG0           |  1571K|    52M|   167   (1)| 00:00:03 |   KEY |    14 |  Q1,06 | PCWP |            |                                                                                                                         
    |  67 |                    BITMAP CONVERSION TO ROWIDS               |                       |       |       |            |          |       |       |  Q1,06 | PCWP |            |                                                                                                                         
    |  68 |                     BITMAP AND                               |                       |       |       |            |          |       |       |  Q1,06 | PCWP |            |                                                                                                                         
    |  69 |                      BITMAP MERGE                            |                       |       |       |            |          |       |       |  Q1,06 | PCWP |            |                                                                                                                         
    |* 70 |                       BITMAP INDEX RANGE SCAN                | MINDX_PAH01V1_DG022   |       |       |            |          |   KEY |    14 |  Q1,06 | PCWP |            |                                                                                                                         
    |  71 |                      BITMAP MERGE                            |                       |       |       |            |          |       |       |  Q1,06 | PCWP |            |                                                                                                                         
    |* 72 |                       BITMAP INDEX RANGE SCAN                | MINDX_PAH01V1_DG0_8   |       |       |            |          |   KEY |    14 |  Q1,06 | PCWP |            |                                                                                                                         
    |  73 |               PX PARTITION RANGE ITERATOR                    |                       |  2594K|    86M| 14858   (1)| 00:03:29 |   KEY |    14 |  Q1,07 | PCWC |            |                                                                                                                         
    |  74 |                TABLE ACCESS BY LOCAL INDEX ROWID             | PAH01V1_JT            |  2594K|    86M| 14858   (1)| 00:03:29 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |  75 |                 BITMAP CONVERSION TO ROWIDS                  |                       |       |       |            |          |       |       |  Q1,07 | PCWP |            |                                                                                                                         
    |* 76 |                  BITMAP INDEX RANGE SCAN                     | MINDX_PAH01V1_JT_PF_  |       |       |            |          |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |  77 |              PARTITION RANGE ITERATOR                        |                       |     1 |    17 |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |* 78 |               TABLE ACCESS BY LOCAL INDEX ROWID              | PAH01V1_DG2           |     1 |    17 |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |* 79 |                INDEX RANGE SCAN                              | PKINDX_PAH01V1_DG2_28 |     1 |       |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |  80 |             PARTITION RANGE ITERATOR                         |                       |     1 |    36 |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |  81 |              TABLE ACCESS BY LOCAL INDEX ROWID               | PAH01V1_DG5           |     1 |    36 |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |* 82 |               INDEX RANGE SCAN                               | PKINDX_PAH01V1_DG5_18 |     1 |       |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |  83 |            PARTITION RANGE ITERATOR                          |                       |     1 |       |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |* 84 |             INDEX RANGE SCAN                                 | PKINDX_PAH01V1_DG1_22 |     1 |       |     1   (0)| 00:00:01 |   KEY |    14 |  Q1,07 | PCWP |            |                                                                                                                         
    |* 85 |           TABLE ACCESS BY LOCAL INDEX ROWID                  | PAH01V1_DG1           |     1 |    23 |     1   (0)| 00:00:01 |     1 |     1 |  Q1,07 | PCWP |            |                                                                                                                         
    135 rows selected

  • Query taking time to execute

    Hello,
    i have created one query based on inventory cube 0IC_C03. when i am executing the infocube based on a particular date i am able to see the output but when i am executing the query on the basis of that particular date given while executing the cube the query is taking long time to execute and throwing a message of time limit exceed.
    could anyone suggest me why the query is showing such nessage along with resolution.
    Thanks,
    Kumkum
    Edited by: kumkum basu on Nov 29, 2010 2:33 PM

    Hi,
    There can be number of reason.
    What you can do is:-
    put the unwanted characteristics in Free Characteristics
    Remove unwanted cell reference
    Try using partitions in cubes
    Use aggregates for summarised data.
    f the above options doesnt work, then try pre-caching.This will definitely help!
    Use proper selections to get small subset of data.
    Goto RSRT>> type your query name>> Query properties>> select cache mode=4
    In addition to RSRT, ST05 (sql trace), SE30 (runtime analysis) and system statistics (ST03) may help you in identifying performance issues with a report.
    Thanks,.
    Saveen Kumar

  • Query taking longer to execute the second time.

    Hello,
    I have a query joing few tables and views and when i execute it the first them, it executes within a seconds, immediately if i execute it the second time it takes about 40 seconds to execute. I am using Oracle 11g [11.2.0.1.0].
    Please find the TKPROF output.
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.26       0.24          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       23      0.81       0.82          0       5610          0         326
    total       25      1.07       1.07          0       5610          0         326
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 127
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.23       0.23          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       23     41.01      41.00          0      38218          0         326
    total       25     41.24      41.24          0      38218          0         326
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 127 

    Hi Nicholay,
    VPD is not being used in our application. ArcSDE Multi-Versionsed View uses some functions in VW_ objects. In Oracle 10g I dont have this issue.
    Here is the output from V$SQL_SHARED_CURSOR.
    "SQL_ID"                      "ADDRESS"                     "CHILD_ADDRESS"               "CHILD_NUMBER"                "UNBOUND_CURSOR"              "SQL_TYPE_MISMATCH"           "OPTIMIZER_MISMATCH"          "OUTLINE_MISMATCH"            "STATS_ROW_MISMATCH"          "LITERAL_MISMATCH"            "FORCE_HARD_PARSE"            "EXPLAIN_PLAN_CURSOR"         "BUFFERED_DML_MISMATCH"       "PDML_ENV_MISMATCH"           "INST_DRTLD_MISMATCH"         "SLAVE_QC_MISMATCH"           "TYPECHECK_MISMATCH"          "AUTH_CHECK_MISMATCH"         "BIND_MISMATCH"               "DESCRIBE_MISMATCH"           "LANGUAGE_MISMATCH"           "TRANSLATION_MISMATCH"        "BIND_EQUIV_FAILURE"          "INSUFF_PRIVS"                "INSUFF_PRIVS_REM"            "REMOTE_TRANS_MISMATCH"       "LOGMINER_SESSION_MISMATCH"   "INCOMP_LTRL_MISMATCH"        "OVERLAP_TIME_MISMATCH"       "EDITION_MISMATCH"            "MV_QUERY_GEN_MISMATCH"       "USER_BIND_PEEK_MISMATCH"     "TYPCHK_DEP_MISMATCH"         "NO_TRIGGER_MISMATCH"         "FLASHBACK_CURSOR"            "ANYDATA_TRANSFORMATION"      "INCOMPLETE_CURSOR"           "TOP_LEVEL_RPI_CURSOR"        "DIFFERENT_LONG_LENGTH"       "LOGICAL_STANDBY_APPLY"       "DIFF_CALL_DURN"              "BIND_UACS_DIFF"              "PLSQL_CMP_SWITCHS_DIFF"      "CURSOR_PARTS_MISMATCH"       "STB_OBJECT_MISMATCH"         "CROSSEDITION_TRIGGER_MISMATCH""PQ_SLAVE_MISMATCH"           "TOP_LEVEL_DDL_MISMATCH"      "MULTI_PX_MISMATCH"           "BIND_PEEKED_PQ_MISMATCH"     "MV_REWRITE_MISMATCH"         "ROLL_INVALID_MISMATCH"       "OPTIMIZER_MODE_MISMATCH"     "PX_MISMATCH"                 "MV_STALEOBJ_MISMATCH"        "FLASHBACK_TABLE_MISMATCH"    "LITREP_COMP_MISMATCH"        "PLSQL_DEBUG"                 "LOAD_OPTIMIZER_STATS"        "ACL_MISMATCH"                "FLASHBACK_ARCHIVE_MISMATCH"  "LOCK_USER_SCHEMA_FAILED"     "REMOTE_MAPPING_MISMATCH"     "LOAD_RUNTIME_HEAP_FAILED"    "HASH_MATCH_FAILED"           "PURGED_CURSOR"               "BIND_LENGTH_UPGRADEABLE"    
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD49C88"            "1"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD3A7B8"            "0"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD46A40"            "2"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD3A7B8"            "0"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD49C88"            "1"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD46A40"            "2"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD3A7B8"            "0"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD49C88"            "1"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                          
    "7rtqvjtyp06k9"               "000007FFABD3A918"            "000007FFABD46A40"            "2"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           "N"                           Edited by: 955237 on 29 Aug, 2012 1:57 AM

  • Problem in sql query because of order by clause

    Hi All,
    I am facing a one problem in my one sql query.I am using Oracle 10gR2.
    Query is given below:
    SELECT t1.ename
            FROM T1, T2
           WHERE T1.EMPNO = 1234
             AND T1.ACCOUNTNO = T2.ACCOUNTNO
             AND T1.SEQ = T2.SEQ
           ORDER BY T2.SEQThe Plan of the query is :
    | Id  | Operation                     | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  1 |  TABLE ACCESS BY INDEX ROWID  | T1                   |     1 |    89 |     1   (0)| 00:00:01 |
    |   2 |   NESTED LOOPS                |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| T2                   |     2 |    40 | 11715   (1)| 00:00:41 |
    |   4 |     INDEX FULL SCAN           | PK_T2_SEQ            | 58752 |       |   122   (5)| 00:00:01 |
    |*  5 |    INDEX RANGE SCAN           | FK_ACCOUNTNO         |     3 |       |     0   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------Now i want to reduce the time of this query.
    If i am removing Order by clause from query than performance of the query is totally perfect but with order by clause its taking a time.
    I have already set SORT_AREA_SIZE but still nothing is improving.
    Welcome and thanks for your suggestions.
    Thanks,
    Edited by: BluShadow on 23-Jun-2011 07:55
    added {noformat}{noformat} tags and formatted explain plan to make it readable.  Please see {message:id=9360002} for details on how to post code and data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    There are a couple of things I do not understand.
    1. Why don't you put {noformat}{noformat} around your code, it makes it so much easier to read, especially your explain plan
    2. You claim that the ORDER BY is problematic compared to no order by. Then why do you choose to post only one plan?
    3. It is hard to understand how your tables relate, and which indexes you have and which you don't.
    - PK_T2_SEQ, does this mean that SEQ alone is primary key of T2?
    - If SEQ is primary key of T2, why do you join on accountno, seq and not just seq?
    - If SEQ is primary key of T2 one of the tables is denormalized.
    4. FK_ACCOUNTNO, is this an index on accountno, alone?
    - Or is this AccountNo, Seq?
    5. Is there no index on T1.EMPNO?
    Above could of course just be a case of my not understanding the names of your indexes.
    So, here are my guesses:
    Above plan is for the ORDER BY query. That means the optimizer, has chosen to full scan PK_T2_SEQ, since data is then read according to the ORDER BY.
    (This could be a bad choice)I
    You could try and order by t1.seq, instead. Result should be the same.
    Regards
    Peter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query takes time to execute

    I am creating a jsp application . . . .I am retreiving some values from my database oracle 10g..my query taking time to execute even in isql plus..am uisng tomcat5 and oracle 10gR2..can anyone pls tell me why it happens...my query fetches data from four tables...i dont know exactly why its taking so muc time say 50seconds...when i run the application in my local host it retrievs fast when i do that in server it creates a problem..
    Actually it works fine when i deployed in my client server it takes time sometimes it takes atmost one minute
    1.pls tell me how can i test my query about the performance
    2.is der any command in oracle to test
    3.how much bytes it takes

    Look at this thread...
    When your query takes too long ...

  • Derived tables and Order by clause

    Hi,
    I have a query that looks as below.
    The execution time of the query (10 sec) is fine when order by clause is removed from the query. But with order by clause, the execution time is 40 times more(400 sec). How to optimize this query so that it will execute within a minute, with ORDER BY clause included?
    select X.a1, X.a2, X.a3, X.a4, Y.b1, Y.b2, Y.b3
    from (select A.a1 a1, A.a2 a2, A.a3 a3, A.a4 a4
    from A_table A
    where A.a1 = 'something') X,
    (select B.b1 b1, B.b2 b2, B.b3 b3
    from B_table B
    where B.b1 = 'some') Y
    where
    X.a1 = Y.a1 (+) AND (some other conditions)
    order by X.a1, X.a2, Y.b1, Y.b2, X.a3, X.a4
    thanks in advance,
    Venkat

    You do need the inline view Y if you are outer joining it because you must apply the
    where B.b1 = 'some'
    condition first.
    However, the inline view X is not needed. Still, I'm not sure that getting rid of it is going to improve performance. Try it and see.
    Incidentally, the outer join condition
    where X.a1 = Y.a1 (+)
    refers to Y.a1, but the inline view Y has no column named a1. Did you mean Y.b1?
    What are the "some other conditions"? Do any of them involve the inline view Y alone (that is, are not join conditions)? If so, it may be that either: a) you don't need an outer join, or, b) those conditions should be moved into the inline view Y. In either case, this may improve performance.
    Are you sure the execution time without the order by clause is really 10 seconds? Or, is that just the elapsed time to return the first row? With the order by clause, Oracle must identify all the rows before it can return the first row.

  • Query taking lot of time to execute..

    Hi,
    I have a very complecated query which I am executing using JDBC. The query has an insert statement. This query takes 15 mins to complete. I'm running the query as stand alone java program. Can some one have some suggestions what is the best way to debug. I need to find out why the query is taking that long. I'm using oracle 10g with sql developer.
    ps = con.prepareStatement(query);
    ps.setString(1,date);
    ps.setString(2,code);
    timeStart = System.currentTimeMillis();
    ps.executeUpdate();
    timeEnd = System.currentTimeMillis();     
    System.out.println("Time Taken::"+(timeStart -timeEnd)+" ms");
    Thanks in advance
    Ajoo

    Perhaps you should post the query so we can see what you are doing.
    In the mean time, try writing a simple update query and run it. If it runs quickly, your original query has problems. If it runs slow, its caused by something other than your original query.
    P.S.:
    should be:
    System.out.println("Time Taken::"(timeEnd -timeStart)" ms");
    and not this:
    System.out.println("Time Taken::"(timeStart -timeEnd)" ms");
    Edited by: njbt7y on Jan 19, 2011 12:07 PM

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

  • Query taking time

    We have this query which is taking a long time to execute. From the explain plan what i found out is there is a full table scan going on W_GL_OTHER_F. Please help in identifying the problem area and solutions.
    The query is,
    select D1.c1 as c1,
         D1.c2 as c2,
         D1.c3 as c3,
         D1.c4 as c4,
         D1.c5 as c5,
         D1.c6 as c6,
         D1.c7 as c7,
         D1.c8 as c8
    from
         (select distinct D1.c2 as c1,
                   D1.c3 as c2,
                   D1.c4 as c3,
                   D1.c5 as c4,
                   D1.c6 as c5,
                   D1.c7 as c6,
                   D1.c8 as c7,
                   D1.c1 as c8,
                   D1.c5 as c9
              from
                   (select sum(case  when T324628.OTHER_DOC_AMT is null then 0 else T324628.OTHER_DOC_AMT end ) as c1,
                             T91397.GL_ACCOUNT_NUM as c2,
                             T149255.SEGMENT_VAL_CODE as c3,
                             T148908.SEGMENT_VAL_DESC as c4,
                             T148543.HIER4_CODE as c5,
                             T148543.HIER4_NAME as c6,
                             T91707.ACCT_DOC_NUM as c7,
                             T91707.X_LINE_DESCRIPTION as c8
                        from
                             W_GL_OTHER_F T91707 /* Fact_W_GL_OTHER_F */ ,
                             W_GL_ACCOUNT_D T91397 /* Dim_W_GL_ACCOUNT_D */ ,
                             W_STATUS_D T96094 /* Dim_W_STATUS_D_Generic */ ,
                             WC_GL_OTHER_F_MV T324628 /* Fact_WC_GL_OTHER_MV */ ,
                             W_GL_SEGMENT_D T149255 /* Dim_W_GL_SEGMENT_D_Segment1 */ ,
                             W_GL_SEGMENT_D T148937 /* Dim_W_GL_SEGMENT_D_Segment3 */ ,
                             W_HIERARCHY_D T148543 /* Dim_W_HIERARCHY_D_Segment3 */ ,
                             W_GL_SEGMENT_D T148908 /* Dim_W_GL_SEGMENT_D_Segment2 */
                        where  ( T91397.ROW_WID = T91707.GL_ACCOUNT_WID and T91707.DOC_STATUS_WID = T96094.ROW_WID and T96094.ROW_WID = T324628.DOC_STATUS_WID and T148543.HIER_CODE = T148937.SEGMENT_LOV_ID and T148543.HIER20_CODE = T148937.SEGMENT_VAL_CODE and T324628.DELETE_FLG = 'N' and T324628.X_CURRENCY_CODE = 'CAD' and T148543.HIER4_CODE <> '00000000000' and T91397.RECON_TYPE_CODE is not null and T91397.ROW_WID = T324628.GL_ACCOUNT_WID and T91397.ACCOUNT_SEG3_CODE = T148937.SEGMENT_VAL_CODE and T91397.ACCOUNT_SEG3_ATTRIB = T148937.SEGMENT_LOV_ID and T91397.ACCOUNT_SEG2_CODE = T148908.SEGMENT_VAL_CODE and T91397.ACCOUNT_SEG2_ATTRIB = T148908.SEGMENT_LOV_ID and T91397.ACCOUNT_SEG1_CODE = T149255.SEGMENT_VAL_CODE and T91397.ACCOUNT_SEG1_ATTRIB = T149255.SEGMENT_LOV_ID and (T96094.W_STATUS_CODE in ('POSTED', 'REVERSED')) and T91397.GL_ACCOUNT_NUM like '%98%' )
                        group by T91397.GL_ACCOUNT_NUM, T91707.ACCT_DOC_NUM, T91707.X_LINE_DESCRIPTION, T148543.HIER4_CODE, T148543.HIER4_NAME, T148908.SEGMENT_VAL_DESC, T149255.SEGMENT_VAL_CODE
                   ) D1
         ) D1
    order by c1, c2, c3, c4, c5, c6, c7The plan is,
    PLAN_TABLE_OUTPUT
    Plan hash value: 3196636288
    | Id  | Operation                             | Name                | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Psto
    |   0 | SELECT STATEMENT                      |                     |   810K|   306M|       |   266K  (1)| 01:20:03 |       |       |
    |   1 |  HASH GROUP BY                        |                     |   810K|   306M|   320M|   266K  (1)| 01:20:03 |       |       |
    |*  2 |   HASH JOIN                           |                     |   810K|   306M|    38M|   239K  (1)| 01:11:56 |       |       |
    |*  3 |    MAT_VIEW ACCESS FULL               | WC_GL_OTHER_F_MV    |  1137K|    40M|       |  9771   (2)| 00:0
    |*  4 |    HASH JOIN                          |                     |   531K|   189M|       |   222K  (1)| 01:06:38 |       |       |
    |   5 |     INLIST ITERATOR                   |                     |       |       |       |            |          |       |       |
    |*  6 |      INDEX RANGE SCAN                 | W_STATUS_D_U2       |     4 |    56 |       |     1   (0)| 00:00:01 |   
    |*  7 |     HASH JOIN                         |                     |   607K|   208M|  8704K|   222K  (1)| 01:06:38 |       |       |
    |*  8 |      HASH JOIN                        |                     | 40245 |  8214K|  2464K| 10843   (2)| 00:03:16 |       |       |
    |   9 |       VIEW                            | index$_join$_007    | 35148 |  2025K|       |   122  (32)| 00:00:03 |       |
    |* 10 |        HASH JOIN                      |                     |       |       |       |            |          |       |       |
    |* 11 |         HASH JOIN                     |                     |       |       |       |            |          |       |       |
    |* 12 |          HASH JOIN                    |                     |       |       |       |            |          |       |       |
    |  13 |           BITMAP CONVERSION TO ROWIDS |                     | 35148 |  2025K|       |     1   (0)| 00:00:01 |       |   
    |  14 |            BITMAP INDEX FULL SCAN     | W_HIERARCHY_D_M2    |       |       |       |            |          |       |     
    |  15 |           BITMAP CONVERSION TO ROWIDS |                     | 35148 |  2025K|       |    24   (0)| 00:00:01 |       |   
    |  16 |            BITMAP INDEX FULL SCAN     | W_HIERARCHY_D_M4    |       |       |       |            |          |       |     
    |  17 |          BITMAP CONVERSION TO ROWIDS  |                     | 35148 |  2025K|       |    24   (0)| 00:00:01 |       |   
    |* 18 |           BITMAP INDEX FULL SCAN      | X_W_HIERARCHY_D_M11 |       |       |       |            |          |       |     
    |  19 |         BITMAP CONVERSION TO ROWIDS   |                     | 35148 |  2025K|       |    33   (0)| 00:00:01 |       |   
    |  20 |          BITMAP INDEX FULL SCAN       | X_W_HIERARCHY_D_M12 |       |       |       |            |          |       |     
    |* 21 |       HASH JOIN                       |                     | 40246 |  5895K|  4096K| 10430   (2)| 00:03:08 |       |      
    |  22 |        VIEW                           | index$_join$_008    | 65417 |  3321K|       |   197  (14)| 00:00:04 |      
    |* 23 |         HASH JOIN                     |                     |       |       |       |            |          |       |       |
    |* 24 |          HASH JOIN                    |                     |       |       |       |            |          |       |       |
    |  25 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  3321K|       |     3   (0)| 00:00:01 |       |   
    |  26 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M1   |       |       |       |            |          |       |     
    |  27 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  3321K|       |    66   (2)| 00:00:02 |       |   
    |  28 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M2   |       |       |       |            |          |       |     
    |  29 |          BITMAP CONVERSION TO ROWIDS  |                     | 65417 |  3321K|       |   100   (1)| 00:00:02 |       |   
    |  30 |           BITMAP INDEX FULL SCAN      | W_GL_SEGMENT_D_M3   |       |       |       |            |          |       |     
    |* 31 |        HASH JOIN                      |                     | 40246 |  3851K|       |  9953   (1)| 00:03:00 |       |       |
    |  32 |         VIEW                          | index$_join$_006    | 65417 |  1149K|       |    82  (18)| 00:00:02 |       |      
    |* 33 |          HASH JOIN                    |                     |       |       |       |            |          |       |       |
    |  34 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  1149K|       |     3   (0)| 00:00:01 |       |   
    |  35 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M1   |       |       |       |            |          |       |     
    |  36 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  1149K|       |    66   (2)| 00:00:02 |       |   
    |  37 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M2   |       |       |       |            |          |       |     
    |* 38 |         HASH JOIN                     |                     | 40246 |  3144K|       |  9870   (1)| 00:02:58 |       |       |
    |  39 |          VIEW                         | index$_join$_005    | 65417 |  1149K|       |    82  (18)| 00:00:02 |       |     
    |* 40 |           HASH JOIN                   |                     |       |       |       |            |          |       |       |
    |  41 |            BITMAP CONVERSION TO ROWIDS|                     | 65417 |  1149K|       |     3   (0)| 00:00:01 |       |   
    |  42 |             BITMAP INDEX FULL SCAN    | W_GL_SEGMENT_D_M1   |       |       |       |            |          |       |     
    |  43 |            BITMAP CONVERSION TO ROWIDS|                     | 65417 |  1149K|       |    66   (2)| 00:00:02 |       |   
    |  44 |             BITMAP INDEX FULL SCAN    | W_GL_SEGMENT_D_M2   |       |       |       |            |          |       |     
    |* 45 |          TABLE ACCESS FULL            | W_GL_ACCOUNT_D      | 40246 |  2436K|       |  9788   (1)| 00:02:57
    |  46 |      PARTITION RANGE ALL              |                     |    11M|  4261M|       |   152K  (2)| 00:45:43 |     1 |1048
    |  47 |       TABLE ACCESS FULL               | W_GL_OTHER_F        |    11M|  4261M|       |   152K  (2)| 00:45:43
    Predicate Information (identified by operation id):
       2 - access("T96094"."ROW_WID"="T324628"."DOC_STATUS_WID" AND "T91397"."ROW_WID"="T324628"."GL_ACC
       3 - filter("T324628"."X_CURRENCY_CODE"='CAD' AND "T324628"."DELETE_FLG"='N')
       4 - access("T91707"."DOC_STATUS_WID"="T96094"."ROW_WID")
       6 - access("T96094"."W_STATUS_CODE"='POSTED' OR "T96094"."W_STATUS_CODE"='REVERSED')
       7 - access("T91397"."ROW_WID"="T91707"."GL_ACCOUNT_WID")
       8 - access("T148543"."HIER_CODE"="T148937"."SEGMENT_LOV_ID" AND "T148543"."HIER20_CODE"="T148937"
      10 - access(ROWID=ROWID)
      11 - access(ROWID=ROWID)
      12 - access(ROWID=ROWID)
      18 - filter("T148543"."HIER4_CODE"<>'00000000000')
      21 - access("T91397"."ACCOUNT_SEG2_CODE"="T148908"."SEGMENT_VAL_CODE" AND
                  "T91397"."ACCOUNT_SEG2_ATTRIB"="T148908"."SEGMENT_LOV_ID")
      23 - access(ROWID=ROWID)
      24 - access(ROWID=ROWID)
      31 - access("T91397"."ACCOUNT_SEG3_CODE"="T148937"."SEGMENT_VAL_CODE" AND
                  "T91397"."ACCOUNT_SEG3_ATTRIB"="T148937"."SEGMENT_LOV_ID")
      33 - access(ROWID=ROWID)
      38 - access("T91397"."ACCOUNT_SEG1_CODE"="T149255"."SEGMENT_VAL_CODE" AND
                  "T91397"."ACCOUNT_SEG1_ATTRIB"="T149255"."SEGMENT_LOV_ID")
      40 - access(ROWID=ROWID)
      45 - filter("T91397"."GL_ACCOUNT_NUM" LIKE '%98%' AND "T91397"."RECON_TYPE_CODE" IS NOT NULL)
    79 rows selected.

    user605926 wrote:
    We have this query which is taking a long time to execute. From the explain plan what i found out is there is a full table scan going on W_GL_OTHER_F. Please help in identifying the problem area and solutions.
    The plan is,
    PLAN_TABLE_OUTPUT
    Plan hash value: 3196636288
    | Id  | Operation                             | Name                | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Psto
    |   0 | SELECT STATEMENT                      |                     |   810K|   306M|       |   266K  (1)| 01:20:03 |       |       |
    |   1 |  HASH GROUP BY                        |                     |   810K|   306M|   320M|   266K  (1)| 01:20:03 |       |       |
    |*  2 |   HASH JOIN                           |                     |   810K|   306M|    38M|   239K  (1)| 01:11:56 |       |       |
    |*  3 |    MAT_VIEW ACCESS FULL               | WC_GL_OTHER_F_MV    |  1137K|    40M|       |  9771   (2)| 00:0
    |*  4 |    HASH JOIN                          |                     |   531K|   189M|       |   222K  (1)| 01:06:38 |       |       |
    |   5 |     INLIST ITERATOR                   |                     |       |       |       |            |          |       |       |
    |*  6 |      INDEX RANGE SCAN                 | W_STATUS_D_U2       |     4 |    56 |       |     1   (0)| 00:00:01 |   
    |*  7 |     HASH JOIN                         |                     |   607K|   208M|  8704K|   222K  (1)| 01:06:38 |       |       |
    |*  8 |      HASH JOIN                        |                     | 40245 |  8214K|  2464K| 10843   (2)| 00:03:16 |       |       |
    |   9 |       VIEW                            | index$_join$_007    | 35148 |  2025K|       |   122  (32)| 00:00:03 |       |
    |* 10 |        HASH JOIN                      |                     |       |       |       |            |          |       |       |
    |* 11 |         HASH JOIN                     |                     |       |       |       |            |          |       |       |
    |* 12 |          HASH JOIN                    |                     |       |       |       |            |          |       |       |
    |  13 |           BITMAP CONVERSION TO ROWIDS |                     | 35148 |  2025K|       |     1   (0)| 00:00:01 |       |   
    |  14 |            BITMAP INDEX FULL SCAN     | W_HIERARCHY_D_M2    |       |       |       |            |          |       |     
    |  15 |           BITMAP CONVERSION TO ROWIDS |                     | 35148 |  2025K|       |    24   (0)| 00:00:01 |       |   
    |  16 |            BITMAP INDEX FULL SCAN     | W_HIERARCHY_D_M4    |       |       |       |            |          |       |     
    |  17 |          BITMAP CONVERSION TO ROWIDS  |                     | 35148 |  2025K|       |    24   (0)| 00:00:01 |       |   
    |* 18 |           BITMAP INDEX FULL SCAN      | X_W_HIERARCHY_D_M11 |       |       |       |            |          |       |     
    |  19 |         BITMAP CONVERSION TO ROWIDS   |                     | 35148 |  2025K|       |    33   (0)| 00:00:01 |       |   
    |  20 |          BITMAP INDEX FULL SCAN       | X_W_HIERARCHY_D_M12 |       |       |       |            |          |       |     
    |* 21 |       HASH JOIN                       |                     | 40246 |  5895K|  4096K| 10430   (2)| 00:03:08 |       |      
    |  22 |        VIEW                           | index$_join$_008    | 65417 |  3321K|       |   197  (14)| 00:00:04 |      
    |* 23 |         HASH JOIN                     |                     |       |       |       |            |          |       |       |
    |* 24 |          HASH JOIN                    |                     |       |       |       |            |          |       |       |
    |  25 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  3321K|       |     3   (0)| 00:00:01 |       |   
    |  26 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M1   |       |       |       |            |          |       |     
    |  27 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  3321K|       |    66   (2)| 00:00:02 |       |   
    |  28 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M2   |       |       |       |            |          |       |     
    |  29 |          BITMAP CONVERSION TO ROWIDS  |                     | 65417 |  3321K|       |   100   (1)| 00:00:02 |       |   
    |  30 |           BITMAP INDEX FULL SCAN      | W_GL_SEGMENT_D_M3   |       |       |       |            |          |       |     
    |* 31 |        HASH JOIN                      |                     | 40246 |  3851K|       |  9953   (1)| 00:03:00 |       |       |
    |  32 |         VIEW                          | index$_join$_006    | 65417 |  1149K|       |    82  (18)| 00:00:02 |       |      
    |* 33 |          HASH JOIN                    |                     |       |       |       |            |          |       |       |
    |  34 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  1149K|       |     3   (0)| 00:00:01 |       |   
    |  35 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M1   |       |       |       |            |          |       |     
    |  36 |           BITMAP CONVERSION TO ROWIDS |                     | 65417 |  1149K|       |    66   (2)| 00:00:02 |       |   
    |  37 |            BITMAP INDEX FULL SCAN     | W_GL_SEGMENT_D_M2   |       |       |       |            |          |       |     
    |* 38 |         HASH JOIN                     |                     | 40246 |  3144K|       |  9870   (1)| 00:02:58 |       |       |
    |  39 |          VIEW                         | index$_join$_005    | 65417 |  1149K|       |    82  (18)| 00:00:02 |       |     
    |* 40 |           HASH JOIN                   |                     |       |       |       |            |          |       |       |
    |  41 |            BITMAP CONVERSION TO ROWIDS|                     | 65417 |  1149K|       |     3   (0)| 00:00:01 |       |   
    |  42 |             BITMAP INDEX FULL SCAN    | W_GL_SEGMENT_D_M1   |       |       |       |            |          |       |     
    |  43 |            BITMAP CONVERSION TO ROWIDS|                     | 65417 |  1149K|       |    66   (2)| 00:00:02 |       |   
    |  44 |             BITMAP INDEX FULL SCAN    | W_GL_SEGMENT_D_M2   |       |       |       |            |          |       |     
    |* 45 |          TABLE ACCESS FULL            | W_GL_ACCOUNT_D      | 40246 |  2436K|       |  9788   (1)| 00:02:57
    |  46 |      PARTITION RANGE ALL              |                     |    11M|  4261M|       |   152K  (2)| 00:45:43 |     1 |1048
    |  47 |       TABLE ACCESS FULL               | W_GL_OTHER_F        |    11M|  4261M|       |   152K  (2)| 00:45:43
    Predicate Information (identified by operation id):
    2 - access("T96094"."ROW_WID"="T324628"."DOC_STATUS_WID" AND "T91397"."ROW_WID"="T324628"."GL_ACC
    3 - filter("T324628"."X_CURRENCY_CODE"='CAD' AND "T324628"."DELETE_FLG"='N')
    4 - access("T91707"."DOC_STATUS_WID"="T96094"."ROW_WID")
    6 - access("T96094"."W_STATUS_CODE"='POSTED' OR "T96094"."W_STATUS_CODE"='REVERSED')
    7 - access("T91397"."ROW_WID"="T91707"."GL_ACCOUNT_WID")
    8 - access("T148543"."HIER_CODE"="T148937"."SEGMENT_LOV_ID" AND "T148543"."HIER20_CODE"="T148937"
    10 - access(ROWID=ROWID)
    11 - access(ROWID=ROWID)
    12 - access(ROWID=ROWID)
    18 - filter("T148543"."HIER4_CODE"<>'00000000000')
    21 - access("T91397"."ACCOUNT_SEG2_CODE"="T148908"."SEGMENT_VAL_CODE" AND
    "T91397"."ACCOUNT_SEG2_ATTRIB"="T148908"."SEGMENT_LOV_ID")
    23 - access(ROWID=ROWID)
    24 - access(ROWID=ROWID)
    31 - access("T91397"."ACCOUNT_SEG3_CODE"="T148937"."SEGMENT_VAL_CODE" AND
    "T91397"."ACCOUNT_SEG3_ATTRIB"="T148937"."SEGMENT_LOV_ID")
    33 - access(ROWID=ROWID)
    38 - access("T91397"."ACCOUNT_SEG1_CODE"="T149255"."SEGMENT_VAL_CODE" AND
    "T91397"."ACCOUNT_SEG1_ATTRIB"="T149255"."SEGMENT_LOV_ID")
    40 - access(ROWID=ROWID)
    45 - filter("T91397"."GL_ACCOUNT_NUM" LIKE '%98%' AND "T91397"."RECON_TYPE_CODE" IS NOT NULL)
    79 rows selected.
    You may want to have a look at <a href="HOW TO: Post a SQL statement tuning request - template posting">HOW TO: Post a SQL statement tuning request - template posting</a> to see what more details are needed in order for somebody to provide better answer.
    Based on what you have posted so far, you may want to share details of following questions (in addition to details in above link)
    1) How much time does the query currently take to execute? How much time do you expect it to take? Also, how are you measuring query execution time?
    2) Your plan suggests that the query is expected to return 810K rows. Is this figure close to actual number of records? What are you doing with this huge amount of data?

  • Query with order by clause

    Hi,
    I found a query with order by clause in procedure which is taking long time.
    Stats are upto date.
    Total Rows :650000.
    It is ordered by primary key column.
    select * from table_name order by col1;
    col1 is a primary key.No of cpu's used is 4.
    can anyone suggest me a better solution to improve the performance of a query.
    Is it better to use parallel hint for above scenario.
    Any help really apprecaited.
    Thanks in advance.

    Hi,
    Thanks for ur immediate reply.
    It doesn't have where clause.
    below is the plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 619071987
    | Id  | Operation                   | Name                 | Rows  | Bytes | Cos
    |   0 | SELECT STATEMENT            |                      |   671K|   255M| 125
    |   1 |  TABLE ACCESS BY INDEX ROWID| FULL_ITEM_FACILITIES |   671K|   255M| 125
    |   2 |   INDEX FULL SCAN           | FIF_PK               |   671K|       |
    9 rows selected
    Executed in 0.094 secondsThanks in advance
    Edited by: unique on Jun 22, 2009 8:26 AM

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

  • Order by clause in Sub query

    Hi,
    Can we use order by clause in Sub query?
    While using the order by clause, I am getting the "missing expression error" . If I remove order by clause query executing fine.
    Here is my query:
    select *
    from emp_mstr
    where emp_no in(select
    emp_no
    from emp_mstr
    order by branch_no);
    Thanks & Regards,
    Mahi

    May be you miss some required spaces also, other than wrong use of ORDER BY
    select *
    from emp_mstr
    where emp_no in
         ( select e2.emp_no
           from emp_mstr e2
    --       order by e2.branch_no
         );Why do you want to ORDER BY in the subquery, which you use with IN clause? That will not make any difference in the result..Means the result you get with ORDER BY will be same as without that.. And in this case, ORDER by is a unncessary overhead.. And Ordering is very costly..
    And why do you want to have the IN clause at all in your query? You are referring the same tables in the main query and sub query..
    The below will give the same result
    select *
    from emp_mstr
    where emp_no is not nullIf you want to use another table in the subquery, always use aliasess...
    select *
    from emp_mstr
    where emp_no in
         ( select e2.emp_no
           from emp_mstr2 e2
    --       order by e2.branch_no
         );

  • 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

Maybe you are looking for

  • My document plays as a continous loop even with the stop(); code at the start of the document HELP!

    I really need help for a school project im working on, it seems as though flash doesnt even recognise the actions in the layers, the codes in the first frame are as follows: stop(); /* Click to Go to Frame and Stop Clicking on the specified symbol in

  • Can I call a function in another package?

    Dear all, Can I call a function in another package? Say I have package A, and package B. Is it possible for me to call a function in inside package A, within a function inside package B? If yes, what's the syntax. Thanks in advance!

  • UNICODE system access for further development of connectors

    As there has been a bit of activity on the forums around issues with UNICODE and the various Scripting Language connectors, I'd like sort this out for Perl, Python and Ruby. Unfortunately I do not have access to a UNICODE based system, so I have neve

  • Error while launching visio in Data Manager

    Hi All, I have installed visio 2003 version and working on SP03 5.5.28.17. The problem I am facing is that I am unable to launch visio through Data manager Client. When I am clicking workflow tab in Data Manager client, it is giving me error as "Erro

  • After Mavericks update where is my "replied" arrow & more missing

    I have upgraded to Mavericks. I should not have yet - too many bugs. Now, my devices are not syncing (also upgraded to iOS 7 on iPad and iPhone) -- My gmail is not syncing now so when I read an email on my phone, it does not show that i have read it