Tuning request

I have a query that takes 7 seconds to complete and I want to speed it up by tuning. Any suggestions are appreciated!
Thanks,
Griff
Features of the query:
* All the columns used in the where clause of the select statement have indexes except one CLOB. (A CLOB cannot have an index.)
* The CLOB column is called “text” and is lowered and searched: lower(text) like '%<search_string>%'
* The select statement orders the query, causing a sort.
* The table in the select statement has about 75,000 rows.
I have 1G of RAM and sga_target is set to 804M. The CPU has 2.13 Ghz.
Here's the output from SQL_TRACE and TKPROF:
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        3      1.52       6.01        848      32668      50057          31
total        5      1.52       6.01        848      32668      50057          31
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 5 
Rows     Row Source Operation
     31  SORT ORDER BY (cr=32668 pr=848 pw=0 time=6012529 us)
    767   TABLE ACCESS FULL SFBAY_JOBS (cr=32668 pr=848 pw=0 time=8876275 us)

Hi Griff,
You can remove the full-table scan with a %like% with text indexes, but there is overhead. Indexing when using the SQL "like" clause can be tricky because the wildcard "%" operator can invalidate the index. For example a last_name index would be OK with a "like 'SMI%'" query, but unusable with "like '%SMI%'.
One obscure trick for indexing queries "like '%SON'" is to create a REVERSE index and them programmatically reverse the like clause to read "like 'NOS%'", effectively indexing on the other side of the text.
http://www.dba-oracle.com/t_sql_like_clause_index_usage.htm
The Oracle*Text utility (formally called Oracle ConText and Oracle Intermedia) allows us to parse through a large text column and index on the words within the column.
Unlike ordinary b-tree or bitmap indexes, Oracle context, ctxcat and ctxrule indexes are NOT updated as content is changed. Since most standard Oracle databases will use the ctxcat index with standard relational tables, you must decide on a refresh interval.
Hence, Oracle Text indexes are only useful for removing full-table scans when the tables are largely read-only and/or the end-users don’t mind not having 100% search recall:
- The target table is relatively static (e.g. nightly batch updates)
- Your end-users would not mind “missing” the latest row data
Oracle Text works with traditional data columns and also with XML, MS-Word docs and Adobe PDF files that are stored within Oracle. Oracle Text has several index types:
- CTXCAT Indexes - A CTXCAT index is best for smaller text fragments that must be indexed along with other standard relational data (VARCHAR2).
WHERE CATSEARCH(text_column, 'ipod')> 0;
- CONTEXT Indexes - The CONTEXT index type is used to index large amounts of text such as Word, PDF, XML, HTML or plain text documents.
WHERE CONTAINS(test_column, 'ipod', 1) > 0
- CTXRULE Indexes - A CTXRULE index can be used to build document classification applications.
These types of indexes allow you to replace the old-fashioned SQL “LIKE” syntax with “CONTAINS” or “CATSEARCH” SQL syntax:
http://www.dba-oracle.com/oracle_tips_like_sql_index.htm
Hope this helps. . .
Donald K. Burleson
Oracle Press author

Similar Messages

  • HOW TO: Post a SQL statement tuning request - template posting

    This post is not a question, but similar to Rob van Wijk's "When your query takes too long ..." post should help to improve the quality of the requests for SQL statement tuning here on OTN.
    On the OTN forum very often tuning requests about single SQL statements are posted, but the information provided is rather limited, and therefore it's not that simple to provide a meaningful advice. Instead of writing the same requests for additional information over and over again I thought I put together a post that describes how a "useful" post for such a request should look like and what information it should cover.
    I've also prepared very detailed step-by-step instructions how to obtain that information on my blog, which can be used to easily gather the required information. It also covers again the details how to post the information properly here, in particular how to use the \ tag to preserve formatting and get a fixed font output:
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
    So again: This post here describes how a "useful" post should look like and what information it ideally covers. The blog post explains in detail how to obtain that information.
    In the future, rather than requesting the same additional information and explaining how to obtain it, I'll simply refer to this HOW TO post and the corresponding blog post which describes in detail how to get that information.
    *Very important:*
    Use the \ tag to enclose any output that should have its formatting preserved as shown below.
    So if you want to use fixed font formatting that preserves the spaces etc., do the following:
    \   This preserves formatting
    \And it will look like this:
       This preserves formatting
       . . .Your post should cover the following information:
    1. The SQL and a short description of its purpose
    2. The version of your database with 4-digits (e.g. 10.2.0.4)
    3. Optimizer related parameters
    4. The TIMING and AUTOTRACE output
    5. The EXPLAIN PLAN output
    6. The TKPROF output snippet that corresponds to your statement
    7. If you're on 10g or later, the DBMS_XPLAN.DISPLAY_CURSOR output
    The above mentioned blog post describes in detail how to obtain that information.
    Your post should have a meaningful subject, e.g. "SQL statement tuning request", and the message body should look similar to the following:
    *-- Start of template body --*
    The following SQL statement has been identified to perform poorly. It currently takes up to 10 seconds to execute, but it's supposed to take a second at most.
    This is the statement:
    select
    from
             t_demo
    where
             type = 'VIEW'
    order by
             id;It should return data from a table in a specific order.
    The version of the database is 11.1.0.7.
    These are the parameters relevant to the optimizer:
    SQL>
    SQL> show parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_capture_sql_plan_baselines boolean     FALSE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      11.1.0.7
    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>
    SQL> show parameter db_file_multi
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     8
    SQL>
    SQL> show parameter db_block_size
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    SQL>
    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
      3           , pname
      4           , pval1
      5           , pval2
      6  from
      7           sys.aux_stats$;
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          01-30-2009 16:25
    SYSSTATS_INFO        DSTOP                           01-30-2009 16:25
    SYSSTATS_INFO        FLAGS                         0
    SYSSTATS_MAIN        CPUSPEEDNW              494,397
    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:
    SQL> explain plan for
      2  -- put your statement here
      3  select
      4             *
      5  from
      6             t_demo
      7  where
      8             type = 'VIEW'
      9  order by
    10             id;
    Explained.
    Elapsed: 00:00:00.01
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    60 |     0   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |     1 |    60 |     0   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    14 rows selected.Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
    SQL> rem Set the ARRAYSIZE according to your application
    SQL> set autotrace traceonly arraysize 100
    SQL> select
      2             *
      3  from
      4             t_demo
      5  where
      6             type = 'VIEW'
      7  order by
      8             id;
    149938 rows selected.
    Elapsed: 00:00:02.21
    Execution Plan
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    60 |     0   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |     1 |    60 |     0   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    Statistics
              0  recursive calls
              0  db block gets
         149101  consistent gets
            800  physical reads
            196  redo size
        1077830  bytes sent via SQL*Net to client
          16905  bytes received via SQL*Net from client
           1501  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         149938  rows processed
    SQL>
    SQL> disconnect
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing optionsThe TKPROF output for this statement looks like the following:
    TKPROF: Release 11.1.0.7.0 - Production on Mo Feb 23 10:23:08 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: orcl11_ora_3376_mytrace1.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select
    from
             t_demo
    where
             type = 'VIEW'
    order by
             id
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch     1501      0.53       1.36        800     149101          0      149938
    total     1503      0.53       1.36        800     149101          0      149938
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 88 
    Rows     Row Source Operation
    149938  TABLE ACCESS BY INDEX ROWID T_DEMO (cr=149101 pr=800 pw=0 time=60042 us cost=0 size=60 card=1)
    149938   INDEX RANGE SCAN IDX_DEMO (cr=1881 pr=1 pw=0 time=0 us cost=0 size=0 card=1)(object id 74895)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                    1501        0.00          0.00
      db file sequential read                       800        0.05          0.80
      SQL*Net message from client                  1501        0.00          0.69
    ********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
    SQL> -- put your statement here
    SQL> -- use the GATHER_PLAN_STATISTICS hint
    SQL> -- if you're not using STATISTICS_LEVEL = ALL
    SQL> select /*+ gather_plan_statistics */
      2  *
      3  from
      4  t_demo
      5  where
      6  type = 'VIEW'
      7  order by
      8  id;
    149938 rows selected.
    Elapsed: 00:00:02.21
    SQL>
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  d4k5acu783vu8, child number 0
    select   /*+ gather_plan_statistics */          * from          t_demo
    where          type = 'VIEW' order by          id
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |
    |   0 | SELECT STATEMENT            |          |      1 |        |    149K|00:00:00.02 |     149K|   1183 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |      1 |      1 |    149K|00:00:00.02 |     149K|   1183 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |      1 |      1 |    149K|00:00:00.02 |    1880 |    383 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    20 rows selected.I'm looking forward for suggestions how to improve the performance of this statement.
    *-- End of template body --*
    I'm sure that if you follow these instructions and obtain the information described, post them using a proper formatting (don't forget about the \ tag) you'll receive meaningful advice very soon.
    So, just to make sure you didn't miss this point:Use proper formatting!
    If you think I missed something important in this sample post let me know so that I can improve it.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Alex Nuijten wrote:
    ...you missed the proper formatting of the Autotrace section ;-)Alex,
    can't reproduce, does it still look unformatted? Or are you simply kidding? :-)
    Randolf
    PS: Just noticed that it actually sometimes doesn't show the proper formatting although the code tags are there. Changing to the \ tag helped in this case, but it seems to be odd.
    Edited by: Randolf Geist on Feb 23, 2009 11:28 AM
    Odd behaviour of forum software                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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

  • Unusual DB tuning request

    Hi,
    We have a situation like this. We have a .Net web application, for which the DB is Oracle (10g R2). The web application is used by agents all over the country. It was just deployed, and now the biggest complaint is that the system is very slow. E.g. when they put a customer code and try to get customer information, it takes about 1 minute for the information to appear.
    The application was developed by 2 teams. The front end .Net part was developed by one team while the DB access APIs (i.e. Oracle packages) was developed by another team. Both have no idea about the workings of each others areas. For example, the .NET team will request the DB team that they need an API which will bring customer information (as a Ref Cursor) when they provide a customer code. The DB access team will write a packaged procedure and give access to it to the DB team.
    Now, it has been found out that the entire system is slow in performance. There are 52 APIs (Oracle packages) in the DB which is used. The SQL statements that are making the system slow could number 10 or 12. But the problem is there is no way for us to find out which SQL is causing the error.
    How do you find out (pinpoint) which SQLs are causing the performance problems?? Can we use some Oracle logging technique to find out which SQL is firing at what time for how long??
    Like, we run the system as usual and then after a day we should be able to read a file and look at all the SQLs that were fired, it's duration and by whom etc.
    Any Oracle supplied tools or 3rd party tools available for this??

    Not unusual at all. There are several methodologies for "my system is slow."
    First of all, using AWR or the equivalent performance screens in enterprise manager requires licensing. If you have standard edition or otherwise can't have the licensing, you can use statspack. See the appropriate docs, and also http://jonathanlewis.wordpress.com/statspack-examples/ In general, you get a snapshot of some amount of time like 15 minutes, which will tell you some likely candidates. Hopefully you will keep some around from when things are running well to compare when things go south.
    Second, this should have come out in testing. Normally in development, developers make their own little bit of the world go fast, integration testing makes sure it all runs well together, and load testing shows where the bottlenecks are, so you can fix them before implementation. It seems you are letting users do the latter.
    So there are a couple of things you can do in addition to looking at magical reports. You can use sqlplus to login to the machine locally, then from a users site, and compare that to the app. Is there a difference in connection time? Are you using shared servers or connection concentrators? Those should have their own instrumentation (you can see some statistics for shared server with some administrative views, for example).
    The general idea is to narrow down where the problem is. From the db viewpoint, SQL tends to be the slowdown, though it could be hardware or other things, so the idea of AWR and such is to give a list of top resource users in a couple of ways, to point you in the right direction. But it is only from the db viewpoint, so configuration errors on the net side could be invisible, unless you are lucky and it shows up like a new login for every ref cursor query or some dumb thing. (Edit: After posting, this made me think of comments I had seen of some apps not handling failed connections properly, leading to logon storms as they keep trying. Google around for things like http://nigelnoble.wordpress.com/2010/05/17/monitoring-connection-pools/ ).
    You can also turn tracing on, but that might give Too Much Information.
    With no further information, we can only speculate, but the two most common issues are SQL using bad plans (a subject for book length treatises) and locking done wrong (which would show up with common performance tools). There is no fast=true parameter, you need to follow the evidence. There's lots of evidence.
    Edit 2: I got interrupted by a call about a shooting near my kids school causing a lockdown, so I forgot a paragraph: You also need to tell us about your server operating system, and use the tools there to get information about what it thinks is going wrong. You also need to give a proper version for your Oracle, which would be something like 10.2.0.4. Here is an example of someone figuring out a problem, including the limitations of AWR and the importance of the exact patch levels: http://www.oaktable.net/content/cursor-pin-s-waits-sporadic-cpu-spikes-and-systematic-troubleshooting Yes, sometimes you have to call in the big guns, but there's a lot you can do first even as a newbie (though you may also be getting a lesson in the value of having a senior person around). People here can help you interpret the AWR/statspack.
    Edited by: jgarry on Dec 4, 2012 4:14 PM
    Edited by: jgarry on Dec 4, 2012 4:26 PM

  • Explain plan shows 300T of TempSpc and 999 hours - tuning request

    Hi,
    I have a query which obtains summary statistics. There is an items table which contains the dictionary of items which can be recorded. There is an events table which contains the item ID, timestamp and a value. The query summarizes the data for each item. e.g. Mean, stddev, sample values, length. I have trimmed the query down as simply as possible and am having a problem with large temp space and runtime estimates in the explain plan. Here is the query:
    WITH ChartItems AS (
        SELECT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          COUNT(*),
          COUNT(distinct subject_id)
        FROM mimic2v26.d_chartitems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
        --WHERE ci.itemid = 51
        GROUP BY ci.itemid,
                 ci.label,
                 ci.category,
                 ci.description
    --select * from ChartItems;
    , RawData AS (
        SELECT DISTINCT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          last_value(ce.value1) ignore nulls over (partition BY ci.itemid order by
          ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS
          value1_last
        FROM ChartItems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
    select * from RawData;Which gives this explain plan:
    Plan hash value: 642453121
    | Id  | Operation                    | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                |  4811G|  1238T|       |  3686M (13)|999:59:59 |
    |   1 |  VIEW                        |                |  4811G|  1238T|       |  3686M (13)|999:59:59 |
    |   2 |   HASH UNIQUE                |                |  4811G|   258T|       |  3686M (13)|999:59:59 |
    |   3 |    WINDOW BUFFER             |                |  4811G|   258T|       |  3686M (13)|999:59:59 |
    |   4 |     SORT GROUP BY            |                |  4811G|   258T|   317T|  3686M (13)|999:59:59 |
    |*  5 |      HASH JOIN               |                |  4811G|   258T|  4943M|    25M (90)| 85:14:28 |
    |   6 |       VIEW                   | VW_DAG_0       |   152M|  3199M|       |  1366K  (1)| 04:33:18 |
    |   7 |        HASH GROUP BY         |                |   152M|  4216M|  5839M|  1366K  (1)| 04:33:18 |
    |*  8 |         HASH JOIN            |                |   152M|  4216M|       |   147K  (2)| 00:29:36 |
    |   9 |          TABLE ACCESS FULL   | D_CHARTITEMS   |  4832 | 96640 |       |     7   (0)| 00:00:01 |
    |  10 |          INDEX FAST FULL SCAN| CHARTEVENTS_O2 |   196M|  1683M|       |   147K  (1)| 00:29:25 |
    |  11 |       TABLE ACCESS FULL      | CHARTEVENTS    |   196M|  6922M|       |   616K  (1)| 02:03:19 |
    Predicate Information (identified by operation id):
       5 - access("CE"."ITEMID"="ITEM_2")300T of temp space! Ouch.
    TKPROF output (I let the query run for a short while. I let it run for ages earlier, but wasn't tracing the session. Should I let it run for longer?):
    TKPROF: Release 11.2.0.3.0 - Development on Tue Jul 10 16:54:27 2012
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    Trace file: /oracle/11gr2/app/oracle/diag/rdbms/mimic2/mimic2/trace/mimic2_ora_6507.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    WITH ChartItems AS (
        SELECT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          COUNT(*),
          COUNT(distinct subject_id)
        FROM mimic2v26.d_chartitems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
        GROUP BY ci.itemid,
                 ci.label,
                 ci.category,
                 ci.description
    , RawData AS (
        SELECT DISTINCT
          ci.itemid,                                                                                                                                                                                           
          ci.label,                                                                                                                                                                                            
          ci.category,                                                                                                                                                                                         
          ci.description,                                                                                                                                                                                      
          last_value(ce.value1) ignore nulls over (partition BY ci.itemid order by                                                                                                                             
          ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS                                                                                                                            
          value1_last                                                                                                                                                                                          
        FROM ChartItems ci                                                                                                                                                                                     
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid                                                                                                                                                 
    select * from RawData                                                                                                                                                                                      
    call     count       cpu    elapsed       disk      query    current        rows                                                                                                                           
    Parse        1      0.02       0.02          0          0          0           0                                                                                                                           
    Execute      1      0.00       0.00          0          0          0           0                                                                                                                           
    Fetch        1    582.40     712.23     705238     737351          0           0                                                                                                                           
    total        3    582.43     712.25     705238     737351          0           0                                                                                                                           
    Misses in library cache during parse: 1                                                                                                                                                                    
    Optimizer mode: ALL_ROWS                                                                                                                                                                                   
    Parsing user id: 85 
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             0          0          0  VIEW  (cr=0 pr=0 pw=0 time=184 us cost=3686387254 size=1361581801333882 card=4811243114254)
             0          0          0   HASH UNIQUE (cr=0 pr=0 pw=0 time=180 us cost=3686387254 size=283863343740986 card=4811243114254)
             0          0          0    WINDOW BUFFER (cr=0 pr=0 pw=0 time=74 us cost=3686387254 size=283863343740986 card=4811243114254)
             0          0          0     SORT GROUP BY (cr=0 pr=0 pw=0 time=59 us cost=3686387254 size=283863343740986 card=4811243114254)
    178073889  178073889  178073889      HASH JOIN  (cr=737351 pr=705238 pw=124635 time=476372451 us cost=25572251 size=283863343740986 card=4811243114254)
       6211631    6211631    6211631       VIEW  VW_DAG_0 (cr=613768 pr=581413 pw=35805 time=286546567 us cost=1366486 size=3354399576 card=152472708)
       6211631    6211631    6211631        HASH GROUP BY (cr=613768 pr=581413 pw=35805 time=281271878 us cost=1366486 size=4421708532 card=152472708)
    196182740  196182740  196182740         HASH JOIN  (cr=613768 pr=545608 pw=0 time=557485047 us cost=147987 size=4421708532 card=152472708)
          4832       4832       4832          TABLE ACCESS FULL D_CHARTITEMS (cr=18 pr=16 pw=0 time=13666 us cost=7 size=96640 card=4832)
    196182740  196182740  196182740          INDEX FAST FULL SCAN CHARTEVENTS_O2 (cr=613750 pr=545592 pw=0 time=148428499 us cost=147046 size=1765644660 card=196182740)(object id 96501)
      10683044   10683044   10683044       TABLE ACCESS FULL CHARTEVENTS (cr=123583 pr=123825 pw=0 time=25175510 us cost=616507 size=7258761380 card=196182740)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
      db file sequential read                         2        0.01          0.01
      db file scattered read                          3        0.02          0.03
      direct path read                             5265        0.75         77.13
      asynch descriptor resize                        1        0.00          0.00
      direct path write temp                      15077        0.71         45.54
      direct path read temp                        2387        0.29         13.54
      SQL*Net break/reset to client                   1        0.66          0.66
      SQL*Net message from client                     1        0.00          0.00
    SQL ID: 7jby2dxrpkkm9 Plan Hash: 1388734953
    select SYS_CONTEXT('USERENV','SESSIONID')
    from
    dual
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.01          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.01          0          0          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 85 
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  FAST DUAL  (cr=0 pr=0 pw=0 time=4 us cost=2 size=0 card=1)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.02       0.04          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch        2    582.40     712.23     705238     737351          0           1
    total        6    582.43     712.27     705238     737351          0           1
    Misses in library cache during parse: 2
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       4        0.00          0.00
      db file sequential read                         2        0.01          0.01
      db file scattered read                          3        0.02          0.03
      direct path read                             5265        0.75         77.13
      asynch descriptor resize                        1        0.00          0.00
      direct path write temp                      15077        0.71         45.54
      direct path read temp                        2387        0.29         13.54
      SQL*Net break/reset to client                   1        0.66          0.66
      SQL*Net message from client                     3       14.99         15.01
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    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        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        2  user  SQL statements in session.
        0  internal SQL statements in session.
        2  SQL statements in session.
    Trace file: /oracle/11gr2/app/oracle/diag/rdbms/mimic2/mimic2/trace/mimic2_ora_6507.trc
    Trace file compatibility: 11.1.0.7
    Sort options: default
           1  session in tracefile.
           2  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           2  SQL statements in trace file.
           2  unique SQL statements in trace file.
       24245  lines in trace file.
         728  elapsed seconds in trace file.Optimizer parameters:
    NAME                                               TYPE        VALUE                                                                                               
    optimizer_capture_sql_plan_baselines               boolean     FALSE                                                                                               
    optimizer_dynamic_sampling                         integer     2                                                                                                   
    optimizer_features_enable                          string      11.2.0.3                                                                                            
    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                                                                                                 Can anyone help me figure out what's wrong?
    This is a data warehouse, with up to date statistics. The DB is version 11.2.0.3.0
    Thanks,
    Dan

    rp0428 wrote:
    >
    I trimmed the query down to the simplest that I could which still exhibited the problem
    >
    The DISTINCT isn't the issue. The issue is that the query you posted isn't necessary and doesn't appear to be represented in the plan that you posted.
    That makes it hard to tell where the cardinality misestimates are coming from. How many records does the actual first query (the one with the group by) return? You have a SELECT * commented out - how many rows?No, it's not necessary, but then it isn't the full query. The estimates are still wrong when I pass the count columns through to the second query. The full query contains many more analytic functions in the second query, and some additions to the first. It could probably be cleaned up a little, but the current structure makes logical sense. Should I change the aggregates to analytics and move them into the second query? In any case, there definitely seems to be something wrong with the plan.
    I don't know what you mean when you say "doesn't appear to be represented in the plan that you posted".
    I just checked the first query and while the temp space has dropped to a reasonable amount, the number of rows in the hash join is still way off (I didn't notice before because I was looking at the temp space). The rows for d_chartitems and the index on chartevents are correct:
    Plan hash value: 1249235674
    | Id  | Operation               | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT        |                |   152M|    35G|       |  1366K  (1)| 04:33:18 |
    |   1 |  VIEW                   |                |   152M|    35G|       |  1366K  (1)| 04:33:18 |
    |   2 |   WINDOW SORT           |                |   152M|  4216M|  5839M|  1366K  (1)| 04:33:18 |
    |*  3 |    HASH JOIN            |                |   152M|  4216M|       |   147K  (2)| 00:29:36 |
    |   4 |     TABLE ACCESS FULL   | D_CHARTITEMS   |  4832 | 96640 |       |     7   (0)| 00:00:01 |
    |   5 |     INDEX FAST FULL SCAN| CHARTEVENTS_O2 |   196M|  1683M|       |   147K  (1)| 00:29:25 |
    Predicate Information (identified by operation id):
       3 - access("CE"."ITEMID"="CI"."ITEMID")Edited by: danscott on Jul 10, 2012 5:43 PM
    Edited by: danscott on Jul 11, 2012 6:28 AM

  • Performance tuning in database side

    Hi All,
    I have a query which consumes 2 hours to run. Since, it is a vendor query, am not supposed to tune the query part.
    Response time needs to be reduced. So far, i have done the below analysis.
    1) All the indexes are working fine
    2) Cost is high while sorting. Hence, tried to increase the sort_area_size in the session level. no benefit.
    3) cursor_sharing set to similar at session level. But no benefits. Default was exact.
    Anyone could help me what parameters need to be altered in v$parameter
    My DB is 9.2.0.8.0
    Thanks in advance
    Regards
    A.Gopal

    Before you do anything, I suggest proper root cause analysis.
    Will this sort_area_size setting at session level will be useful? See template tuning threads:
    [url https://forums.oracle.com/forums/thread.jspa?threadID=863295]How to post a SQL tuning request
    [url https://forums.oracle.com/forums/thread.jspa?messageID=1812597]When your query takes too long
    Only by knowing where the time is going and why can anyone suggest a course of action that is relevant.
    Do an extended trace (event 10046) at level 12 and run the trace file through tkprof.
    Identify waits and any significant differences between estimates and actuals.
    If your actual execution metrics indicate that you are spending excessive time sorting or on temp space usage THEN you can consider changing sort_area_size parameters, etc.
    All the indexes are working fineWhat is this meant to mean?
    If you don't know anything about your execution plan or where time is spent in the query, how can you judge the effectiveness of the indexes?
    Edited by: Dom Brooks on Nov 21, 2012 3:02 PM

  • Performance tuning in PL/SQL code

    Hi,
    I am working on already existing PL/SQL code which is written by someone else on validation and conversion of data from a temporary table to base table. It usually has 3.5 million rows. and the procedure takes arount 2.5 - 3 hrs to complete.
    Can I enhance the PL/SQL code for better performance ? or, is this OK to take so long to process these many rows?
    Thanks!
    Yogini

    Can I enhance the PL/SQL code for better performance ? Probably you can enhance it.
    or, is this OK to take so long to process these many rows? It should take a few minutes, not several hours.
    But please provide some more details like your database version etc.
    I suggest to TRACE the session that executes the PL/SQL code, with WAIT events, so you'll see where and on what time is spent, you'll identify your 'problem statements very quickly' (after you or your DBA have TKPROF'ed the trace file).
    SQL> alter session set events '10046 trace name context forever, level 12';
    SQL> execute your PL/SQL code here
    SQL> exitWill give you a .trc file in your udump directory on the server.
    http://www.oracle-base.com/articles/10g/SQLTrace10046TrcsessAndTkprof10g.php
    Also this informative thread can give you more ideas:
    HOW TO: Post a SQL statement tuning request - template posting
    as well as doing a search on 10046 at AskTom, http://asktom.oracle.com will give you more examples.
    and reading Oracle's Performance Tuning Guide: http://www.oracle.com/pls/db102/to_toc?pathname=server.102%2Fb14211%2Ftoc.htm&remark=portal+%28Getting+Started%29

  • Performance tuning in Cubes in Anlytic Workspace Manager 10g

    Hi,
    Can anyone tell me or suggest anything how i should i improve the performance of cube maintainance in Analytic Workspace Manager..

    generate statspack/AWR reports
    HOW To Make TUNING request
    https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360003

  • Performance tuning in oracle 10g

    Hi Guys
    i hope all are well,Have a nice day Today
    i have discuss with some performance tuning issue
    recently , i joined the new project that project improve the efficiency of the applicaton. in this environment oracle plsql langauage are used , so if i need to improve effiency of application what are the step are taken
    and what are the way to go through the process improvement
    kindly help me

    generate statspack/AWR reports
    HOW To Make TUNING request
    https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360003

  • Help Required in Tuning a SQL

    Hi All,
    We have a query which is taking hell lot of time in production due to Full Table Scan on the table AP_ACCOUNTING_EVENTS.
    We have then tried to force the index AP_ACCOUNTING_EVENTS_N1 on the query by applying hints.
    Now the table is doing a range scan using index AP_ACCOUNTING_EVENTS_N1.
    But to my surprise, the query with hints is taking even more time than that of query without hint.
    Database: 10.0.2
    and Application : 11.5.10.2
    PFB the query:
    SELECT api.invoice_id,
    SUBSTR(pov.segment1, 1, 5) supplier_code,
    DECODE(pov.segment1,
    'A',
    SUBSTR(api.attribute7, 1, 20),
    SUBSTR(pov.vendor_name, 1, 20)) supplier_name,
    MIN(TRUNC(aae.creation_date)) approval_date
    FROM po_vendors pov, ap_invoices api, ap_accounting_events aae
    WHERE api.payment_status_flag = 'Y'
    AND api.source not in ('A', 'B', 'C')
    AND aae.source_table = 'AP_INVOICES'
    AND aae.creation_date >= sysdate - 2
    AND aae.creation_Date < sysdate
    AND aae.accounting_event_id = aae.ACCOUNTING_EVENT_ID
    AND pov.vendor_id = api.vendor_id
    AND aae.source_id = api.invoice_id
    GROUP BY api.invoice_id,
    SUBSTR(pov.segment1, 1, 5),
    DECODE(pov.segment1,
    'A',
    SUBSTR(api.attribute7, 1, 20),
    SUBSTR(pov.vendor_name, 1, 20))
    Kindly Help.
    Thanks,

    Tuning request
    Take a look at the
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting

  • Performance Tuning the AVG function

    Dear All,
    I have a table which is rapidly growing. We have a query which is frequently executed on this table and it utilizes AVG function without a WHERE clause. Is there a way to tune this query?
    I tried to create a Materialized View but Oracle rejects as AVG cannot be used in MV's. Also, it is now really easy at this point in time to rewrite the query.
    Appreciate if anybody can help me out in this situation.
    OS: Windows 2003 EE
    Database: Oracle 10g R2 10.2.0.4
    Sample Table:
    Create table t(id number, name varchar2(30), amt number);
    insert into t select level, 'level - ' || level, level * 100 from dual connect by dual level <= 1000;
    commit;
    Query:
    select avg(amount) from t;
    Thanks for you time.
    - P

    >
    ... and it utilizes AVG function without a WHERE clause
    >
    As Aman stated, a full table scan will be needed for a statement without a WHERE clause.
    See these threads on how to post a tuning request
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HTH
    Srini

  • Can the query be tuned to make it run faster?

    select distinct
    A.DEPTID,
    A.POSITION_NBR,
    A.EMPLID,
    A.EMPL_RCD_NBR,
    A.EFFDT,
    B.NAME,
    A.EMPL_STATUS,
    A.JOBCODE,
    A.ANNUAL_RT,
    A.STD_HOURS,
    A.PRIMARY_JOB,
    C.POSN_STATUS,
    case when A.POSITION_NBR = ' ' then 0 else C.STD_HOURS end,
    case when A.POSITION_NBR = ' ' then ' ' else C.DEPTID end
    from PS_JOB A,
    PS_PERSONAL_DATA B,
    PS_POSITION_DATA C
    where A.EMPLID = B.EMPLID
    and
    ((A.POSITION_NBR = C.POSITION_NBR
    and A.EFFSEQ = (select max(D.EFFSEQ)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT = A.EFFDT)
    and C.POSN_STATUS <> 'G'
    and C.EFFDT = (select max(E.EFFDT)
    from PS_POSITION_DATA E
    where E.POSITION_NBR = A.POSITION_NBR
    and E.EFFDT <= A.EFFDT)
    and C.EFFSEQ = (select max(F.EFFSEQ)
    from PS_POSITION_DATA F
    where F.POSITION_NBR = A.POSITION_NBR
    and F.EFFDT = C.EFFDT))
    or
    (A.POSITION_NBR = C.POSITION_NBR
    and A.EFFDT = (select max(D.EFFDT)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT <= C.EFFDT)
    and A.EFFSEQ = (select max(E.EFFSEQ)
    from PS_JOB E
    where E.EMPLID = A.EMPLID
    and E.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and E.EFFDT = A.EFFDT)
    and C.POSN_STATUS <> 'G'
    and C.EFFSEQ = (select max(F.EFFSEQ)
    from PS_POSITION_DATA F
    where F.POSITION_NBR = A.POSITION_NBR
    and F.EFFDT = C.EFFDT)))
    or
    (A.POSITION_NBR = ' '
    and A.EFFSEQ = (select max(D.EFFSEQ)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT = A.EFFDT))

    Repost... I'll put in the same valuable reply that Blu made last time....
    Read This
    HOW TO: Post a SQL statement tuning request - template posting

  • Query tuning for query using connect by prior

    I have written following query to fetch the data. The query is written in this format because there are multiple rows, which make one recrd and we need to bring that record into one row.
    For one CAT(commented here), this query takes around 4 minutes and fetches 6900 records but when it runs for 3 CAT, it takes 17 mins.
    I want to tune this as this has to run for 350 CAT values.
    It is doing FTS on the main table. I tried to use different hints like PARALLEL, APPEND (in insert) but nothing worked.
    The cost of the query is 51.
    Any help/suggestions will be appreciated.
    SELECT DISTINCT MIN(SEQ) SEQ,
    PT, APP, IT, LR, QT,CD, M_A_FLAG,
    STRAGG(REM) REM, -- aggregates the data from different columns to one which is parent
    CAT
    FROM (WITH R AS (SELECT CAT, SEQ, PT, M_A_FLAG, IT, LR,QT,CD, REM, APP
    FROM table1
    WHERE REC = '36' AND M_A_FLAG = '1'
    --AND CAT = '11113')
    SELECT CAT, SEQ,
    CONNECT_BY_ROOT PT AS PT,
    CONNECT_BY_ROOT APP AS APPL,
    M_A_FLAG,
    CONNECT_BY_ROOT IT AS IT,
    CONNECT_BY_ROOT LR AS LR,
    CONNECT_BY_ROOT QT AS QT,
    CONNECT_BY_ROOT CD AS CD,
    REM
    FROM R A
    START WITH PT IS NOT NULL
    CONNECT BY PRIOR SEQ + 1 = SEQ
    AND PRIOR CAT = CAT
    AND PT IS NULL)
    GROUP BY PT, APP, IT,LR, QT, CD, M_A_FLAG, CAT
    ORDER BY SEQ;
    Thanks.
    Edited by: user2544469 on Feb 11, 2011 1:12 AM

    The following threads detail the approach and information required.
    Please gather relevant info and post back.
    How to post a SQL tuning request - HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long - When your query takes too long ...

  • Tuning the query : Very Urgent

    Hi
    We have query wich needs tuning.when we are putting REGULAR EXPRESSION query is running fine but whne we put like LIKE stmt it is taking time.Here is the query below.Please help on tuning.
    SELECT a.order_number, b.last_update_date,TO_CHAR( b.split_percent,'FM99999.009') SPLIT_PERCENTAGE,
    rs.NAME " SALES_PERSON_NAME ", rs.salesrep_number, b.effective_date,
    b.creation_date "CREATION_DATE", rt.NAME "TERRITORY_NAME",
    rt.segment1 "ERP_CODE", a.booked_date "DATE_BOOKED",
    TO_CHAR(ROUND((( (SELECT SUM (ordered_quantity * unit_selling_price)
    FROM apps.oe_order_lines_all ol
    WHERE ol.header_id = a.header_id)
    * b.split_percent
    / 100
    ) , 2),'FM99999999999999999999.009') order_total ,
    (SELECT user_name
    FROM fnd_user
    WHERE user_id = b.last_updated_by) requested_by,
    b.obsolete_date
    FROM oe_order_headers_all a,
    apps.csm_header_sales_cr_hist b,
    jtf_rs_salesreps rs,
    ra_territories rt
    WHERE 1 = 1
    AND a.header_id = b.source_header_id
    AND b.territory_id = rt.territory_id
    AND b.salesrep_id = rs.salesrep_id
    AND b.source_type = 'O'
    AND a.order_number IN (
    SELECT a.order_number
    FROM oe_order_headers_all a,
    apps.csm_header_sales_cr_hist b,
    jtf_rs_salesreps rs,
    ra_territories rt
    WHERE 1 = 1
    AND a.header_id = b.source_header_id
    AND b.territory_id = rt.territory_id
    AND b.salesrep_id = rs.salesrep_id
    AND b.source_type = 'O'
    -- AND b.obsolete_date IS NULL --ommented by andondap as per TD#9648 Changes
    AND  REGEXP_LIKE ( rs.name , '(svc)|(Muti.*Y)|(Multi.*Y)|(._MY)')  Commented by andondap as per TD#9648 Changes
    AND b.last_update_date BETWEEN TO_DATE ('2012/11/25', 'YYYY/MM/DD') AND TO_DATE ('2013/03/23', 'YYYY/MM/DD')+ 0.9999
    AND REGEXP_LIKE ( rs.name,'(.MY)|(Muti.*Y))|(Multi.*Y)|(._MY) |(mlti)')
    AND rs.name LIKE '%SVC%MULTI%' OR rs.name NOT LIKE '%DUMMY%' OR rs.name LIKE 'Svc%Multi%' OR rs.name LIKE 'Svc%MY%'
    OR rs.name LIKE 'Service%Multi%' OR rs.name LIKE '%MY_SHARE_TM' OR rs.name LIKE '%MY_SHARE_T')
    ORDER BY a.order_number, b.creation_date
    Thanks
    Hibin

    Hmmm, let's see...
    1. OP provided formatted code using {noformat}{noformat} tags.... - FAILED
    2. OP provided database version in full... - FAILED
    3. OP provided table structures and index information... - FAILED
    4. OP provided cardinality and selectivity information... - FAILED
    5. OP provided explain plans... - FAILED
    6. OP provided execution traces... - FAILED
    7. OP is a new member and can be excused for above failures... - FAILED
    8. OP has asked previous questions and followed forum etiquette by marking them as answered... - FAILED
    9. OP has respected volunteers and other questioners by not marking his question as Urgent... - FAILED
    10. OP has read the forum FAQ ({message:id=9360002}) for posting his question...  - FAILED
    11. OP has read the forum FAQ ({message:id=9360003}) for posting a tuning question... - FAILED
    It's a good job you're not a computer program, you wouldn't have even compiled.
    so, points to note:
    This is a forum of volunteers.  There's no such thing as an Urgent question here, and it's considered rude to suggest your question is urgent, as that indicates you want immediate attention from the people who are giving up their own time to help, and who have their own jobs to do.  It's also rude for the other people who are asking questions, as everyone would like an answer to their problem as soon as possible, so what makes you any more special?  An urgent issue is one where a live system is down potentially putting people's lives at risk or causing a company to lose money, or somehow damage their services.  Such issues should be logged with Oracle Support, not on the free OTN forums.
    Next, when you post your question, ensure you provide all the information that is needed for people to be able to help you.  Read the FAQ posts which point to useful threads indicating what information is required, especially for tuning requests.
    Finally, when your questions have been answered, it is common courtesy to mark them as answered (and award points if appropriate), otherwise it indicates that you have no respect for the people who are helping you.
    If you follow all the advice above, you will end up creating a good question that people will be willing to help you with.   If you don't follow the advice above, such as in this question you've posted, you will find that few experts will bother to help (or if they post it will not likely be helpful advise you receive).  The choice is yours.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Regarding Query tuning

    Hi,
    I am executing this query but it is taking more time to execute.
    SELECT TO_CHAR(A.CALLEND,'MON-YYYY')ROAMERMONTH,
    C.OPCCIRCLE INROAMCIRCLE,
    COUNT(DISTINCT (A.CDPADIGITS))INROAMERCOUNT,
    B.DPCCIRCLE OUTROAMCIRCLE,
    C.REPORTOPERATORNAME INROAMREPORTOPERATORNAME,
    B.REPORTOPERATORNAME OUTROAMREPORTOPERATORNAME
    FROM TBLMEDRATINTRIM_DETAIL_ROAM A,
    ROAMDPCNEW B,
    ROAMOPCNEW C
    WHERE A.DPC not in ('002-045-004') AND A.OPC not in ('004-008-000')
    AND A.DPC=B.DPC
    AND A.OPC=C.OPC
    AND TO_CHAR(A.CALLEND,'MON-YYYY')= 'OCT-2009'
    GROUP BY TO_CHAR(A.CALLEND,'MON-YYYY'),B.DPCCIRCLE,C.OPCCIRCLE,C.REPORTOPERATORNAME,B.REPORTOPERATORNAME;
    How can i write this query so it will take less time to execute.
    HOW to Tune this query?

    [How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
    [When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
    And when you post source code:
    {{noformat}code{noformat}}
    ....Post Your Code Here....
    {{noformat}code{noformat}}

Maybe you are looking for

  • Strange bug when sending messages in parallel with same sender component

    We have one sender business system sending messages to two different interfaces in parallel using an asynchronous soap channel : Interface1 and Interface2.  In this scenario the Interface1 messages appear to be conflicting in some way with the Interf

  • TS3989 iCloud, Photo Stream

    I've tried all your suggestions here and my Photo Stream still doesn't work. I'm using iPhoto 11, I'v updated all my devices to the latest software versions on all my devices and it still doesn't work. I have not upgraded to Mountain Lion yet and I r

  • Safari crashes instantly and does not even load. Please help.

    Process:         Safari [527] Path:            /Applications/Safari.app/Contents/MacOS/Safari Identifier:      com.apple.Safari Version:         6.0.5 (7536.30.1) Build Info:      WebBrowser-7536030001000000~1 Code Type:       X86-64 (Native) Parent

  • IPhoto quits on first launch

    Hello, every first time (and indeed every odd time) I open iPhoto after login the application displays a message: 'Upgrading Library, Scanning Library' for a few seconds and then iPhoto quits. The second time (every even time) iPhoto launches without

  • Pinch zoom not working in firefox

    Both pinch to zoom and double tap to zoom work fine for me so long as I am viewing web pages in Safari. But I can't seem to use those gestures in Firefox. Has anyone else had this problem and is there a way to make thse gestures work in FF or are the