Tuning VPD predicate

Hi,
I'm using VPD(RLS) to filter data based.
I have a performance issue due to the VPD predicate my VPD function generate.
I have two tables:
- MARKER which is the table I want to secure and contains a primary key named marker_id and a filed use by VPD name VPD_IS_PUBLIC.
- DATASECURITY which is the table containing security information and tells to VPD wich data can be seen for a given role.
I put the script at the end of the message.
If you look to the code, the VPD function can return two predicates:
VPD_IS_PUBLIC=1
or
VPD_IS_PUBLIC=1 or marker_id in (select field_id from datasecurity where roleid=3)
The problem with the second query is that more I have data in my MARKER table more the query is slow.
This is because of "VPD_IS_PUBLIC=1 or" statement.
Is there another way to write that predicate?
Does someone can help me?
Cheers,
Sebastien
CREATE TABLE DATASECURITY
OBJECT_DB_ID NUMBER(10),
ROLEID NUMBER(10),
FIELD_ID NUMBER(10),
CREATION_DATE TIMESTAMP(6) WITH TIME ZONE DEFAULT systimestamp CONSTRAINT NN_DATASECURITY_CREATIONDATE NOT NULL,
CONSTRAINT PK_DATASECURITY
PRIMARY KEY
(OBJECT_DB_ID, ROLEID, FIELD_ID)
CREATE INDEX INDEX_DATASECURITY ON DATASECURITY
(FIELD_ID);
CREATE OR REPLACE TRIGGER TRG_AFT_INSERT_DATASECURITY
AFTER INSERT
ON DATASECURITY
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
BEGIN
UPDATE marker
SET vpd_is_public = 0
WHERE marker_id = :new.field_id;
END TRG_BEF_INSERT_DATASECURITY;
CREATE TABLE MARKER
MARKER_ID NUMBER(10) NOT NULL,
MARKER_TYPE_ID NUMBER(10),
MARKER_ACC VARCHAR2(50 BYTE),
VERSION VARCHAR2(10 BYTE),
DISPLAY_SYNONYM_ID NUMBER(10),
SPECIES_ID NUMBER(10) NOT NULL,
GERMPLASM_ID NUMBER(10),
LIBRARY_ID NUMBER(10),
DESCRIPTION VARCHAR2(2000 BYTE),
DATE_CREATED DATE,
DATE_UPDATED DATE,
VPD_IS_PUBLIC NUMBER(1) DEFAULT 1 CONSTRAINT NN_MARKER_VPD_IS_PUBLIC NOT NULL,
CONSTRAINT PK_MARKER
PRIMARY KEY
(MARKER_ID)
CREATE INDEX INDEX_MARKER ON MARKER
(VPD_IS_PUBLIC);
-- This function return the value stored in the session client info
CREATE OR REPLACE FUNCTION CSFDS.get_cwid
RETURN VARCHAR2
IS
retval VARCHAR2 (50);
BEGIN
DBMS_APPLICATION_INFO.READ_CLIENT_INFO (retval);
RETURN retval;
EXCEPTION
WHEN OTHERS
THEN
RAISE;
END get_cwid;
-- This function sets the value to the session client info
CREATE OR REPLACE FUNCTION CSFDS.set_cwid (cwid IN VARCHAR2)
RETURN NUMBER
IS
BEGIN
DBMS_APPLICATION_INFO.set_client_info (cwid);
RETURN 1;
EXCEPTION
WHEN OTHERS
THEN
RETURN 0;
END set_cwid;
-- This function is the vpd function.
-- It returns differents predicate according the value in the session client info
CREATE OR REPLACE FUNCTION CSFDS.vpd (sch_name IN VARCHAR2, tab_name IN VARCHAR2)
RETURN VARCHAR2
IS
retval VARCHAR2 (500) DEFAULT '' ;
l_roleid NUMBER DEFAULT 3 ;
BEGIN
IF GET_CWID = 'csfds'
THEN
retval := 'VPD_IS_PUBLIC=1 or ';
retval :=
retval
|| 'marker_id in (select field_id from datasecurity where roleid='
|| l_roleid
|| ')';
ELSE
retval := 'VPD_IS_PUBLIC=1';
END IF;
RETURN retval;
EXCEPTION
WHEN OTHERS
THEN
RAISE;
END vpd;
-- To create the VPD policy
BEGIN
SYS.DBMS_RLS.ADD_POLICY (
object_schema => 'CSFDS'
,object_name => 'MARKER'
,policy_name => 'TEST_VPD'
,function_schema => 'CSFDS'
,policy_function => 'VPD'
,statement_types => 'SELECT'
,policy_type => dbms_rls.dynamic
,long_predicate => FALSE
,sec_relevant_cols => 'MARKER_ID,MARKER_TYPE_ID,MARKER_ACC,VERSION,DISPLAY_SYNONYM_ID,SPECIES_ID,GERMPLASM_ID,LIBRARY_ID,DESCRIPTION,DATE_CREATED,DATE_UPDATED,VPD_IS_PUBLIC'
,sec_relevant_cols_opt => NULL
,update_check => TRUE
,static_policy => FALSE
,enable => TRUE );
END;
Edited by: sfrade on Mar 18, 2009 2:00 PM

Hi
Done using the following commands:
execute DBMS_STATS.gather_table_stats ( ownname => 'CSFDS', tabname => 'DATASECURITY', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE );
execute DBMS_STATS.gather_table_stats ( ownname => 'CSFDS', tabname => 'MARKER', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE );
and the plan for the following query
SELECT COUNT ( * )
FROM MARKER
WHERE marker_id in (SELECT FIELD_ID
FROM DATASECURITY
WHERE roleid = 1)
OR vpd_is_public = 1;
Plan
SELECT STATEMENT ALL_ROWSCost: 314 Bytes: 10 Cardinality: 1                          
     7 SORT AGGREGATE Bytes: 10 Cardinality: 1                     
          6 FILTER                
               4 VIEW VIEW CSFDS.index$_join$_001 Cost: 314 Bytes: 176,780 Cardinality: 17,678           
                    3 HASH JOIN      
                         1 INDEX FAST FULL SCAN INDEX (UNIQUE) CSFDS.PK_MARKER Cost: 83 Bytes: 176,780 Cardinality: 17,678
                         2 INDEX FAST FULL SCAN INDEX CSFDS.INDEX_MARKER Cost: 89 Bytes: 176,780 Cardinality: 17,678
               5 INDEX SKIP SCAN INDEX (UNIQUE) CSFDS.PK_DATASECURITY Cost: 2 Bytes: 10 Cardinality: 1
By the way, how do you know that the stat were out of date?
Edited by: sfrade on Mar 20, 2009 8:54 AM

Similar Messages

  • Are Joins possible with VPD predicates?

    Hi everybody,
    I have read the articles about VPD and row level security. What occurs to me is that all examples return predicates where the WHERE clause selects from the same table as the FROM clause. Is there a way to generate a predicate that goes to other tables as well?
    Example:
    table_1 holds sales records information, e.g.:
    product, price, date of sale transaction.
    table_2 holds information about the customers, e.g.:
    customer_company, product, price, date_of_sale_transaction.
    table_3 holds information about the customer account managers, e.g.:
    employee_id, family_name, name, customer_company, customer_department.
    Now if an account manager logs in to the database he shall only see the sold products in table_1 which were bought by the customers who he is in charge of. The select statement would something like:
    select t1.product, t1.price from table_1 t1, table_2 t2, table_3 t3 where t1.product=t2.product and t2.customer_company=t3.customer_company and t3.employee_id=?
    Certainly, ? would be the the id of the logged in user.
    How can I realize a JOIN like this with VPD?
    Thank you for every help!
    Jie

    Jie,
    This is trivial to do in VPD. In your case, you would define a different policy on each table. For instance, the policy function for the policy on table_3 will return a preciate
    employee_id = USER
    or something similar. The policy function for policy on table_2 will return
    customer_company in (select customer_company from table_1)
    Similarly, the function for table_1 will return
    product_in (select product from table_2)
    However, you will note that the query containing IN quickly becomes inefficient when the data volume is high. Therefore, an alternative solution may be in order. One option is to use application contexts where you prepopulate the values when the user logs in and use that in the predicate. It's not possible to describe the whole procedure here; but youmay find the paper I presented at New York Oracle User Group helpful at my website www.proligence.com/nyoug_fgac.pdf.
    Hope this helps.
    Arup Nanda

  • How do I avoid ORA-01473 when querying hierarchial on tables with VPD predicates

    My question is how to circumvent what seems to be a limitation i ORACLE, if at all possible. Please read on.
    When using VPD (Virtual Private Database) predictaes on a table and performing a hierarchial query on that table I get the following error message:
    ORA-01473: cannot have subqueries in CONNECT BY CLAUSE
    My query may look like the folwing:
    SELECT FIELD
    FROM TABLE
    START WITH ID = 1
    CONNECT BY PRIOR ID = PARENT
    As my predicate contains a query in it self, I suspect that the implicit augmentation of the predicate results in a query that looks like:
    SELECT FIELD
    FROM TABLE
    START WITH ID = 1
    CONNECT BY PRIOR ID = PARENT
    AND OWNER IN (SELECT OWNER FROM TABLE2 WHERE ...)
    at least, when executing a query like the one above (with the explicit predicate) I get the identical error message.
    So my question is:
    Do you know of any way to force the predicate to augment itslef onto the WHERE-clause? I would be perfectly happy with a query that looks like:
    SELECT FIELD
    FROM TABLE
    START WITH ID = 1
    CONNECT BY PRIOR ID = PARENT
    WHERE OWNER IN (SELECT OWNER FROM TABLE2 WHERE ...)
    or do you know of any fix/patch/release to ORACLE that allows you to include subqueries in the CONNECT BY-clause and eliminates the error message?

    The WHERE clause or AND clause applies to the line directly above it. Please see the examples of valid and invalid queries below, which differ only in the placement of the WHERE or AND clause. If this is not sufficient, please provide some sample data and desired output to clarify what you need.
    -- valid:
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  WHERE     deptno IN
      6            (SELECT deptno
      7             FROM     dept
      8             WHERE     dname = 'RESEARCH')
      9  START WITH mgr = 7566
    10  CONNECT BY PRIOR empno = mgr
    11  /
         EMPNO        MGR     DEPTNO                           
          7788       7566         20                           
          7876       7788         20                           
          7902       7566         20                           
           800       7902         20                           
    -- invalid:
    SQL>
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  START WITH mgr = 7566
      6  CONNECT BY PRIOR empno = mgr
      7  WHERE     deptno IN
      8            (SELECT deptno
      9             FROM     dept
    10             WHERE     dname = 'RESEARCH')
    11  /
    WHERE      deptno IN
    ERROR at line 7:
    ORA-00933: SQL command not properly ended
    -- valid:
    SQL>
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  START WITH mgr = 7566
      6  AND     deptno IN
      7            (SELECT deptno
      8             FROM     dept
      9             WHERE     dname = 'RESEARCH')
    10  CONNECT BY PRIOR empno = mgr
    11  /
         EMPNO        MGR     DEPTNO                           
          7788       7566         20                           
          7876       7788         20                           
          7902       7566         20                           
           800       7902         20                           
    -- invalid:
    SQL>
    SQL> SELECT     empno,
      2            mgr,
      3            deptno
      4  FROM     emp
      5  START WITH mgr = 7566
      6  CONNECT BY PRIOR empno = mgr
      7  AND     deptno IN
      8            (SELECT deptno
      9             FROM     dept
    10             WHERE     dname = 'RESEARCH')
    11  /
    FROM       emp
    ERROR at line 4:
    ORA-01473: cannot have subqueries in CONNECT BY clause

  • What restrictions apply to VPD functions for column masking?

    I want to understand the restrictions that apply to VPD functions when used for column masking, compared with their use for Row-Level Security.
    According to the Oracle Database Security Guide (11g Release 1)
    Column-masking conditions generated by the policy function must be simple Boolean expressions, unlike regular Oracle Virtual Private Database predicates.
    I have long understood the above as implying that column-masking conditions should not contain sub-queries (i.e. inner selects).
    However, we tested using a condition with a select inside another select (2-level nesting) and yet it worked. We were on 11g Release 2, by the way.
    So, I wonder, does anyone have experience with using sub-queries in column-masking conditions? Or, alternatively, does anyone have more information on what Oracle means with "regular VPD predicates" and "simple Boolean expressions" (of course, in the context of VPD)?
    Thanks,
    Pablo

    Thanks Harm,
    that was very useful.
    According to the grammar of CASE expressions, <predicate> is generated by the non-terminal "condition". This is the same non-terminal used for WHERE clauses in SELECT statements, and thus <predicate> can contain any number of nested SELECTs.
    Cheers,
    Pablo

  • VPD - what happens if predicate already coded on sql statement?

    Does anyone know, when using VPD, what happens if a where clause already exists on an sql statement that a policy predicate would duplicate?
    ie the examples are all simple, like adding a "where customer = xx" to a statement like "select * from customer_tab"
    what if the user-entered statement is instead "select * from customer_tab where customer = yy", and then the VPD policy appends "where customer = xx" to that? That would result in an error, unless VPD is intelligent enough to handle this condition.
    Can anyone tell me what VPD will do in this scenario?

    Yes, the VPD is sufficient intelligent to this.
    In this in case that the message is returned below:
    ORA-28115: policy with check option violation
    Cause: Policy predicate was evaluated to FALSE with the updated values.
    Action:     none

  • Predicate info in query tuning

    Hi All,
    I just wished to know , what kind of help the predicate information do while you are given the task of SQL tuning.
    I am refering the predicate information which appears after EXPLAIN PLAN is done for some query with tracing ON.
    I refered many queries and there predicate info's but not able to understand how and what kind of helpful info it provides?
    Any small example would be helpful. I would have pasted my queries but they are too large and I just want to begin with small queries and understand this thing.
    Thanks,
    Aashish

    The predicate section is invaluable.
    It tells you the conditions being used as filter/access predicates.
    Amongst other things, it can show you:
    - why indexes are being used;
    - more importantly, why indexes might not be being used
    - unexpected implicit datatype conversions
    - transitive closure and other optimizer tricks
    Some useful links:
    http://jonathanlewis.wordpress.com/2008/12/03/predicate-problems/
    http://jonathanlewis.wordpress.com/2010/04/15/predicate-again/
    http://mwidlake.wordpress.com/2010/04/21/internal_function-impact/

  • Tuning Greater than predicate query on dates

    Hi,
    I have the below query which is doing FTS and is very expensive causing load to timeout.
    I did my analysis and found that table is having large number of records and hence FTS is taking long time causing timeout from app side.
    I proposed to have this table partitioned but this is still pending with business and they in meantime want some solution other solution to fix this issue.
    below is the query and plan
    SELECT TRANSACTION_LOG.ID, TRANSACTION_LOG.USER_IDENTIFIER, TRANSACTION_LOG.START_TIME, TRANSACTION_LOG.END_TIME, TRANSACTION_LOG.REQUEST, TRANSACTION_LOG.RESPONSE
    FROM
    WP61PD1COLTRDB.TRANSACTION_LOG
    WHERE TRANSACTION_LOG.END_TIME > TO_DATE('07/26/2012 10:16:41','MM/DD/YYYY hh24:mi:ss')
    Plan hash value: 2462480644
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 5 | 5360 | 1480K (1)| 04:56:09 |
    |* 1 | TABLE ACCESS FULL| TRANSACTION_LOG | 5 | 5360 | 1480K (1)| 04:56:09 |
    Predicate Information (identified by operation id):
    1 - filter("TRANSACTION_LOG"."END_TIME">TIMESTAMP' 2012-07-26 10:16:41')
    Count of no. of records:
    select count(*) from WP61PD1COLTRDB.TRANSACTION_LOG
    COUNT(*)
    43537767
    There is only one index on ID column of the table which is normal index.
    desc WP61PD1COLTRDB.TRANSACTION_LOG
    Name Null Type
    ID NOT NULL NUMBER(38)
    USER_IDENTIFIER NOT NULL VARCHAR2(255)
    CLIENT_IP_ADDRESS VARCHAR2(255)
    START_TIME NOT NULL TIMESTAMP(6)
    END_TIME NOT NULL TIMESTAMP(6)
    REQUEST NOT NULL VARCHAR2(4000)
    RESPONSE VARCHAR2(4000)
    Is there any other way we can tune this query?
    Thanks
    JP

    Please read the FAQ for how to post a tuning request and the information that is needed (e.g. table and index ddl, record counts for the tables, record counts for the predicates in the where clause)
    >
    I have the below query which is doing FTS and is very expensive causing load to timeout.
    >
    Just how can a SELECT query cause a 'load' to timeout?
    >
    Is there any other way we can tune this query?
    >
    There is no way to know since you didn't provide any information about how many records there are in the table and how many might satisfy the date predicate you are using.
    Other than doing the query in parallel you can't speed it up unless there was an index on END_TIME that could be used effectively.
    Even with an index on that column a full table scan that does multi-block reads might be lower cost than using the index and doing single-block reads.
    If the table has 100 million records and your query is trying to return 99 million of them don't you think a full table scan should be used?

  • Effect of RLS policy (VPD) on execution plan of a query

    Hi
    I have been working on tuning of few queries. A RLS policy is defined on most of the tables which appends an extra where condition (something like AREA_CODE=1). I am not able to understand the effect of this extra where clause on the execution plan of the query. In the execution plan there is no mention of the clause added by VPD. In 10046 trace it does show the policy function being executed but nothing after that.
    Can someone shed some light on the issue that has VPD any effect on the execution plan of the query ? Also would it matter whether the column on which VPD is applied, was indexed or non-indexed ?
    Regards,
    Amardeep Sidhu

    Amardeep Sidhu wrote:
    I have been working on tuning of few queries. A RLS policy is defined on most of the tables which appends an extra where condition (something like AREA_CODE=1). I am not able to understand the effect of this extra where clause on the execution plan of the query. In the execution plan there is no mention of the clause added by VPD. In 10046 trace it does show the policy function being executed but nothing after that.
    VPD is supposed to be invisible - which is why you get minimal information about security predicates in the standard trace file. However, if you reference a table with a security preidcate in your query, the table is effectively replaced by an inline view of the form: "select * from original_table where {security_predicate}", and the result is then optimised. So the effects of the security predicate is just the same as you writing the predicate into the query.
    Apart from your use of v$sql_plan to show the change in plan and the new predicates, you can see the effects of the predicates by setting event 10730 with 10046. In current versions of Oracle this causes the substitute view being printed in the trace file.
    Bear in mind that security predicates can be very complex - including subqueries - so the effect isn't just that of including the selectivity of "another simple predicate".
    Can someone shed some light on the issue that has VPD any effect on the execution plan of the query ? Also would it matter whether the column on which VPD is applied, was indexed or non-indexed ?
    Think of the effect of changing the SQL by hand - and how you would need to optimise the resultant query. Sometimes you do need to modify your indexing to help the security predicates, sometimes it won't make enough difference to matter.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    "Science is more than a body of knowledge; it is a way of thinking"
    Carl Sagan
    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help for query tuning

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

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

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need Help in Breaking a big view into multiple small views or tuning the vw

    Hi
    I have the following view can some one help me in breaking the view in small views or any recommendations for tuning it.
    CODE
    CREATE OR REPLACE FORCE VIEW "CRUVPD"."PX16_CHK_VW_SUMMARY_VW" ("CIDN", "BATCH_NUMBER", "BUSINESS_UNIT", "CHECK_VOUCHER_NUMBER", "CHECK_VOUCHER_CODE", "CHECKVIEW_CLOCK_NUMBER", "COMPANY_CHECKVIEW_HOME_DEPT", "PERIOD_END_DATE", "FEDERAL_TAX", "GROSS_PAY"
    , "HOME_DEPARTMENT", "HOME_DEPARTMENT_DESC", "LIVED_LOCAL_TAX_CODE", "LIVED_STATE_TAX_CODE", "LIVED_LOCAL_TAX", "LIVED_STATE_TAX", "MEDICARE_TAX", "NET_PAY", "DEPARTMENT_WORKED_IN", "PAY_TO_COMPANY_INDICATOR", "PAY_DATE", "PAYROLL_NUMBER", "SCHOOL_DISTRIC
    T_TAX", "CHECKVIEW_SCHOOL_DISTRICT", "SOCIAL_SECURITY_TAX", "SUI_SDI_TAX", "SUI_SDI_TAX_CODE", "VOID_CHECK_INDICATOR", "WEEK_NUMBER", "WORKED_LOCAL_TAX_CODE", "WORKED_STATE_TAX_CODE", "WORKED_LOCAL_TAX", "WORKED_STATE_TAX", "YEAR", "COMPANY_CODE", "FILE_N
    UMBER", "FIRST_NAME", "LAST_NAME", "LAST_NAME_FIRST_NAME", "SOCIAL_SECURITY_NUMBER", "STATUS", "OVERTIME_EARNINGS", "OVERTIME_HOURS", "REGULAR_EARNINGS", "REGULAR_HOURS", "VIEWPK", "HOME_COST_NUMBER", "TAX_FREQUENCY", "COMPANY_COST_NUMBER", "COST_NUMBER_W
    ORKED_IN", "DISTRIBUTION_NUMBER", "TOTAL_DEDUCTIONS_AMOUNT", "TOTAL_HOURS_AMOUNT", "TOTAL_MEMO_AMOUNT", "TOTAL_OTHER_EARNINGS", "TOTAL_OTHER_HOURS", "CHECK_SEQ_NO", "JOINKEY", "CHECK_REVERSAL_INDICATOR") AS
    with user_security_homedept
    AS
    (select /*+ INLINE */ distinct cg.cidn,co_code,asso.oid,asso.name,department_Access ,t2.column_value dep,cg.oid
    from px16_cocodegroup cg ,
    px16_associate asso ,
    px16_securityobject so,
    px16_cocodegrp_securitygrp cs,
    px16_security_group sg ,
    TABLE(f_str2tbl_px16(cg.department_access)) t2
    where cg.USEROID = asso.OID
    and cg.co_code = substr(so.name,8,3)
    and upper(asso.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
    and cg.oid = cs.cocodegroupoid
    and cs.securitygroupoid = sg.oid
    and cg.cidn = asso.cidn
    and cg.cidn = so.cidn
    and cg.cidn = cs.cidn
    and cs.cidn = sg.cidn
    order by 2,1
    user_security_cost_no
    AS
    (select /*+ INLINE */
    cg.cidn,co_code,count(distinct cd.code)cost_no,cd.code
    from px16_cocodegroup cg ,
    px16_associate asso ,
    px16_securityobject so,
    px16_cocodegrp_securitygrp cs,
    px16_security_group sg ,
    px16_customaccessdetail cd
    where cg.USEROID = asso.OID
    and cg.co_code = substr(so.name,8,3)
    and upper(asso.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
    and cg.oid = cs.cocodegroupoid
    and cs.securitygroupoid = sg.oid
    and cg.oid = cd.cocodegroupoid(+)
    and cg.cidn = cd.cidn(+)
    and cg.cidn = asso.cidn
    and cg.cidn = so.cidn
    and cg.cidn = cs.cidn
    and cs.cidn = sg.cidn
    group by cg.cidn,co_code,cd.code
    order by 2,1
    super_user_check as
    (SELECT
    distinct a.cidn su_cidn,1 as su_user
    FROM
    px16_LINK LN
    , px16_userprofile up
    , px16_ASSOCIATE a
    , px16_pcp_user pu
    WHERE
    a.oid = pu.oid
    AND pu.userprofileoid = up.oid
    AND LN.parentoid = up.oid
    AND a.active = 1
    AND a.cidn=pu.cidn
    AND pu.cidn=up.cidn
    AND ln.cidn=up.cidn
    AND upper(a.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
    AND upper(up.name) = upper('Super user')
    nonsuper_user_check as
    SELECT distinct a.cidn s_cidn , 1 as non_user
    FROM
    px16_LINK LN
    , px16_userprofile up
    , px16_ASSOCIATE a
    , px16_pcp_user pu
    WHERE
    a.oid = pu.oid
    AND pu.userprofileoid = up.oid
    AND LN.parentoid = up.oid
    AND a.active = 1
    AND a.cidn=pu.cidn
    AND pu.cidn=up.cidn
    AND ln.cidn=up.cidn
    AND upper(a.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
    AND LN.childoid IN ( 'SYS:5:7478')
    SELECT distinct
    cidn
    ,batch_number Batch_Number
    , business_unit Business_Unit
    , check_voucher_number Check_Voucher_Number
    , check_voucher_code Check_Voucher_Code
    , clock_number CheckView_Clock_Number
    , company_code_or_dept Company_CheckView_Home_Dept
    , period_end_date Period_End_Date
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, 1, (INSTR(taxes_and_rates, '~', 1, 1) -1)), CHR(155), NULL)) Federal_Tax
    , gross_pay Gross_Pay
    , home_department Home_Department
    , home_department_descr Home_Department_Desc
    , SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 1) +1)
    , INSTR(taxes_and_rates, '~', 1, 2) - (INSTR(taxes_and_rates, '~', 1, 1) +1)), CHR(155), NULL), 1, 32) Lived_Local_Tax_Code
    , SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 2) +1)
    , INSTR(taxes_and_rates, '~', 1, 3) - (INSTR(taxes_and_rates, '~', 1, 2) +1)), CHR(155), NULL), 1, 32) Lived_State_Tax_Code
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 3) +1)
    , INSTR(taxes_and_rates, '~', 1, 4) - (INSTR(taxes_and_rates, '~', 1, 3) +1)), CHR(155), NULL)) Lived_Local_Tax
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 4) +1)
    , INSTR(taxes_and_rates, '~', 1, 5) - (INSTR(taxes_and_rates, '~', 1, 4) +1)), CHR(155), NULL)) Lived_State_Tax
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 5) +1)
    , INSTR(taxes_and_rates, '~', 1, 6) - (INSTR(taxes_and_rates, '~', 1, 5) +1)), CHR(155), NULL)) Medicare_Tax
    , net_pay Net_Pay
    , department_paid Department_Worked_In
    , to_pay_indicator Pay_to_Company_Indicator
    , pay_date Pay_Date
    , payroll_number Payroll_Number
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 6) +1)
    , INSTR(taxes_and_rates, '~', 1, 7) - (INSTR(taxes_and_rates, '~', 1, 6) +1)), CHR(155), NULL)) School_District_Tax
    , SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 7) +1)
    , INSTR(taxes_and_rates, '~', 1, 8) - (INSTR(taxes_and_rates, '~', 1, 7) +1)), CHR(155), NULL), 1, 32) CheckView_School_District
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 8) +1)
    , INSTR(taxes_and_rates, '~', 1, 9) - (INSTR(taxes_and_rates, '~', 1, 8) +1)), CHR(155), NULL)) Social_Security_Tax
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 9) +1)
    , INSTR(taxes_and_rates, '~', 1, 10) - (INSTR(taxes_and_rates, '~', 1, 9) +1)), CHR(155), NULL)) SUI_SDI_Tax
    , SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 10) +1)
    , INSTR(taxes_and_rates, '~', 1, 11) - (INSTR(taxes_and_rates, '~', 1, 10) +1)), CHR(155), NULL), 1, 32) SUI_SDI_Tax_Code
    , void_check_indicator Void_Check_Indicator
    , week_number Week_Number
    , SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 11) +1)
    , INSTR(taxes_and_rates, '~', 1, 12) - (INSTR(taxes_and_rates, '~', 1, 11) +1)), CHR(155), NULL), 1, 32) Worked_Local_Tax_Code
    , SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 12) +1)
    , INSTR(taxes_and_rates, '~', 1, 13) - (INSTR(taxes_and_rates, '~', 1, 12) +1)), CHR(155), NULL), 1, 32) Worked_State_Tax_Code
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 13) +1)
    , INSTR(taxes_and_rates, '~', 1, 14) - (INSTR(taxes_and_rates, '~', 1, 13) +1)), CHR(155), NULL)) Worked_Local_Tax
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 14) +1)
    , INSTR(taxes_and_rates, '~', 1, 15) - (INSTR(taxes_and_rates, '~', 1, 14) +1)), CHR(155), NULL)) Worked_State_Tax
    , year Year
    , company_code Company_Code
    , file_number File_Number
    , first_name First_Name
    , last_name Last_Name
    , name Last_Name_First_Name
    , ssn Social_Security_Number
    , status Status
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 15) +1)
    , INSTR(taxes_and_rates, '~', 1, 16) - (INSTR(taxes_and_rates, '~', 1, 15) +1)), CHR(155), NULL)) Overtime_Earnings
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 16) +1)
    , INSTR(taxes_and_rates, '~', 1, 17) - (INSTR(taxes_and_rates, '~', 1, 16) +1)), CHR(155), NULL)) Overtime_Hours
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 17) +1)
    , INSTR(taxes_and_rates, '~', 1, 18) - (INSTR(taxes_and_rates, '~', 1, 17) +1)), CHR(155), NULL)) Regular_Earnings
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 18) +1)
    , INSTR(taxes_and_rates, '~', 1, 19) - (INSTR(taxes_and_rates, '~', 1, 18) +1)), CHR(155), NULL)) Regular_Hours
    , (company_code || '/' || ssn || '/' || file_number || '/' || TO_CHAR(payroll_number) || '/'
    || TO_CHAR(year) || '/' || TO_CHAR(week_number) || '/' || check_voucher_number
    || '/' || to_char(check_seq_num) || '/' || TO_CHAR(distribution_number)) Viewpk
    , home_costnumber_desc Home_Cost_Number
    , tax_frequency Tax_Frequency
    , co_chkv_home_cost_no Company_Cost_Number
    , cost_no_worked_in Cost_Number_Worked_In
    , distribution_number Distribution_Number
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 19) +1)
    , INSTR(taxes_and_rates, '~', 1, 20) - (INSTR(taxes_and_rates, '~', 1, 19) +1)), CHR(155), NULL)) Total_Deductions_Amount
    , NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 20) +1)
    , INSTR(taxes_and_rates, '~', 1, 21) - (INSTR(taxes_and_rates, '~', 1, 20) +1)), CHR(155), NULL)), 0) Total_Hours_Amount
    , NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 21) +1)
    , INSTR(taxes_and_rates, '~', 1, 22) - (INSTR(taxes_and_rates, '~', 1, 21) +1)), CHR(155), NULL)), 0) Total_Memo_Amount
    , NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 22) +1)
    , INSTR(taxes_and_rates, '~', 1, 23) - (INSTR(taxes_and_rates, '~', 1, 22) +1)), CHR(155), NULL)), 0) Total_Other_Earnings
    , TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 23) +1)), CHR(155), NULL)) Total_Other_Hours
    , check_seq_num Check_Seq_No
    , (NVL(company_code, '~') || CHR(155) || NVL(file_number, '~') || CHR(155) || NVL(ssn, '~') || CHR(155) || NVL(TO_CHAR(year), '~') || CHR(155)
    || NVL(TO_CHAR(week_number), '~') || CHR(155) || NVL(TO_CHAR(payroll_number), '~')
    || CHR(155) || NVL(check_voucher_number, '~') || CHR(155) || NVL(TO_CHAR(check_seq_num), '~') || CHR(155) || NVL(TO_CHAR(distribution_number), '~')) Joinkey
    , chk_reverse Check_Reversal_Indicator
    FROM
    SELECT
    ch.cidn cidn
    /*BATCH NUMBER*/
    , ch.batch_nb batch_number
    , /*BUSINESS UNIT*/
    (select asso.description
    from px16_appointment ap,
    px16_jobposition jp,
    px16_corporation co,
    px16_associate asso,
    px16_payrollagreement pa,
    px16_payrollgroup pg
    where
    ch.cidn = pg.cidn
    AND ch.cidn = pa.cidn
    AND pa.cidn = pg.cidn
    AND pa.cidn = ap.cidn
    AND em.cidn = ap.cidn
    AND ap.cidn = jp.cidn
    and jp.cidn = co.cidn
    and co.cidn = asso.cidn
    and ch.co_code=pg.co_code
    and ch.file_nb=pa.file_number
    and pa.cocodeoid=pg.oid
    and pa.appointmentoid=ap.oid
    and em.oid=ap.employmentoid
    and ap.jobpositionoid=jp.oid
    and jp.corporationoid=co.oid
    and co.oid=asso.oid) business_unit
    , /*CHECK/VOUCHER NUMBER*/
    ch.check_nb check_voucher_number
    , /*CHECK/VOUCHER CODE*/
    SUBSTR(f_type_px16(ch.cidn,ch.chkvchcodeoid, 'NAME'), 1, 255) check_voucher_code
    , /*CLOCK NUMBER*/
    ch.clock_id clock_number
    , /* COMPANY CODE OR DEPT*/
    ch.co_code||'/'||substr(ch.home_dept_code,1,20) company_code_or_dept
    , /*PERIOD END DATE*/
    ch.payroll_ending_date period_end_date
    , /*GROSS PAY*/
    NVL(chd.gross_pay_amt,0) gross_pay
    , /*HOME DEPARTMENT*/
    ch.home_dept_code home_department
    , /*HOME DEPARTMENT DESCRIPTION*/
    (select ty.description
    from px16_type ty,px16_securityobject sc
    where
    ch.cidn = sc.cidn
    and ty.cidn in ('COMMON', ch.cidn)
    and ch.home_dept_code=ty.name
    and ty.category='T_CO_DEPT'
    and ty.securityoid=sc.oid
    and ch.co_code=substr(sc.name,8)) home_department_descr
    , /*NET PAY*/
    nvl(chd.net_pay_amt,0) net_pay
    , /*DEPARTMENT PAID*/
    -- ch.paid_in_debt_code department_paid
    chd.worked_in_dept department_paid
    , /*TO PAY INDICATOR*/
    decode(to_char(ch.pay_to_co),'1','Y','0','N',to_char(ch.pay_to_co)) to_pay_indicator
    , /*PAY DATE*/
    ch.pay_date pay_date
    , /*PAYROLL NUMBER*/
    to_char(ch.payroll_nb) payroll_number
    , /*VOID CHECK INDICATOR*/
    decode(to_char(ch.void_flag),'1','Y','0','N',to_char(ch.void_flag)) void_check_indicator
    , /*WEEK NUMBER*/
    TO_number(ch.week) week_number
    , /*YEAR*/
    to_char(ch.year) year
    , /*COMPANY CODE*/
    ch.co_code company_code
    , /*FILE NUMBER*/
    LPAD(ch.file_nb,6,0) file_number
    , /*FIRST NAME*/
    pe.first_name first_name
    , /*LAST NAME*/
    pe.last_name last_name
    , /*NAME*/
    pe.last_name||', '||pe.first_name name
    , /*SSN*/
    payx_r16_principal_info.masked_ssn(pe.unique_id, ch.cidn) ssn
    , /*STATUS*/
    (SELECT SUBSTR(f_type_px16(ap.cidn,ap.currentstatusoid, 'DESC'), 1, 255)
    from
    px16_appointment ap,
    /*context co_ap,*/
    px16_payrollagreement pa,
    px16_payrollgroup pg
    where
    pg.cidn=ch.cidn
    and pa.cidn=ch.cidn
    and ap.cidn=pa.cidn
    and ap.cidn = em.cidn
    and ap.employmentoid=em.oid
    and ap.active=1
    and ap.oid=pa.appointmentoid
    and lpad(to_char(pa.file_number),6,0)=ch.file_nb
    and pa.cocodeoid=pg.oid
    and pg.co_code=ch.co_code) status
    -- FED TAX
    -- , LIVED LOCAL TAX CODE, LIVED STATE TAX CODE, LIVED LOCAL TAX, LIVED STATE TAX, MEDICARE TAX
    -- , SCHOOL DISTRICT TAX, SCHOOL DISTRICT, SOCIAL SECURITY TAX, SUI SDI TAX, SUI SDI TAX CODE
    -- , WORKED LOCAL TAX CODE, WORKED STATE TAX CODE, WORKED LOCAL TAX, WORKED STATE TAX
    -- , OVERTIME EARNINGS, OVERTIME HOURS, REGULAR EARNINGS, REGULAR HOURS
    NVL (
    (SELECT
    TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2982', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2984', ci.code, NULL), NULL)), CHR(155)) || '~'
    || NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2987', DECODE(ci.code,'XX',null,ci.code), NULL), NULL)), CHR(155)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2984', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2987', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4118', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4114', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4114', ci.code, NULL), NULL)), CHR(155)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2988', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2989', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2989', ci.code, NULL), NULL)), CHR(155)) || '~'
    || NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2983', ci.code, NULL), NULL)), CHR(155)) || '~'
    || NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2986', ci.code, NULL), NULL)), CHR(155)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2983', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2986', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3713', NVL(ci.amount,0), 0)), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3727', NVL(ci.amount,0), 0)), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3715', NVL(ci.amount,0), 0)), 0)) || '~'
    || TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3716', NVL(ci.amount,0), 0)), 0)) || '~'
    -- R16 columns.
    -- Total Deductions Amount === Other Deductions on UI screen.
    || TO_CHAR(NVL(SUM(DECODE(chcat.name, 'DeductionHistory'
    , DECODE(NVL(ci.statutory_ded, 0), 0
    , DECODE(ci.taxcodeoid, NULL
    , DECODE(ci.code, NULL, 0, NVL(ci.amount,0)), 0), 0), 0)), 0)) || '~' -- "Total Deductions Amount"
    || TO_CHAR(NVL(SUM(DECODE(chcat.name, 'OvertimeHours', NVL(ci.amount,0)
    , 'AdditionalHours', NVL(ci.amount,0), 'RegularHours', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Hours Amount"
    || TO_CHAR(NVL(SUM(DECODE(chcat.name, 'Memo', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Memo Amount"
    || TO_CHAR(NVL(SUM(DECODE(chcat.name, 'AdditionalEarnings', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Other Earnings"
    || TO_CHAR(NVL(SUM(DECODE(chcat.name, 'AdditionalHours', NVL(ci.amount,0), 0)), 0)) -- "Total Other Hours"
    FROM
    px16_checkhistoryitem ci
    , px16_sys_type chcat
    WHERE
    ci.cidn=chd.cidn
    AND ci.checkhistorydistributionoid = chd.oid
    AND chcat.category = 'CheckHistoryItem'
    AND chcat.oid = ci.histtypeoid
    -- AND ci.histtypeoid IN ('SYS:4:3713', 'SYS:4:3727', 'SYS:4:3715', 'SYS:4:3716', 'SYS:4:3709')
    ), '0' || '~' || CHR(155) || '~' || CHR(155)
    || '0~0~0~0~' || CHR(155) || '~0~0~' || CHR(155) || '~' || CHR(155) || '~'
    || CHR(155) || '~0~0~0~0~0~0'
    ) taxes_and_rates
    , ch.check_seq_num check_seq_num
    , ch.home_cost_number home_costnumber_desc
    , SUBSTR(f_type_px16(ch.cidn,ch.payfrequencyoid, 'NAME'), 1, 255) tax_frequency
    , (ch.co_code || '/' || ch.home_cost_number) co_chkv_home_cost_no
    , chd.worked_in_cost_number cost_no_worked_in
    , chd.distribution_number distribution_number
    , DECODE(NVL(ch.reversed_flag, 0), 1, 'Y', 'N') chk_reverse
    FROM
    px16_checkhistory ch
    , px16_employment em
    , px16_person pe
    , px16_payrollgroup pg
    , px16_checkhistory_dist chd
    , px16_appointment ap
    WHERE
    ch.cidn = em.cidn
    and em.cidn = pe.cidn
    and pg.cidn = ch.cidn
    and ch.cidn = chd.cidn
    and ap.cidn(+) = em.cidn
    and ch.employmentoid=em.oid
    AND em.personoid=pe.oid
    AND pg.co_code = ch.co_code
    AND ch.active = 1
    AND ch.oid = chd.checkhistoryoid
    AND ap.employmentoid(+) = em.oid
    AND DECODE(ap.oid, NULL, 1, NVL((SELECT 1 FROM px16_payrollagreement pa
    WHERE
    pa.cidn = ap.cidn
    and pa.cidn = ch.cidn
    and pa.cidn = pg.cidn
    and pa.appointmentoid = ap.oid
    AND pa.file_number = ch.file_nb
    AND pa.cocodeoid = pg.oid), 0)) = 1
    and ch.cidn in (select distinct s_cidn from nonsuper_user_check)
    AND ( sys_context('payx_r16_app_context', 'app_role') in ('ADP', 'CSR')
    or (exists (select 1 from super_user_check where su_cidn =ch.cidn))
    or (ch.cidn,ch.co_code,ch.home_dept_code) in (select cidn,co_code,dep from user_security_homedept)
    or (ch.cidn,ch.co_code,ch.home_cost_number) in (select cidn,co_code,code from user_security_cost_no)
    or ( exists(select co_code from user_security_homedept where cidn=ch.cidn and co_code = ch.co_code and dep is null)
    and exists(select co_code from user_security_cost_no where cidn=ch.cidn and co_code = ch.co_code and cost_no = 0) )
    Explain plan
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 1 | 7519 | 99 (2)|
    | 1 | VIEW | PX16_CHK_VW_SUMMARY_VW | 1 | 7519 | |
    | 2 | SORT UNIQUE | | 1 | 445 | 78 (0)|
    |* 3 | FILTER | | | | |
    | 4 | NESTED LOOPS OUTER | | 1 | 445 | 63 (2)|
    | 5 | NESTED LOOPS | | 1 | 414 | 58 (2)|
    | 6 | NESTED LOOPS | | 1 | 362 | 53 (2)|
    | 7 | NESTED LOOPS | | 1 | 331 | 48 (3)|
    | 8 | NESTED LOOPS | | 1 | 306 | 43 (3)|
    | 9 | NESTED LOOPS | | 1 | 253 | 38 (3)|
    | 10 | NESTED LOOPS | | 1 | 120 | 23 (5)|
    | 11 | NESTED LOOPS | | 1 | 79 | 18 (6)|
    | 12 | NESTED LOOPS | | 1 | 53 | 13 (8)|
    |* 13 | INDEX FAST FULL SCAN | USERPROFILE_GG_U | 5 | 110 | 11 (0)|
    |* 14 | INDEX RANGE SCAN | UQ_LINK | 1 | 31 | |
    | 15 | TABLE ACCESS BY INDEX ROWID | PCP_USER | 1 | 26 | 6 (17)|
    |* 16 | INDEX RANGE SCAN | XIF3PCP_USER | 1 | | |
    |* 17 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 41 | 6 (17)|
    |* 18 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
    |* 19 | TABLE ACCESS BY INDEX ROWID | CHECKHISTORY | 1 | 133 | 16 (7)|
    |* 20 | INDEX RANGE SCAN | J_CO_CODE | 13 | | 2 (0)|
    | 21 | TABLE ACCESS BY INDEX ROWID | CHECKHISTORYDISTRIBUTION | 1 | 53 | 6 (17)|
    |* 22 | INDEX RANGE SCAN | TMP_IDX11 | 1 | | |
    | 23 | TABLE ACCESS BY INDEX ROWID | PAYROLLGROUP | 1 | 25 | 6 (17)|
    |* 24 | INDEX RANGE SCAN | PAYROLLGROUP_IDX2 | 1 | | |
    | 25 | TABLE ACCESS BY INDEX ROWID | EMPLOYMENT | 1 | 31 | 6 (17)|
    |* 26 | INDEX UNIQUE SCAN | EMPLOYMENT_GG_U | 1 | | |
    | 27 | TABLE ACCESS BY INDEX ROWID | PERSON | 1 | 52 | 6 (17)|
    |* 28 | INDEX UNIQUE SCAN | PERSON_GG_U | 1 | | |
    | 29 | TABLE ACCESS BY INDEX ROWID | APPOINTMENT | 1 | 31 | 6 (17)|
    |* 30 | INDEX RANGE SCAN | XIF12APPOINTMENT | 1 | | |
    |* 31 | FILTER | | | | |
    |* 32 | TABLE ACCESS BY INDEX ROWID | PAYROLLAGREEMENT | 1 | 34 | 21 (5)|
    |* 33 | INDEX RANGE SCAN | UQ_FILE_NO_COCODE | 1 | | 3 (0)|
    |* 34 | FILTER | | | | |
    | 35 | NESTED LOOPS | | 1 | 130 | 27 (4)|
    | 36 | NESTED LOOPS | | 1 | 89 | 22 (5)|
    | 37 | NESTED LOOPS | | 1 | 63 | 17 (6)|
    |* 38 | TABLE ACCESS BY INDEX ROWID | USERPROFILE | 1 | 41 | 16 (7)|
    |* 39 | INDEX RANGE SCAN | XIF1USERPROFILE | 1 | | 2 (0)|
    |* 40 | INDEX RANGE SCAN | LINK_IDX2 | 1 | 22 | |
    | 41 | TABLE ACCESS BY INDEX ROWID | PCP_USER | 1 | 26 | 6 (17)|
    |* 42 | INDEX RANGE SCAN | XIF3PCP_USER | 1 | | |
    |* 43 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 41 | 6 (17)|
    |* 44 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
    |* 45 | FILTER | | | | |
    | 46 | NESTED LOOPS | | 1 | 144 | 48 (3)|
    | 47 | MERGE JOIN CARTESIAN | | 1 | 142 | 37 (3)|
    | 48 | NESTED LOOPS | | 1 | 116 | 32 (4)|
    | 49 | NESTED LOOPS | | 1 | 96 | 31 (4)|
    | 50 | NESTED LOOPS | | 1 | 72 | 26 (4)|
    |* 51 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 1 | 34 | 21 (5)|
    |* 52 | INDEX RANGE SCAN | XIF1COCODEGROUP | 9 | | 2 (0)|
    |* 53 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
    |* 54 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
    |* 55 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
    |* 56 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
    | 57 | BUFFER SORT | | 1 | 26 | 35 (0)|
    |* 58 | INDEX RANGE SCAN | UQ_SECURITYOBJECT | 1 | 26 | 1 (0)|
    |* 59 | COLLECTION ITERATOR PICKLER FETCH | F_STR2TBL_PX16 | | | |
    |* 60 | FILTER | | | | |
    | 61 | SORT GROUP BY | | 1 | 183 | 66 (0)|
    | 62 | NESTED LOOPS | | 1 | 183 | 51 (2)|
    | 63 | NESTED LOOPS | | 1 | 163 | 50 (2)|
    |* 64 | HASH JOIN OUTER | | 1 | 139 | 45 (3)|
    | 65 | NESTED LOOPS | | 1 | 96 | 42 (3)|
    |* 66 | HASH JOIN | | 1 | 58 | 37 (3)|
    | 67 | TABLE ACCESS BY INDEX ROWID | SECURITYOBJECT | 13 | 338 | 16 (7)|
    |* 68 | INDEX RANGE SCAN | SECURITYOBJECT_IDX1 | 13 | | 2 (0)|
    | 69 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 9 | 288 | 21 (5)|
    |* 70 | INDEX RANGE SCAN | XIF1COCODEGROUP | 1 | | 2 (0)|
    |* 71 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
    |* 72 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
    |* 73 | TABLE ACCESS FULL | CUSTOMACCESSDETAIL | 9 | 387 | 2 (0)|
    |* 74 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
    |* 75 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
    | 76 | VIEW | | 1 | 2032 | |
    | 77 | SORT UNIQUE | | 1 | 144 | 63 (0)|
    |* 78 | FILTER | | | | |
    | 79 | NESTED LOOPS | | 1 | 144 | 48 (3)|
    | 80 | NESTED LOOPS | | 1 | 142 | 37 (3)|
    | 81 | NESTED LOOPS | | 1 | 104 | 32 (4)|
    | 82 | NESTED LOOPS | | 1 | 84 | 31 (4)|
    | 83 | NESTED LOOPS | | 1 | 60 | 26 (4)|
    |* 84 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 1 | 34 | 21 (5)|
    |* 85 | INDEX RANGE SCAN | XIF1COCODEGROUP | 9 | | 2 (0)|
    |* 86 | INDEX RANGE SCAN | UQ_SECURITYOBJECT | 1 | 26 | 1 (0)|
    |* 87 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
    |* 88 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
    |* 89 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
    |* 90 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
    |* 91 | COLLECTION ITERATOR PICKLER FETCH| F_STR2TBL_PX16 | | | |
    | 92 | VIEW | | 1 | 43 | |
    |* 93 | FILTER | | | | |
    | 94 | SORT GROUP BY | | 1 | 183 | 55 (0)|
    |* 95 | FILTER | | | | |
    | 96 | NESTED LOOPS | | 1 | 183 | 40 (3)|
    | 97 | NESTED LOOPS | | 1 | 163 | 39 (3)|
    |* 98 | HASH JOIN OUTER | | 1 | 139 | 34 (3)|
    | 99 | NESTED LOOPS | | 1 | 96 | 31 (4)|
    | 100 | NESTED LOOPS | | 1 | 58 | 26 (4)|
    |*101 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 1 | 32 | 21 (5)|
    |*102 | INDEX RANGE SCAN | XIF1COCODEGROUP | 9 | | 2 (0)|
    |*103 | INDEX RANGE SCAN | UQ_SECURITYOBJECT | 1 | 26 | 1 (0)|
    |*104 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
    |*105 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
    |*106 | TABLE ACCESS FULL | CUSTOMACCESSDETAIL | 9 | 387 | 2 (0)|
    |*107 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
    |*108 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
    Predicate Information (identified by operation id):
    3 - filter(DECODE("SYS_ALIAS_19"."OID",NULL,1,NVL( (SELECT /*+ */ 1 FROM "PAYX_R16"."PAYROLLAGREEMENT"
    "PX16_PAYROLLAGREEMENT" WHERE :B1='C69C1Y' AND :B2=:B3 AND :B4=:B5 AND
    "PX16_PAYROLLAGREEMENT"."FILE_NUMBER"=TO_NUMBER(:B6) AND "PX16_PAYROLLAGREEMENT"."COCODEOID"=:B7 AND
    "PX16_PAYROLLAGREEMENT"."CIDN"=:B8 AND "PX16_PAYROLLAGREEMENT"."APPOINTMENTOID"=:B9),0))=1 AND
    (SYS_CONTEXT('payx_r16_app_context','app_role')='ADP' OR
    SYS_CONTEXT('payx_r16_app_context','app_role')='CSR' OR EXISTS (SELECT /*+ */ 0 FROM
    "PAYX_R16"."PCP_USER" "PX16_PCP_USER","PAYX_R16"."ASSOCIATE" "PX16_ASSOCIATE","PAYX_R16"."USERPROFILE"
    "PX16_USERPROFILE","PAYX_R16"."LINK" "PX16_LINK" WHERE :B10='C69C1Y' AND
    "PX16_LINK"."PARENTOID"="PX16_USERPROFILE"."OID" AND "PX16_LINK"."CIDN"='C69C1Y' AND
    "PX16_LINK"."CIDN"=:B11 AND "PX16_USERPROFILE"."CIDN"='C69C1Y' AND UPPER("PX16_USERPROFILE"."NAME")='SUPER
    USER' AND "PX16_USERPROFILE"."CIDN"=:B12 AND "PX16_ASSOCIATE"."CIDN"=:B13 AND
    "PX16_ASSOCIATE"."OID"="PX16_PCP_USER"."OID" AND "PX16_ASSOCIATE"."ACTIVE"=1 AND
    UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')) AND
    "PX16_PCP_USER"."USERPROFILEOID"="PX16_USERPROFILE"."OID" AND "PX16_PCP_USER"."CIDN"='C69C1Y' AND
    "PX16_PCP_USER"."USERPROFILEOID" IS NOT NULL AND "PX16_PCP_USER"."CIDN"=:B14) OR EXISTS (SELECT /*+ */ 0
    FROM TABLE("CRUVPD"."F_STR2TBL_PX16"("PX16_COCODEGROUP"."DEPARTMENT_ACCESS"))
    "KOKBF$","PAYX_R16"."SECURITY_GROUP" "PX16_SECURITY_GROUP","PAYX_R16"."COCODEGROUP_SECURITYGROUP"
    "PX16_COCODEGRP_SECURITYGRP","PAYX_R16"."SECURITYOBJECT" "PX16_SECURITYOBJECT","PAYX_R16"."ASSOCIATE"
    "PX16_ASSOCIATE","PAYX_R16"."COCODEGROUP" "PX16_COCODEGROUP" WHERE :B15='C69C1Y' AND
    "PX16_COCODEGROUP"."CIDN"=:B16 AND "PX16_COCODEGROUP"."CO_CODE"=:B17 AND "PX16_ASSOCIATE"."CIDN"='C69C1Y'
    AND "PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND
    UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')) AND
    "PX16_ASSOCIATE"."CIDN"=:B18 AND "PX16_SECURITYOBJECT"."CIDN"='C69C1Y' AND
    SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B19 AND "PX16_SECURITYOBJECT"."CIDN"=:B20 AND
    "PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"=:B21 AND "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y' AND
    "PX16_SECURITY_GROUP"."CIDN"='C69C1Y' AND "PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GR
    OUP"."OID" AND "PX16_SECURITY_GROUP"."CIDN"=:B22 AND VALUE(KOKBF$)=:B23) OR EXISTS (SELECT /*+ */ 0 FROM
    "PAYX_R16"."CUSTOMACCESSDETAIL" "PX16_CUSTOMACCESSDETAIL","PAYX_R16"."SECURITY_GROUP"
    "PX16_SECURITY_GROUP","PAYX_R16"."COCODEGROUP_SECURITYGROUP"
    "PX16_COCODEGRP_SECURITYGRP","PAYX_R16"."SECURITYOBJECT" "PX16_SECURITYOBJECT","PAYX_R16"."ASSOCIATE"
    "PX16_ASSOCIATE","PAYX_R16"."COCODEGROUP" "PX16_COCODEGROUP" WHERE "PX16_COCODEGROUP"."CIDN"='C69C1Y' AND
    "PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN" AND
    "PX16_COCODEGROUP"."CO_CODE"=SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3) AND "PX16_ASSOCIATE"."CIDN"='C69C1Y'
    AND "PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND
    UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')) AND
    "PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN" AND "PX16_SECURITYOBJECT"."CIDN"='C69C1Y' AND
    "PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
    "PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y' AND "PX16_SECURITY_GROUP"."CIDN"='C69C1Y' AND
    "PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN" AND
    "PX16_COCODEGROUP"."CIDN"="PX16_CUSTOMACCESSDETAIL"."CIDN"(+) AND
    "PX16_COCODEGROUP"."OID"="PX16_CUSTOMACCESSDETAIL"."COCODEGROUPOID"(+) AND
    "PX16_CUSTOMACCESSDETAIL"."CIDN"(+)='C69C1Y' GROUP BY
    "PX16_COCODEGROUP"."CIDN","PX16_COCODEGROUP"."CO_CODE","PX16_CUSTOMACCESSDETAIL"."CODE" HAVING
    "PX16_COCODEGROUP"."CIDN"=:B24 AND "PX16_COCODEGROUP"."CO_CODE"=:B25 AN)
    13 - filter("PX16_USERPROFILE"."CIDN"='C69C1Y')
    14 - access("PX16_LINK"."CIDN"='C69C1Y' AND "PX16_LINK"."CHILDOID"='SYS:5:7478' AND
    "PX16_LINK"."PARENTOID"="PX16_USERPROFILE"."OID")
    filter("PX16_LINK"."CIDN"="PX16_USERPROFILE"."CIDN")
    16 - access("PX16_PCP_USER"."CIDN"='C69C1Y' AND "PX16_PCP_USER"."USERPROFILEOID"="PX16_USERPROFILE"."OID"
    filter("PX16_PCP_USER"."USERPROFILEOID" IS NOT NULL AND
    "PX16_PCP_USER"."CIDN"="PX16_USERPROFILE"."CIDN")
    17 - filter("PX16_ASSOCIATE"."ACTIVE"=1 AND UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_ap
    p_context','app_userid')))
    18 - access("PX16_ASSOCIATE"."OID"="PX16_PCP_USER"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
    filter("PX16_ASSOCIATE"."CIDN"="PX16_PCP_USER"."CIDN")
    19 - filter("SYS_ALIAS_32"."ACTIVE"=1)
    20 - access("SYS_ALIAS_32"."CIDN"='C69C1Y')
    filter("SYS_ALIAS_32"."CIDN"="PX16_ASSOCIATE"."CIDN")
    22 - access("SYS_ALIAS_15"."CIDN"='C69C1Y' AND "SYS_ALIAS_32"."OID"="SYS_ALIAS_15"."CHECKHISTORYOID")
    filter("SYS_ALIAS_32"."CIDN"="SYS_ALIAS_15"."CIDN")
    24 - access("SYS_ALIAS_21"."CIDN"='C69C1Y' AND "SYS_ALIAS_21"."CO_CODE"="SYS_ALIAS_32"."CO_CODE")
    filter("SYS_ALIAS_21"."CIDN"="SYS_ALIAS_32"."CIDN")
    26 - access("SYS_ALIAS_32"."EMPLOYMENTOID"="SYS_ALIAS_11"."OID" AND "SYS_ALIAS_11"."CIDN"='C69C1Y')
    filter("SYS_ALIAS_32"."CIDN"="SYS_ALIAS_11"."CIDN")
    28 - access("SYS_ALIAS_11"."PERSONOID"="PX16_PERSON"."OID" AND "PX16_PERSON"."CIDN"='C69C1Y')
    filter("SYS_ALIAS_11"."CIDN"="PX16_PERSON"."CIDN")
    30 - access("SYS_ALIAS_19"."CIDN"(+)='C69C1Y' AND "SYS_ALIAS_19"."EMPLOYMENTOID"(+)="SYS_ALIAS_11"."OID")
    filter("SYS_ALIAS_19"."CIDN"(+)="SYS_ALIAS_11"."CIDN")
    31 - filter(:B1='C69C1Y' AND :B2=:B3 AND :B4=:B5)
    32 - filter("PX16_PAYROLLAGREEMENT"."APPOINTMENTOID"=:B1)
    33 - access("PX16_PAYROLLAGREEMENT"."CIDN"=:B1 AND "PX16_PAYROLLAGREEMENT"."COCODEOID"=:B2 AND
    "PX16_PAYROLLAGREEMENT"."FILE_NUMBER"=TO_NUMBER(:B3))
    34 - filter(:B1='C69C1Y')
    38 - filter(UPPER("PX16_USERPROFILE"."NAME")='SUPER USER')
    39 - access("PX16_USERPROFILE"."CIDN"='C69C1Y')
    filter("PX16_USERPROFILE"."CIDN"=:B1)
    40 - access("PX16_LINK"."CIDN"='C69C1Y' AND "PX16_LINK"."PARENTOID"="PX16_USERPROFILE"."OID")
    filter("PX16_LINK"."CIDN"=:B1)
    42 - access("PX16_PCP_USER"."CIDN"='C69C1Y' AND "PX16_PCP_USER"."USERPROFILEOID"="PX16_USERPROFILE"."OID"
    filter("PX16_PCP_USER"."USERPROFILEOID" IS NOT NULL AND "PX16_PCP_USER"."CIDN"=:B1)
    43 - filter("PX16_ASSOCIATE"."ACTIVE"=1 AND UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_ap
    p_context','app_userid')))
    44 - access("PX16_ASSOCIATE"."OID"="PX16_PCP_USER"."OID" AND "PX16_ASSOCIATE"."CIDN"=:B1)
    45 - filter(:B1='C69C1Y')
    51 - filter("PX16_COCODEGROUP"."CO_CODE"=:B1)
    52 - access("PX16_COCODEGROUP"."CIDN"=:B1)
    53 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
    54 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
    filter("PX16_ASSOCIATE"."CIDN"=:B1)
    55 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"=:B1 AND "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    56 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
    "PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
    filter("PX16_SECURITY_GROUP"."CIDN"=:B1)
    58 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
    filter(SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B1 AND "PX16_SECURITYOBJECT"."CIDN"=:B2)
    59 - filter(VALUE(KOKBF$)=:B1)
    60 - filter("PX16_COCODEGROUP"."CIDN"=:B1 AND "PX16_COCODEGROUP"."CO_CODE"=:B2 AND
    "PX16_CUSTOMACCESSDETAIL"."CODE"=:B3)
    64 - access("PX16_COCODEGROUP"."OID"="PX16_CUSTOMACCESSDETAIL"."COCODEGROUPOID"(+) AND
    "PX16_COCODEGROUP"."CIDN"="PX16_CUSTOMACCESSDETAIL"."CIDN"(+))
    66 - access("PX16_COCODEGROUP"."CO_CODE"=SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3) AND
    "PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN")
    68 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
    70 - access("PX16_COCODEGROUP"."CIDN"='C69C1Y')
    71 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
    72 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
    filter("PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN")
    73 - filter("PX16_CUSTOMACCESSDETAIL"."CIDN"(+)='C69C1Y')
    74 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    filter("PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    75 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
    "PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
    filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN")
    78 - filter('C69C1Y'=:B1)
    84 - filter("PX16_COCODEGROUP"."CO_CODE"=:B1)
    85 - access("PX16_COCODEGROUP"."CIDN"='C69C1Y')
    86 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
    filter(SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B1 AND
    "PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN")
    87 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    filter("PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    88 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
    "PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
    filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN")
    89 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
    90 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
    filter("PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN")
    91 - filter(VALUE(KOKBF$) IS NULL)
    93 - filter(COUNT(DISTINCT "PX16_CUSTOMACCESSDETAIL"."CODE")=0)
    95 - filter('C69C1Y'=:B1)
    98 - access("PX16_COCODEGROUP"."OID"="PX16_CUSTOMACCESSDETAIL"."COCODEGROUPOID"(+) AND
    "PX16_COCODEGROUP"."CIDN"="PX16_CUSTOMACCESSDETAIL"."CIDN"(+))
    101 - filter("PX16_COCODEGROUP"."CO_CODE"=:B1)
    102 - access("PX16_COCODEGROUP"."CIDN"='C69C1Y')
    103 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
    filter(SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B1 AND
    "PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN")
    104 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
    105 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
    filter("PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN")
    106 - filter("PX16_CUSTOMACCESSDETAIL"."CIDN"(+)='C69C1Y')
    107 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    filter("PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
    "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
    108 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
    "PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
    filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN")
    277 rows selected.
    Really need advice on it.

    Without formatting using [ PRE ] and [ /PRE ] tags it is nearly impossible to read much less provide help.
    But what is it you hope to accomplish by breaking it up into smaller views?
    Improvements in ease of maintenance will likely be offset by poorer performance.

  • Oracle DB 10g - Count records from a subquery is to slow. (after tuning)

    Hi everybody:
    I have the following problem.
    1.- I have a transactional table with 11 millions of records.
    2.- The user asked for a few reports, to know some sumarized data for business decisions.
    3.- Initialy the query was developed in a development environment, with a subset smaller than the actual data mentioned in label 1.
    4.- When the report was delivered to the end user, the report never return data.
    5.- at this point, we performed tuning, adding indexes, re-writing the query, using hints, etc. and the following scenario is ocurring:
    a) the query without the count, before the tuning was taking about 3 to 5 minutes, and returned aproximatelly 332,000 records-.
    b) the numer of records was counted and this query takes aproximatelly 15 to 23 minutes.
    c) after the tuning, the raw data, returns in 1 second, we used some b-tree indexes, some FBI (because the report needs to filter by to_char functions).
    that time is ok for us, 1 second is a great time in comparison with the 3 to five minutes.
    d) the funny thing, is that when we add a simple count(1), count(x) or wathever flavor of count, the count takes about 3 minutes to return, with the 332,00
    records. is better than de 15 minutes of course, but we dont need count(1), we need to use group by, order by, etc, and will increase the time of query.
    6.- Another thing is happening, if I use count(1) with a transactional table with 600,000 records, without filtering, the count returns in les than 2 seconds. Even if the data is more than the result of my query defined in label 5.c, and that query returns in 1 second.
    Please help me with this, I know that maybe is something that i'm not considering on tuning. Or if there is a way to run this count query faster, please let me know.
    This is the query:
    WITH historial_depurado_v AS (
    select serie, identificador,
           cc_form_cc_tifo_tipo_forma
          ,cc_form_serie
          ,cc_form_folio
          ,estatus_nuevo
          ,to_char(fecha,'MM') Mes
          ,to_char(fecha,'YYYY') Anio  -- the table has a FBI for this.
          ,get_recaudacion_x_forma (hifo.CC_FORM_CC_TIFO_TIPO_FORMA
                                   ,hifo.CC_FORM_SERIE
                                   ,hifo.CC_FORM_FOLIO) Recaudacion  -- function for description.
    from  cc_historial_formas hifo
    where not exists (select 1
                         from ve_tipos_placas tipl
                        where tipl.cc_tifo_tipo_forma = hifo.cc_form_cc_tifo_tipo_forma)
    SELECT serie
      FROM historial_depurado_v hide
    WHERE Anio = '2009'  -- using the function based index.
       AND Mes = '01'
       AND Estatus_nuevo = 'UT'
    -- returns in 1 second, but if I use count(serie) takes 3 to 5 minutes, and still is not complete, I need to use group by some fields returned by the firs subset.
    -- if I count a table with more records, returns in 2 seconds.

    alopez wrote:
    WHERE Anio = '2009'  -- using the function based index.
    AND Mes = '01'
    AND Estatus_nuevo = 'UT'
    Also, i'm not sure if your internal comment is correct, but if you have a function based index on any of those columns, it will ONLY work when you apply the exact function as defined in the FBI (you aren't using any functions on ANY of your columns).
    An example.
    create table use_the_fbi
       column1  date
    insert into use_the_fbi
    select
       trunc(sysdate, 'dd') - level
    from dual connect by level <= 10000;
    create index use_the_fbi_FBI on use_the_fbi (to_char(column1, 'YYYYMM') );
    exec dbms_stats.gather_table_stats( user, 'USE_THE_FBI', cascade=> true, method_opt=> 'for all hidden columns');Let's try without querying in the manner in which we defined the index.
    explain plan for
    select *
    from use_the_fbi
      4  where column1 = '201006';
    Explained.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?@xplain
    PLAN_TABLE_OUTPUT
    Plan hash value: 1722805582
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |             |   100 |   900 |     7   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| USE_THE_FBI |   100 |   900 |     7   (0)| 00:00:01 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1 / USE_THE_FBI@SEL$1
    Predicate Information (identified by operation id):
       1 - filter("COLUMN1"='201006')
    Column Projection Information (identified by operation id):
       1 - "COLUMN1"[DATE,7]
    23 rows selected.
    Elapsed: 00:00:00.02Sad Christmas .. no index love.
    Now, query as we defined the index
    explain plan for
    select *
    from use_the_fbi
    where to_char(column1, 'YYYYMM') = '201006';
    Explained.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?TUBBY_TUBBZ?@xplain
    PLAN_TABLE_OUTPUT
    Plan hash value: 268331390
    | Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                 |    30 |   450 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| USE_THE_FBI     |    30 |   450 |     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | USE_THE_FBI_FBI |    30 |       |     1   (0)| 00:00:01 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1 / USE_THE_FBI@SEL$1
       2 - SEL$1 / USE_THE_FBI@SEL$1
    Predicate Information (identified by operation id):
       2 - access(TO_CHAR(INTERNAL_FUNCTION("COLUMN1"),'YYYYMM')='201006')
    Column Projection Information (identified by operation id):
       1 - "USE_THE_FBI"."COLUMN1"[DATE,7]
       2 - "USE_THE_FBI".ROWID[ROWID,10], TO_CHAR(INTERNAL_FUNCTION("COLUMN1"),'YYYYMM')[VA
           RCHAR2,6]
    27 rows selected.
    Elapsed: 00:00:00.03
    TUBBY_TUBBZ?Happy times.

  • Query Tuning

    Hi All,
    My Oracle database is running on 10.2.0.2.0 on RHEL 5.4 64 bit.
    I need some tuning guide line for below SQL:
    select  rnii.order_id,
              rnii.asin,
              rnii.gl_product_group,
              rnii.warehouse_id,
              rtrim(rnii.vendor_ordering_id) distributor_id,
              rnii.cost,
              sum(rnii.rnii_quantity_available + rnii.rnii_quantity_in_progress) quantity
            from
              O_RECEIVED_NOT_INVOICED_ITEMS rnii
            where
              rnii.legal_entity_id = 101 and
              rnii.received_date < to_date('2010-02-28','YYYY-MM-DD') + 1 and
              rnii.snapshot_day = to_date('2010-02-28','YYYY-MM-DD') + 1 and
              rnii.rnii_quantity_available + rnii.rnii_quantity_in_progress != 0
            group by
              rnii.order_id,
              rnii.asin,
              rnii.gl_product_group,
              rnii.warehouse_id,
              rtrim(rnii.vendor_ordering_id),
              rnii.cost
            having
              sum(rnii.rnii_quantity_available + rnii.rnii_quantity_in_progress) != 0
    /Here is execution plan :
    PLAN_TABLE_OUTPUT
    Plan hash value: 2086243943
    | Id  | Operation                | Name                          | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT         |                               |   366K|    23M|       |   103K  (3)| 00:20:37 |       |       |        |      |            |
    |   1 |  PX COORDINATOR          |                               |       |       |       |            |          |       |       |        |      |            |
    |   2 |   PX SEND QC (RANDOM)    | :TQ10001                      |   366K|    23M|       |   103K  (3)| 00:20:37 |       |       |  Q1,01 | P->S | QC (RAND)  |
    |*  3 |    FILTER                |                               |       |       |       |            |          |       |       |  Q1,01 | PCWC |            |
    |   4 |     HASH GROUP BY        |                               |   366K|    23M|   707M|   103K  (3)| 00:20:37 |       |       |  Q1,01 | PCWP |            |
    |   5 |      PX RECEIVE          |                               |  7326K|   475M|       |   102K  (3)| 00:20:35 |       |       |  Q1,01 | PCWP |            |
    |   6 |       PX SEND HASH       | :TQ10000                      |  7326K|   475M|       |   102K  (3)| 00:20:35 |       |       |  Q1,00 | P->P | HASH       |
    |   7 |        PX BLOCK ITERATOR |                               |  7326K|   475M|       |   102K  (3)| 00:20:35 |     1 |     4 |  Q1,00 | PCWC |            |
    |*  8 |         TABLE ACCESS FULL| O_RECEIVED_NOT_INVOICED_ITEMS |  7326K|   475M|       |   102K  (3)| 00:20:35 |   197 |   200 |  Q1,00 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - filter(SUM("RNII"."RNII_QUANTITY_AVAILABLE"+"RNII"."RNII_QUANTITY_IN_PROGRESS")<>0)
       8 - filter("RNII"."RNII_QUANTITY_AVAILABLE"+"RNII"."RNII_QUANTITY_IN_PROGRESS"<>0 AND "RNII"."LEGAL_ENTITY_ID"=101 AND
                  "RNII"."SNAPSHOT_DAY"=TO_DATE('2010-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND "RNII"."RECEIVED_DATE"<TO_DATE('2010-03-01 00:00:00', 'yyyy-mm-dd
                  hh24:mi:ss'))I tried to auto trace it and got below results:
    3522852 rows selected.
    Elapsed: 00:03:29.65
    Statistics
            101  recursive calls
              3  db block gets
        4033298  consistent gets
        4019237  physical reads
            972  redo size
      169791511  bytes sent via SQL*Net to client
        2583851  bytes received via SQL*Net from client
         234858  SQL*Net roundtrips to/from client
              4  sorts (memory)
              0  sorts (disk)
        3522852  rows processed
    select partition_name,num_rows,sample_size,last_analyzed from dba_tab_partitions where table_name='O_RECEIVED_NOT_INVOICED_ITEMS' AND
    PARTITION_NAME LIKE '%ORNII101_2010%' ORDER BY 1;
    PARTITION_NAME                   NUM_ROWS SAMPLE_SIZE LAST_ANALYZED
    ORNII101_201001                 135228000     2704560 2010/03/02 06:30:39
    ORNII101_201002                 143515850     2870317 2010/03/02 06:30:48
    ORNII101_201003                 146559550     2931191 2010/03/02 06:30:57
    ORNII101_201004                         0             2010/03/02 06:30:57Table 'O_RECEIVED_NOT_INVOICED_ITEMS' is COMPOSITE PARTITIONED by 'LEGAL_ENTITY_ID' & 'SNAPSHOT_DAY' and subpartitioned by 'RNII_ID'.
    There are 227 partitions (Monthly) with 4 sub partitions in each of them.
    Table is sized at 520 GB and there is no index on the table. Table is having DEGREE=8.
    Query runs on first date of every month.
    Looking forward to have tuning recommendations to reduce query elapsed time. Is there any advantage by creating any index (local ?) on this table?

    The parallel processing of the query is not helping (at least when executed from SQL*Plus) much.can you bit elaborate this please ?
    Here is TKPROF report :
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.21          0         32          0           0
    Fetch   234858      8.47     123.70          0          0          0     3522852
    total   234860      8.48     123.93          0         32          0     3522852
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 153
    Rows     Row Source Operation
    3522852  PX COORDINATOR  (cr=32 pr=0 pw=0 time=119427010 us)
          0   PX SEND QC (RANDOM) :TQ10001 (cr=0 pr=0 pw=0 time=0 us)
          0    FILTER  (cr=0 pr=0 pw=0 time=0 us)
          0     HASH GROUP BY (cr=0 pr=0 pw=0 time=0 us)
          0      PX RECEIVE  (cr=0 pr=0 pw=0 time=0 us)
          0       PX SEND HASH :TQ10000 (cr=0 pr=0 pw=0 time=0 us)
          0        PX BLOCK ITERATOR PARTITION: 1 4 (cr=0 pr=0 pw=0 time=0 us)
          0         TABLE ACCESS FULL O_RECEIVED_NOT_INVOICED_ITEMS PARTITION: 197 200 (cr=0 pr=0 pw=0 time=0 us)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      reliable message                                1        0.00          0.00
      enq: KO - fast object checkpoint                1        0.00          0.00
      PX Deq: Join ACK                               10        0.00          0.00
      os thread startup                               8        0.02          0.18
      PX Deq: Parse Reply                             9        0.00          0.00
      SQL*Net message to client                  234858        0.00          0.10
      PX Deq: Execute Reply                         405        1.95        115.65
      PX qref latch                                   3        0.00          0.00
      SQL*Net message from client                234858        0.27         75.93
      PX Deq: Signal ACK                             11        0.00          0.00
      latch: session allocation                       2        0.00          0.00
      enq: PS - contention                            2        0.00          0.00
    ********************************************************************************

  • 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

  • SQL Tuning - Not understanding the explain plan.

    Hi All,
    I am using 11g R2 and I have 2 questions about tuning a query.
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - ProductionMy parameters relevant to the optimizer are :
    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     TRUEThe query I would like to execute is pretty simple. It just returns some exceptions with a filter.
    SELECT ERO.DVC_EVT_ID,  E.DVC_EVT_DTTM
    FROM D1_DVC_EVT E,  D1_DVC_EVT_REL_OBJ ERO
    WHERE ERO.MAINT_OBJ_CD = 'D1-DEVICE'
    AND ERO.PK_VALUE1 = :H1
    AND ERO.DVC_EVT_ID = E.DVC_EVT_ID
    AND E.DVC_EVT_TYPE_CD IN ('END-GSMLOWLEVEL-EXCP-SEV-1', 'STR-GSMLOWLEVEL-EXCP-SEV-1')
    ORDER BY E.DVC_EVT_DTTM DESC;The execution plan is the following :
    Plan hash value: 3627978539
    | Id  | Operation                            | Name               | Starts | E-Rows |E-Bytes| Cost (%CPU)| Pstart| Pstop | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
    |   0 | SELECT STATEMENT                     |                    |      1 |        |       |  7131 (100)|       |       |   1181 |00:00:17.17 | 8627 |   2978 |       |       |          |
    |   1 |  SORT ORDER BY                       |                    |      1 |   3137 |   275K|  7131   (1)|       |       |   1181 |00:00:17.17 | 8627 |   2978 | 80896 | 80896 |71680  (0)|
    |   2 |   NESTED LOOPS                       |                    |      1 |        |       |            |       |       |   1181 |00:00:17.16 | 8627 |   2978 |       |       |          |
    |   3 |    NESTED LOOPS                      |                    |      1 |   3137 |   275K|  7130   (1)|       |       |   2058 |00:00:08.09 | 6709 |   1376 |       |       |          |
    |   4 |     TABLE ACCESS BY INDEX ROWID      | D1_DVC_EVT_REL_OBJ |      1 |   3137 |   125K|   845   (1)|       |       |   2058 |00:00:04.37 |  820 |    799 |       |       |          |
    |*  5 |      INDEX RANGE SCAN                | D1T404S0           |      1 |   3137 |       |    42   (0)|       |       |   2058 |00:00:00.08 |   27 |     23 |       |       |          |
    |   6 |     PARTITION RANGE ITERATOR         |                    |   2058 |      1 |       |     1   (0)|   KEY |   KEY |   2058 |00:00:03.69 | 5889 |    577 |       |       |          |
    |*  7 |      INDEX UNIQUE SCAN               | D1T400P0           |   2058 |      1 |       |     1   (0)|   KEY |   KEY |   2058 |00:00:03.66 | 5889 |    577 |       |       |          |
    |*  8 |    TABLE ACCESS BY GLOBAL INDEX ROWID| D1_DVC_EVT         |   2058 |      1 |    49 |     2   (0)| ROWID | ROWID |   1181 |00:00:09.05 | 1918 |   1602 |       |       |          |
    Peeked Binds (identified by position):
       1 - (VARCHAR2(30), CSID=178): '271792300706'
    Predicate Information (identified by operation id):
       5 - access("ERO"."PK_VALUE1"=:H1 AND "ERO"."MAINT_OBJ_CD"='D1-DEVICE')
           filter("ERO"."MAINT_OBJ_CD"='D1-DEVICE')
       7 - access("ERO"."DVC_EVT_ID"="E"."DVC_EVT_ID")
       8 - filter(("E"."DVC_EVT_TYPE_CD"='END-GSMLOWLEVEL-EXCP-SEV-1' OR "E"."DVC_EVT_TYPE_CD"='STR-GSMLOWLEVEL-EXCP-SEV-1'))So as you can see, row 8, I have a TABLE ACCESS BY GLOBAL INDEX ROWID. But what I am failling to see is how Oracle display a TABLE ACCESS BY GLOBAL INDEX ROWID without using any index. As thought that Oracle always got a ROWID because of an index.
    I also have an index on the column DVC_EVT_TYPE_CD in my table (row 8 of the predicate information section)
    And finally what would be your suggestion to improve the runtime of this query...
    Many thanks.

    if I read the rowsource statistics information and the plan correctly then the table access in step 4 on D1_DVC_EVT_REL_OBJ needs 4.37 sec and accesses 820 buffers. If you had an index D1_DVC_EVT_REL_OBJ(MAINT_OBJ_CD, PK_VALUE1, DVC_EVT_ID) I assume that this table access could be avoided. To avoid the table access on D1_DVC_EVT an index on D1_DVC_EVT(DVC_EVT_ID, DVC_EVT_TYPE_CD, DVC_EVT_DTTM) should be sufficient.
    I think these indexes would improve the performance of the given query but of course they would have a negative impact on DML performance on the table and they could influence other queries on the table.

Maybe you are looking for

  • How to link output page to output excel sheet?

    Hi, I have written a program where the output is downloaded as an excel sheet.There are 2 option in the output either we can display the output in the form of a ALV or we can download it into an excel sheet. Now,I want to know how I can link that exc

  • Acrobat 8.1.7 WillClose in a Browser

    Running 8.1.7 Professional in OSX 10.6 using Safari 4.0.3 (32-bit) I noticed that my WillClose handler no longer runs when I close my PDF document inside of a browser window.  Is this a matter of some settings that I need to enable, or has 8.1.7 disa

  • Database upgrade - Oracle 10g r2 ,RAC(2 Nodes with ASM) upgrade from HP-UX to RHEL 5.9

    Hi All I am planning to upgrade our RAC database 2 nodes with ASM from HP-UX to RHEL 5.9. Following is our setup Current setup: Oracle Database 10g r2 (10.2.0.5.0) RAC database. Nodes: 2 Storage: ASM OS: HP-UX ia64 Database Size: 1.2 TB New Setup: Or

  • For mass upload of documents

    Hi Everybody Is there any tools available for mass upload of documents into server? please provide me the information. Thanks Prasad

  • Functions of Balance in BPS0

    Hi everyone, I have a questions, I'm working in a server for BW 7.0 in a customer, but when I execute the transaction BPS0 and I want to create a balance function or investment function, there not appear. I only can see All function and conversion. B