Explain plan cardinallity is way off compared to actual rows being returned

Database version 11.2.0.3
We have a small but rapidly growing datawarehouse which has OBIEE as its front end reporting tool. Our DBA has set up a automatic stats gathering method in OEM and we can see that it run and gathers stats on stale objects on a regular basis. So we know the statistics are upto date.
In checking some slow queries I can see that the cardinality being reported in explain plans is way off compared to what is actually being returned.
For example the actual number of rows returned are 8000 but the cardinality estimate is > 300,000.
Now as per an Oracle White paper(The Oracle Optimizer Explain the Explain Plan) having "multiple single column predicates on a single table" can affect cardinality estimates and in case of our query that is true. Here is the "WHERE Clause section" of the query
SQL> select D1.c1  as c1,
  2         D1.c2  as c2,
  3         D1.c3  as c3,
  4         D1.c4  as c4,
  5         D1.c5  as c5,
  6         D1.c6  as c6,
  7         D1.c7  as c7,
  8         D1.c8  as c8,
  9         D1.c9  as c9,
10         D1.c10 as c10,
11         D1.c11 as c11,
12         D1.c12 as c12,
13         D1.c13 as c13,
14         D1.c14 as c14,
15         D1.c15 as c15,
16         D1.c16 as c16
17    from (select D1.c4 as c1,
18                 D1.c5 as c2,
19                 D1.c3 as c3,
20                 D1.c1 as c4,
21                 D1.c6 as c5,
22                 D1.c7 as c6,
23                 D1.c2 as c7,
24                 D1.c8 as c8,
25                 D1.c9 as c9,
26                 D1.c10 as c10,
27                 D1.c9 as c11,
28                 D1.c11 as c12,
29                 D1.c2 as c13,
30                 D1.c2 as c14,
31                 D1.c12 as c15,
32                 'XYZ' as c16,
33                 ROW_NUMBER() OVER(PARTITION BY D1.c2, D1.c3, D1.c4, D1.c5, D1.c6, D1.c7, D1.c8, D1.c9, D1.c10, D1.c11, D1.c12 ORDER BY D1.c2 ASC, D1.c3 ASC, D1.c4 ASC, D1.c5 ASC, D1.c6 ASC, D1.c
ASC, D1.c8 ASC, D1.c9 ASC, D1.c10 ASC, D1.c11 ASC, D1.c12 ASC) as c17
34            from (select distinct D1.c1 as c1,
35                                  D1.c2 as c2,
36                                  'CHANNEL1' as c3,
37                                  D1.c3 as c4,
38                                  D1.c4 as c5,
39                                  D1.c5 as c6,
40                                  D1.c6 as c7,
41                                  D1.c7 as c8,
42                                  D1.c8 as c9,
43                                  D1.c9 as c10,
44                                  D1.c10 as c11,
45                                  D1.c11 as c12
46                    from (select sum(T610543.GLOBAL1_EXCHANGE_RATE * case
47                                       when T610543.X_ZEB_SYNC_EBS_FLG = 'Y' then
48                                        T610543.X_ZEB_AIA_U_REVN_AMT
49                                       else
50                                        0
51                                     end) as c1,
52                                 T536086.X_ZEBRA_TERRITORY as c2,
53                                 T526821.LEVEL9_NAME as c3,
54                                 T526821.LEVEL1_NAME as c4,
55                                 T577698.PER_NAME_FSCL_YEAR as c5,
56                                 T577698.FSCL_QTR as c6,
57                                 T31796.X_ZEBRA_TERRITORY as c7,
58                                 T31796.X_OU_NUM as c8,
59                                 T664055.TERRITORY as c9,
60                                 T536086.X_OU_NUM as c10,
61                                 T526821.LEVEL4_NAME as c11
62                            from W_INT_ORG_D        T613144 /* Dim_ZEB_W_INT_ORG_D_POS_Client_Attr_Direct */,
63                                 W_ZEBRA_REGION_D   T664055 /* Dim_ZEB_W_ZEBRA_REGION_D_POS_Client_Direct */,
64                                 W_DAY_D            T577698 /* Dim_ZEB_W_DAY_D_Order_Invoice_Date */,
65                                 WC_PRODUCT_HIER_DH T526821 /* Dim_WC_PRODUCT_HIER_DH */,
66                                 W_PRODUCT_D        T32069 /* Dim_W_PRODUCT_D */,
67                                 W_ORG_D            T31796,
68                                 W_ORG_D            T536086 /* Dim_ZEB_W_ORG_D_Reseller */,
69                                 W_ORDERITEM_TMP_F      T610543 /* Fact_ZEB_W_ORDERITEM_F_Direct */
70                           where (T610543.PR_OWNER_BU_WID = T613144.ROW_WID and
71                                 T577698.ROW_WID =
72                                 T610543.X_ZEB_AIA_TRXN_DT_WID and
73                                 T32069.ROW_WID = T526821.PROD_WID and
74                                 T32069.ROW_WID = T610543.ROOT_LN_PROD_WID and
75                                 T536086.ROW_WID = T610543.ACCNT_WID and
76                                 T31796.DATASOURCE_NUM_ID =
77                                 T610543.DATASOURCE_NUM_ID and
78                                 T31796.INTEGRATION_ID = T610543.VIS_PR_BU_ID and
79                                 T536086.DELETE_FLG = 'N' and
80                                 T610543.X_ZEB_DELETE_FLG = 'N' and
81                                 T613144.X_ZEB_REGION_WID = T664055.ROW_WID and
82                                 T577698.FSCL_DAY_OF_YEAR < 97 and
83                                 '2006' < T577698.PER_NAME_FSCL_YEAR and
84                                 T536086.X_OU_NUM <> '11073' and
85                                 T536086.X_ZEBRA_TERRITORY !=
86                                 'XX23' and
87                                 T536086.X_OU_NUM != '56791647728774' and
88                                 T536086.X_OU_NUM != '245395890' and
89                                 T536086.X_ZEBRA_TERRITORY !=
90                                 'STRATEGIC ACCTS 2' and
91                                 T526821.LEVEL2_NAME != 'Charges' and
92                                 T526821.LEVEL9_NAME != 'Unspecified' and
93                                 T536086.X_ZEBRA_TERRITORY !=
94                                 'XX1' and T536086.X_ZEBRA_TERRITORY !=
95                                 'XX2' and T536086.X_ZEBRA_TERRITORY !=
96                                 'XX3' and T536086.X_ZEBRA_TERRITORY !=
97                                 'XX4' and
98                                 (T536086.X_ZEBRA_TERRITORY in
99                                 ( ... In List of 22 values )) and
125                                 T32069.X_ZEB_EBS_PRODUCT_TYPE is null)
126                           group by T31796.X_ZEBRA_TERRITORY,
127                                    T31796.X_OU_NUM,
128                                    T526821.LEVEL1_NAME,
129                                    T526821.LEVEL4_NAME,
130                                    T526821.LEVEL9_NAME,
131                                    T536086.X_OU_NUM,
132                                    T536086.X_ZEBRA_TERRITORY,
133                                    T577698.FSCL_QTR,
134                                    T577698.PER_NAME_FSCL_YEAR,
135                                    T664055.TERRITORY) D1) D1) D1
136   where (D1.c17 = 1)
137  /
Elapsed: 00:00:35.19
Execution Plan
Plan hash value: 3285002974
| Id  | Operation                                         | Name               | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |
|   0 | SELECT STATEMENT                                  |                    |  2145M|  2123G|       |   612K  (1)| 03:03:47 |       |       |        |      |            |
|   1 |  PX COORDINATOR                                   |                    |       |       |       |            |          |       |       |        |      |            |
|   2 |   PX SEND QC (RANDOM)                             | :TQ10012           |  2145M|  2123G|       |   612K  (1)| 03:03:47 |       |       |  Q1,12 | P->S | QC (RAND)  |
|*  3 |    VIEW                                           |                    |  2145M|  2123G|       |   612K  (1)| 03:03:47 |       |       |  Q1,12 | PCWP |            |
|*  4 |     WINDOW NOSORT                                 |                    |  2145M|   421G|       |   612K  (1)| 03:03:47 |       |       |  Q1,12 | PCWP |            |
|   5 |      SORT GROUP BY                                |                    |  2145M|   421G|   448G|   612K  (1)| 03:03:47 |       |       |  Q1,12 | PCWP |            |
|   6 |       PX RECEIVE                                  |                    |  2145M|   421G|       |  1740  (11)| 00:00:32 |       |       |  Q1,12 | PCWP |            |
|   7 |        PX SEND HASH                               | :TQ10011           |  2145M|   421G|       |  1740  (11)| 00:00:32 |       |       |  Q1,11 | P->P | HASH       |
|*  8 |         HASH JOIN BUFFERED                        |                    |  2145M|   421G|       |  1740  (11)| 00:00:32 |       |       |  Q1,11 | PCWP |            |
|   9 |          PX RECEIVE                               |                    |   268K|  7864K|       |    93   (2)| 00:00:02 |       |       |  Q1,11 | PCWP |            |
|  10 |           PX SEND HASH                            | :TQ10009           |   268K|  7864K|       |    93   (2)| 00:00:02 |       |       |  Q1,09 | P->P | HASH       |
|  11 |            PX BLOCK ITERATOR                      |                    |   268K|  7864K|       |    93   (2)| 00:00:02 |       |       |  Q1,09 | PCWC |            |
|  12 |             TABLE ACCESS FULL                     | W_ORG_D            |   268K|  7864K|       |    93   (2)| 00:00:02 |       |       |  Q1,09 | PCWP |            |
|  13 |          PX RECEIVE                               |                    |   345K|    59M|       |  1491   (2)| 00:00:27 |       |       |  Q1,11 | PCWP |            |
|  14 |           PX SEND HASH                            | :TQ10010           |   345K|    59M|       |  1491   (2)| 00:00:27 |       |       |  Q1,10 | P->P | HASH       |
|* 15 |            HASH JOIN BUFFERED                     |                    |   345K|    59M|       |  1491   (2)| 00:00:27 |       |       |  Q1,10 | PCWP |            |
|  16 |             PX RECEIVE                            |                    |  1321 | 30383 |       |     2   (0)| 00:00:01 |       |       |  Q1,10 | PCWP |            |
|  17 |              PX SEND BROADCAST                    | :TQ10006           |  1321 | 30383 |       |     2   (0)| 00:00:01 |       |       |  Q1,06 | P->P | BROADCAST  |
|  18 |               PX BLOCK ITERATOR                   |                    |  1321 | 30383 |       |     2   (0)| 00:00:01 |       |       |  Q1,06 | PCWC |            |
|  19 |                TABLE ACCESS FULL                  | W_ZEBRA_REGION_D   |  1321 | 30383 |       |     2   (0)| 00:00:01 |       |       |  Q1,06 | PCWP |            |
|* 20 |             HASH JOIN                             |                    |   345K|    52M|       |  1488   (2)| 00:00:27 |       |       |  Q1,10 | PCWP |            |
|  21 |              JOIN FILTER CREATE                   | :BF0000            |  9740 |   114K|       |     2   (0)| 00:00:01 |       |       |  Q1,10 | PCWP |            |
|  22 |               PX RECEIVE                          |                    |  9740 |   114K|       |     2   (0)| 00:00:01 |       |       |  Q1,10 | PCWP |            |
|  23 |                PX SEND HASH                       | :TQ10007           |  9740 |   114K|       |     2   (0)| 00:00:01 |       |       |  Q1,07 | P->P | HASH       |
|  24 |                 PX BLOCK ITERATOR                 |                    |  9740 |   114K|       |     2   (0)| 00:00:01 |       |       |  Q1,07 | PCWC |            |
|  25 |                  TABLE ACCESS FULL                | W_INT_ORG_D        |  9740 |   114K|       |     2   (0)| 00:00:01 |       |       |  Q1,07 | PCWP |            |
|  26 |              PX RECEIVE                           |                    |   344K|    47M|       |  1486   (2)| 00:00:27 |       |       |  Q1,10 | PCWP |            |
|  27 |               PX SEND HASH                        | :TQ10008           |   344K|    47M|       |  1486   (2)| 00:00:27 |       |       |  Q1,08 | P->P | HASH       |
|  28 |                JOIN FILTER USE                    | :BF0000            |   344K|    47M|       |  1486   (2)| 00:00:27 |       |       |  Q1,08 | PCWP |            |
|* 29 |                 HASH JOIN BUFFERED                |                    |   344K|    47M|       |  1486   (2)| 00:00:27 |       |       |  Q1,08 | PCWP |            |
|  30 |                  JOIN FILTER CREATE               | :BF0001            | 35290 |   964K|       |    93   (2)| 00:00:02 |       |       |  Q1,08 | PCWP |            |
|  31 |                   PX RECEIVE                      |                    | 35290 |   964K|       |    93   (2)| 00:00:02 |       |       |  Q1,08 | PCWP |            |
|  32 |                    PX SEND HASH                   | :TQ10004           | 35290 |   964K|       |    93   (2)| 00:00:02 |       |       |  Q1,04 | P->P | HASH       |
|  33 |                     PX BLOCK ITERATOR             |                    | 35290 |   964K|       |    93   (2)| 00:00:02 |       |       |  Q1,04 | PCWC |            |
|* 34 |                      TABLE ACCESS FULL            | W_ORG_D            | 35290 |   964K|       |    93   (2)| 00:00:02 |       |       |  Q1,04 | PCWP |            |
|  35 |                  PX RECEIVE                       |                    |   344K|    38M|       |  1392   (2)| 00:00:26 |       |       |  Q1,08 | PCWP |            |
|  36 |                   PX SEND HASH                    | :TQ10005           |   344K|    38M|       |  1392   (2)| 00:00:26 |       |       |  Q1,05 | P->P | HASH       |
|  37 |                    JOIN FILTER USE                | :BF0001            |   344K|    38M|       |  1392   (2)| 00:00:26 |       |       |  Q1,05 | PCWP |            |
|* 38 |                     HASH JOIN BUFFERED            |                    |   344K|    38M|       |  1392   (2)| 00:00:26 |       |       |  Q1,05 | PCWP |            |
|  39 |                      PX RECEIVE                   |                    | 93791 |  4671K|       |     7   (0)| 00:00:01 |       |       |  Q1,05 | PCWP |            |
|  40 |                       PX SEND HASH                | :TQ10001           | 93791 |  4671K|       |     7   (0)| 00:00:01 |       |       |  Q1,01 | P->P | HASH       |
|  41 |                        PX BLOCK ITERATOR          |                    | 93791 |  4671K|       |     7   (0)| 00:00:01 |       |       |  Q1,01 | PCWC |            |
|* 42 |                         TABLE ACCESS FULL         | WC_PRODUCT_HIER_DH | 93791 |  4671K|       |     7   (0)| 00:00:01 |       |       |  Q1,01 | PCWP |            |
|* 43 |                      HASH JOIN                    |                    |   894K|    57M|       |  1384   (2)| 00:00:25 |       |       |  Q1,05 | PCWP |            |
|  44 |                       JOIN FILTER CREATE          | :BF0002            |   243K|  1904K|       |    48   (3)| 00:00:01 |       |       |  Q1,05 | PCWP |            |
|  45 |                        PX RECEIVE                 |                    |   243K|  1904K|       |    48   (3)| 00:00:01 |       |       |  Q1,05 | PCWP |            |
|  46 |                         PX SEND HASH              | :TQ10002           |   243K|  1904K|       |    48   (3)| 00:00:01 |       |       |  Q1,02 | P->P | HASH       |
|  47 |                          PX BLOCK ITERATOR        |                    |   243K|  1904K|       |    48   (3)| 00:00:01 |       |       |  Q1,02 | PCWC |            |
|* 48 |                           TABLE ACCESS FULL       | W_PRODUCT_D        |   243K|  1904K|       |    48   (3)| 00:00:01 |       |       |  Q1,02 | PCWP |            |
|  49 |                       PX RECEIVE                  |                    |   894K|    50M|       |  1336   (2)| 00:00:25 |       |       |  Q1,05 | PCWP |            |
|  50 |                        PX SEND HASH               | :TQ10003           |   894K|    50M|       |  1336   (2)| 00:00:25 |       |       |  Q1,03 | P->P | HASH       |
|  51 |                         JOIN FILTER USE           | :BF0002            |   894K|    50M|       |  1336   (2)| 00:00:25 |       |       |  Q1,03 | PCWP |            |
|* 52 |                          HASH JOIN                |                    |   894K|    50M|       |  1336   (2)| 00:00:25 |       |       |  Q1,03 | PCWP |            |
|  53 |                           PX RECEIVE              |                    |   292 |  3504 |       |   136   (0)| 00:00:03 |       |       |  Q1,03 | PCWP |            |
|  54 |                            PX SEND BROADCAST LOCAL| :TQ10000           |   292 |  3504 |       |   136   (0)| 00:00:03 |       |       |  Q1,00 | P->P | BCST LOCAL |
|  55 |                             PX BLOCK ITERATOR     |                    |   292 |  3504 |       |   136   (0)| 00:00:03 |       |       |  Q1,00 | PCWC |            |
|* 56 |                              TABLE ACCESS FULL    | W_DAY_D            |   292 |  3504 |       |   136   (0)| 00:00:03 |       |       |  Q1,00 | PCWP |            |
|  57 |                           PX BLOCK ITERATOR       |                    |  4801K|   215M|       |  1199   (2)| 00:00:22 |     1 |    11 |  Q1,03 | PCWC |            |
|* 58 |                            TABLE ACCESS FULL      | W_ORDERITEM_TMP_F  |  4801K|   215M|       |  1199   (2)| 00:00:22 |     1 |    44 |  Q1,03 | PCWP |            |
Note
   - dynamic sampling used for this statement (level=5)
Statistics
        498  recursive calls
       2046  db block gets
    1193630  consistent gets
      74398  physical reads
          0  redo size
     655170  bytes sent via SQL*Net to client
      11761  bytes received via SQL*Net from client
        541  SQL*Net roundtrips to/from client
         64  sorts (memory)
          0  sorts (disk)
       8090  rows processed
SQL>So my question is if, cardinality estimates are way off, is that an indicator that the explain plans being generated are sub-optimal?
Can you provide me with some tips or links to blog post or books on how I approach tuning such queries where cardinalities are not good?
Edited by: qqq on Apr 7, 2013 2:27 PM

As already asked in your other thread:
Please see the FAQ for how to post a tuning request and the information that you need to provide.
Part of that information is:
1. DDL for the table and indexes
2. The query being used
3. row counts for the table and for the predicates used in the query
4. info about stats. You did update the table and index stats didn't you?
5. The 'actual' execution plans.
An explain plan just shows what Oracle 'thinks' it is going to do. The actual plans show what Oracle actually 'did' do. Just because Oracle expected to save doesn't mean the savings were actually achieved.
When you post the plans use on the line before and on the line after to preserve formatting.
Your partial code is virtually unusable because of the missing conditions in the predicates. You need to use '!=' for 'not equals' if that's what those missing conditions are.
Please edit your post to use code tags, add the missing conditions and provide the other information needed for a tuning request.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • EXPLAIN PLAN estimate is WAY off!

    I used Explain Plan to estimate the time it will take to run a SQL query.
    This is the query:
    select to_char (a.calldate,'yyyy')as "date", a.CALL_TYPE_ABBR_NAME, b.name, sum(a.call_price) as "monthly revenue"
    from allcalls a, call_types b
    where a.CALL_TYPE_ABBR_NAME= b.code
    group by to_char (a.calldate,'yyyy'), a.CALL_TYPE_ABBR_NAME, b.name
    order by to_char (a.calldate,'yyyy'),a.CALL_TYPE_ABBR_NAME, b.name;
    allcalls table has 12,669,348 records and call_types has only 3.
    Both tables have been analyzed.
    The query actually takes only 2 minutes and 21 seconds to complete execution.
    But according to EXPLAIN PLAN and SELECT plan_table_output FROM table(dbms_xplan.display) it will take 2 hours. The output of the table(dbms_xplan.display) is:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD></HEAD>
    <BODY><!--StartFragment--><TABLE>
    <TBODY>
    <TR bgcolor=#afafaf>
    <TD><B>PLAN_TABLE_OUTPUT</B></TD></TR><TR>
    <TD>Plan hash value: 3083213950</TD>
    </TR>
    <TR>
    <TD> </TD>
    </TR>
    <TR>
    <TD>------------------------------------------------------------------------------------------</TD>
    </TR>
    <TR>
    <TD>| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |</TD>
    </TR>
    <TR>
    <TD>------------------------------------------------------------------------------------------</TD>
    </TR>
    <TR>
    <TD>| 0 | SELECT STATEMENT | | 12M| 241M| | 215K (1)| 00:43:05 |</TD>
    </TR>
    <TR>
    <TD>| 1 | SORT GROUP BY | | 12M| 241M| 776M| 215K (1)| 00:43:05 |</TD>
    </TR>
    <TR>
    <TD>|* 2 | HASH JOIN | | 12M| 241M| | 138K (1)| 00:27:40 |</TD>
    </TR>
    <TR>
    <TD>| 3 | TABLE ACCESS FULL| CALL_TYPES | 3 | 30 | | 3 (0)| 00:00:01 |</TD>
    </TR>
    <TR>
    <TD>| 4 | TABLE ACCESS FULL| ALLCALLS | 12M| 120M| | 138K (1)| 00:27:39 |</TD>
    </TR>
    <TR>
    <TD>------------------------------------------------------------------------------------------</TD>
    </TR>
    <TR>
    <TD> </TD>
    </TR>
    <TR>
    <TD>Predicate Information (identified by operation id):</TD>
    </TR>
    <TR>
    <TD>---------------------------------------------------</TD>
    </TR>
    <TR>
    <TD> </TD>
    </TR>
    <TR>
    <TD> 2 - access("A"."CALL_TYPE_ABBR_NAME"="B"."CODE")</TD>
    </TR>
    </TBODY></TABLE><!--EndFragment--></BODY>
    </HTML>
    So, it's basically useless to rely on EXPLAIN PLAIN to estimate the time it will take to run a query? Or is there something else we can do to get the estimate better?

    Hello Channa,
    You are really going about this thing the wrong way... but... you have amused a few :)
    As you've been told (a number of times and, a number of different ways :) ) any attempt at pegging the execution time of a SQL statement is quite futile and rather irrelevant to boot.
    This is what I suggest you do:
    1. Whatever application you are selling, it must handle a certain volume of data. Since I don't know anything about the application you're selling, I'm going to give you an example while pulling numbers out of my magic hat ;) . Let's presume that your application should handle reasonably well 12,000,000 rows spread across 100 tables and, that there are a number of reports that are run with greater frequency than others. (since you know your application, you'll need to adjust these numbers for whatever are representative numbers for your app).
    1.1 As an aside, I would not tell a prospective customer that you've tested the system using 14 rows. That could turn a few of them off ;) In other words, would you buy a database product from anyone that told you "Oh yeah! we tested it with 14 rows, it did great! ... runs like champ!" ? probably not. That's why you need larger numbers as pointed out in 1. above.
    2. Once you have a setup with a reasonable number of rows ;) you run whatever reports are important to your customers and you time them. The timings don't have to be exact, they'll vary but, everything being kept equal, the variation won't be as dramatic as using 14 rows ;)
    2.1 Given a reasonable test sample - meaning: more rows than there are donuts in a cop's car at 7:00 a.m - you customarily throw away the best and worst run times because those are often not representative.
    2.2 You compute an average and a standard deviation (this is not hard to do)
    2.3 You tell your customers that in order to get similar results to what you've presented they need xyz hardware configuration. In other words, you qualify the environment in which those results can be obtained.
    If someone asks for an exact figure, you tell them that there are refreshments on the table ;) or, if you are so inclined, you explain that exact is not possible.
    HTH,
    John.

  • Explain plan different with no stats but with no rows & rows in a table

    Hi All,
    This is in Oracle 8.1.7.4.0 DB.
    1. Query was taking long time to return rows. It was based on a view.
    2. View has multiple tables.
    3. The explain plan was showing one of the Table(e.g. TABLE1) using incorrect INDEX. At the time of explain plan table has no statistics.
    4. truncated Table TABLE1
    5. The explain plan now taking correct INDEX for the table TABLE1.
    How does optimizer choosing the incorrect index when rows in a table & correct index when there are no rows in the table ?
    any insights.
    Thanks
    Sandeep

    I don't know about your particular db version, but CBO in absence of statistics uses some default values (e.g. average row length 100 bytes) and also uses actual number of block for the table. I assume something similar might be for indexes.
    To be sure what has changed you can run 10053 level trace.
    Gints Plivna
    http://www.gplivna.eu

  • Clip duration way off compared to original file

    I have looked around like crazy and I am resorting to posting something about it.
    I am using Premiere Elements, getting media from WDM device in Premiere with a VCR attached to a TV tuner card.  Premiere sees and records the video no issue.  The organizer and every program under the sun see's a 48 minute .avi file.
    The problem occurs when I send it to Premiere Elements it only sees it as being 2 minutes and 30 seconds long.
    Clearly this a Duration Flag issue in which premiere sees the wrong duration, but how do I fix this?
    I have seen several posts in this regards, but no one has posted a true fix.  I have found that I can import it into Windows Movie Maker and export it as a .wmv, but that is another step that I dont really want to have to take with every VHS that I record.
    Anyone have any ideas?
    Thanks in advance.

    Hi, omega7441. Premiere Elements has its own forum, which is here:
    http://forums.adobe.com/community/premiere_elements
    and you'll usually get better answers to video questions if you post there.
    Good luck!

  • Explain plan only in spool file

    Hi there,
    I am trying to spool only my explain plan to a file, at the moment i can only return all the results and then explain plan to the file. This is a bit of a problem as i am running some rather long queries and some of them return over 80MB of data. this is what i have so far:
    set termout off
    timing start
    set autotrace on
    set heading off
    spool h:\test1.lst
    select unique1 from table1;
    timing stop
    spool off
    set autotrace off
    set termout on
    any help on this would be great.
    Thanks!

    Or for a handy way to preview the expected plan without executing the query, try www.williamrobertson.net/code/xplan.sql
    SQL> SELECT COUNT(*) FROM dept d
      2  WHERE  EXISTS
      3         ( SELECT NULL FROM emp e
      4           WHERE  e.deptno = d.deptno )
      5 
    SQL> -- Note we did not execute anything...
    SQL> @xplan
    Plan hash value: 4196393176
    | Id  | Operation            | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |         |     1 |     6 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE      |         |     1 |     6 |            |          |
    |   2 |   NESTED LOOPS       |         |     3 |    18 |     4  (25)| 00:00:01 |
    |   3 |    SORT UNIQUE       |         |    14 |    42 |     3   (0)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL| EMP     |    14 |    42 |     3   (0)| 00:00:01 |
    |*  5 |    INDEX UNIQUE SCAN | PK_DEPT |     1 |     3 |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       5 - access("E"."DEPTNO"="D"."DEPTNO")
    SQL> -- And the query is still there:
    SQL> l
      1  SELECT COUNT(*) FROM dept d
      2  WHERE  EXISTS
      3         ( SELECT NULL FROM emp e
      4*          WHERE  e.deptno = d.deptno )

  • Explain Plan Understanding

    Hi,
    Is this both plan are same. Table names are change. Both execution wise would choose same plan of execution
    No Hint
    | Id  | Operation              | Name        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |                                                                                                                                                                                   
    |   0 | INSERT STATEMENT       |             |  1285M|   326G|       |    45M  (1)|178:06:59 |       |       |                                                                                                                                                                                    
    |   1 |  LOAD AS SELECT        | E           |       |       |       |            |          |       |       |                                                                                                                                                                                    
    |*  2 |   HASH JOIN            |             |  1285M|   326G|  5153M|    45M  (1)|178:06:59 |       |       |                                                                                                                                                                                    
    |   3 |    TABLE ACCESS FULL   | D           |   135M|  3607M|       |   254K  (2)| 00:59:17 |       |       |                                                                                                                                                                                    
    |*  4 |    HASH JOIN           |             |  1261M|   287G|  2857M|    32M  (1)|124:52:03 |       |       |                                                                                                                                                                                    
    |   5 |     TABLE ACCESS FULL  | C           |    76M|  1978M|       |   143K  (2)| 00:33:33 |       |       |                                                                                                                                                                                    
    |*  6 |     HASH JOIN          |             |  1241M|   252G|  1727M|    20M  (1)| 78:33:50 |       |       |                                                                                                                                                                                   
    |   7 |      TABLE ACCESS FULL | B           |    54M|  1099M|       | 23217   (4)| 00:05:26 |       |       |                                                                                                                                                                                   
    |   8 |      PARTITION HASH ALL|             |  1241M|   227G|       |  3452K  (4)| 13:25:29 |     1 |    64 |                                                                                                                                                                                    
    |   9 |       TABLE ACCESS FULL| A           |  1241M|   227G|       |  3452K  (4)| 13:25:29 |     1 |    64 |                                                                                                                                                                                    
    Fix card for table A with 10M
    | Id  | Operation              | Name        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |                                                                                                                                                                                   
    |   0 | INSERT STATEMENT       |             |    10M|  2696M|       |  4578K  (1)| 17:48:26 |       |       |                                                                                                                                                                                    
    |   1 |  LOAD AS SELECT        | E           |       |       |       |            |          |       |       |                                                                                                                                                                                    
    |*  2 |   HASH JOIN            |             |    10M|  2696M|  2491M|  4578K  (1)| 17:48:26 |       |       |                                                                                                                                                                                    
    |*  3 |    HASH JOIN           |             |    10M|  2374M|  2193M|  3996K  (1)| 15:32:36 |       |       |                                                                                                                                                                                   
    |*  4 |     HASH JOIN          |             |    10M|  2079M|  1727M|  3636K  (1)| 14:08:30 |       |       |                                                                                                                                                                                   
    |   5 |      TABLE ACCESS FULL | B           |    54M|  1099M|       | 23217   (4)| 00:05:26 |       |       |                                                                                                                                                                                    
    |   6 |      PARTITION HASH ALL|             |    10M|  1878M|       |  3362K  (1)| 13:04:42 |     1 |    64 |                                                                                                                                                                                    
    |   7 |       TABLE ACCESS FULL| A           |    10M|  1878M|       |  3362K  (1)| 13:04:42 |     1 |    64 |                                                                                                                                                                                    
    |   8 |     TABLE ACCESS FULL  | C           |    76M|  1978M|       |   143K  (2)| 00:33:33 |       |       |                                                                                                                                                                                    
    |   9 |    TABLE ACCESS FULL   | D           |   135M|  3607M|       |   254K  (2)| 00:59:17 |       |       |                                                                                                                                                                                   
    Also, both have same predicates
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       2 - access(A."ID"="D"."ID")                                                                                                                                                                                                                                                         
       3 - access("A"."E_ID"="C"."E_ID")                                                                                                                                                                                                                                                        
       4 - access("A"."M_ID"="B"."M_ID")                                                                                                                                   If my understanding is right then
    1. A Is hashed and then Join with B with hash join. While accessing B will apply predicate 4
    2. Then result will be joined to C while with hash join while accessing C will apply using 3 access predicate
    3. Then result will be applied to D
    4. Then will load with direct path to E
    Is not the case please explain both in details and also, please let me know which is best with some guidance and explanation

    Taral Desai wrote:
    Hi,
    Is this both plan are same. Table names are change. Both execution wise would choose same plan of execution
    No Hint
    | Id  | Operation              | Name        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |                                                                                                                                                                                   
    |   0 | INSERT STATEMENT       |             |  1285M|   326G|       |    45M  (1)|178:06:59 |       |       |                                                                                                                                                                                    
    |   1 |  LOAD AS SELECT        | E           |       |       |       |            |          |       |       |                                                                                                                                                                                    
    |*  2 |   HASH JOIN            |             |  1285M|   326G|  5153M|    45M  (1)|178:06:59 |       |       |                                                                                                                                                                                    
    |   3 |    TABLE ACCESS FULL   | D           |   135M|  3607M|       |   254K  (2)| 00:59:17 |       |       |                                                                                                                                                                                    
    |*  4 |    HASH JOIN           |             |  1261M|   287G|  2857M|    32M  (1)|124:52:03 |       |       |                                                                                                                                                                                    
    |   5 |     TABLE ACCESS FULL  | C           |    76M|  1978M|       |   143K  (2)| 00:33:33 |       |       |                                                                                                                                                                                    
    |*  6 |     HASH JOIN          |             |  1241M|   252G|  1727M|    20M  (1)| 78:33:50 |       |       |                                                                                                                                                                                   
    |   7 |      TABLE ACCESS FULL | B           |    54M|  1099M|       | 23217   (4)| 00:05:26 |       |       |                                                                                                                                                                                   
    |   8 |      PARTITION HASH ALL|             |  1241M|   227G|       |  3452K  (4)| 13:25:29 |     1 |    64 |                                                                                                                                                                                    
    |   9 |       TABLE ACCESS FULL| A           |  1241M|   227G|       |  3452K  (4)| 13:25:29 |     1 |    64 |                                                                                                                                                                                    
    Fix card for table A with 10M
    | Id  | Operation              | Name        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |                                                                                                                                                                                   
    |   0 | INSERT STATEMENT       |             |    10M|  2696M|       |  4578K  (1)| 17:48:26 |       |       |                                                                                                                                                                                    
    |   1 |  LOAD AS SELECT        | E           |       |       |       |            |          |       |       |                                                                                                                                                                                    
    |*  2 |   HASH JOIN            |             |    10M|  2696M|  2491M|  4578K  (1)| 17:48:26 |       |       |                                                                                                                                                                                    
    |*  3 |    HASH JOIN           |             |    10M|  2374M|  2193M|  3996K  (1)| 15:32:36 |       |       |                                                                                                                                                                                   
    |*  4 |     HASH JOIN          |             |    10M|  2079M|  1727M|  3636K  (1)| 14:08:30 |       |       |                                                                                                                                                                                   
    |   5 |      TABLE ACCESS FULL | B           |    54M|  1099M|       | 23217   (4)| 00:05:26 |       |       |                                                                                                                                                                                    
    |   6 |      PARTITION HASH ALL|             |    10M|  1878M|       |  3362K  (1)| 13:04:42 |     1 |    64 |                                                                                                                                                                                    
    |   7 |       TABLE ACCESS FULL| A           |    10M|  1878M|       |  3362K  (1)| 13:04:42 |     1 |    64 |                                                                                                                                                                                    
    |   8 |     TABLE ACCESS FULL  | C           |    76M|  1978M|       |   143K  (2)| 00:33:33 |       |       |                                                                                                                                                                                    
    |   9 |    TABLE ACCESS FULL   | D           |   135M|  3607M|       |   254K  (2)| 00:59:17 |       |       |                                                                                                                                                                                   
    Also, both have same predicates
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
    2 - access(A."ID"="D"."ID")                                                                                                                                                                                                                                                         
    3 - access("A"."E_ID"="C"."E_ID")                                                                                                                                                                                                                                                        
    4 - access("A"."M_ID"="B"."M_ID")                                                                                                                                   If my understanding is right then
    1. A Is hashed and then Join with B with hash join. While accessing B will apply predicate 4
    2. Then result will be joined to C while with hash join while accessing C will apply using 3 access predicate
    3. Then result will be applied to D
    4. Then will load with direct path to E
    Is not the case please explain both in details and also, please let me know which is best with some guidance and explanationBoth the explain plan are good when you compare the number of rows in each table.
    Here I see for same table optimizer is taking different number of rows in both the xplain plan.
    Are they both generated on same database or different different database?
    It is always better to do a hash on small table and join to the bigger table which it is doing in both the plan
    Regards
    Anurag

  • Understanding explain plan

    Oracle Gurus,
    I am trying to understand the below explain plan which I generated using DBMS_XPLAN. This explain plan shows 380M cost, what do "M" and "K" mean here? If anyone has any good documentation to understand explain plan, please pass on.
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
    | 0 | INSERT STATEMENT | | 9 | 801 | 380M(100)| 09:11:35 | | | | | |
    | 1 | HASH UNIQUE | | 9 | 801 | 380M(100)| 09:11:35 | | | | | |
    |* 2 | FILTER | | | | | | | | | | |
    | 3 | PX COORDINATOR | | | | | | | | | | |
    | 4 | PX SEND QC (RANDOM) | :TQ10002 | 3625K| 307M| 4282 (70)| 00:00:01 | | | Q1,02 | P->S | QC (RAND) |
    |* 5 | HASH JOIN BUFFERED | | 3625K| 307M| 4282 (70)| 00:00:01 | | | Q1,02 | PCWP | |
    | 6 | PX RECEIVE | | 362K| 14M| 1219 (52)| 00:00:01 | | | Q1,02 | PCWP | |
    | 7 | PX SEND HASH | :TQ10000 | 362K| 14M| 1219 (52)| 00:00:01 | | | Q1,00 | P->P | HASH |
    | 8 | PX BLOCK ITERATOR | | 362K| 14M| 1219 (52)| 00:00:01 | 7 | 7 | Q1,00 | PCWC | |
    |* 9 | TABLE ACCESS FULL | TOP10_UL_SECTOR_LUCENT | 362K| 14M| 1219 (52)| 00:00:01 | 7 | 7 | Q1,00 | PCWP | |
    | 10 | PX RECEIVE | | 411K| 18M| 1427 (52)| 00:00:01 | | | Q1,02 | PCWP | |
    | 11 | PX SEND HASH | :TQ10001 | 411K| 18M| 1427 (52)| 00:00:01 | | | Q1,01 | P->P | HASH |
    | 12 | PX BLOCK ITERATOR | | 411K| 18M| 1427 (52)| 00:00:01 | 182 | 212 | Q1,01 | PCWC | |
    |* 13 | TABLE ACCESS FULL | BH_UL_SECTOR_LUCENT | 411K| 18M| 1427 (52)| 00:00:01 | 182 | 212 | Q1,01 | PCWP | |
    | 14 | SORT AGGREGATE | | 1 | 14 | | | | | | | |
    | 15 | PARTITION RANGE ITERATOR| | 10 | 140 | 120 (100)| 00:00:01 | 182 | 212 | | | |
    |* 16 | INDEX SKIP SCAN | IDX2_BH_UL_SECTOR_LUCENT | 10 | 140 | 120 (100)| 00:00:01 | 182 | 212 | | | |
    -----------------------------------------------------------------------------------------------------------------------------------------------------

    Hello,
    Once again K is number of (1000) rows fetched and M is for bytes repsentation. Check this oracle doc for reading xplan
    Cost of the operation as estimated by the optimizer's query approach. Cost is not determined for table access operations. The value of this column does not have any particular unit of measurement; it is merely a weighted value used to compare costs of execution plans. The value of this column is a function of the CPU_COST and IO_COST columns
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/ex_plan.htm#i16971
    Regards

  • Explain Plan for Procedure

    Hi,
    For getting the explain plan for a query, we use the statement
    "explain plan for " + Query
    Similarly, to get an explain plan for a procedure, do we have any way like
    "explain plan for " + "Execute " + Procedure
    How do we get an explain plan for a procedure that is executed
    Thanks in Advance.

    teckfreak wrote:
    Hi Robert,
    I am working on an utility application which will execute the procedure and show the explain plan to the user for him to analyze the explain plan and take necessary steps for optimization. I am showing the Procedure inputs to the user, allowing him to enter values and taking them and executing the procedure. I am setting the trace and extracting the explain plan for the procedure using TKPROF utility and showing it to the user.
    While doing so, the trace file is stored in udump folder. I am accessing the trace file from TKPROF utility. I am able to run the TKPROF from the command prompt. But if I try automating the TKPROF command in a .NET application using Process.Start, it says "Not able to access the file.". I tried giving full permissions to Everyone and it still throws the error. Kindly guide me how to proceed.. A different approach that you might want to consider (as indicated by William):
    - Flush the shared pool and use a unique MODULE description for each execution of your procedure (e.g. using DBMS_APPLICATION_INFO.SET_MODULE), e.g. using a logon trigger
    - Query V$SQL for your unique MODULE description and run DBMS_XPLAN.DISPLAY_CURSOR for each corresponding child cursor found (SQL_ID + CHILD_NUMBER) in the shared pool. This plan generation could be automated using a procedure
    The result of this approach corresponds to the tracing using TKPROF since it will provide the actual execution plans used at runtime rather than separate EXPLAIN PLAN results which might differ from the actual plans.
    This assumes that your shared pool is sufficiently large to hold all the child cursor created by your procedure without aging them out while the procedure is running. It's probably also only applicable to an environment where not too much work is being done while running this test and the recommended flushing of the shared pool.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Hi when i run this in toad for explain plan  its showing an error ORA_22905

    hi when i run this query in toad for explain plan its showing an error ORA_22905 cannot accesss rows from an non nested table item can anyone help me out
    SELECT
    DISTINCT SERVICE_TBL.SERVICE_ID , SERVICE_TBL.CON_TYPE, SERVICE_TBL.S_DESC || '(' || SERVICE_TBL.CON_TYPE || ')' AS SERVICE_DESC ,SERVICE_TBL.CON_STAT
    FROM
    TABLE(:B1 )SERVICE_TBL
    WHERE
    CON_NUM = :B2
    thanks

    Note the name of this forum is SQL Developer *(Not for general SQL/PLSQL questions)* (so for issues with the SQL Developer tool). Please post these questions under the dedicated SQL And PL/SQL forum.
    Regards,
    K.

  • Efficient way to read through big explain plan and genterate html explain plan for sql id's executed in past

    Hi,
    I have a sql which is recently having a performance problems in Production. I have generated a explain plan for it trying to find out what it is doing but plan itself is close to 1000 lines. I want to check if there is any efficient way to go through big plan like this one and quickly find the damaging areas..
    2) I also wanted to know if there is way to generate explain plans in HTML format which executed in past and have entry in dba_hist_sqltext.
    3) I also have two sql_monitor reports which I want to compare. is there any efficient way to do it as well?
    Please share your thoughts!
    Thanks in advance!
    Regards,
    Suman-

    Hi,
    I suggest you can try running sql advisor on the query maybe something fruitful comes up
    http://www.oracle-base.com/articles/11g/sql-access-advisor-11gr1.php
    I am not sure about the explain plan being printed in html format but
    You may also want to try the sqlhistory.sql query from below page
    http://evdbt.com/scripts/
    I have used it many times to check on executions and explain plans which may have changed over the period
    I have faced it many times , the query picks up a bad explain plan and performs poorly

  • Save and Compare Explain Plans

    We have a requirement to save all explain plans per statement run out of two long-running batch jobs. The purpose is to be able to compare these plans before/after upgrades. patches, or tuning. The environement is:
    O/S: Tru-64 Unix
    DB: Oracle 9.2.0.4
    I am not having much luck finding anything at all about this anywhere on the web.
    Has anyone done anything like this or have any ideas on how it can be done (all ideas are welcome)?
    Thank you.

    You've got a variety of options
    - You can do 10046 event traces on the jobs, run those through tkprof, and store the results off
    - You can run the jobs and periodically query the data dictionary looking for new SQL statements (and their plans) in the shared pool
    - You can capture the SQL being run and just do an EXPLAIN PLAN on each query
    - You can use optimizer plan stability to generate outlines for every statement run as part of the jobs and store off those outlines for comparison
    Justin

  • Explain plan - lower cost but higher response time in 11g compared to 10g

    Hello,
    I have a strange scenario where 'm migrating a db from standalone Sun FS running 10g RDBMS to a 2-Node Sun/ASM 11g RAC env. The issue is with response time of queries -
    In 11g Env:
    SQL> select last_analyzed, num_rows from dba_tables where owner='MARKETHEALTH' and table_name='NCP_DETAIL_TAB';
    LAST_ANALYZED NUM_ROWS
    11-08-2012 18:21:12 3413956
    Elapsed: 00:00:00.30
    In 10g Env:
    SQL> select last_analyzed, num_rows from dba_tables where owner='MARKETHEALTH' and table_name='NCP_DETAIL_TAB';
    LAST_ANAL NUM_ROWS
    07-NOV-12 3502160
    Elapsed: 00:00:00.04If you look @ the response times, even a simple query on the dba_tables takes ~8 times. Any ideas what might be causing this? I have compared the XPlans and they are exactly the same, moreover, the cost is less in the 11g env compared to the 10g env, but still the response time is higher.
    BTW - 'm running the queries directly on the server, so no network latency in play here.
    Thanks in advance
    aBBy.

    *11g Env:*
    PLAN_TABLE_OUTPUT
    Plan hash value: 4147636274
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1104 | 376K| 394 (1)| 00:00:05 |
    | 1 | SORT ORDER BY | | 1104 | 376K| 394 (1)| 00:00:05 |
    | 2 | TABLE ACCESS BY INDEX ROWID| NCP_DETAIL_TAB | 1104 | 376K| 393 (1)| 00:00:05 |
    |* 3 | INDEX RANGE SCAN | IDX_NCP_DET_TAB_US | 1136 | | 15 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    3 - access("UNIT_ID"='ten03.burien.wa.seattle.comcast.net')
    15 rows selected.
    *10g Env:*
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 4147636274
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1137 | 373K| 389 (1)| 00:00:05 |
    | 1 | SORT ORDER BY | | 1137 | 373K| 389 (1)| 00:00:05 |
    | 2 | TABLE ACCESS BY INDEX ROWID| NCP_DETAIL_TAB | 1137 | 373K| 388 (1)| 00:00:05 |
    |* 3 | INDEX RANGE SCAN | IDX_NCP_DET_TAB_US | 1137 | | 15 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    3 - access("UNIT_ID"='ten03.burien.wa.seattle.comcast.net')
    15 rows selected.
    The query used is:
    explain plan for
    select
    NCP_DETAIL_ID ,
    NCP_ID ,
    STATUS_ID ,
    FIBER_NODE ,
    NODE_DESC ,
    GL ,
    FTA_ID ,
    OLD_BUS_ID ,
    VIRTUAL_NODE_IND ,
    SERVICE_DELIVERY_TYPE ,
    HHP_AUDIT_QTY ,
    COMMUNITY_SERVED ,
    CMTS_CARD_ID ,
    OPTICAL_TRANSMITTER ,
    OPTICAL_RECEIVER ,
    LASER_GROUP_ID ,
    UNIT_ID ,
    DS_SLOT ,
    DOWNSTREAM_PORT_ID ,
    DS_PORT_OR_MOD_RF_CHAN ,
    DOWNSTREAM_FREQ ,
    DOWNSTREAM_MODULATION ,
    UPSTREAM_PORT_ID ,
    UPSTREAM_PORT ,
    UPSTREAM_FREQ ,
    UPSTREAM_MODULATION ,
    UPSTREAM_WIDTH ,
    UPSTREAM_LOGICAL_PORT ,
    UPSTREAM_PHYSICAL_PORT ,
    NCP_DETAIL_COMMENTS ,
    ROW_CHANGE_IND ,
    STATUS_DATE ,
    STATUS_USER ,
    MODEM_COUNT ,
    NODE_ID ,
    NODE_FIELD_ID ,
    CREATE_USER ,
    CREATE_DT ,
    LAST_CHANGE_USER ,
    LAST_CHANGE_DT ,
    UNIT_ID_IP ,
    US_SLOT ,
    MOD_RF_CHAN_ID ,
    DOWNSTREAM_LOGICAL_PORT ,
    STATE
    from markethealth.NCP_DETAIL_TAB
    WHERE UNIT_ID = :B1
    ORDER BY UNIT_ID, DS_SLOT, DS_PORT_OR_MOD_RF_CHAN, FIBER_NODE
    This is the query used for Query 1.
    Stats differences are:
    1. Rownum differes by apprx - 90K more rows in 10g env
    2. RAC env has 4 additional columns (excluded in the select statement for analysis purposes).
    3. Gather Stats was performed with estimate_percent = 20 in 10g and estimate_percent = 50 in 11g.

  • Quick way to look at explain plan for executing a package?

    I can look at explain plans for queries without any problem. But i'm troubleshooting the performance of executing a package and i'm wondering if there is a way to look at what's happening without using EM tools? i.e. command lines.
    for queries, i've used set autotrace on or explain plan for query...
    but how do you do this for the execution of a package?

    Thanks for the reply..i've tried sql_trace=TRUE but somehow i don't get the execution plan..i only see the number of parses, executes and fetches...
    e.g. in my tkprof output, i have:
    one of the select statements is here
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.00 0.00 0 6 0 0
    total 3 0.00 0.00 0 6 0 0
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 58 (recursive depth: 1)
    But there is no execution plan..i've never done this when executing a package...what am i missing? this works fine for query statements..but not for packages..

  • Comparing Explain Plans

    I have a Oracle 10g R2 Database. It is on ALL_ROWS.
    I have a sql query as follows:
    SELECT COUNT (*) , LPAD(EMPLOYEE_ID , 7 , '0' ) ,
    LPAD(INSURED_ID , 2 , '0' )
    FROM EMPDPN_POLICY_DT
    WHERE LPAD(CLIENT_ID , 5 , '0' ) = :1 GROUP BY
    LPAD(CLIENT_ID , 5 , '0' ) , LPAD(EMPLOYEE_ID , 7 , '0' ) ,
    LPAD(INSURED_ID , 2 , '0' ) HAVING COUNT (*) > 1
    This is the explain plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 4034831743
    Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    0 | SELECT STATEMENT | | 46 | 782 | 124 (11)| 00:00:02 |
    * 1 | FILTER | | | | | |
    2 | HASH GROUP BY | | 46 | 782 | 124 (11)| 00:00:02 |
    * 3 | INDEX FAST FULL SCAN| EMPDPN_POLICY_DT_1 | 911 | 15487 | 123 (10)| 00:00:02 |
    This is when no index is used, instead a table scan takes place.
    PLAN_TABLE_OUTPUT
    Plan hash value: 3002308830
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 46 | 782 | 547 (4)| 00:00:07 |
    |* 1 | FILTER | | | | | |
    | 2 | HASH GROUP BY | | 46 | 782 | 547 (4)| 00:00:07 |
    |* 3 | TABLE ACCESS FULL| EMPDPN_POLICY_DT | 911 | 15487 | 546 (3)| 00:00:07 |
    But why as the %CPU cost decreased? Any explanation?
    Thanks
    Adith

    My interpretation:
    Because, when doing a full scan of a table, the
    1. hash value calculation to find index entry
    2. address translation with rowid
    3. mapping to actual row in table and getting row (involving disk operation)
    4. and disk operations (involved for index lookup)
    are not needed. Its just a plain disk operation to read the values from table and perform a grouping operation.
    I may not have used the correct words though.

  • Help in interpreting the output of explain plan

    Hi,
    I have written a query in two different ways and then run an explain plan on both of them. Both these queries give same result. I want to know which one will be more efficient. I am giving the output of explain plan for both the queries:
    The second plan has a lower cost but has much higher consistent gets !!
    Please advise.
    Plan 1:
    Execution Plan
       0      SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=8637 Card= 1 Bytes=10132)
       1    0   SORT (ORDER BY) (Cost=8637 Card=1 Bytes=10132)
       2    1     WINDOW (SORT) (Cost=8637 Card=1 Bytes=10132)
       3    2       COUNT (STOPKEY)
       4    3         VIEW (Cost=8635 Card=1 Bytes=10132)
       5    4           SORT (ORDER BY) (Cost=8635 Card=1 Bytes=862)
       6    5             WINDOW (SORT) (Cost=8635 Card=1 Bytes=862)
       7    6               MAT_VIEW ACCESS (FULL) OF 'PRD_SEARCH_MVW' (MAT_VIEW) (Cost=8633 Card=1 Bytes=862)
    Statistics
            577  recursive calls
              0  db block gets
          39202  consistent gets
          34798  physical reads
              0  redo size
          72348  bytes sent via SQL*Net to client
           4295  bytes received via SQL*Net from client
              9  SQL*Net roundtrips to/from client
             10  sorts (memory)
              0  sorts (disk)
            100  rows processed
    Plan-2
    Execution Plan
       0      SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=982 Card=1 Bytes=10145)
       1    0   SORT (ORDER BY) (Cost=982 Card=1 Bytes=10145)
       2    1     WINDOW (SORT) (Cost=982 Card=1 Bytes=10145)
       3    2       COUNT (STOPKEY)
       4    3         VIEW (Cost=980 Card=1 Bytes=10145)
       5    4           SORT (ORDER BY) (Cost=980 Card=1 Bytes=10132)
       6    5             WINDOW (SORT) (Cost=980 Card=1 Bytes=10132)
       7    6               WINDOW (SORT) (Cost=980 Card=1 Bytes=10132)
       8    7                 VIEW (Cost=977 Card=1 Bytes=10132)
       9    8                   WINDOW (SORT PUSHED RANK) (Cost=977 Card=1 Bytes=889)
      10    9                     NESTED LOOPS (Cost=976 Card=1 Bytes=889)
      11   10                       HASH JOIN (Cost=305 Card=670 Bytes=18090)
      12   11                         HASH JOIN (Cost=23 Card=140 Bytes=2240)
      13   12                           INDEX (FAST FULL SCAN) OF 'GLCAT_GRP_TO_CAT_PK' (INDEX (UNIQUE)) (Cost=2 Card=52 Bytes=364)
      14   12                           MAT_VIEW ACCESS (FULL) OF 'GLCAT_CAT_TO_MCAT' (MAT_VIEW) (Cost=20 Card=1039 Bytes=9351)
      15   11                         INDEX (FAST FULL SCAN) OF 'PCITEM2GLCATMCAT_FK_IDS' (INDEX) (Cost=281 Card=16903 Bytes=185933)
      16   10                       MAT_VIEW ACCESS (BY INDEX ROWID) OF 'PRD_SEARCH_MVW' (MAT_VIEW) (Cost=1 Card=1 Bytes=862)
      17   16                         INDEX (UNIQUE SCAN) OF 'PK_PRD_SEARCH_ID' (INDEX (UNIQUE)) (Cost=0 Card=1)
    Statistics
            481    recursive calls
              2      db block gets
         195742  consistent gets
           7516  physical reads
              0  redo size
          71567  bytes sent via SQL*Net to client
           6629  bytes received via SQL*Net from client
              9  SQL*Net roundtrips to/from client
             15  sorts (memory)
              1  sorts (disk)
            100  rows processedRegards
    Madhup
    Message was edited by:
    Madhup

    Thanks a lot for you input. I am posting both the queries below. My requirements are following:
    1) I have a products table
    2) I have Created grouping hierarchy - Groups, Categories and then Micro-categories - and have setup a separate table for each of them in my database
    3) Then I have mapping tables, i.e. a table that stores group to category mapping, another table that stores category to micro-category mapping.
    4) Products are mapped directly to micro-categories and one product could be mapped to multiple micro-categories.
    5) I have created a materialized view on product and store the mappings as comma separated list of IDs - I have three fields there, on to store comma separated group id, second to store comma separated category ids and third to store the comma separated micro category ids to which the product is mapped.
    Now I want to write a query that will return a specified number of matches from this table based on user defined criterion. There are few other filter cirterion apart from Group/Category and Microcategory. These are Company Name, Country, Type of company etc.
    This query when run on production will be accessed very frequently - I expect the access to be in the tune of around 5-10 times per second.
    There are 50 records in the group table
    There are 500 categories
    There are 20000 micro-categories
    Group to category mapping table has around 1000 records
    Category to microcategory table has around 25000 records
    The product table has around 100,000 products.
    Product to microcategory mapping table has 350000 records
    The product mview has the same number of records as that in products table.
    The first query uses the single materialized view to access data, however, it always does a full table scan and does not use any index.
    When I noticed this in the explain plan, then I tried to write the second query which is using JOINs to arrive at the same output.
    The explain plan now says that it is using Index scans.
    I did a sample run of both the queries on my production system and I had to withdraw both of them as both brought my system to grinding halt within few minutes of going live.
    My system at present receives around 3000 requests per hour during peak load and around 600 requests per hour during off-peak hours.
    And I was testing these queries in Off-peak hours !!
    Here are the two sql queries just for reference - there are several variables plugged in where clause which are the key drivers of the query:
    SQL-1
    SELECT DECODE(:OPT,2,A.SC,(MAX(A.SC) OVER (PARTITION BY A.PRD_SEARCH_COMPANY))) AS SO,
         A.SC,                           A.PRD_SEARCH_ID,
         A.PRD_SEARCH_COMPANY_ID,        A.PRD_SEARCH_COMPANY,            A.PRD_SEARCH_COMPANYID_ENCRYPTED,
         A.PRD_SEARCH_PCID,              A.PRD_SEARCH_URL,                A.PRD_SEARCH_PC_CLNT_HOME,
         A.PRD_SEARCH_CLNT_ENABLED,      A.PRD_SEARCH_CODE,               A.PRD_SEARCH_NAME,
         A.PRD_SEARCH_DESC_SMALL,        A.PRD_SEARCH_DESC_DETAILED,      A.PRD_SEARCH_DESC_HTML,
         A.PRD_SEARCH_IMG_SMALL,         A.PRD_SEARCH_IMG_LARGE,          A.PRD_SEARCH_WEIGHT_ITEM,
         A.PRD_SEARCH_MODIFIEDDATE,      A.PRD_SEARCH_SIZE,               A.PRD_SEARCH_LABEL1,
         A.PRD_SEARCH_LABEL1_VALUE,      A.PRD_SEARCH_LABEL2,             A.PRD_SEARCH_LABEL2_VALUE,
         A.PRD_SEARCH_LABEL3,            A.PRD_SEARCH_LABEL3_VALUE,       A.PRD_SEARCH_LABEL4,
         A.PRD_SEARCH_LABEL4_VALUE,      A.PRD_SEARCH_LABEL5,             A.PRD_SEARCH_LABEL5_VALUE,
         A.PRD_SEARCH_LABEL6,            A.PRD_SEARCH_LABEL6_VALUE,       A.PRD_SEARCH_CAT_ID,
         A.PRD_SEARCH_CAT_NAME,          A.PRD_SEARCH_CAT_FLNAME,         A.PRD_SEARCH_NAVIGATION_TREE,
         A.PRD_SEARCH_NAVIGATION_TREE_ID,A.PRD_SEARCH_CITY,               A.PRD_SEARCH_STATE,
         A.PRD_SEARCH_COUNTRY,           A.PRD_SEARCH_PRICE_SALE,         A.PRD_SEARCH_PC_CLNT_TYPE,
         A.PRD_SEARCH_PC_CLNT_TYPE_DESC,
         A.PRD_SEARCH_COMPANY_PHONE,     A.PRD_SEARCH_COMPANY_MOBILE,     A.PRD_SEARCH_COMPANY_FAX,
         A.PRD_SEARCH_COMPANY_EMAIL,     A.PRD_SEARCH_GLCAT_MCAT_ID_LIST, A.PRD_SEARCH_GLCAT_CAT_ID_LIST,
         A.PRD_SEARCH_GLCAT_GRP_ID_LIST, A.PRD_SEARCH_GL_COUNTRY_ISO,     A.PRD_SEARCH_GLUSR_USR_ID,
         A.PRD_SEARCH_TRUSTSEAL_CODE,    A.PRD_SEARCH_CUSTTYPE_ID,        A.PRD_SEARCH_CUSTTYPE_NAME,
         A.PRD_SEARCH_CUSTTYPE_WEIGHT,   A.PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, A.PRD_SEARCH_CUSTTYPE_RANK,
         A.PRD_SEARCH_PC_ITEM_HOTNEW,    A.RK
         FROM
              (SELECT  /*+ FIRST_ROWS (500) */     DECODE(:S_MODE,2,1,3,to_number(to_char(PRD_SEARCH_MODIFIEDDATE,'yyyymmdd')),1) AS SC,
              PRD_SEARCH_ID,
              PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
              PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
              PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
              PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
              PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
              PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
              PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
              PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
              PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
              PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
              PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
              PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
              PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
              PRD_SEARCH_PC_CLNT_TYPE_DESC,
              PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
              PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
              PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
              PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
              PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
              PRD_SEARCH_PC_ITEM_HOTNEW,
              ROW_NUMBER() OVER (PARTITION BY PRD_SEARCH_COMPANY_ID
                                  ORDER BY DECODE(:S_MODE,2,1,3,to_number(to_char(PRD_SEARCH_MODIFIEDDATE,'yyyymmdd')),1) DESC) AS RK
              FROM      PRD_SEARCH
              WHERE     DECODE(:GRP_ID_STR,NULL,1,REGEXP_INSTR(','||REPLACE(PRD_SEARCH_GLCAT_GRP_ID_LIST,' ','')||',',:MYGRP_ID_STR)) > 0
              AND       DECODE(:CAT_ID_STR,NULL,1,REGEXP_INSTR(','||REPLACE(PRD_SEARCH_GLCAT_CAT_ID_LIST,' ','')||',',:MYCAT_ID_STR)) > 0
              AND       DECODE(:MCAT_ID_STR,NULL,1,REGEXP_INSTR(','||REPLACE(PRD_SEARCH_GLCAT_MCAT_ID_LIST,' ','')||',',:MYMCAT_ID_STR)) > 0
              AND       DECODE(:ITEM_ID_STR,NULL,1,REGEXP_INSTR(','||PRD_SEARCH_ID||',',:MYITEM_ID_STR)) > 0
              AND       DECODE(:COUNTRY_ISO,NULL,1,REGEXP_INSTR(','||PRD_SEARCH_GL_COUNTRY_ISO||',',:COUNTRY_ISO)) > 0
              AND       DECODE(nvl(NULL,0),0,1,PRD_SEARCH_COMPANY_ID) = DECODE(nvl(NULL,0),0,1,NULL)
              AND       DECODE(nvl(NULL,0),0,1,PRD_SEARCH_GLUSR_USR_ID) = DECODE(nvl(NULL,0),0,1,NULL)
              AND       PRD_SEARCH_CLNT_ENABLED >= nvl(:LIST_TYPE,0)
              AND       NVL(Length(PRD_SEARCH_TRUSTSEAL_CODE),0) >= :TSONLY
              ORDER BY SC DESC, PRD_SEARCH_CUSTTYPE_WEIGHT ASC, DBMS_RANDOM.RANDOM
              )  A
    WHERE A.RK <= :MY_PRD_PER_COMP
    AND   ROWNUM <= :MYMAXREC
    ORDER BY SO DESC, DECODE(:OPT,2,'1',A.PRD_SEARCH_COMPANY), A.RK ASC, DBMS_RANDOM.RANDOM
    SQL-2
         SELECT
              DECODE(:OPT,2,SC,(MAX(SC) OVER (PARTITION BY PRD_SEARCH_COMPANY))) AS SO,
              SC,                           PRD_SEARCH_ID,
              PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
              PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
              PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
              PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
              PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
              PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
              PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
              PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
              PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
              PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
              PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
              PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
              PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
              PRD_SEARCH_PC_CLNT_TYPE_DESC,
              PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
              PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
              PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
              PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
              PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
              PRD_SEARCH_PC_ITEM_HOTNEW,    RK
         FROM
                   SELECT
                        /*+ FIRST_ROWS (500) */ DECODE(:OPT,2,SC,(MAX(SC) OVER (PARTITION BY PRD_SEARCH_COMPANY))) AS SO,
                        SC,PRD_SEARCH_ID,
                        PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
                        PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
                        PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
                        PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
                        PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
                        PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
                        PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
                        PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
                        PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
                        PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
                        PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
                        PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
                        PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
                        PRD_SEARCH_PC_CLNT_TYPE_DESC,
                        PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
                        PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
                        PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
                        PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
                        PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
                        PRD_SEARCH_PC_ITEM_HOTNEW,
                        ROW_NUMBER() OVER (PARTITION BY PRD_SEARCH_COMPANY_ID
                                  ORDER BY DECODE(:S_MODE,2,1,3,TO_NUMBER(TO_CHAR(PRD_SEARCH_MODIFIEDDATE,'YYYYMMDD')),1) DESC) AS RK
                   FROM
                             SELECT
                                  DECODE(:S_MODE,2,1,3,TO_NUMBER(TO_CHAR(PRD_SEARCH_MODIFIEDDATE,'YYYYMMDD')),1) AS SC,
                                  PRD_SEARCH_ID,
                                  PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
                                  PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
                                  PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
                                  PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
                                  PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
                                  PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
                                  PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
                                  PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
                                  PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
                                  PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
                                  PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
                                  PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
                                  PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
                                  PRD_SEARCH_PC_CLNT_TYPE_DESC,
                                  PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
                                  PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
                                  PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
                                  PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
                                  PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
                                  PRD_SEARCH_PC_ITEM_HOTNEW,
                                  ROW_NUMBER() OVER (PARTITION BY P.PRD_SEARCH_ID ORDER BY P.PRD_SEARCH_ID) RK1
                             FROM
                                  GLCAT_GRP_TO_CAT G2C, GLCAT_CAT_TO_MCAT C2M, PC_ITEM_TO_GLCAT_MCAT M, PRD_SEARCH P
                             WHERE
                                  G2C.FK_GLCAT_CAT_ID = C2M.FK_GLCAT_CAT_ID
                                  AND C2M.FK_GLCAT_MCAT_ID = M.FK_GLCAT_MCAT_ID
                                  AND M.FK_PC_ITEM_ID = P.PRD_SEARCH_ID
                                  AND DECODE(:MCAT_ID_STR, NULL, 1, INSTR(','||:MCAT_ID_STR||',',','||M.FK_GLCAT_MCAT_ID||',',1))> 0
                                  AND DECODE(:CAT_ID_STR, NULL, 1, INSTR(','||:CAT_ID_STR||',',','||C2M.FK_GLCAT_CAT_ID||',',1)) > 0
                                  AND DECODE(:GRP_ID_STR, NULL, 1, INSTR(','||:GRP_ID_STR||',',','||G2C.FK_GLCAT_GRP_ID||',',1)) > 0
                                  AND DECODE(:ITEM_ID_STR,NULL,1,INSTR(','||:ITEM_ID_STR||',' , ','||P.PRD_SEARCH_ID||',')) > 0
                                  AND DECODE(:COUNTRY_ISO,NULL,1,INSTR(','||:COUNTRY_ISO||',', ','||P.PRD_SEARCH_GL_COUNTRY_ISO||',')) > 0
                                  AND DECODE(NVL(:COMPANY_ID,0),0,1,P.PRD_SEARCH_COMPANY_ID) = DECODE(NVL(:COMPANY_ID,0),0,1,:COMPANY_ID)
                                  AND DECODE(NVL(:GLUSR_ID,0),0,1,P.PRD_SEARCH_GLUSR_USR_ID) = DECODE(NVL(:GLUSR_ID,0),0,1,:GLUSR_ID)
                                  AND P.PRD_SEARCH_CLNT_ENABLED >= NVL(:LIST_TYPE,0)
                                  AND NVL(LENGTH(P.PRD_SEARCH_TRUSTSEAL_CODE),0) >= :TSONLY
                   WHERE RK1=1
                   ORDER BY SC DESC, PRD_SEARCH_CUSTTYPE_WEIGHT ASC, DBMS_RANDOM.RANDOM
              ) A
         WHERE A.RK <= :MY_PRD_PER_COMP
         AND   ROWNUM <= :MYMAXREC
         ORDER BY A.SO DESC, DECODE(:OPT,2,'1', A.PRD_SEARCH_COMPANY), A.RK ASC, DBMS_RANDOM.RANDOMRegards
    Madhup

Maybe you are looking for

  • Plz help me

    hi , plz i got the following error while running a J2ME program cannot resolve symbol symbol : method add (java.lang.String) location: class java.util.Vector any ideas????

  • Recording on DVD - "Unable to recover TOC" error

    Hi all Whenever I try to record on a DVD a face "Unable to recover TOC" I've tried to change the recording speed but no use. When I go to DVD properties and click on enable recording it does not recognize the DVD or any other CD in the drive. Please

  • Added music track to video..entire screen is green and I cannot delete music track

    I added music track to video, inadvertently dropped outside of clip now entire area outside of track is green and I can't remove or delete music.

  • Register Button not active in CCMS Agent Configuration

    Hello, I'm trying to register the SAPCCMSR agent via visual administrator and my Register button is not enabled. Has anyone faced this problem. I have created CSMREG user, created and downloaded CSMCONF file and placed the file in appropriate directo

  • FAQ: SAP Messaging Certification

    Welcome to SAP Messaging Certification Forum! This forum is actively monitored and moderated by SAP Integration and Certification Center (ICC). Frequently Asked Questions: ========================================== Q1: What are the interface certific