Query tuning help required:

I have a query which is taking long time. Is there any way I can improve the query to shorten its time of execution.
I have given below the details of it.
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
Elapsed: 00:00:00.25
SQL> SELECT   pa.regn_no,
  2             (SELECT mst.status_desc
  3                FROM m_status mst
  4               WHERE mst.trans_id = 'PA01'
  5                 AND mst.status_code = pa.regn_status) AS regn_status,
  6             (SELECT pp.NAME
  7                FROM people_profile pp
  8               WHERE pp.pp_id = pa.ident_no) AS NAME, pa.ident_no,
  9             TO_CHAR (pa.approval_date, 'dd/mm/yyyy') AS approval_date,
10             TO_CHAR (pa.de_reg_date, 'dd/mm/yyyy') AS de_regist_date,
11             TO_CHAR (pa.cert_reg_exp_date, 'dd/mm/yyyy') AS cert_expiry_date,
12             pa.gender, pa.fax_no,
13             (SELECT nationality_desc
14                FROM people_profile pp, m_nationality
15               WHERE pp.pp_id = pa.ident_no
16                 AND pp.nationality = nationality_code) AS nationality,
17             (SELECT pp.email_add
18                FROM people_profile pp
19               WHERE pp.pp_id = pa.ident_no) AS email_add,
20             (SELECT pp.mobile_no
21                FROM people_profile pp
22               WHERE pp.pp_id = pa.ident_no) AS mobile_no,
23             TO_CHAR ((SELECT pp.birth_date
24                      FROM people_profile pp
25                     WHERE pp.pp_id = pa.ident_no),
26                   'dd/mm/yyyy'
27                  ) AS birth_date,
28             REPLACE (sf_get_address_people (pa.ident_no, '2', 'C'),
29                   '<br>',
30                   CHR (10)
31                  ) AS address,
32             sf_get_pa_firm_info (pa.ident_no) AS firm_profile,
33             sf_get_pa_firm_partner (pa.ident_no) AS firm_partner,
34             sf_get_pa_pmp_code (pa.ident_no) AS pmp_code, ppv.pae_name,
35             ppv.pmp_code AS pmp_code_1, ppv.cycle_no, ppv.seq_no,
36             DECODE (ppv.visit_type,
37                  'I', 'INITIAL',
38                  'R', 'REVISIT',
39                  ''
40                 ) AS visit_type,
41             TO_CHAR (ppv.initial_ltr_date, 'dd/mm/yyyy') AS initial_ltr_date,
42             TO_CHAR (ppv.sec_ltr_date, 'dd/mm/yyyy') AS sec_ltr_date,
43             TO_CHAR (ppv.review_from, 'dd/mm/yyyy') AS review_from,
44             TO_CHAR (ppv.review_to, 'dd/mm/yyyy') AS review_to,
45             TO_CHAR (ppv.finding_date, 'dd/mm/yyyy') AS finding_date,
46             TO_CHAR (ppv.finding_due_date, 'dd/mm/yyyy') AS finding_due_date,
47             TO_CHAR (ppv.finding_reply_date,
48                   'dd/mm/yyyy'
49                  ) AS finding_reply_date,
50             ppv.pmsc,
51             TO_CHAR (ppv.clarif_ltr_date, 'dd/mm/yyyy') AS clarif_ltr_date,
52             ppv.paoc_date,
53             TO_CHAR (ppv.final_paoc_date, 'dd/mm/yyyy') AS final_paoc_date,
54             (SELECT result_desc
55                FROM m_pmp_result ms
56               WHERE result_id = ppv.pmp_status) AS pmp_status,
57             TO_CHAR (ppv.suspension_end_date,
58                   'dd/mm/yyyy'
59                  ) AS suspension_end_date,
60             TO_CHAR (ppv.final_ltr_date, 'dd/mm/yyyy') AS final_ltr_date,
61             ppv.findings_summary,
62             TO_CHAR (ppv.invoice_date, 'dd/mm/yyyy') AS invoice_date,
63             ppv.amount_billed,
64             TO_CHAR (ppv.payment_date, 'dd/mm/yyyy') AS payment_date,
65             DECODE (ppv.pay_icpas,
66                  'Y', 'YES',
67                  'N', 'NO',
68                  'V', 'NA',
69                  ''
70                 ) AS pay_icpas,
71             ppv.updated_date, ppv.updated_by, ppv.remarks,
72             DECODE ((SELECT ppr.review_status
73                     FROM pa_pmp_reviews ppr
74                    WHERE ppr.regn_no = ppv.regn_no
75                      AND ppr.cycle_no = ppv.cycle_no),
76                  'P', 'In Progress',
77                  'C', 'Closed',
78                  ''
79                 ) AS review_status,
80             pcl.complaint_no,
81             DECODE (pcl.complaint_status,
82                  'P', 'Pending',
83                  'C', 'Closed',
84                  ''
85                 ) AS complaint_status,
86             pcl.remarks AS remarks_1,
87             DECODE (pcl.complaint_outcome,
88                  'C', 'Cancelled',
89                  'R', 'Restriction of Practice',
90                  'P', 'Penalty (Fine) - Disciplinary',
91                  'E', 'Censure - Disciplinary',
92                  'S', 'Suspended - Disciplinary',
93                  ''
94                 ) AS complaint_outcome,
95             TO_CHAR (pcl.complaint_date, 'dd/mm/yyyy') AS complaint_date,
96             pcl.complainant_nric, pcl.complainant_name, pcl.complaint_details,
97             TO_CHAR (pcl.effective_date, 'dd/mm/yyyy') AS effective_date,
98             TO_CHAR (pcl.effective_date_to,
99                   'dd/mm/yyyy') AS effective_date_to,
100             sf_get_pa_exam_info (pa.regn_no, 'L') AS local_exam_detail,
101             sf_get_pa_exam_info (pa.regn_no, 'F') AS foreign_exam_detail,
102             sf_get_pa_exempt_info (pa.regn_no) AS exempt_detail
103           FROM pa_profile pa, pa_pmp_visits ppv, pa_complaint pcl
104          WHERE pa.regn_no = ppv.regn_no(+) AND pa.regn_no = pcl.regn_no(+)
105       ORDER BY pa.regn_no DESC;
1163 rows selected.
Elapsed: 00:02:08.87
Execution Plan
Plan hash value: 2912197266
| Id  | Operation                    | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT             |                  |  1109 |   330K|    17  (12)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID | M_STATUS         |     1 |    23 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN           | PK_M_STATUS      |     1 |       |     1   (0)| 00:00:01 |
|   3 |  TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE   |     1 |    25 |     3   (0)| 00:00:01 |
|*  4 |   INDEX UNIQUE SCAN          | SYS_C00103408    |     1 |       |     2   (0)| 00:00:01 |
|   5 |  NESTED LOOPS                |                  |     1 |    26 |     4   (0)| 00:00:01 |
|   6 |   TABLE ACCESS BY INDEX ROWID| PEOPLE_PROFILE   |     1 |    12 |     3   (0)| 00:00:01 |
|*  7 |    INDEX UNIQUE SCAN         | SYS_C00103408    |     1 |       |     2   (0)| 00:00:01 |
|*  8 |   INDEX RANGE SCAN           | PK_M_NATIONALITY |     1 |    14 |     1   (0)| 00:00:01 |
|   9 |  TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE   |     1 |    20 |     3   (0)| 00:00:01 |
|* 10 |   INDEX UNIQUE SCAN          | SYS_C00103408    |     1 |       |     2   (0)| 00:00:01 |
|  11 |  TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE   |     1 |    11 |     3   (0)| 00:00:01 |
|* 12 |   INDEX UNIQUE SCAN          | SYS_C00103408    |     1 |       |     2   (0)| 00:00:01 |
|  13 |  TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE   |     1 |    10 |     3   (0)| 00:00:01 |
|* 14 |   INDEX UNIQUE SCAN          | SYS_C00103408    |     1 |       |     2   (0)| 00:00:01 |
|  15 |  TABLE ACCESS BY INDEX ROWID | M_PMP_RESULT     |     1 |    37 |     1   (0)| 00:00:01 |
|* 16 |   INDEX UNIQUE SCAN          | XPK_M_PMP_RESULT |     1 |       |     0   (0)| 00:00:01 |
|  17 |  TABLE ACCESS BY INDEX ROWID | PA_PMP_REVIEWS   |     1 |     8 |     1   (0)| 00:00:01 |
|* 18 |   INDEX UNIQUE SCAN          | SYS_C00103321    |     1 |       |     0   (0)| 00:00:01 |
|  19 |  SORT ORDER BY               |                  |  1109 |   330K|    17  (12)| 00:00:01 |
|* 20 |   HASH JOIN RIGHT OUTER      |                  |  1109 |   330K|    16   (7)| 00:00:01 |
|  21 |    TABLE ACCESS FULL         | PA_COMPLAINT     |   146 | 20294 |     3   (0)| 00:00:01 |
|* 22 |    HASH JOIN RIGHT OUTER     |                  |  1109 |   179K|    13   (8)| 00:00:01 |
|  23 |     TABLE ACCESS FULL        | PA_PMP_VISITS    |    90 | 11340 |     3   (0)| 00:00:01 |
|  24 |     TABLE ACCESS FULL        | PA_PROFILE       |  1109 | 44360 |     9   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   2 - access("MST"."TRANS_ID"='PA01' AND "MST"."STATUS_CODE"=:B1)
       filter("MST"."STATUS_CODE"=:B1)
   4 - access("PP"."PP_ID"=:B1)
   7 - access("PP"."PP_ID"=:B1)
   8 - access("PP"."NATIONALITY"="NATIONALITY_CODE")
  10 - access("PP"."PP_ID"=:B1)
  12 - access("PP"."PP_ID"=:B1)
  14 - access("PP"."PP_ID"=:B1)
  16 - access("RESULT_ID"=:B1)
  18 - access("PPR"."REGN_NO"=:B1 AND "PPR"."CYCLE_NO"=:B2)
  20 - access("PA"."REGN_NO"="PCL"."REGN_NO"(+))
  22 - access("PA"."REGN_NO"="PPV"."REGN_NO"(+))
Statistics
      17577  recursive calls
          0  db block gets
    8703644  consistent gets
       6138  physical reads
          0  redo size
     424453  bytes sent via SQL*Net to client
       3641  bytes received via SQL*Net from client
         13  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
       1163  rows processed
NAME                                 TYPE        VALUE
user_dump_dest                       string      /opt/app/oracle/diag/rdbms/ebi
                                                 zfile/EBIZFILE/trace
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     100
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     128
SQL> show parameter db_block_size
NAME                                 TYPE        VALUE
db_block_size                        integer     8192
SQL> show parameter cursor_sharing
NAME                                 TYPE        VALUE
cursor_sharing                       string      EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
  2  sname, pname, pval1, pval2
  3  from
  4  sys.aux_stats$;
SNAME                PNAME                     PVAL1 PVAL2
SYSSTATS_INFO        STATUS                          COMPLETED
SYSSTATS_INFO        DSTART                          11-20-2009 09:46
SYSSTATS_INFO        DSTOP                           11-20-2009 09:46
SYSSTATS_INFO        FLAGS                         1
SYSSTATS_MAIN        CPUSPEEDNW           1676.76768
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

Hi,
obviously the problem you are having is described by the following lines of your execution plan
SORT ORDER BY | | 1109 | 330K| 17 (12)| 00:00:01 |
|* 20 | HASH JOIN RIGHT OUTER | | 1109 | 330K| 16 (7)| 00:00:01 |
| 21 | TABLE ACCESS FULL | PA_COMPLAINT | 146 | 20294 | 3 (0)| 00:00:01 |
|* 22 | HASH JOIN RIGHT OUTER | | 1109 | 179K| 13 (8)| 00:00:01 |
| 23 | TABLE ACCESS FULL | PA_PMP_VISITS | 90 | 11340 | 3 (0)| 00:00:01 |
| 24 | TABLE ACCESS FULL | PA_PROFILE | 1109 | 44360 | 9
You don't have a "real" "WHERE" condition in the query that could lead the Oracle CBO to consider using an index.
This leads to a full scan of PA_PMP_VISITS and PA_PROFILE and subsequently -in order to process the join condition between these two tables-
to this "HASH JOIN RIGHT OUTER". You cannot avoid this, with the current WHERE condition ...
Following thoughts :
1) Try narrowing down your result set by specifying a "real" WHERE Condition on one of the two tables, specifying an indexed column
2) If this cannot be done, try using query parallelism (parallel hint). This will give you acceptable SQL-execution times.
3) If this is not possible, there would be a third approach : You could consider the definition of an index on "pa.regn" and use a hint on your query in order to use it. Due to your order condition there is a possibility that CBO is going to use it, especially if you specify WHERE ROWNUM < ...
Regards,
Michalis

Similar Messages

  • Query Tuning Help please

    I ran the below query two times . first this query run within 4 minutes now it is running withing 20 minutes only . and how can I reduce the running time of this query.
    my first table TABLE1 has partitioned day wise.
    Total 14 partition in TABLE1 so if it runs for total 14 partitions it will take 14*20= 280 minutes.
    Index created for TABLE1 and TABLE2
    CREATE INDEX TABLE1_COL_A_INX ON TABLE1(COL_A);
    CREATE INDEX TABLE1_COL_B_INX ON TABLE1(COL_B);
    CREATE INDEX TABLE2_BNO_TYP_INX ON TABLE2(COL_B,RECORD_TYP);TABLE1 contain 3 billion records
    TABLE2 contain 87 thousand records
    INSERT INTO TARGET_TABLE
    SELECT   t1.col_A,
                             t1.col_b,
                             t1.record_typ,
                             TO_date('14/06/2012','DD/MM/YYYY') ,
                             MIN( start_dt) AS First_Seen,
                             MAX( start_dt) AS Last_Seen
                    FROM     TABLE1  t1,
                             TABLE2  t2
                    WHERE    t1.start_dt = TO_date('14/06/2012','DD/MM/YYYY') - 12   
                             AND t1.col_b = t2.col_b
                             AND t1.record_typ = t2.record_typ                                                                                    
                    GROUP BY t1.col_a,t1.col_b,t1.record_typ,TO_date('14/06/2012','DD/MM/YYYY') ;Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Explain plan with statistics
    SQL>
    117794 rows selected.
    Execution Plan
    Plan hash value: 1844245574
    | Id  | Operation                           | Name                    | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT                    |                         |   147K|  7362K|       |   615K  (1)| 02:03:05 |       |       |
    |   1 |  HASH GROUP BY                      |                         |   147K|  7362K|  9320K|   615K  (1)| 02:03:05 |       |       |
    |   2 |   NESTED LOOPS                      |                         |       |       |       |         |             |       |       |
    |   3 |    NESTED LOOPS                     |                         |   147K|  7362K|       |   613K  (1)| 02:02:43 |       |       |
    |   4 |     TABLE ACCESS FULL               | TABEL2                  | 87586 |  1282K|       |   137   (1)| 00:00:02 |       |       |
    |   5 |     PARTITION RANGE SINGLE          |                         |     3 |       |       |     3   (0)| 00:00:01 |     4 |     4 |
    |*  6 |      INDEX RANGE SCAN               | TABLE1_COL_B_INX        |     3 |       |       |     3   (0)| 00:00:01 |     4 |     4 |
    |*  7 |    TABLE ACCESS BY LOCAL INDEX ROWID| TABLE1                  |     2 |    72 |       |     7   (0)| 00:00:01 |     4 |     4 |
    Predicate Information (identified by operation id):
       6 - access("T1"."COL_B"="T2"."COL_B")
       7 - filter("T1"."START_DT"=TO_DATE(' 2012-06-02 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "T1"."RECORD_TYP"="T2"."RECORD_TYP")
    Statistics
            105  recursive calls
              0  db block gets
         640720  consistent gets
         363307  physical reads
         635656  redo size
        3896682  bytes sent via SQL*Net to client
          86718  bytes received via SQL*Net from client
           7854  SQL*Net roundtrips to/from client
              2  sorts (memory)
              0  sorts (disk)
         117794  rows processed
    SQL>TKPROF
    SELECT   t1.COL_A,
                             t1.COL_B,
                             t1.record_typ,
                             TO_date('14/06/2012','DD/MM/YYYY') ,
                             MIN(start_dt) AS First_Seen,
                             MAX(start_dt) AS Last_Seen
                    FROM     TABLE1  t1,
                             TABLE2 t2
                    WHERE    t1.start_dt = TO_date('14/06/2012','DD/MM/YYYY') - 12
                             AND
                             t1.COL_B = t2.COL_B
                             AND t1.record_typ = t2.record_typ
                    GROUP BY t1.col_a,t1.col_b,t1.record_typ,TO_date('14/06/2012','DD/MM/YYYY')
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch     7853      0.15       0.28          0          0          0      117793
    total     7853      0.15       0.28          0          0          0      117793
    Misses in library cache during parse: 0
    Parsing user id: 85  Which parameters or settings I want to check , because this query run before 4 minutes. now it takes 20 minutes... or in anyway I can rewrite this query using multiple staging table or something like that...

    Hi,
    1) you didn't trace the session correctly -- you probably switched tracing off before the session finished fetching all rows. Do it again, and this time end tracing by exiting the session (this way you make sure that the cursor is closed and plan stats are dumped to the trace file)
    2) the plan seems to be sensible -- it costs you only 600k reads to retrieve 150k rows, that's good read-to-row ratio. You can improve it if you get read of TABLE ACCESS BY ROWID operation, but that would require creating an index on all the columns that the query needs (both in WHERE clause and in column projection) which looks like a big overhead (especially given that this is a table with 3 billion records)
    3) autotrace stats seem to agree with the plan -- you're making 600k gets and half of them result in single-block disk reads. Assuming 5ms per read that's close to 20 min that you are getting. Of course, 50% buffer cache ratio is far from being perfect, and better caching is most likely the reason why the query was performing better in the past. Look at the the buffer hit ratio trend for the database -- perhaps some other activity is trashing the buffer cache, resulting in performance degradation of this query as well
    Best regards,
    Nikolay

  • Query Tuning-Help Needed

    Hi ,
    11.2.0.1
    AIX 6.1
    I have following query which is executed from Application,the query comes back within 2 secs for not so common last_name combined with gender but it is taking longer time for common last_names like 'BROWN' or 'JONES' or 'SMITH' with gender_id .
    select customerin0_.ROW_NUMBER as ROW1_22596_, customerin0_.ADDRESS_ID as
      ADDRESS2_22596_, customerin0_.addressTypeId as addressT3_22596_,
      customerin0_.city as city22596_, customerin0_.CONTACT_DETAILS_CODE_ID as
      CONTACT5_22596_, customerin0_.county as county22596_, customerin0_.countyID
      as countyID22596_, customerin0_.dob as dob22596_, customerin0_.eyecolor as
      eyecolor22596_, customerin0_.eyecolorid as eyecolorid22596_,
      customerin0_.FIRST_NAME as FIRST11_22596_, customerin0_.gender as
      gender22596_, customerin0_.genderid as genderid22596_,
      customerin0_.ID_NUMBER as ID14_22596_, customerin0_.JURISDICTION_CODE as
      JURISDI15_22596_, customerin0_.LAST_NAME as LAST16_22596_,
      customerin0_.LEGAL_ENTITY_ID as LEGAL17_22596_,
      customerin0_.LEGAL_ENTITY_NUMBER as LEGAL18_22596_,
      customerin0_.LEGAL_ENTITY_TYPE as LEGAL19_22596_, customerin0_.MIDDLE_NAME
      as MIDDLE20_22596_, customerin0_.STREET_ADDRESS_1 as STREET21_22596_,
      customerin0_.suffix_value as suffix22_22596_, customerin0_.ZIP_CODE as
      ZIP23_22596_, customerin0_.ZIP_PLUS_4 as ZIP24_22596_
    from
    CUSTOMER_IND_SEARCH_VIEW customerin0_ where (customerin0_.LAST_NAME like :1)
      and customerin0_.genderid=:2 and rownum<=200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch       18      1.88     123.53       8245      12403          0         179
    total       18      1.88     123.53       8245      12403          0         179
    Misses in library cache during parse: 0
    Parsing user id: 135  (???)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                 259        0.00          0.00
      gc cr grant 2-way                             259        0.00          0.08
      db file sequential read                     10126        1.40        148.07
      SQL*Net message from client                    19        0.02          0.10
      SQL*Net message to client                      18        0.00          0.00
    ********************************************************************************Was not able to generate plan out of tkrprof ,captured it from OEM.
      10 |     NESTED LOOPS                  |                              |   805 | 73255 |  3477   (1)| 00:00:42 |
    |  11 |      NESTED LOOPS                 |                              |   805 | 51520 |  1866   (1)| 00:00:23 |
    |  12 |       NESTED LOOPS                |                              |   805 | 33005 |   254   (0)| 00:00:04 |
    |* 13 |        TABLE ACCESS BY INDEX ROWID| REF_CONTACT_DETAILS          |     1 |    10 |     1   (0)| 00:00:01 |
    |* 14 |         INDEX UNIQUE SCAN         | XAK1_REF_CD_VALUE            |     1 |       |     0   (0)|          |
    |  15 |        TABLE ACCESS BY INDEX ROWID| PERSON_PROFILE_NAMES         |   805 | 24955 |   253   (0)| 00:00:04 |
    |* 16 |         INDEX RANGE SCAN          | IDX$$_D7D50001               |   805 |       |     4   (0)| 00:00:01 |
    |* 17 |       TABLE ACCESS BY INDEX ROWID | PERSON_PROFILE               |     1 |    23 |     2   (0)| 00:00:01 |
    |* 18 |        INDEX UNIQUE SCAN          | XPK_PERSON_PROFILE           |     1 |       |     1   (0)| 00:00:01 |
    |* 19 |      TABLE ACCESS BY INDEX ROWID  | LEGAL_ENTITY                 |     1 |    27 |     2   (0)| 00:00:01 |
    |* 20 |       INDEX UNIQUE SCAN           | XPK_LEGAL_ENTITY             |     1 |       |     1   (0)| 00:00:01 |
    |* 21 |     TABLE ACCESS BY INDEX ROWID   | LEGAL_ENTITY_ADDRESSES       |     1 |    81 |     3   (0)| 00:00:01 |
    |* 22 |      INDEX RANGE SCAN             | LENUM_CODE_ID                |     1 |       |     2   (0)| 00:00:01 |
    |* 23 |    TABLE ACCESS BY INDEX ROWID    | LEGAL_ENTITY_IDENTIFICATIONS |     1 |    36 |     3   (0)| 00:00:01 |
    |* 24 |     INDEX RANGE SCAN              | XIF1_LEGAL_ENTITY_ID         |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("REFCOUNTIES"."ID"=:B1)
       4 - access("REFEYECOLORS"."ID"=:B1)
       6 - access("REFGENDER"."ID"=:B1)
       7 - filter(ROWNUM<=200)
      13 - filter("REFCONTACTDETAILS"."MODE_TYPE"=4)
      14 - access("REFCONTACTDETAILS"."VALUE"='PRA')
      16 - access("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0)
           filter(("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0))
      17 - filter("SYS_ALIAS_2"."GENDER_ID"=:2)
      18 - access("SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER"="PERSONPROFILENAMES"."PP_LEGALENTITY_NUMBER")
      19 - filter(("LEGALENTITY"."IS_DELETED"=0 OR "LEGALENTITY"."IS_DELETED"=NULL))
      20 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER")
      21 - filter("LEGALENTITYADDRESSES"."IS_DELETED"=0)
      22 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="LEGALENTITYADDRESSES"."LEGAL_ENTITY_NUMBER" AND
                  "REFCONTACTDETAILS"."ID"="LEGALENTITYADDRESSES"."CONTACT_DETAILS_CODE_ID")
      23 - filter(("LEGAL_ENTITY_ID"."END_DATE">=SYSDATE@! AND "LEGAL_ENTITY_ID"."EFFECTIVE_DATE"<=SYSDATE@!))
      24 - access("LEGAL_ENTITY_ID"."LEGAL_ENTITY_NUMBER"="LEGALENTITY"."LEGAL_ENTITY_NUMBER")
      Please advice ....
    Thanks
    Edited by: Monto on Aug 22, 2012 4:22 AM

    Explain Plan with common name.
    SELECT  customerin0_.ROW_NUMBER AS ROW1_22596_,
             customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
             customerin0_.addressTypeId AS addressT3_22596_,
             customerin0_.city AS city22596_,
             customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
             customerin0_.county AS county22596_,
             customerin0_.countyID AS countyID22596_,
             customerin0_.dob AS dob22596_,
             customerin0_.eyecolor AS eyecolor22596_,
             customerin0_.eyecolorid AS eyecolorid22596_,
             customerin0_.FIRST_NAME AS FIRST11_22596_,
             customerin0_.gender AS gender22596_,
             customerin0_.genderid AS genderid22596_,
             customerin0_.ID_NUMBER AS ID14_22596_,
             customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
             customerin0_.LAST_NAME AS LAST16_22596_,
             customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
             customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
             customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
             customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
             customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
             customerin0_.suffix_value AS suffix22_22596_,
             customerin0_.ZIP_CODE AS ZIP23_22596_,
             customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
      FROM   xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
    WHERE   (customerin0_.LAST_NAME LIKE 'SMITH%')
             AND customerin0_.genderid = 2
             AND ROWNUM <= 200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.04       0.05          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       15      5.05     167.51      14050      20246          0         200
    total       17      5.09     167.56      14050      20246          0         200
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
         41  TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=58 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
         41   INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=17 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
          7  TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=11 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          7   INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
          1  TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
          1   INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
        200  COUNT STOPKEY (cr=20175 pr=14050 pw=0 time=2540633 us)
        200   NESTED LOOPS OUTER (cr=20175 pr=14050 pw=0 time=2540633 us cost=103 size=1248 card=6)
        200    NESTED LOOPS  (cr=19756 pr=13775 pw=0 time=17003952 us cost=80 size=1032 card=6)
        200     NESTED LOOPS  (cr=19304 pr=13586 pw=0 time=14271285 us cost=55 size=1092 card=12)
        200      NESTED LOOPS  (cr=19017 pr=13453 pw=0 time=13593988 us cost=31 size=768 card=12)
       4923       NESTED LOOPS  (cr=4640 pr=4614 pw=0 time=63281900 us cost=7 size=492 card=12)
          1        TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          1         INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
       4923        TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=4638 pr=4614 pw=0 time=63269280 us cost=6 size=372 card=12)
       4923         INDEX RANGE SCAN IDX$$_D7D50001 (cr=30 pr=16 pw=0 time=60326 us cost=2 size=0 card=12)(object id 311149)
        200       TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=14377 pr=8839 pw=0 time=0 us cost=2 size=23 card=1)
       4923        INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=9454 pr=4288 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
        200      TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=287 pr=133 pw=0 time=0 us cost=2 size=27 card=1)
        200       INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=225 pr=80 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
        200     TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=452 pr=189 pw=0 time=0 us cost=3 size=81 card=1)
        200      INDEX RANGE SCAN LENUM_CODE_ID (cr=281 pr=94 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
        200    TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=419 pr=275 pw=0 time=0 us cost=4 size=36 card=1)
        200     INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=219 pr=77 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                8576        0.00          0.02
      library cache lock                              7        0.00          0.00
      library cache pin                               7        0.00          0.00
      SQL*Net message to client                      15        0.00          0.00
      Disk file operations I/O                       19        0.01          0.03
      gc cr grant 2-way                            8554        0.01          3.09
      db file sequential read                     14050        0.91        158.32
      SQL*Net message from client                    15       32.28         35.97
      gc cr grant congested                           8        0.00          0.01
    ********************************************************************************Plan with rare names.
    SELECT   customerin0_.ROW_NUMBER AS ROW1_22596_,
             customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
             customerin0_.addressTypeId AS addressT3_22596_,
             customerin0_.city AS city22596_,
             customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
             customerin0_.county AS county22596_,
             customerin0_.countyID AS countyID22596_,
             customerin0_.dob AS dob22596_,
             customerin0_.eyecolor AS eyecolor22596_,
             customerin0_.eyecolorid AS eyecolorid22596_,
             customerin0_.FIRST_NAME AS FIRST11_22596_,
             customerin0_.gender AS gender22596_,
             customerin0_.genderid AS genderid22596_,
             customerin0_.ID_NUMBER AS ID14_22596_,
             customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
             customerin0_.LAST_NAME AS LAST16_22596_,
             customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
             customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
             customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
             customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
             customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
             customerin0_.suffix_value AS suffix22_22596_,
             customerin0_.ZIP_CODE AS ZIP23_22596_,
             customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
      FROM   xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
    WHERE       (customerin0_.LAST_NAME LIKE 'KUMAR%')
             AND customerin0_.genderid = '2'
             AND ROWNUM <= 200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.05       0.07          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       15      0.02       0.03          0       1829          0         200
    total       17      0.07       0.10          0       1829          0         200
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
         23  TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=37 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
         23   INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=14 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
          5  TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=9 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          5   INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
          1  TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
          1   INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
        200  COUNT STOPKEY (cr=1781 pr=0 pw=0 time=15124 us)
        200   NESTED LOOPS OUTER (cr=1781 pr=0 pw=0 time=14726 us cost=103 size=1248 card=6)
        200    NESTED LOOPS  (cr=1383 pr=0 pw=0 time=35422 us cost=80 size=1032 card=6)
        200     NESTED LOOPS  (cr=980 pr=0 pw=0 time=20198 us cost=55 size=1092 card=12)
        200      NESTED LOOPS  (cr=741 pr=0 pw=0 time=15422 us cost=31 size=768 card=12)
        289       NESTED LOOPS  (cr=129 pr=0 pw=0 time=3648 us cost=7 size=492 card=12)
          1        TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          1         INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
        289        TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=127 pr=0 pw=0 time=3360 us cost=6 size=372 card=12)
        289         INDEX RANGE SCAN IDX$$_D7D50001 (cr=18 pr=0 pw=0 time=672 us cost=2 size=0 card=12)(object id 311149)
        200       TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=612 pr=0 pw=0 time=0 us cost=2 size=23 card=1)
        289        INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=323 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
        200      TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=239 pr=0 pw=0 time=0 us cost=2 size=27 card=1)
        200       INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=194 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
        200     TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=403 pr=0 pw=0 time=0 us cost=3 size=81 card=1)
        200      INDEX RANGE SCAN LENUM_CODE_ID (cr=230 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
        200    TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=398 pr=0 pw=0 time=0 us cost=4 size=36 card=1)
        200     INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=198 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                  14        0.00          0.00
      library cache lock                              7        0.00          0.00
      library cache pin                               7        0.00          0.00
      KJC: Wait for msg sends to complete             2        0.00          0.00
      SQL*Net message to client                      15        0.00          0.00
      SQL*Net message from client                    15       18.88         21.81
    ********************************************************************************PERSONPROFILENAMES-16 Milion rows
    LEGALENTITYADDRESSES-34 Milion rows
    PERSONPROFILE-16 Milion rows
    LEGALENTITY 17 Milion rows
    refcontactdetails 45 rows
    Thanks

  • Help for query tuning

    hello all
    my one of query is returning result in 1-2 mins only for 1 lakh record but i am not sure if it showed me complete rows or not because when I an trying to get count of result ..its taking lot of time .when I am using this query on plsql code ..code is running slow so just wanted to confirm on query tuning point of view if its fine or not ..please look onto it and let me know if query is fine or not by explain plan .my oracle version is 11g
    this is my query
    SELECT ROWNUM , TRUNC(rownum/5000) + 20000 ,'FOR_UPDATE', sku_org.NAME ,
    acct_promo_sku.src_num , acct_promo_sku.sub_type ,
    promo_actual.sku_actual_pos
    FROM siebel.s_src acct_promo_hdr,
    siebel.s_src acct_title_format,
    siebel.s_src acct_promo_sku,
    siebel.s_src_x acct_promo_hdrx,
    siebel.s_src_x acct_promo_skux,
    siebel.s_prod_int prod,
    siebel.s_bu promo_hdr_org,
    siebel.s_bu sku_org,
    siebelwb.stg_sbl_acct_promo_actuals2 promo_actual
    WHERE acct_promo_hdr.sub_type = 'PLAN_ACCOUNT_PROMOTION'
    AND acct_promo_hdr.row_id = acct_title_format.par_src_id
    AND acct_title_format.sub_type = 'PLAN_ACCT_PROMOTION_CATEGORY'
    AND acct_title_format.row_id = acct_promo_sku.par_src_id
    AND acct_promo_sku.sub_type = 'PLAN_ACCOUNT_PROMOTION_PRODUCT'
    AND acct_promo_hdr.row_id = acct_promo_hdrx.par_row_id
    AND acct_promo_sku.row_id = acct_promo_skux.par_row_id(+)
    AND acct_promo_sku.prod_id = prod.row_id
    AND acct_promo_hdr.bu_id = promo_hdr_org.row_id
    AND acct_promo_sku.bu_id = sku_org.row_id
    AND prod.x_prod_material_num = promo_actual.material_number
    and prod.X_PROD_SALES_ORG=promo_actual.sales_org
    AND acct_promo_hdr.row_id = promo_actual.acct_promo_id
    and nvl(acct_promo_hdr.pr_accnt_id,0)=nvl(promo_actual.acct_siebel_rowid,0)
    and nvl(acct_promo_hdr.x_indirect_id,0)=nvl(promo_actual.indirect_acct_siebel_rowid,0)
    AND promo_actual.load_date >= TRUNC(SYSDATE)
    AND promo_actual.load_date < TRUNC(SYSDATE + 1)
    explain plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 3864590768
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 298 | 2300 (1)| 00:00:28 |
    | 1 | COUNT | | | | | |
    |* 2 | FILTER | | | | | |
    | 3 | NESTED LOOPS | | | | | |
    | 4 | NESTED LOOPS | | 1 | 298 | 2300 (1)| 00:00:28 |
    | 5 | NESTED LOOPS OUTER | | 1 | 273 | 2298 (1)| 00:00:28 |
    | 6 | NESTED LOOPS | | 1 | 263 | 2296 (1)| 00:00:28 |
    | 7 | NESTED LOOPS | | 1 | 236 | 2295 (1)| 00:00:28 |
    | 8 | NESTED LOOPS | | 1 | 165 | 2292 (1)| 00:00:28 |
    | 9 | NESTED LOOPS | | 1 | 117 | 2289 (1)| 00:00:28 |
    | 10 | NESTED LOOPS | | 1 | 109 | 2289 (1)| 00:00:28 |
    | 11 | NESTED LOOPS | | 1 | 99 | 2287 (1)| 00:00:28 |
    |* 12 | TABLE ACCESS FULL | STG_SBL_ACCT_PROMO_ACTUALS2 | 1 | 49 | 2285 (1)| 00:0
    |* 13 | TABLE ACCESS BY INDEX ROWID| S_SRC | 1 | 50 | 2 (0)| 00:00:01 |
    |* 14 | INDEX UNIQUE SCAN | S_SRC_P1 | 1 | | 1 (0)| 00:00:01 |
    |* 15 | INDEX RANGE SCAN | S_SRC_X_U1 | 1 | 10 | 2 (0)| 00:00:01 |
    |* 16 | INDEX UNIQUE SCAN | S_BU_P1 | 1 | 8 | 0 (0)| 00:00:01 |
    |* 17 | TABLE ACCESS BY INDEX ROWID | S_SRC | 1 | 48 | 3 (0)| 00:00:01 |
    |* 18 | INDEX RANGE SCAN | S_SRC_F2 | 2 | | 2 (0)| 00:00:01 |
    |* 19 | TABLE ACCESS BY INDEX ROWID | S_SRC | 1 | 71 | 3 (0)| 00:00:01 |
    |* 20 | INDEX RANGE SCAN | S_SRC_F2 | 2 | | 2 (0)| 00:00:01 |
    | 21 | TABLE ACCESS BY INDEX ROWID | S_BU | 1 | 27 | 1 (0)| 00:00:01 |
    |* 22 | INDEX UNIQUE SCAN | S_BU_P1 | 1 | | 0 (0)| 00:00:01 |
    |* 23 | INDEX RANGE SCAN | S_SRC_X_U1 | 1 | 10 | 2 (0)| 00:00:01 |
    |* 24 | INDEX UNIQUE SCAN | S_PROD_INT_P1 | 1 | | 1 (0)| 00:00:01 |
    |* 25 | TABLE ACCESS BY INDEX ROWID | S_PROD_INT | 1 | 25 | 2 (0)| 00:00:
    Predicate Information (identified by operation id):
    2 - filter(TRUNC(SYSDATE@!)<TRUNC(SYSDATE@!+1))
    12 - filter("PROMO_ACTUAL"."LOAD_DATE">=TRUNC(SYSDATE@!) AND "PROMO_ACTUAL"."LOAD_DATE"<TRUNC(SYSD
    13 - filter("ACCT_PROMO_HDR"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION' AND
    NVL("ACCT_PROMO_HDR"."PR_ACCNT_ID",'0')=NVL("PROMO_ACTUAL"."ACCT_SIEBEL_ROWID",'0') AND
    NVL("ACCT_PROMO_HDR"."X_INDIRECT_ID",'0')=NVL("PROMO_ACTUAL"."INDIRECT_ACCT_SIEBEL_ROWID",'0'
    14 - access("ACCT_PROMO_HDR"."ROW_ID"="PROMO_ACTUAL"."ACCT_PROMO_ID")
    15 - access("ACCT_PROMO_HDR"."ROW_ID"="ACCT_PROMO_HDRX"."PAR_ROW_ID")
    16 - access("ACCT_PROMO_HDR"."BU_ID"="PROMO_HDR_ORG"."ROW_ID")
    17 - filter("ACCT_TITLE_FORMAT"."SUB_TYPE"='PLAN_ACCT_PROMOTION_CATEGORY')
    18 - access("ACCT_PROMO_HDR"."ROW_ID"="ACCT_TITLE_FORMAT"."PAR_SRC_ID")
    19 - filter("ACCT_PROMO_SKU"."PROD_ID" IS NOT NULL AND
    "ACCT_PROMO_SKU"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION_PRODUCT')
    20 - access("ACCT_TITLE_FORMAT"."ROW_ID"="ACCT_PROMO_SKU"."PAR_SRC_ID")
    22 - access("ACCT_PROMO_SKU"."BU_ID"="SKU_ORG"."ROW_ID")
    23 - access("ACCT_PROMO_SKU"."ROW_ID"="ACCT_PROMO_SKUX"."PAR_ROW_ID"(+))
    24 - access("ACCT_PROMO_SKU"."PROD_ID"="PROD"."ROW_ID")
    25 - filter("PROD"."X_PROD_MATERIAL_NUM" IS NOT NULL AND
    "PROD"."X_PROD_MATERIAL_NUM"="PROMO_ACTUAL"."MATERIAL_NUMBER" AND
    "PROD"."X_PROD_SALES_ORG"="PROMO_ACTUAL"."SALES_ORG")
    55 rows selected.
    thanks

    Hi,
    the plan you posted has the cost of 2300, i.e. 2300 single-block reads or equivalent number f multi-block reads. Even if none of the blocks is found in cache, 2300 reas shouldn't take more than a couple of minutes, beacause for most of the hard drives available today a disk read is typically within 5-10 ms.
    This means that if there is a problem, we will never find out about it by looking in the plan. And it's quite likely that there is, in fact, a problem, because the plan contains a bunch of nested joins, and the cost of each nested join is directly proportional to the cardinality of the previous nested loop. I.e. it suffices to make one bad mistake in estimating the number of rows coming fom one of the nested rows to screw up the entire plan and get all remaining estimates (including the total cost of the query) completely wrong.
    In order for us to be able to tell more, we need to see the plan with rowsource statistics, and please don't forget to use tags to preserve formatting (use the preview tab to make sure the posted plan is actually readable).
    Best regards,
      Nikolay                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Urgent help required: Query regarding LC Variables

    Hi All
    Sometime earlier I was working on a performance issue raised by a customer. It was shell script that was taking almost 8-9 hrs to complete. During my research I came across a fact that there were some variables which were not set, the LC variables were impacting the sort funnel operations because of which the script was taking a long time to execute.
    I asked them to export the following commands, after which the program went on smoothly and finished in a couple of mins:
    export LC_COLLATE=en_US.ISO8859-1
    export LC_MESSAGES=C
    export LC_MONETARY=en_US.ISO8859-1
    export LC_MONETARY=en_US.ISO8859-1
    export HZ=100
    export LC_CTYPE=en_US.ISO8859-1
    export LANG=en_US.UTF-8
    Later I did recover that setting the LC_COLLATE to C, is not helping and the program was again taking a lot of time. Few questions that I want to ask are:
    1. Can someone please tell me, what each of these variable mean and how these values make a difference.
    2. When I exported LC_COLLATE=en_US.ISO8859-1, it worked fine, but when i tried with the defalut value LC_COLLATE=C, then why the program didnt work.
    As this issue is still going on, hence I would request All to provide their valuable inputs and let me know as much as possible.
    Appreciate your help in this regard.
    Thanks
    Amit
    Hi All
    A new development in this regard. The customer has send us a screen shot in which they were trying to export the locale variable using the commands which I have pasted above. I can see in the screen shot that while exporting LC_COLLATE and LC_TYPE, they get a message that ""ksh: export: couldn't set locale correctly"".
    Request everyone to please give their inputs as it's a bit urgent.
    Thanks for all the help in advance.
    Thanks
    Amit
    Some help required please...
    Edited by: amitsinhaengg on Jul 22, 2009 2:03 AM
    Edited by: amitsinhaengg on Jul 22, 2009 2:06 AM

    LC_CTYPE
    Controls the behavior of character handling functions.
    LC_TIME
    Specifies date and time formats, including month names, days of the week, and common full and abbreviated representations.
    LC_MONETARY
    Specifies monetary formats, including the currency symbol for the locale, thousands separator, sign position, the number of fractional digits, and so forth.
    LC_NUMERIC
    Specifies the decimal delimiter (or radix character), the thousands separator, and the grouping.
    LC_COLLATE
    Specifies a collation order and regular expression definition for the locale.
    LC_MESSAGES
    Specifies the language in which the localized messages are written, and affirmative and negative responses of the locale (yes and no strings and expressions).
    You can use command
    # locale -k LC_CTYPE
    to see more detail about each type.

  • Query Tuning! - Need your help

    Hi Guys,
    I have got a problem in Query Tuning.
    I have a query, in which I am accesing tables from different users. Example:
    2 tables are from my own schema, 3 tables from other users and 3 tables from yet another user.
    I am using DISTINCT on this select statement. The 1st two columns in teh select list are concatenated with each other.
    There is yet another select in the from clause to get few other records from other tables.
    Thee query returns 163 records and takes around 14 seconds.
    I referred PLAN_TABLE, its showing NESTED LOOPS and CARTESIAN JOIN in the SORT OPERATION.
    Can anyone of you please suggest areas where I can concentrate?
    Thanks in advance
    Himanshu Dabir

    DISTINCT always do an inherent sort.
    SQL> EXPLAIN PLAN FOR
      2   SELECT DISTINCT principal_due,outstand_balance
      3     FROM outstanding_ledger
      4    WHERE dnum=1030003931
      5  /
    Explained.
    SQL> SET LINE 200
    SQL> SELECT * FROM TABLE(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 1765098853
    | Id  | Operation                    | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                         |    17 |   272 |     1 (100)| 00:00:01 |
    | 1 | SORT UNIQUE | | 17 | 272 | 1 (100)| 00:00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| OUTSTANDING_LEDGER      |    17 |   272 |            |          |
    |*  3 |    INDEX SKIP SCAN           | DLINE_COM_DDATE_DNUM_PK |    17 |       |            |          |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - access("DNUM"=1030003931)
           filter("DNUM"=1030003931)
    16 rows selected.
    SQL> DELETE plan_table
      2  /
    4 rows deleted.
    SQL> commit
      2  /
    Commit complete.
    SQL> EXPLAIN PLAN FOR
      2   SELECT  principal_due,outstand_balance
      3     FROM outstanding_ledger
      4    WHERE dnum=1030003931
      5  /
    Explained.
    SQL> SELECT * FROM TABLE(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 3157896501
    | Id  | Operation                   | Name                    | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT            |                         |    17 |   272 |     0   (0)|
    |   1 |  TABLE ACCESS BY INDEX ROWID| OUTSTANDING_LEDGER      |    17 |   272 |            |
    |*  2 |   INDEX SKIP SCAN           | DLINE_COM_DDATE_DNUM_PK |    17 |       |            |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       2 - access("DNUM"=1030003931)
           filter("DNUM"=1030003931)
    15 rows selected.
    SQL>
    Can anyone of you please suggest areas where I can concentrate?Paste yours plan with updated stats.
    Khurram

  • Query tuning : you can do it yourself

    Hello,
    This thread is not a question.
    How tune my query ?
    My query didn't use indexes why ?
    I have indexes on table, stats are up-to-date why Oracle does a full scan on table ?
    What are the hint which I can use ?
    etc...
    I would like try to answer to many such questions posted in this forum about query tuning.
    And explain that tuning is not always complicated, is not always reserved to some consultants, is not always solved by hints usage, and not require to buy some books which would give some magic solutions.
    By this thread, I would explain to people which have some query performance issues, that the solution is maybe here, in front of their eyes, inside the query itself. The solution may come from their own side, and that they can be happy to solve such question themself.
    I'll develop here below a case from a real word situation encountered some time ago.

    At this point, remove this huge and nightmarish hint. We'll use it only if no other ways may found.
    First, a look into the data model to see if the joins may be rewrite differently.
    Original joins :
        dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID and
        dw.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID and
        dw.REGION_ROUTING_ID = rr.REGION_ROUTING_ID and
        dw.CITY_ROUTING_ID  = cr.CITY_ROUTING_ID andAnd indeed, the join may be rewrite as below :
        and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
        and ar.CITY_ROUTING_ID    = cr.CITY_ROUTING_ID
        and cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID 
        and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_IDNote the aliases were change here. Is it complicated to try to rewrite query like that ?
    Secondly, we will try to see how avoid or, at least, workaround the all OR conditions. It would be well if we could merge all the FROM (bind variable :a) in one column, same for all TO (bind variable :b), unfortunately, the data model cannot be change (of course). Ok, we will try to work with a temporary table by combining all the possiblities between the two conditions.
    create global temporary table REGION_ROUTING_TMP
    on commit preserve rows
    as
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
    from   REGION_ROUTING
    where  1=2;And an index based on the two mains criteria of the query may help :
    create index IDX_REGION_ROUTING_TMP on REGION_ROUTING_TMP(REGION_FROM,REGION_TO);Then we'll populate table :
    insert into REGION_ROUTING_TMP
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP2 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP2 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP3 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING;The insert take near 9 seconds, which is a reasonnable elapse time.
    At this point, the query become :
    Select
       ap.AIRPORT_PAIR,  
       dw.DELIVERY_PERIOD,
       dw.TOTAL_PAX As Demand,
       od.GLOBAL_TOTAL_PAX as Total_OD_Demand,
       dw.REPORTED_PAX As ReportedPax,
       ap.AIRPORT_FROM,
       ap.AIRPORT_TO,
       ap.CITY_FROM,
       ap.CITY_TO,
       ap.COUNTRY_FROM_NAME,
       ap.COUNTRY_TO_NAME,
       ap.REGION_FROM_NAME,
       ap.REGION_TO_NAME,
       ar.AIRPORT_ROUTING,
       cr.CITY_ROUTING,
       cor.COUNTRY_ROUTING_NAMES,
       rr.REGION_ROUTING_NAMES,
       ar.NUMBER_OF_STOP,
       dw.PERCENT_OF_TOTAL_PAX_VS_OD,
       dw.AIRLINE1,
       dw.AIRLINE2,
       dw.AIRLINE3,
       dw.AIRLINE4,
       dw.NUMBER_OF_AIRLINE,
       dw.AIRCRAFTCLASS_NAME,
       dw.FARE
    From
       REGION_ROUTING_TMP rr, -- here we use now the temporary table instead of REGION_ROUTING table
       DETAILED_FLIGHTS dw,
       AIRPORT_PAIR ap,
       AIRPORT_ROUTING ar,
       CITY_ROUTING cr,
       COUNTRY_ROUTING cor,
       OD od
    where
            dw.DELIVERY_PERIOD  in ('2006-09','2006-08','2006-07')
    and dw.AIRPORT_PAIR_ID    = ap.AIRPORT_PAIR_ID
    and dw.OD_ID              = od.OD_ID
    and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
    and ar.CITY_ROUTING_ID    = cr.CITY_ROUTING_ID
    and     cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID 
    and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_ID
    and rr.REGION_FROM        = '7'  |
    and rr.REGION_TO          = '8'  |-> these two lines replace all the OR conditions;And explain plan :
    | Id  | Operation                             |  Name                          | Rows  | Bytes | Cost  | Pstart| Pstop |
    |   0 | SELECT STATEMENT                      |                                |   469 |   174K|  3462 |       |       |
    |   1 |  NESTED LOOPS                         |                                |   469 |   174K|  3462 |       |       |
    |   2 |   NESTED LOOPS                        |                                |   458 |   166K|  3004 |       |       |
    |   3 |    NESTED LOOPS                       |                                |   454 |   127K|  2096 |       |       |
    |   4 |     NESTED LOOPS                      |                                |   258 | 58308 |   548 |       |       |
    |   5 |      NESTED LOOPS                     |                                |   246 | 48216 |    56 |       |       |
    |   6 |       NESTED LOOPS                    |                                |    26 |  4420 |     4 |       |       |
    |   7 |        TABLE ACCESS BY INDEX ROWID    | REGION_ROUTING_TMP             |     1 |   123 |   
    |*  8 |         INDEX RANGE SCAN              | IDX_REGION_ROUTING_TMP         |     1 |       |     1 |       | 
    |   9 |        TABLE ACCESS BY INDEX ROWID    | COUNTRY_ROUTING                |    32 |  1504 |     2
    |* 10 |         INDEX RANGE SCAN              | IX9_COUNTRY_ROUTING            |    32 |       |     1 |       | 
    |  11 |       TABLE ACCESS BY INDEX ROWID     | CITY_ROUTING                   |     9 |   234 |     2 | 
    |* 12 |        INDEX RANGE SCAN               | IX9_CITY_ROUTING               |    12 |       |     1 |    
    |  13 |      TABLE ACCESS BY INDEX ROWID      | AIRPORT_ROUTING                |     1 |    30 |     2
    |* 14 |       INDEX RANGE SCAN                | IX10_AIRPORT_ROUTING           |     1 |       |     1 |   
    |* 15 |     TABLE ACCESS BY GLOBAL INDEX ROWID| DETAILED_FLIGHTS               |     2 |   122 |   
    |* 16 |      INDEX RANGE SCAN                 | IX3_DETAILED_FLIGHTS           |     9 |       |     2 |    
    |  17 |    TABLE ACCESS BY INDEX ROWID        | AIRPORT_PAIR                   |     1 |    85 |     2 |  
    |* 18 |     INDEX RANGE SCAN                  | IX1_AIRPORT_PAIR               |     1 |       |     1 |       |
    |  19 |   TABLE ACCESS BY INDEX ROWID         | OD                             |     1 |    10 |     1 |       |   
    |* 20 |    INDEX UNIQUE SCAN                  | PK_OD                          |     1 |       |       |       |       |
    ----------------------------------------------------------------------------------------------------Ouf, this sound like better, isn't it ? Was it complicated to arrive as such result ?
    Ok, now launch the query and see the elapse time :
    104103 rows selected.
    Elapsed: 00:09:00.12
    Statistics
              0  recursive calls
              0  db block gets
        1214845  consistent gets
         272481  physical reads
              0  redo size
       11164355  bytes sent via SQL*Net to client
         257032  bytes received via SQL*Net from client
           6942  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         104103  rows processedWoaw, developer is now very happy, less than 10 minutes instead of one hour... and without modify anything else in database and server settings, without add indexes, without add any hints...
    Ok, now the problem is in the number of returned lines. Have you see the number of return client/server ? We'll now to try to reduce this one. Increasing the number of line returned by fetch :
    set arraysize 5000
    --run the query
    104103 rows selected.
    Elapsed: 00:02:25.49
    Statistics
              0  recursive calls
              0  db block gets
        1150893  consistent gets
         271432  physical reads
              0  redo size
       11018641  bytes sent via SQL*Net to client
           1013  bytes received via SQL*Net from client
             22  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         104103  rows processedOk, the number of retunr client/server is now low, and elapse time is ok user.

  • Query tuning request

    This is my first post in this forum regarding query tuning, so my sincere apologies in advance if I have:
    1) not included sufficient information,
    2) included too much information,
    3) not posted to the correct forum
    I read through Randolf Geist's web page on instructions to post a query tuning request
    and attempted to follow it as closely as possible.
    I am attempting to figure out where a view I have constructed can be optimized.
    It takes approx. 45 seconds to 1 minute to run; I would like to cut that down to 10 seconds if possible.
    The view itself is somewhat complex; I will post the actual code if it will help you help me. Please advise.
    I was under the impression that posting the code was not necessary, but if it is, let me know and I will post it.
    I have been doing SQL development for a few years, but only recently in Oracle.
    I have no experience in looking through the following output and being able to tell where I can improve performance,
    so this will be a learning experience for me. Thanks in advance for your help - I appreciate it.
    Some additional information - my view is based on tables over which I have no control - it is a third-party application
    which I do reporting from. I do have the freedom to create indexes on columns within the tables if necessary.
    The statement is simply
    SELECT * FROM LLU_V_PRODUCTION_DETAIL_03
    which is the name of my view.
    here's all the information I've been able to retrieve by following Randolf's instructions:
    Oracle version is 10.2.0.1.0 - 64bit
    Here are optimizer parameters:
    NAME                                 TYPE        VALUE
    user_dump_dest                       string      C:\ORACLE\PRODUCT\10.2.0\ADMIN
                                                     \AXIUMPRODUCTION\UDUMP
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.1
    optimizer_index_caching              integer     90
    optimizer_index_cost_adj             integer     20
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     16
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          10-29-2005 01:36
    SYSSTATS_INFO        DSTOP                           10-29-2005 01:36
    SYSSTATS_INFO        FLAGS                         1
    SYSSTATS_MAIN        CPUSPEEDNW           1298.56584
    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
    13 rows selected.Here is the output of EXPLAIN PLAN:
    PLAN_TABLE_OUTPUT
    Plan hash value: 662813077
    | Id  | Operation                              | Name                        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                       |                             |    23M|    53G|       | 62330   (2)| 00:12:28 |
    |   1 |  VIEW                                  | LLU_V_PRODUCTION_DETAIL_03  |    23M|    53G|       | 62330   (2)| 00:12:28 |
    |   2 |   UNION-ALL                            |                             |       |       |       |            |          |
    |*  3 |    HASH JOIN                           |                             |    18M|  5062M|       |  1525  (10)| 00:00:19 |
    |   4 |     VIEW                               | index$_join$_007            |  1725 | 25875 |       |     4  (25)| 00:00:01 |
    |*  5 |      HASH JOIN                         |                             |       |       |       |            |          |
    |   6 |       INDEX FAST FULL SCAN             | USERS_PRIMARY               |  1725 | 25875 |       |     1   (0)| 00:00:01 |
    |   7 |       INDEX FAST FULL SCAN             | USERS_PRODUCER              |  1725 | 25875 |       |     2   (0)| 00:00:01 |
    |*  8 |     HASH JOIN                          |                             |   416K|   105M|       |  1399   (2)| 00:00:17 |
    |   9 |      TABLE ACCESS FULL                 | PRODUCER                    |  1396 |   118K|       |    24   (0)| 00:00:01 |
    |* 10 |      HASH JOIN                         |                             | 29819 |  5183K|       |  1372   (2)| 00:00:17 |
    |  11 |       TABLE ACCESS FULL                | CLASS                       |    20 |  1660 |       |     3   (0)| 00:00:01 |
    |* 12 |       TABLE ACCESS FULL                | QR_PRODUCTION               |   149K|    13M|       |  1367   (2)| 00:00:17 |
    |* 13 |    FILTER                              |                             |       |       |       |            |          |
    |* 14 |     HASH JOIN                          |                             |    16M|  5651M|       | 32983   (2)| 00:06:36 |
    |  15 |      VIEW                              | index$_join$_014            |  1725 | 25875 |       |     4  (25)| 00:00:01 |
    |* 16 |       HASH JOIN                        |                             |       |       |       |            |          |
    |  17 |        INDEX FAST FULL SCAN            | USERS_PRIMARY               |  1725 | 25875 |       |     1   (0)| 00:00:01 |
    |  18 |        INDEX FAST FULL SCAN            | USERS_PRODUCER              |  1725 | 25875 |       |     2   (0)| 00:00:01 |
    |* 19 |      HASH JOIN                         |                             |   149K|    49M|       | 32874   (1)| 00:06:35 |
    |  20 |       TABLE ACCESS FULL                | CLASS                       |    20 |  1660 |       |     3   (0)| 00:00:01 |
    |* 21 |       HASH JOIN                        |                             |   149K|    37M|       | 32870   (1)| 00:06:35 |
    |  22 |        TABLE ACCESS FULL               | PRODUCER                    |  1396 |   118K|       |    24   (0)| 00:00:01 |
    |* 23 |        HASH JOIN                       |                             |   222K|    37M|    12M| 32844   (1)| 00:06:35 |
    |  24 |         TABLE ACCESS FULL              | PATIENT                     |   188K|    10M|       |  6979   (1)| 00:01:24 |
    |* 25 |         HASH JOIN                      |                             |   222K|    24M|       | 23860   (2)| 00:04:47 |
    |* 26 |          TABLE ACCESS FULL             | PROCEDUR                    |   888 | 44400 |       |    11   (0)| 00:00:01 |
    |* 27 |          TABLE ACCESS FULL             | TRX                         |   442K|    28M|       | 23845   (2)| 00:04:47 |
    |* 28 |     TABLE ACCESS FULL                  | USERS                       |     1 |    11 |       |    55   (0)| 00:00:01 |
    |  29 |    NESTED LOOPS                        |                             |     1 |   473 |       | 25798   (1)| 00:05:10 |
    |  30 |     NESTED LOOPS                       |                             |     1 |   413 |       | 25797   (1)| 00:05:10 |
    |  31 |      NESTED LOOPS                      |                             |     1 |   398 |       | 25796   (1)| 00:05:10 |
    |  32 |       NESTED LOOPS                     |                             |     1 |   390 |       | 25795   (1)| 00:05:10 |
    |* 33 |        HASH JOIN                       |                             |     1 |   303 |       | 25794   (1)| 00:05:10 |
    |  34 |         TABLE ACCESS FULL              | LLU_EVALUATION_DESCRIPTIONS |    95 |  6175 |       |     3   (0)| 00:00:01 |
    |* 35 |         HASH JOIN                      |                             |  4630 |  1076K|       | 25791   (1)| 00:05:10 |
    |* 36 |          HASH JOIN                     |                             |  9607 |  1623K|       | 23834   (1)| 00:04:47 |
    |  37 |           MERGE JOIN                   |                             |   888 | 91464 |       |    13   (8)| 00:00:01 |
    |  38 |            TABLE ACCESS BY INDEX ROWID | CLASS                       |    20 |  1660 |       |     1   (0)| 00:00:01 |
    |  39 |             INDEX FULL SCAN            | CLASS_PRIMARY               |    20 |       |       |     1   (0)| 00:00:01 |
    |* 40 |            SORT JOIN                   |                             |   888 | 17760 |       |    12   (9)| 00:00:01 |
    |* 41 |             TABLE ACCESS FULL          | PROCEDUR                    |   888 | 17760 |       |    11   (0)| 00:00:01 |
    |* 42 |           TABLE ACCESS FULL            | TRX                         | 19125 |  1307K|       | 23820   (1)| 00:04:46 |
    |* 43 |          TABLE ACCESS FULL             | GRADITEM                    |   655K|    40M|       |  1952   (1)| 00:00:24 |
    |  44 |        TABLE ACCESS BY INDEX ROWID     | PRODUCER                    |     1 |    87 |       |     1   (0)| 00:00:01 |
    |* 45 |         INDEX UNIQUE SCAN              | PRODUCER_PRIMARY            |     1 |       |       |     1   (0)| 00:00:01 |
    |* 46 |       TABLE ACCESS BY INDEX ROWID      | GRADING                     |     1 |     8 |       |     1   (0)| 00:00:01 |
    |* 47 |        INDEX UNIQUE SCAN               | GRADING_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |  48 |      TABLE ACCESS BY INDEX ROWID       | USERS                       |   221 |  3315 |       |     1   (0)| 00:00:01 |
    |* 49 |       INDEX RANGE SCAN                 | USERS_PRODUCER              |     1 |       |       |     1   (0)| 00:00:01 |
    |  50 |     TABLE ACCESS BY INDEX ROWID        | PATIENT                     |     1 |    60 |       |     1   (0)| 00:00:01 |
    |* 51 |      INDEX UNIQUE SCAN                 | PATIENT_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |  52 |    TABLE ACCESS BY INDEX ROWID         | USERS                       |   109 |  1635 |       |     1   (0)| 00:00:01 |
    |  53 |     NESTED LOOPS                       |                             |     1 |   438 |       |  2023   (1)| 00:00:25 |
    |  54 |      NESTED LOOPS                      |                             |     1 |   423 |       |  2022   (1)| 00:00:25 |
    |  55 |       NESTED LOOPS                     |                             |     1 |   363 |       |  2021   (1)| 00:00:25 |
    |  56 |        NESTED LOOPS                    |                             |     1 |   276 |       |  2020   (1)| 00:00:25 |
    |  57 |         NESTED LOOPS                   |                             |     1 |   193 |       |  2019   (1)| 00:00:25 |
    |  58 |          NESTED LOOPS                  |                             |     1 |   185 |       |  2018   (1)| 00:00:25 |
    |  59 |           NESTED LOOPS                 |                             |     1 |   173 |       |  2017   (1)| 00:00:25 |
    |  60 |            NESTED LOOPS                |                             |     1 |   140 |       |  2016   (1)| 00:00:25 |
    |* 61 |             TABLE ACCESS FULL          | GRADITEM                    |   317 | 23141 |       |  1953   (2)| 00:00:24 |
    |* 62 |             TABLE ACCESS BY INDEX ROWID| TRX                         |     1 |    67 |       |     1   (0)| 00:00:01 |
    |* 63 |              INDEX UNIQUE SCAN         | TRX_PRIMARY                 |     1 |       |       |     1   (0)| 00:00:01 |
    |* 64 |            TABLE ACCESS BY INDEX ROWID | TRX                         |     1 |    33 |       |     1   (0)| 00:00:01 |
    |* 65 |             INDEX UNIQUE SCAN          | TRX_PRIMARY                 |     1 |       |       |     1   (0)| 00:00:01 |
    |* 66 |           TABLE ACCESS BY INDEX ROWID  | GRADITEM                    |     1 |    12 |       |     1   (0)| 00:00:01 |
    |* 67 |            INDEX RANGE SCAN            | GRADITEM_ID                 |    19 |       |       |     1   (0)| 00:00:01 |
    |* 68 |          TABLE ACCESS BY INDEX ROWID   | GRADING                     |     1 |     8 |       |     1   (0)| 00:00:01 |
    |* 69 |           INDEX UNIQUE SCAN            | GRADING_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |  70 |         TABLE ACCESS BY INDEX ROWID    | CLASS                       |     1 |    83 |       |     1   (0)| 00:00:01 |
    |* 71 |          INDEX UNIQUE SCAN             | CLASS_PRIMARY               |     1 |       |       |     1   (0)| 00:00:01 |
    |  72 |        TABLE ACCESS BY INDEX ROWID     | PRODUCER                    |     1 |    87 |       |     1   (0)| 00:00:01 |
    |* 73 |         INDEX UNIQUE SCAN              | PRODUCER_PRIMARY            |     1 |       |       |     1   (0)| 00:00:01 |
    |  74 |       TABLE ACCESS BY INDEX ROWID      | PATIENT                     |     1 |    60 |       |     1   (0)| 00:00:01 |
    |* 75 |        INDEX UNIQUE SCAN               | PATIENT_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |* 76 |      INDEX RANGE SCAN                  | USERS_PRODUCER              |     1 |       |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("QRP"."ProviderID"="U1"."Producer")
       5 - access(ROWID=ROWID)
       8 - access(TRIM("QRP"."ProviderID")=TRIM("P"."Producer"))
      10 - access(TRIM("QRP"."axiUm_Discipline")=TRIM("CLASS"."Class"))
      12 - filter("QRP"."ProviderID" IS NOT NULL AND "QRP"."Location"<'9990' AND "QRP"."ProcedureID"<>185 AND
                  "QRP"."PatientFirstName"<>'NON-PATIENT' AND ("QRP"."PatientFirstName"<>'TED' OR "QRP"."PatientLastName" NOT LIKE
                  'CAVENDER%'))
      13 - filter( NOT EXISTS (SELECT 0 FROM AXIUM."USERS" "USERS" WHERE "Custom3"='YES' AND LNNVL("User"<>:B1)) OR
                  TO_CHAR(INTERNAL_FUNCTION("P"."EndDate"),'YYYY')<'2011' OR TRIM(TO_CHAR(INTERNAL_FUNCTION("P"."EndDate"),'YYYY')) IS
                  NULL OR "TRX"."Procedure"='A0021' OR "TRX"."Procedure"='A0022')
      14 - access("TRX"."Producer"="U1"."Producer")
      16 - access(ROWID=ROWID)
      19 - access("PROC"."Discipline"="CLASS"."Class")
      21 - access("TRX"."Producer"="P"."Producer")
      23 - access("TRX"."Patient"="PAT"."Patient")
      25 - access("TRX"."Procedure"="PROC"."Procedure")
      26 - filter("PROC"."Discipline" IS NOT NULL)
      27 - filter("TRX"."Deleted"=0 AND "TRX"."Status"='C' AND "TRX"."Procedure" NOT LIKE 'D0149%' AND
                  "TRX"."Procedure"<>'D5001C')
      28 - filter("Custom3"='YES' AND LNNVL("User"<>:B1))
      33 - access(TRIM(UPPER("GI"."QuestionText"))=TRIM(UPPER("LLU"."GRADITEM_QuestionText")) AND
                  TRIM(UPPER("GI"."Text"))=TRIM(UPPER("LLU"."GRADITEM_Text")) AND TRIM("TRX"."Procedure")=TRIM("LLU"."ProcedureCode"))
      35 - access("TRX"."Type"="GI"."Type" AND "TRX"."Id"="GI"."Id" AND "TRX"."Treatment"="GI"."Treatment")
      36 - access("TRX"."Procedure"="PROC"."Procedure")
      40 - access("PROC"."Discipline"="CLASS"."Class")
           filter("PROC"."Discipline"="CLASS"."Class")
      41 - filter("PROC"."Discipline" IS NOT NULL)
      42 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C')
      43 - filter("GI"."Grading"<>0)
      45 - access("TRX"."Producer"="P"."Producer")
      46 - filter("G"."Deleted"=0)
      47 - access("TRX"."Grading"="G"."Grading")
           filter("G"."Grading"<>0 AND "G"."Grading"="GI"."Grading")
      49 - access("TRX"."Producer"="U1"."Producer")
      51 - access("TRX"."Patient"="PAT"."Patient")
      61 - filter("GI"."IsHeading"=3 AND TRIM("GI"."QuestionText")='Comments' AND "GI"."Grading"<>0)
      62 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C' AND ("TRX"."Procedure"='G1002' OR
                  "TRX"."Procedure"='G1003'))
      63 - access("GI"."Type"="TRX"."Type" AND "GI"."Id"="TRX"."Id" AND "GI"."Treatment"="TRX"."Treatment")
      64 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C' AND ("TRX"."Procedure"='G1002' OR
                  "TRX"."Procedure"='G1003') AND "TRX"."Grading"="TRX"."Grading")
      65 - access("TRX"."Type"="TRX"."Type" AND "TRX"."Id"="TRX"."Id" AND "TRX"."Treatment"="TRX"."Treatment")
      66 - filter("GI"."RelValue"<>0 AND "TRX"."Type"="GI"."Type" AND "TRX"."Treatment"="GI"."Treatment")
      67 - access("TRX"."Id"="GI"."Id")
      68 - filter("G"."Deleted"=0)
      69 - access("TRX"."Grading"="G"."Grading")
           filter("G"."Grading"<>0 AND "GI"."Grading"="G"."Grading")
      71 - access("TRX"."Discipline"="CLASS"."Class")
      73 - access("TRX"."Producer"="P"."Producer")
      75 - access("TRX"."Patient"="PAT"."Patient")
      76 - access("TRX"."Producer"="U1"."Producer")
    138 rows selected.
    Elapsed: 00:00:00.62
    631015 rows selected.
    Elapsed: 00:01:49.13Output from AUTOTRACE (I think)
    NOTE: this post was too long for the forum, so I have removed a number of lines in the following output which appeared to be duplicating the above section (EXPLAIN PLAN).
    Statistics
           2657  recursive calls
              0  db block gets
       12734113  consistent gets
          13499  physical reads
              0  redo size
      103697740  bytes sent via SQL*Net to client
          69744  bytes received via SQL*Net from client
           6312  SQL*Net roundtrips to/from client
             76  sorts (memory)
              0  sorts (disk)
         631015  rows processedThe TKPROF output
    select * from llu_v_production_detail_03
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.51       0.51          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch     6312     88.09      98.01      13490   12733584          0      631015
    total     6314     88.60      98.52      13490   12733584          0      631015
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 57 
    Rows     Row Source Operation
    631015  VIEW  LLU_V_PRODUCTION_DETAIL_03 (cr=12733584 pr=13490 pw=0 time=92145592 us)
    631015   UNION-ALL  (cr=12733584 pr=13490 pw=0 time=91514573 us)
    125485    HASH JOIN  (cr=8099 pr=6396 pw=0 time=1523326 us)
       1725     VIEW  index$_join$_007 (cr=24 pr=0 pw=0 time=4777 us)
       1725      HASH JOIN  (cr=24 pr=0 pw=0 time=3051 us)
       1725       INDEX FAST FULL SCAN USERS_PRIMARY (cr=7 pr=0 pw=0 time=50 us)(object id 55023)
       1725       INDEX FAST FULL SCAN USERS_PRODUCER (cr=17 pr=0 pw=0 time=16 us)(object id 55024)
    144513     HASH JOIN  (cr=8075 pr=6396 pw=0 time=2326445 us)
       1396      TABLE ACCESS FULL PRODUCER (cr=107 pr=0 pw=0 time=29 us)
    144513      HASH JOIN  (cr=7968 pr=6396 pw=0 time=2035684 us)
         20       TABLE ACCESS FULL CLASS (cr=7 pr=0 pw=0 time=71 us)
    151043       TABLE ACCESS FULL QR_PRODUCTION (cr=7961 pr=6396 pw=0 time=313553 us)
    462685    FILTER  (cr=10755862 pr=7094 pw=0 time=58570941 us)
    466790     HASH JOIN  (cr=145247 pr=7094 pw=0 time=11007301 us)
       1725      VIEW  index$_join$_014 (cr=24 pr=0 pw=0 time=6817 us)
       1725       HASH JOIN  (cr=24 pr=0 pw=0 time=5091 us)
       1725        INDEX FAST FULL SCAN USERS_PRIMARY (cr=7 pr=0 pw=0 time=35 us)(object id 55023)
       1725        INDEX FAST FULL SCAN USERS_PRODUCER (cr=17 pr=0 pw=0 time=19 us)(object id 55024)
    485205      HASH JOIN  (cr=145223 pr=7094 pw=0 time=10945107 us)
         20       TABLE ACCESS FULL CLASS (cr=7 pr=0 pw=0 time=105 us)
    507772       HASH JOIN  (cr=145216 pr=7094 pw=0 time=11947534 us)
       1396        TABLE ACCESS FULL PRODUCER (cr=107 pr=0 pw=0 time=18 us)
    507772        HASH JOIN  (cr=145109 pr=7094 pw=0 time=10924473 us)
    188967         TABLE ACCESS FULL PATIENT (cr=31792 pr=0 pw=0 time=188998 us)
    507772         HASH JOIN  (cr=113317 pr=7094 pw=0 time=9652037 us)
        895          TABLE ACCESS FULL PROCEDUR (cr=46 pr=0 pw=0 time=65 us)
    509321          TABLE ACCESS FULL TRX (cr=113271 pr=7094 pw=0 time=5604567 us)
       8548     TABLE ACCESS FULL USERS (cr=10610615 pr=0 pw=0 time=39053120 us)
      42669    NESTED LOOPS  (cr=507317 pr=0 pw=0 time=3686506 us)
      42669     NESTED LOOPS  (cr=421535 pr=0 pw=0 time=3217140 us)
      45269      NESTED LOOPS  (cr=301155 pr=0 pw=0 time=2449542 us)
      45323       NESTED LOOPS  (cr=210131 pr=0 pw=0 time=2134056 us)
      45323        HASH JOIN  (cr=119056 pr=0 pw=0 time=1635472 us)
         95         TABLE ACCESS FULL LLU_EVALUATION_DESCRIPTIONS (cr=7 pr=0 pw=0 time=118 us)
      98272         HASH JOIN  (cr=119049 pr=0 pw=0 time=1446703 us)
      46996          HASH JOIN  (cr=109018 pr=0 pw=0 time=944857 us)
        786           MERGE JOIN  (cr=50 pr=0 pw=0 time=1528 us)
         20            TABLE ACCESS BY INDEX ROWID CLASS (cr=4 pr=0 pw=0 time=99 us)
         20             INDEX FULL SCAN CLASS_PRIMARY (cr=1 pr=0 pw=0 time=10 us)(object id 53850)
        786            SORT JOIN (cr=46 pr=0 pw=0 time=750 us)
        895             TABLE ACCESS FULL PROCEDUR (cr=46 pr=0 pw=0 time=18 us)
      47196           TABLE ACCESS FULL TRX (cr=108968 pr=0 pw=0 time=805137 us)
    696300          TABLE ACCESS FULL GRADITEM (cr=10031 pr=0 pw=0 time=277 us)
      45323        TABLE ACCESS BY INDEX ROWID PRODUCER (cr=91075 pr=0 pw=0 time=414937 us)
      45323         INDEX UNIQUE SCAN PRODUCER_PRIMARY (cr=45752 pr=0 pw=0 time=198709 us)(object id 54581)
      45269       TABLE ACCESS BY INDEX ROWID GRADING (cr=91024 pr=0 pw=0 time=353081 us)
      45270        INDEX UNIQUE SCAN GRADING_PRIMARY (cr=45753 pr=0 pw=0 time=173185 us)(object id 54088)
      42669      TABLE ACCESS BY INDEX ROWID USERS (cr=120380 pr=0 pw=0 time=703786 us)
      42669       INDEX RANGE SCAN USERS_PRODUCER (cr=46127 pr=0 pw=0 time=249186 us)(object id 55024)
      42669     TABLE ACCESS BY INDEX ROWID PATIENT (cr=85782 pr=0 pw=0 time=407452 us)
      42669      INDEX UNIQUE SCAN PATIENT_PRIMARY (cr=43098 pr=0 pw=0 time=198477 us)(object id 54370)
        176    TABLE ACCESS BY INDEX ROWID USERS (cr=49426 pr=0 pw=0 time=1783886 us)
        367     NESTED LOOPS  (cr=49149 pr=0 pw=0 time=6159428 us)
        190      NESTED LOOPS  (cr=48953 pr=0 pw=0 time=409391 us)
        190       NESTED LOOPS  (cr=48569 pr=0 pw=0 time=407105 us)
        190        NESTED LOOPS  (cr=48185 pr=0 pw=0 time=404820 us)
        191         NESTED LOOPS  (cr=47991 pr=0 pw=0 time=410291 us)
        193          NESTED LOOPS  (cr=47603 pr=0 pw=0 time=422507 us)
        193           NESTED LOOPS  (cr=46979 pr=0 pw=0 time=416890 us)
        193            NESTED LOOPS  (cr=46396 pr=0 pw=0 time=414374 us)
      14285             TABLE ACCESS FULL GRADITEM (cr=9602 pr=0 pw=0 time=85793 us)
        193             TABLE ACCESS BY INDEX ROWID TRX (cr=36794 pr=0 pw=0 time=128427 us)
       8218              INDEX UNIQUE SCAN TRX_PRIMARY (cr=28576 pr=0 pw=0 time=64353 us)(object id 54930)
        193            TABLE ACCESS BY INDEX ROWID TRX (cr=583 pr=0 pw=0 time=2169 us)
        193             INDEX UNIQUE SCAN TRX_PRIMARY (cr=390 pr=0 pw=0 time=918 us)(object id 54930)
        193           TABLE ACCESS BY INDEX ROWID GRADITEM (cr=624 pr=0 pw=0 time=4840 us)
       1547            INDEX RANGE SCAN GRADITEM_ID (cr=395 pr=0 pw=0 time=2910 us)(object id 54093)
        191          TABLE ACCESS BY INDEX ROWID GRADING (cr=388 pr=0 pw=0 time=1887 us)
        191           INDEX UNIQUE SCAN GRADING_PRIMARY (cr=197 pr=0 pw=0 time=943 us)(object id 54088)
        190         TABLE ACCESS BY INDEX ROWID CLASS (cr=194 pr=0 pw=0 time=1306 us)
        190          INDEX UNIQUE SCAN CLASS_PRIMARY (cr=4 pr=0 pw=0 time=551 us)(object id 53850)
        190        TABLE ACCESS BY INDEX ROWID PRODUCER (cr=384 pr=0 pw=0 time=1617 us)
        190         INDEX UNIQUE SCAN PRODUCER_PRIMARY (cr=194 pr=0 pw=0 time=715 us)(object id 54581)
        190       TABLE ACCESS BY INDEX ROWID PATIENT (cr=384 pr=0 pw=0 time=1941 us)
        190        INDEX UNIQUE SCAN PATIENT_PRIMARY (cr=194 pr=0 pw=0 time=939 us)(object id 54370)
        176      INDEX RANGE SCAN USERS_PRODUCER (cr=196 pr=0 pw=0 time=1389 us)(object id 55024)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                    6312        0.00          0.00
      db file scattered read                       1614        0.02          2.08
      SQL*Net message from client                  6312        0.00         10.11
      SQL*Net more data to client                 48662        0.00          0.70
      db file sequential read                      4645        0.02          7.11
      latch: shared pool                              7        0.00          0.00
      latch: cache buffers chains                     1        0.00          0.00
    ********************************************************************************Again, I apologize if this is way more information than is necessary.
    All advice/suggestions/assistance will be gratefully accepted.
    Carl

    Hi Rob,
    Thank you for replying. Here is the view definition . . . it looks pretty convoluted, I know.
    I am reporting from a database which I have no control over other than to add indexes where needed.
    For reporting purposes, I am needing to create the dataset from a number of different tables; hence all the UNION clauses.
    -- CODE FOLLOWS
    CREATE OR REPLACE VIEW LLU_V_PRODUCTION_DETAIL_03
    AS
    SELECT
      'QR' AS "Source",
      U1."User" AS "UserID",
      QRP."ProviderID" AS "ProviderID",
      P."LastName" AS "ProviderLastName",
      P."FirstName" AS "ProviderFirstName",
      TO_CHAR(P."EndDate",'YYYY') AS "GraduationYear",
      P."PGroup",
      QRP."PatientID",
      QRP."ChartNumber",
      QRP."PatientLastName",
      QRP."PatientFirstName",
      QRP."ProcedureID" || '-' || QRP."ProcedureSuffix" AS "Procedure",
      QRP."ProcedureDescription",
      QRP."Tooth" AS "Site",
      QRP."Surface",
      QRP."axiUm_Discipline" AS "Discipline",
      "CLASS"."Rank" AS "DisciplineSorter",
      "CLASS"."Name" AS "DisciplineName",
      QRP."Points",
      0 AS "Hours",
      QRP."ServiceDate",
      0 AS "Id",
      QRP."UniqueID" AS "Grading",
      0 AS "LastSort",
      QRP."CategoryID",
      '' AS "CPAR comments"
    FROM QR_PRODUCTION QRP
    INNER JOIN PRODUCER P
      ON TRIM(QRP."ProviderID") = TRIM(P."Producer")
    INNER JOIN CLASS
      ON TRIM(QRP."axiUm_Discipline") = TRIM(CLASS."Class")
    INNER JOIN USERS U1
      ON QRP."ProviderID" = U1."Producer"
    WHERE (QRP."Location" < '9990')
    AND (QRP."ProviderID" IS NOT NULL)
    AND (QRP."ProcedureID" <> 185)
    -- skip the Cavender family - training patients
    AND NOT (QRP."PatientLastName" LIKE 'CAVENDER%' AND QRP."PatientFirstName" = 'TED')
    AND QRP."PatientFirstName" <> 'NON-PATIENT'
    --ORDER BY QRP."ProcedureID"
    UNION ALL
    SELECT
      'axiUm TRX' AS "Source",
      U1."User" AS "UserID",
      TRX."Producer" AS "ProviderID",
      P."LastName",
      P."FirstName",
      TO_CHAR(P."EndDate",'YYYY') AS "GraduationYear",
      P."PGroup",
      PAT."Patient",
      PAT."Chart",
      PAT."Last" AS "PatientLastName",
      PAT."First" AS "PatientFirstName",
      TRX."Procedure",
      PROC."Description",
      TRX."Site",
      TRX."Surface",
      TRIM(PROC."Discipline") AS "Discipline",
      "CLASS"."Rank" AS "DisciplineSorter",
      "CLASS"."Name",
      CASE WHEN
          ((TRX."Procedure" IN ('A0013','A0019','A0020','A0021','A0023','A0024','A0025','A0026','A0027','A0028','A0029','A0030','O179'))
          OR
          -- no points are to be awarded for any procedures performed on typodonts
          (EXISTS (SELECT 1 FROM PTTYPES PTT WHERE PTT."Patient" = PAT."Patient" and PTT."PatType" = 'TYPO' and PTT."Deleted" = 0)))
        AND  -- except for the following procedures
          (TRX."Procedure" NOT IN ('A0015','A0016','A0018','D0210'))
        THEN 0 ELSE PROC."RelValue" END AS "Points",
      CASE WHEN TRX."Procedure" IN ('A0013','A0019','A0020','A0021','A0023','A0024','A0025','A0026','A0027','A0028','A0029','A0030','O179')
        THEN PROC."RelValue" ELSE 0 END AS "Hours",
      TRX."TreatmentDate",
      TRX."Id",
      TRX."Grading",
      -1 AS "LastSort",
      -- additional link conditions added and table name changed on 1 July 2009 - cji
      SELECT "CategoryID" FROM LLU_CATEGORIES_X_PROCEDURES_03 LLU
      WHERE TRX."Procedure" = LLU."ProcedureID"
      AND TO_CHAR(P."EndDate",'YYYY') = LLU."GraduationYear"
      AND SUBSTR(TRX."Producer",1,1) = LLU."ProviderType"
      AND LLU."CategoryID" NOT IN (82)
      ) AS "CategoryID",
      '' AS "CPAR comments"
    FROM TRX
    INNER JOIN PATIENT PAT
      ON TRX."Patient" = PAT."Patient"
    INNER JOIN USERS U1
      ON TRX."Producer" = U1."Producer"
    INNER JOIN PROCEDUR PROC
      ON TRX."Procedure" = PROC."Procedure"
    INNER JOIN CLASS
      ON PROC."Discipline" = CLASS."Class"
    INNER JOIN PRODUCER P
      ON TRX."Producer" = P."Producer"
    WHERE (TRX."Status" = 'C')
    AND (TRX."Deleted" = 0)
    --AND (TRX."Grading" = 0)
    AND (TRX."Procedure" NOT LIKE 'D0149%')
    AND (TRX."Procedure" <> 'D5001C')
    -- exclude all procedures approved by Peds faculty ONLY FOR CLASS OF 2011 AND LATER
    -- EXCEPT FOR the Peds Block code (A0021 and A0022) - always include those
    AND NOT
    TRX."AppUser" IN (SELECT "User" FROM USERS WHERE "Custom3" = 'YES') -- Peds faculty
    AND
    TO_CHAR(P."EndDate",'YYYY') >= '2011'
    AND
    TRIM(TO_CHAR(P."EndDate",'YYYY')) IS NOT NULL
    AND
    TRX."Procedure" NOT IN ('A0021','A0022')
    UNION ALL
    SELECT
      'axiUm GRADING' AS "Source",
      U1."User" AS "UserID",
      TRX."Producer" AS "ProviderID",
      P."LastName",
      P."FirstName",
      TO_CHAR(P."EndDate",'YYYY'), -- Graduation year
      P."PGroup",
      PAT."Patient",
      PAT."Chart",
      PAT."Last" AS "PatientLastName",
      PAT."First" AS "PatientFirstName",
      TRX."Procedure",
      LLU."Description",
      TRX."Site",
      TRX."Surface",
      TRIM(PROC."Discipline") AS "Discipline",
      "CLASS"."Rank" AS "DisciplineSorter",
      "CLASS"."Name",
      LLU."Points", --LLU_POINTS_FROM_EVALUATIONS(TRX."Procedure", nvl(GI."Text",0)),
      0 AS "Hours",
      TRX."TreatmentDate",
      GI."Id",
      GI."Grading",
      GI."Row" AS "LastSort",
      LLU."CategoryID",
      '' AS "CPAR comments"
    FROM TRX
    INNER JOIN PATIENT PAT
      ON TRX."Patient" = PAT."Patient"
    INNER JOIN PRODUCER P
      ON TRX."Producer" = P."Producer"
    INNER JOIN GRADING G
      ON TRX."Grading" = G."Grading"
    INNER JOIN GRADITEM GI
      ON G."Grading" = GI."Grading"
      AND TRX."Type" = GI."Type"
      AND TRX."Id" = GI."Id"
      AND TRX."Treatment" = GI."Treatment"
    INNER JOIN PROCEDUR PROC
      ON TRX."Procedure" = PROC."Procedure"
    INNER JOIN CLASS
      ON PROC."Discipline" = CLASS."Class"
    INNER JOIN LLU_EVALUATION_DESCRIPTIONS LLU
      ON (TRIM(UPPER(GI."QuestionText")) = TRIM(UPPER(LLU."GRADITEM_QuestionText")))
      AND (TRIM(UPPER(GI."Text")) = TRIM(UPPER(LLU."GRADITEM_Text")))
      AND (TRIM(TRX."Procedure") = TRIM(LLU."ProcedureCode"))
    INNER JOIN USERS U1
      ON TRX."Producer" = U1."Producer"
    WHERE (TRX."Status" = 'C')
    AND (TRX."Deleted" = 0)
    AND (TRX."Grading" <> 0)
    AND (G."Deleted" = 0)
    UNION ALL
    SELECT 'ClinPtsAdj',
      U1."User" AS "UserID",
      TRX."Producer",
      P."LastName", P."FirstName",
      TO_CHAR(P."EndDate",'YYYY'), -- Graduation year
      P."PGroup", PAT."Patient", PAT."Chart", PAT."Last", PAT."First",
      TRX."Procedure",
      'Clinic points adjustment',
      '' AS "Site",
      '' AS "Surface",
      TRIM(TRX."Discipline"),
      "CLASS"."Rank",
      "CLASS"."Name",
      DERIVED."Points",
      0 AS "Hours",
      GI."Date",
      GI."Id",
      GI."Grading",
      GI."Row",
      NULL AS "CategoryID",
      TRIM(REPLACE(GI."Note", CHR(13) || CHR(10), ' '))
    FROM TRX
    INNER JOIN PATIENT PAT
      ON (TRX."Patient" = PAT."Patient")
    INNER JOIN PRODUCER P
      ON (TRX."Producer" = P."Producer")
    INNER JOIN CLASS
      ON (TRX."Discipline" = CLASS."Class")
    INNER JOIN GRADING G
      ON (TRX."Grading" = G."Grading")
    INNER JOIN GRADITEM GI
      ON (GI."Grading" = G."Grading")
      AND (GI."Type" = TRX."Type")
      AND (GI."Id" = TRX."Id")
      AND (GI."Treatment" = TRX."Treatment")
    INNER JOIN USERS U1
      ON TRX."Producer" = U1."Producer"
    INNER JOIN
      SELECT TRX."Type", TRX."Id", TRX."Treatment", TRX."Grading",
        CASE WHEN TRX."Procedure" = 'G1003' THEN GI."RelValue" * -1 ELSE "RelValue" END AS "Points"
      FROM TRX, GRADITEM GI
      WHERE (TRX."Type" = GI."Type")
      AND (TRX."Id" = GI."Id")
      AND (TRX."Treatment" = GI."Treatment")
      AND (TRX."Procedure" IN ('G1002','G1003'))
      AND (TRX."Status" = 'C')
      AND (TRX."Deleted" = 0)
      AND (TRX."Grading" <> 0)
      AND (GI."RelValue" <> 0)
      ) DERIVED
      ON (TRX."Type" = DERIVED."Type")
      AND (TRX."Id" = DERIVED."Id")
      AND (TRX."Treatment" = DERIVED."Treatment")
      AND (TRX."Grading" = DERIVED."Grading")
    WHERE (TRX."Status" = 'C')
    AND (TRX."Deleted" = 0)
    AND (TRX."Grading" <> 0)
    AND (G."Deleted" = 0)
    AND (TRX."Procedure" IN ('G1002','G1003'))
    AND (GI."IsHeading" = 3)
    AND (TRIM(GI."QuestionText") = 'Comments')
    --ORDER BY "ProviderID", "DisciplineSorter", "Id", "Grading", "Site", "LastSort";A couple of additional points:
    The table USERS already had an index on column "Producer"; I added an index on column "Custom3" but it did not seem to make any difference.
    Table USERS has 1,725 rows
    Table PRODUCER (aliased as P) has 1,396 rows
    Table TRX has 1,443,764 rows.
    Any additional information you need I will be glad to provide.
    Thanks a bunch; it may not be too late to teach an old dog new tricks.
    And thank you all for the kind words about the posting; about the only thing I can do well is follow directions.
    Carl

  • Query tuning basics..

    Friends and gurus...
    OS: Linux
    DB: 11gR2
    Recently I have found myself trapped into many sql query tuning with and without bind variables and main aim of all tuning is to reduce total elapsed time displayed in AWR report.
    I found myself run all over the places just to identify problem and then try to solve it..
    with near to zero experience in query tuning I'm trying to learn this art and have below questions...
    Q.
    1. Identify problem: could somebody please list what all internal oracle tools available just to identify problem and what should be best approach?
    like sqltrace, explain plan, tkprof etc... list goes on so wanting to know which to follow and when...
    2. any idea how to get all details of steps listed in explain plan? since predicate information only list few steps where filter is used but some steps which takes long (hash join, nested loops) I don't know what caused it...
    3. how to identify problems in queries with bind variable?
    please note I don't have any 3rd party tool and all I work on is sqlplus session.
    thanks,

    khallas301, beside SB's reference to the Performance and Tuning Guide I want to point out that use of the AWR requires purchase of the extra cost EM Diagnositc and potentially also the Performance Pack License.
    You can use statspack if you do not have the EM liceses.
    How you approach what to tune depends a bit on the envornment. If only a few processes are having issues then you can look into customer complaints and tune what people are complaigning about. On the other hand if the entire system is having issues then you might want to identify critical processes and start with them.
    One approach would be to run sql trace on a critical process. Review the traces and tune the SQL statements you find having issues. Record the results and move on to the next critical process.
    Another approach would be to query the dynamic performance views for SQL with high logical IO counts, determine what processes the SQL is coming from, and tune that SQL.
    HTH -- Mark D Powell --

  • Query tuning and using the "better" index.

    I have a database table with about 40,000 records in it. Using
    a certain index first limits the number of rows to 11,000
    records. Using a different index first (by disabling the other
    index in the query) limits the number of rows to 2,500 records.
    Using the explain plan, the rest of the query is parsed the same
    way for both queries. What reasons can explain why when the
    index that returns 11,000 records first runs faster than
    the "better" index? I thought the whole idea behind query
    tuning is to use the index that limits the data the most.

    It looks like Oracle likes the equality condition more than the greater than -less than combination (which you might like to recode as a BETWEEN condition for clarity).
    There are a number of factors here.
    i) Are the "test names" equally distributed? Do some test names appear with greater frequency than others? If so, collecting column statistics might cause the BATCH_2 index to be used for some test names, and not for others.
    ii) Likewise, what is the distribution of cdates? How does the distribution of cdates vary by test name?
    iii) You could force the use of the BATCH_6 index over the BATCH_2 by using an optimizer hint instead of dropping the BATCH_2 index ...
    select /*+ index(batch batch_6) */ id, test, cdate
    from batch
    where test = 'Some test name'
    and cdate >= &start date&
    and cdate < &end date& + 1
    ... or even try prompting Oracle to use both indexes ...
    select /*+ index(batch batch_6) index(batch batch_2) */ id, test, cdate
    from batch
    where test = 'Some test name'
    and cdate >= &start date&
    and cdate < &end date& + 1
    ... and test the response times, then chose to use the optimizer hint in your application
    iv) You might like to replace the rather unselective BATCH_2 index with a BATCH_2_6 index on both test and cdate (in that order). That would probably give you an excellent result, and the BATCH_6 index can still be used to satisfy queries slective on cdate that are not selective on test (in very recent versions of Oracle the BATCH_2_6 index might be used for such an operation, and you could drop both BATCH_6 and BATCH_2)
    Well, see if any of this helps.

  • SQL query tunning help

    Hi All,
    Could you please help me out the below SQL query tuning .
    Temp table is having 1 Million records
    Master table is having 60 Million records
    Query :
    SELECT B.*,U.ID, SD, LE, LAE
    FROM client.Temp B, client.Master
    U WHERE U.policyno = B.policyno
    AND B.UPFLAG = 0
    1.     Indexes are created on both email columns and Upflag for both tables.
    2.     Gathered DBMS Stats for MASTER Table
    Data is loading 100k/hour on production .

    When your query takes too long ...
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • BPPO - Query Tuning in BI

    Hi Experts,
    We received red alert in EWA report for BI check. We have BI NetWeaver 2004 system. We have raised an OSS message for this red alert. SAP has replied with the following comments.
    "Based on the EWA report, it seems that the overall runtime for all
    queries is very high thus the reason behind the red rated report. In
    section 11.1.1 (BI-KPI) the 'BPPO - Query Tuning' service is
    recommended"
    Can anyone tell me how to do the BBPO Query Tuning. I am from Basis team, does this task come under Basis activity. If yes please, send some links and blogs which explains about Query Tuning.
    Thanks & Regards,
    Sundara.

    Dear experts:
    Can anyone help us ,I have the same issues as descriot above.
    any reply is hightly appreiciated.
    BR Cai

  • Ebooks on SQL Query tuning

    HI.
    can somebody post me any links for ebooks on SQL Query tuning techniques for either 10g or 11g.
    Tuning SQL Queries is something I would like to build my expertise on..
    There may be a lot of advisors like SQL Query Advisor, Access Advisor and so on...but nothing like tuning your queries manually to maximum optimization.
    Kindly help me in this !!

    Check Oracle docs http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/toc.htm
    But you should really also be checking:
    http://www.asktom.oracle.com
    http://tkyte.blogspot.com
    AND all other blogs he referres to ( like Jonathan Lewis' site and blog ) you'll find many interesting articles over there, from 'the real world', regarding performance and tuning.
    Edited by: hoek on Mar 24, 2009 10:40 AM

  • Performance tuning or Query tuning

    Hi,
    I am a PL/SQL programmer and I wanna learn Query tuning or performance tuning to extend my knowledge.
    Can any one please suggest me where to start? I read somthing RBO and CBO and get into confusion is oracle supports both? which one is better? how to use them...is it differ from version to version like 9i/10g
    I appreciate any kind of help.
    Thanks and Regards
    Mai

    Hi,
    If you a pl/sql programmer than I shall assume that you don't do much database activity and at the moment , would be upgrading yourself with the database knowledge. I shall suggest in addition to Oracle docs, these books in order to understand Query Tuning.
    Effective-Oracle-By-Design
    Cost-Based-Oracle-Fundamentals
    Practical-Oracle8i
    I have found these books as the best ones in the understandng of various very important factors in query tuning and I use these books every day.
    HTH
    Aman....

  • XSLT mapping Help Required.

    XSLT mapping Help Required.
    Hi Experts,
    I am New to XSLT Mapping. I am practising the below Example:
    InputXML File:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="Persons111.xsl"?>
    <ns0:MT_XSLT_Source xmlns:ns0="http://XYZ.com/gen">
    <Person>
    <FirstName>Anshul</FirstName>
    <LastName>Chowdhary</LastName>
    <Gender>Male</Gender>
    <Address>
    <Street>2nd Main</Street>
    <Houseno>83/b</Houseno>
    <City>Mysore</City>
    </Address> </Person>
    </ns0:MT_XSLT_Source>
    XSL StyleSheet File:
    <?xml version='1.0' encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://XYZ.com/Gen"
    Xmlns:ns1=”http://XYZ.com/Test”>
    <xsl:template match="/">
    <ns1:MT_XSLT_Target>
    <Title> <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/> </Title>
    <Name> <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/>
    </Name>
    <Street> <xsl:value-of select="concat(concat(ns0:Mt_XSLT_Source/Person/Address/Houseno,' '),
    ns0:Mt_XSLT_Source/Person/Address/Street)"/> </Street>
    <City> <xsl:value-of select="ns0:Mt_XSLT_Source/Person/Address/City"/> </City>
    </ns1:MT_XSLT_Target>
    </xsl:template>
    </xsl:stylesheet>
    The Desired Output shuold be:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns1:MT_XSLT_Target xmlns:ns1="http://XYZ.com/Test">
    <Title>Male</Title>
    <Name>Anshul Chowdhary</Name>
    <Street>83/b 2nd Main</Street>
    <City>Mysore</City>
    </ns1:MT_XSLT_Target>
    I have refered the xsl in xml and i am getting the below Oupt in a Single line like this:
    Anshul Chowdhary Male 2nd Main 83/b Mysore
    I am Unable to display in Target XML Fomrat as shown above. Please check and do the needful.
    Regards,
    GIRIDHAR

    Hi,
    I have used below for testing.
    Input xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="Persons111.xsl"?>
    <ns0:MT_XSLT_Source xmlns:ns0="http://XYZ.com/gen">
    <Person>
    <FirstName>Anshul</FirstName>
    <LastName>Chowdhary</LastName>
    <Gender>Male</Gender>
    <Address>
    <Street>2nd Main</Street>
    <Houseno>83/b</Houseno>
    <City>Mysore</City>
    </Address> </Person>
    </ns0:MT_XSLT_Source>
    xsl code:
    <?xml version='1.0' encoding="UTF-8"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://XYZ.com/gen" 
        xmlns:ns1="http://XYZ.com/Test"> 
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
        <xsl:template match="/"> 
            <ns1:MT_XSLT_Target> 
                <Title> <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/> </Title> 
                <Name> <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/> 
                </Name> 
                <Street> <xsl:value-of select="concat(concat(/ns0:MT_XSLT_Source/Person/Address/Houseno,' '), 
                    /ns0:MT_XSLT_Source/Person/Address/Street)"/> </Street> 
                <City> <xsl:value-of select="/ns0:MT_XSLT_Source/Person/Address/City"/> </City> 
            </ns1:MT_XSLT_Target> 
        </xsl:template> 
    </xsl:stylesheet>
    For testing in PI ,change the extension from .txt to .xsl and zip it and upload into PI as an imported archive .
    Regards
    Venkat

Maybe you are looking for

  • Please shed some light on Chunked Transfer Coding for HTTP 1.1?

    I am writing a HTTP proxy in Java, but I have a problem. I am writing a HTTP 1.0 proxy. As you probably know, HTTP 1.0 determines the length of the message body using Content-Length and HTTP 1.1 server are supposed to send a Content-Length header to

  • Interactive PDF not working. Please help.

    Hi, Can anyone help me please? I've created a website prototype with just two pages (home and lower page). For the relevant navigation I have created two links and and rollover states to demonstrate interactivity. I've set this up using slices and sw

  • Purchasing apps through Apple's web store without going through iTunes?

    Is there any way to purchase iPad app without billing through iTunes account? The reason is that I want to purchase the app through corporate's billing service, such as using a PO (purchase order) rather than through credit card. Is there an alternat

  • Changes are not reflected when objects transported from Quality to Productn

    Hi In case of moving some Transport requests from Quality to Production, some times the changes made to the selection screen of a report program doesn't reflect in Production. Also we don't see any Transport error while transporting. Moreover, we can

  • Declined Invitation.

    I have read over this forum numerous times to try and figure this out, but still no luck with the problem. I am trying to video chat over iChat. My girlfriend uses AIM and a Dell laptop. I can connect to the Apple test buddies just fine but whenever