Performace of query

HI All,
I am working on BO XIR3.1. i want to know about the query performance between 2 scenario -
1) i have 4 dim obj with aggregate object in single query so all 4 object come under group by i have created 4 table in report with individual object & aggregate table and need to show group by with dim object into each table.
2) i am creating 4 dataprovider with individual dim object and agg. obj.
When data will grow can be million records as per performace wise which scenario will work fast.
Regards,
Kumar

Thanks Stratos for giving ANS,
but in 2nd scenario also inspite of having diff. data provider for grouping ..in the report label we have to show groping on dim. column bz we have to show data like that will it be any performace issue for this.or bz of query already doing group by as per agg. measure it will not effect on performance which using group on report also...
Ex-
A  56     
A   72
A     5
B      8
B    89
after groupby   
            56
  A       72
              5
               8
B         89
same way 4 table into same report..

Similar Messages

  • Need to Improve performace of query

    Hi,
    I have 2 tables TAB1 and TAB2. TAB1 has around 55,000,000 rows and TAB2 has aound 150,000 rows.
    I am inserting all the rows from TAB2 to TAB1 and I am using following query
    MERGE INTO TAB1 TRG
    USING (SELECT COL1,COL2.....
    FROM TAB2 ) SRC
    ON (TRG.COL1 = SRC.COL1
    AND TRG.COL2 = SRC.COL2
    AND TRG.COL3 = SRC.COL3)
    WHEN NOT MATCHED THEN
    INSERT (TRG.COL1,TRG.COL2 ....)
    VALUES (SRC.COL1,SRC.COL2 ....);
    Following is the explain plan for this statement
    Plan
    MERGE STATEMENT ALL_ROWS Cost: 14,380 Bytes: 81,668,417 Cardinality: 143,027                
         6 MERGE TAB2                     
              5 VIEW                
                   4 HASH JOIN OUTER Cost: 14,380 Bytes: 32,324,102 Cardinality: 143,027      
                        1 TABLE ACCESS FULL TABLE TAB1 Cost: 304 Bytes: 14,588,754 Cardinality: 143,027      
                        3 TABLE ACCESS BY GLOBAL INDEX ROWID TABLE TAB2 Cost: 12,999 Bytes: 69,025,716 Cardinality: 556,659 Partition #: 5      
                        2 INDEX RANGE SCAN INDEX IDX2 Cost: 1,551 Cardinality: 573,852
    There are 2 indexes in TAB1
    1. IDX1 on col1 and col2
    2. IDX2 on col3
    There is one index in TAB2
    1.IDX1 on col1 and col2
    TAB2 is truncated and populated with rows every 2-3 days.
    This process takes too much time to complete.
    Is there any other way to improve the performace of this process(inserting data from TAB2 to TAB1)?
    or Is there any way other than using MERGE to improve performace?
    Thanks.

    The trick here would be to optimise the hash outer join, and I have a couple of suggestions:
    Firstly, you could do this by hash partitioning (or subpartitioning) on the join keys. Partition-wise joins would reduce the chances of the join spilling to disk.
    Secondly, you might be able to introduce a redundant predicate into the source query that can be used to partition prune on the target table.
    The latter option works in a situation where you are merging a set of data into a table that has a limited range of values on the join key, and a classic example of this would be in maintaining an aggregate table in a data warehouse by merging in recent data only. The aggregate table might be range partitioned on date_of_transaction and cover a range of values over ten years, but the new data might just cover the most recent week. In that case you would like to be able to place a predicate directly on the target table to say "I'm only going to find a join on this range of rows". You can't do that directly but the optimiser can infer it if you place a redundant predicate in the USING clause.
    Demonstration script:
    create table src (col1 number, col2 number);
    insert into src
    select 2, rownum
    from   dual
    connect by rownum < 10000
    create table tgt (col1 number, col2 number)
    partition by range (col1)
    partition p1 values less than (2),
    partition p2 values less than (3)
    insert into tgt
    select 1, rownum
    from   dual
    connect by rownum < 100000
    commit;
    exec dbms_stats.gather_table_stats(user,'src');
    exec dbms_stats.gather_table_stats(user,'tgt');Table tgt only has values in partition P1, but the merge is only going to populate partition P2.
    explain plan for
    merge into tgt
    using (select * from src) src
    on (tgt.col1 = src.col1)
    when matched then update
    set col2 = src.col2
    when not matched then insert
    values (src.col1, src.col2)
    select * from table(dbms_xplan.display)
    explain plan succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 3718868795                                                                                                                                                                                                                                                                                 
    | Id  | Operation              | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |                                                                                                                                                                                                             
    |   0 | MERGE STATEMENT        |      |  9999 |   449K|    64   (5)| 00:00:01 |       |       |                                                                                                                                                                                                             
    |   1 |  MERGE                 | TGT  |       |       |            |          |       |       |                                                                                                                                                                                                             
    |   2 |   VIEW                 |      |       |       |            |          |       |       |                                                                                                                                                                                                             
    |*  3 |    HASH JOIN OUTER     |      |  9999 |   126K|    64   (5)| 00:00:01 |       |       |                                                                                                                                                                                                             
    |   4 |     TABLE ACCESS FULL  | SRC  |  9999 | 59994 |     6   (0)| 00:00:01 |       |       |                                                                                                                                                                                                             
    |   5 |     PARTITION RANGE ALL|      | 99999 |   683K|    56   (2)| 00:00:01 |     1 |     2 |                                                                                                                                                                                                             
    |   6 |      TABLE ACCESS FULL | TGT  | 99999 |   683K|    56   (2)| 00:00:01 |     1 |     2 |                                                                                                                                                                                                             
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       3 - access("TGT"."COL1"(+)="SRC"."COL1")                                                                                                                                                                                                                                                                 
    18 rows selectedSo you see from the above that a full scan of both partitions of TGT is performed.
    We introduce a redundant predicate into the USING clause:
    explain plan for
    merge into tgt
    using (select * from src where col1 >= 2) src
    on (tgt.col1 = src.col1)
    when matched then update
    set col2 = src.col2
    when not matched then insert
    values (src.col1, src.col2)
    select * from table(dbms_xplan.display)
    explain plan succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 2500172128                                                                                                                                                                                                                                                                                 
    | Id  | Operation                 | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |                                                                                                                                                                                                          
    |   0 | MERGE STATEMENT           |      |  9999 |   449K|     9  (12)| 00:00:01 |       |       |                                                                                                                                                                                                          
    |   1 |  MERGE                    | TGT  |       |       |            |          |       |       |                                                                                                                                                                                                          
    |   2 |   VIEW                    |      |       |       |            |          |       |       |                                                                                                                                                                                                          
    |*  3 |    HASH JOIN RIGHT OUTER  |      |  9999 |   429K|     9  (12)| 00:00:01 |       |       |                                                                                                                                                                                                          
    |   4 |     PARTITION RANGE SINGLE|      |     1 |    38 |     2   (0)| 00:00:01 |     2 |     2 |                                                                                                                                                                                                          
    |   5 |      TABLE ACCESS FULL    | TGT  |     1 |    38 |     2   (0)| 00:00:01 |     2 |     2 |                                                                                                                                                                                                          
    |*  6 |     TABLE ACCESS FULL     | SRC  |  9999 | 59994 |     6   (0)| 00:00:01 |       |       |                                                                                                                                                                                                          
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       3 - access("TGT"."COL1"(+)="SRC"."COL1")                                                                                                                                                                                                                                                                 
       6 - filter("COL1">=2)                                                                                                                                                                                                                                                                                    
    19 rows selectedYou see from the plan that only one partition of TGT is now being scanned, and as that is empty in this case it will be a very fast action.
    Even without partition pruning this could well be more efficient than the "vanilla" alternative by giving the optimiser more information about the size of the subset of TGT rows that are being merged into and giving the opportunity of a more efficient path for reading them.

  • What is Database Hinging, regards of multi proiver performance improvement

    Hello,
    I have heard that instead of creating a query on a single cube, create a multiporvider on that single cube and create a query on the same.
    How multi Provider is going to improve the performace of query runtime  when only single cube in base?
    I  heard abt database hinglng as a answer of my question.
    Does any one have any idea abt database hinging and how can we use it?
    Expert Ideas Appreciated!!!

    Hello,
    I think you have got the concept wrong. It should be database hinging (in terms of hinge).
    As per the simple meaning of hinge whihc is joint, MPRO if used can help us in future if need comes to club more multiproviders for reporting. So this improves the effecincy of time taken for redesigning or remodelling. It has nothing to do with enhancing query performace.
    Hope it helps!!
    Regards,
    Shashank

  • SQL query performace help

    Hi,
    I have a question about the performace of this SQL query. I have to display only 8 rows from this query. How is this query will be executed? What happens if the inside query returns more than 500 rows? Will it slow down?
    SELECT * FROM (SELECT prod_date, create_date, prod_name, priority, status FROM CUST_PROD
    WHERE cust_id = 100 and Status in(1, 5) order by priority, prod_name ) WHERE ROWNUM < = 8
    Thank you..

    Its hard to tell what effect more data will have on a query until it happens. As BluShadow pointed out you're not talking about huge amounts of data; with luck the numbers you mentioned will not make any difference.
    It looks like you're using the inline view to a top N query. You could look into using the RANK() function to do something similar.

  • Performace of a select query

    Hello Experts,
    I have created a select statement based on input from selection-screen.
    Basically the users want to run it wide open for all the selections except "ERDAT" field. They usually enter current date for this field.
    Here's the query. Can I improve this selection in any way?
    Your help is appreciated. Thanks.
    data: begin of i_sdoc occurs 0,
           vbeln like vbak-vbeln,
           posnr like vbap-posnr,
           werks like vbap-werks,
           matnr like vbap-matnr,
           kunnr like vbpa-kunnr,
          end of i_sdoc.
      select a~vbeln
             b~posnr
             b~werks
             b~matnr
             c~kunnr
        into table i_sdoc
        from vbak as a
        join vbap as b
          on a~vbeln = b~vbeln
        join vbpa as c
          on b~vbeln = c~vbeln
         and b~posnr = c~posnr
       where a~vbeln in s_vbeln
         and b~matnr in s_matnr
         and b~werks in s_werks
         and b~erdat in s_erdat
         and b~mvgr3 in s_mvgr3
         and a~augru in s_augru
         and c~parvw = 'SH'.
         append i_sdoc.
         clear i_sdoc.

    No you can not improve this statement in all possible cases
    where a~vbeln in s_vbeln
         and b~matnr in s_matnr
         and b~werks in s_werks
         and b~erdat in s_erdat
         and b~mvgr3 in s_mvgr3
         and a~augru in s_augru
         and c~parvw = 'SH'.
    The problem is the the IN-clauses, you must define which IN-clauses are filled.
    Only the filled one will appear in the database statement, so there are 2**6 = 64 combinations possible. 64 Statements which you would have to optimize.
    Check which IN-clauses you will always need, and reduce the number of possiblities.
    Try to optimize the ones which you really need. I don't know which they are.
    Siegfried

  • Performace query on catalogues

    Hello,
    i've performance problems running the following query :
    SELECT ALL_TAB_COLUMNS.OWNER , ALL_TAB_COLUMNS.TABLE_NAME , SUBSTR(ALL_TAB_COLUMNS.COLUMN_NAME,1,30), DECODE(ALL_CONSTRAINTS.CONSTRAINT_TYPE,NULL,'N','P','Y','N') as PKEY FROM SYS.ALL_TAB_COLUMNS
    LEFT OUTER JOIN SYS.ALL_CONS_COLUMNS ON
    ALL_TAB_COLUMNS.OWNER = ALL_CONS_COLUMNS.OWNER AND
    ALL_TAB_COLUMNS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND
    ALL_TAB_COLUMNS.COLUMN_NAME = ALL_CONS_COLUMNS.COLUMN_NAME
    LEFT OUTER JOIN SYS.ALL_CONSTRAINTS ON
    ALL_CONSTRAINTS.OWNER = ALL_CONS_COLUMNS.OWNER AND ALL_CONSTRAINTS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND ALL_CONS_COLUMNS.CONSTRAINT_NAME = ALL_CONSTRAINTS.CONSTRAINT_NAME,
    SYS.ALL_TABLES
    WHERE ( ALL_TAB_COLUMNS.OWNER = ALL_TABLES.OWNER ) and ( ALL_TAB_COLUMNS.TABLE_NAME = ALL_TABLES.TABLE_NAME )
    AND ALL_TAB_COLUMNS.OWNER = 'MYOWNER'
    Can you help me?
    Thanks in advance
    Luigi

    I cutted ALL_TABLES that i can exclude from query (however ALL_TABLES was linked to ALL_TAB_COLUMNS)
    This is the resulting query :
    ====
    SELECT ALL_TAB_COLUMNS.OWNER, ALL_TAB_COLUMNS.TABLE_NAME , ALL_TAB_COLUMNS.COLUMN_NAME ,
    DATA_TYPE , DATA_LENGTH , DATA_PRECISION , DATA_SCALE , NULLABLE , DATA_DEFAULT, DECODE(ALL_CONSTRAINTS.CONSTRAINT_TYPE,NULL,'N','P','Y','N') as PKEY
    FROM ALL_TAB_COLUMNS
    LEFT OUTER JOIN ALL_CONS_COLUMNS ON
    ALL_TAB_COLUMNS.OWNER = ALL_CONS_COLUMNS.OWNER AND
    ALL_TAB_COLUMNS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND
    ALL_TAB_COLUMNS.COLUMN_NAME = ALL_CONS_COLUMNS.COLUMN_NAME
    LEFT OUTER JOIN ALL_CONSTRAINTS ON
    ALL_CONSTRAINTS.OWNER = ALL_CONS_COLUMNS.OWNER AND ALL_CONSTRAINTS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND ALL_CONSTRAINTS.CONSTRAINT_TYPE = 'P' AND ALL_CONS_COLUMNS.CONSTRAINT_NAME = ALL_CONSTRAINTS.CONSTRAINT_NAME
    WHERE ALL_TAB_COLUMNS.OWNER = 'USERNAME'
    =====
    I use this query to list all the accessible columns by USERNAME
    I need to know if column is a primary Key for the table
    ON the above mentioned query i still have performance problems !!!
    PS: I have tried to count records with the following query
    =====
    SELECT count(*)
    FROM ALL_TAB_COLUMNS
    LEFT OUTER JOIN ALL_CONS_COLUMNS ON
    ALL_TAB_COLUMNS.OWNER = ALL_CONS_COLUMNS.OWNER AND
    ALL_TAB_COLUMNS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND
    ALL_TAB_COLUMNS.COLUMN_NAME = ALL_CONS_COLUMNS.COLUMN_NAME
    LEFT OUTER JOIN ALL_CONSTRAINTS ON
    ALL_CONSTRAINTS.OWNER = ALL_CONS_COLUMNS.OWNER AND ALL_CONSTRAINTS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND ALL_CONSTRAINTS.CONSTRAINT_TYPE = 'P' AND ALL_CONS_COLUMNS.CONSTRAINT_NAME = ALL_CONSTRAINTS.CONSTRAINT_NAME
    WHERE ALL_TAB_COLUMNS.OWNER = 'USERNAME'
    ======
    .... it needs more than 1 minutes !!!
    Best regards

  • SDO_RDF_MATCH() Query Performace on 10g - ontology model size-5000 triples

    Hi,
    We are observing severe degradation in the performance of the queries as their size increases? In this context, I want to know if the performance of the query is dependent on the query pattern size? For example, a query with 25 triples in the query pattern is taking nearly 10 secs, to retrieve results from a ontology of size 5000 triples. (no rule bases attached, no inferencing).
    Does using query API in Jena Adapter (instead of using sdo_rdf_match() directly) help improve the performance? Also, can u suggest any tuning on the ontology model for speeding up the query execution?
    Thanks,
    Rajesh.
    Edited by: rajesh narni on Oct 8, 2009 4:29 AM

    Please see my comments in the following post.
    Failing to execute large queries --> 11.1.0.7.0
    Cheers,
    Zhe Wu

  • Query performace with "partition by" clause.

    Below is my query
    >
    select event_type, time, count(event_id) as no_of_events from (
    select e.event_type, t.time , e.id as event_id from time t
    left outer join events e partition by (event_type)
    on t.time < e.end_time and (t.time + 1) > e.start_time
    where t.time >= '2008-01-01' and t.time < '2008-02-01'
    ) events_by_event_type
    group by event_type, time
    order by event_type, time
    The idea is to get a count of active "events" of each "event_type", for each day between 2 dates. The "time" table has one row each for each day. An event is said to be active for a day , when it's end_time - start_time overlaps the day's beginning and end.
    The query works but always does a full table scan of the events table.
    I tried creating following indexes on the events table , but none of them is ever used.
    (event_type,start_time)
    (event_type,end_time)
    (event_type,start_time,end_time)
    (start_time)
    (end_time)
    (start_time,end_time)
    How can I avoid the full table scan of the "events" table in the above query ?
    fyi the events table looks like
    >
    id number not null primary key,
    event_type number not null,
    start_date date not null,
    end_date date not null

    What I want is to avoid the full table scan on the
    "events" table. I don't think adding an index on the
    'time' table will help there.The conditions you have on events are
    t.time < e.end_time and (t.time + 1) > e.start_timeSo you should have an index on the columns end_time and start_time to avoid a full table scan.
    But anyway is that query slow?
    Bye Alessandro
    Message was edited by:
    Alessandro Rossi
    Plus I would add two more predicates to the query to enforce a range scan. If I did well they should always be true for the rows you want. They are there just to tell the CBO that the scan on end_time has to begin from '2008-02-01' and the scan on start_time has to finish on ('2008-01-01' - 1). Sometime this kind of additional conditions helped me.
    select event_type, time, count(event_id) as no_of_events
    from (
              select e.event_type, t.time , e.id as event_id from time t
              left outer join events e partition by (event_type) on (
                   t.time between e.start_time - 1 and e.end_time
              where t.time >= '2008-01-01' and t.time < '2008-02-01'
                   and e.end_time >= '2008-02-01' and e.start_time <= '2008-01-01' - 1
    ) events_by_event_type
    group by event_type, time
    order by event_type, time

  • Query Performace and Order by

    Hello All -
    I have a query which executes in 250msecs. The moment I throw an order by clause in it the query takes 25secs to execute.
    The order by clause in on PK (just 1 column of type NUMBER)
    Records Returned : 300K
    Point to Note is I only need top 500 rows after the sorting is done.
    Can you please suggest some ways to reduce the time of query execution and still have order by clause in it.
    Thanks for your help.

    Point to Note is I only need top 500 rows after the
    sorting is done.
    Can you please suggest some ways to reduce the time
    of query execution and still have order by clause in
    it.
    Thanks for your help.Show us your query. Maybe we can find a way to make it faster. Also do you order ascending or descending and what is your oracle database version?
    This won't help much probably.
    SELECT *
    FROM (SELECT rownum rn, yourotherCols
          FROM yourTables order by PK)
    WHERE RN <= 500;Message was edited by:
    Sven W.

  • Query Performace Issue-Usage of SAP_DROP_EMPTY_FPARTITIONS Program

    Hi Experts,
    We are facing query peroformance issue in our BW Production System. Queries on the Sales Multiprovider are taking lot of time to run. We need to tune the query perofrmace.
    We need to drop the empty partitions at the database level. Have anyone of you used the program SAP_DROP_EMPTY_FPARTITIONS to drop the empty partitions ? If Yes, Please provide me with details of your experience of using this program. Please let me know, whether there are any disadvantages using this program in the Production System.
    Kindly treat this as an urgent requirement.
    Your help will be appreciated....
    Thanks,
    Shalaka

    Hi Shwetha,
    I think that pgm drops if partition contains no records(in DEL_CNT)
    or if partitions requid is not in dimtab (DEL_DIM)
    Hope it helps!
    (and don't forget to reward the answer, if you want !)
    Bye,
    Roberto

  • Query Performace

    Hi,
    The below two queries will do same work. i want to know which one is performance low.
    UPDATE (SELECT p.ph_country_code,c.country_code
                   FROM address a,
                        phone p,
                        country c
                  WHERE a.user_id = p.user_id
                    AND a.country_id = c.country_id) u
            SET u.ph_country_code = u.country_code;
    DECLARE
      v_ph_country_code  country.country_code%TYPE;
      CURSOR cur_ph IS
          SELECT user_id
            FROM phone;
    BEGIN
      FOR rec_ph IN cur_ph LOOP
          SELECT c.country_code
            INTO v_ph_country_code
            FROM address a,
                 country c
           WHERE a.country_id = c.country_id
             AND a.user_id    = rec_ph.user_id;
          UPDATE phone
             SET ph_country_code   = v_ph_country_code
           WHERE user_id            = rec_ph.user_id;
      END LOOP;
    END;   Thank you,
    Vi

    GHD wrote:
    The below two queries will do same work. i want to know which one is performance low.Let's say there are a substantial volume of data - and the CBO can parallelise access.
    This means that (under the right circumstances) your native SQL can be executed using parallel processing (Oracle supports both parallel DML and DDL).
    The PL/SQL code is your manual attempt at doing the same thing as that single SQL statement. How are you going to scale it for processing huge volumes in parallel? The PL/SQL engine cannot do that for you. The SQL your code generates for the SQL engine to execute is row-by-row processing. So no way that the SQL engine can do that in parallel as your code is a single session expecting a single row at a time.
    Performance is therefore not only faster using native SQL (as the others indicated with their responses), native SQL is also a lot more scalable than doing row-by-row processing using PL/SQL.
    There is a simple mantra for this: Maximise SQL. Minimise PL/SQL.
    SQL is the superior language to crunch data in the database. Not PL/SQL.

  • How to make sql to use index/make to query to perform better

    Hi,
    I have 2 sql query which results the same.
    But both has difference in SQL trace.
    create table test_table
    (u_id number(10),
    u_no number(4),
    s_id number(10),
    s_no number(4),
    o_id number(10),
    o_no number(4),
    constraint pk_test primary key(u_id, u_no));
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030301, 1, 1001, 1, 2001, 1);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030302, 1, 1001, 1, 2001, 2);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030303, 1, 1001, 1, 2001, 3);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030304, 1, 1001, 1, 2001, 4);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030305, 1, 1002, 1, 1001, 2);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030306, 1, 1002, 1, 1002, 1);
    commit;
    CREATE INDEX idx_test_s_id ON test_table(s_id, s_no);
    set autotrace on
    select s_id, s_no, o_id, o_no
    from test_table
    where s_id <> o_id
    and s_no <> o_no
    union all
    select o_id, o_no, s_id, s_no
    from test_table
    where s_id <> o_id
    and s_no <> o_no;
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    3 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    Statistics
    223 recursive calls
    2 db block gets
    84 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    5 sorts (memory)
    0 sorts (disk)
    8 rows processed
    -- i didnt understand why the above query is not using the index idx_test_s_id.
    -- But still it is faster
    select s_id, s_no, o_id, o_no
    from test_table
    where (u_id, u_no) in
    (select u_id, u_no from test_table
    minus
    select u_id, u_no from test_table
    where s_id = o_id
    or s_no = o_no)
    union all
    select o_id, o_no, s_id, s_no
    from test_table
    where (u_id, u_no) in
    (select u_id, u_no from test_table
    minus
    select u_id, u_no from test_table
    where s_id = o_id
    or s_no = o_no);
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=16 Card=2 Bytes=156)
    1 0 UNION-ALL
    2 1 FILTER
    3 2 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=6 Bytes=468)
    4 2 MINUS
    5 4 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=26)
    6 4 TABLE ACCESS (BY INDEX ROWID) OF 'TEST_TABLE' (TABLE) (Cost=2 Card=1 Bytes=78)
    7 6 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1)
    8 1 FILTER
    9 8 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=6 Bytes=468)
    10 8 MINUS
    11 10 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=26)
    12 10 TABLE ACCESS (BY INDEX ROWID) OF 'TEST_TABLE' (TABLE) (Cost=2 Card=1 Bytes=78)
    13 12 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1)
    Statistics
    53 recursive calls
    8 db block gets
    187 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    4 sorts (memory)
    0 sorts (disk)
    8 rows processed
    -- The above query is using index PK_TEST. But still it has FULL SCAN to the
    -- table two times it has the more cost.
    1st query --> SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    2nd query --> SELECT STATEMENT Optimizer=ALL_ROWS (Cost=16 Card=2 Bytes=156)
    My queries are:
    1) performance wise which query is better?
    2) how do i make the 1st query to use an index
    3) is there any other method to get the same result by using any index
    Appreciate your immediate help.
    Best regards
    Muthu

    Hi William
    Nice...it works.. I have added "o_id" and "o_no" are in part of the index
    and now the query uses the index
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    3 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    Statistics
    7 recursive calls
    0 db block gets
    21 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    But my questions are:
    1) In a where clause, if "<>" condition is used, then, whether the system will use the index. Because I have observed in several situations even though the column in where clause is indexed, since the where condition is "like" or "is null/is not null"
    then the index is not used. Same as like this, i assumed, if we use <> then indexes will not be used. Is it true?
    2) Now, after adding "o_id" and "o_no" columns to the index, the Execution plan is:
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    3 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    Before it was :
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    3 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    Difference only in Cost (reduced), not in Card, Bytes.
    Can you explain, how can i decide which makes the performace better (Cost / Card / Bytes). Full Scan / Range Scan?
    On statistics also:
    Before:
    Statistics
    52 recursive calls
    0 db block gets
    43 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    After:
    Statistics
    7 recursive calls
    0 db block gets
    21 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    Difference in recursive calls & consistent gets.
    Which one shows the query with better performance?
    Please explain..
    Regards
    Muthu

  • Long running Query Tuning

    Hi all,
    We are using Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production on
    Linux 2.6.5-7.282-bigsmp #1 SMP box.
    The following query is taking aproximately 1 hr to execute.
    SELECT item.ap_id, item.ap_version_id, oa.customer_id,CI.CAPTION OFFER_ID, ITEM.BILL_START_DATE , ITEM.CTDB_CRE_DATETIME , oa.order_unit_id
    FROM tbap_item item,
    tbprice_plan pp,
    tborder_action oa,
    tborder_action_impl oaimpl,
         TBCATALOG_ITEM CI
    WHERE item.entity_type = 'amdocs.oms.sbcproduct.ApPricePlanImpl'
    AND item.item_def_id = pp.cid
    AND item.item_def_ver = pp.pcversion_id
    AND pp.is_promote = '1'
    AND item.order_action_id = oa.order_unit_id
    AND oa.order_unit_id = oaimpl.order_unit_id
    AND oaimpl.bypass_reason_id = 'MI'
    AND oa.xml_id IS NOT NULL
    AND item.state IN ('AS', 'OR')
    AND item.status = 'AC'
    AND CI.CID = ITEM.ITEM_DEF_ID
    AND CI.PCVERSION_ID = ITEM.ITEM_DEF_VER
    AND item.ap_version_id = '0'
    AND EXISTS (SELECT 1 FROM TBAP_ITEM TEMP WHERE TEMP.AP_ID = ITEM.AP_ID AND TEMP.END_DATE > SYSDATE AND TEMP.STATE IN ('AS' , 'OR') AND TEMP.STATUS ='AC');
    the execution plan before collecting the stats is:
    Query Plan
    SELECT STATEMENT [CHOOSE] Cost=120002
    NESTED LOOPS SEMI Cost=120002 Card=98407 Bytes=18402109
    MERGE JOIN Cost=80639 Card=98407 Bytes=16040341
    SORT JOIN Cost=80607 Card=98407 Bytes=13481759
    MERGE JOIN Cost=78626 Card=98407 Bytes=13481759
    SORT JOIN Cost=76699 Card=119937 Bytes=14992125
    MERGE JOIN Cost=76699 Card=119937 Bytes=14992125
    SORT JOIN Cost=76682 Card=171602 Bytes=19219424
    MERGE JOIN Cost=76682 Card=171602 Bytes=19219424
    SORT JOIN Cost=74698 Card=990661 Bytes=82224863
    TABLE ACCESS FULL TBAP_ITEM [ANALYZED] Cost=62069 Card=990661 Bytes=82224863
    SORT JOIN Cost=1985 Card=89365 Bytes=2591585
    TABLE ACCESS FULL TBORDER_ACTION [ANALYZED] Cost=1511 Card=89365 Bytes=2591585
    SORT JOIN Cost=17 Card=195 Bytes=2535
    TABLE ACCESS FULL TBPRICE_PLAN [ANALYZED] Cost=2 Card=195 Bytes=2535
    SORT JOIN Cost=1928 Card=73323 Bytes=879876
    TABLE ACCESS FULL TBORDER_ACTION_IMPL [ANALYZED] Cost=1698 Card=73323 Bytes=879876
    SORT JOIN Cost=33 Card=3017 Bytes=78442
    TABLE ACCESS FULL TBCATALOG_ITEM [ANALYZED] Cost=4 Card=3017 Bytes=78442
    TABLE ACCESS BY INDEX ROWID TBAP_ITEM [ANALYZED] Cost=1 Card=2037512 Bytes=48900288
    INDEX RANGE SCAN TBAP_ITEM_PK [ANALYZED] Cost=2 Card=2 Bytes=
    after collecting the stats:
    SELECT STATEMENT [CHOOSE] Cost=64972
    NESTED LOOPS SEMI Cost=64972 Card=333 Bytes=62937
    NESTED LOOPS Cost=64839 Card=333 Bytes=54945
    MERGE JOIN Cost=64446 Card=1965 Bytes=300645
    SORT JOIN Cost=64414 Card=1965 Bytes=249555
    MERGE JOIN Cost=64414 Card=1965 Bytes=249555
    SORT JOIN Cost=62429 Card=13393 Bytes=1312514
    MERGE JOIN Cost=62429 Card=13393 Bytes=1312514
    SORT JOIN Cost=2 Card=140 Bytes=1820
    TABLE ACCESS FULL TBPRICE_PLAN [ANALYZED] Cost=2 Card=140 Bytes=1820
    SORT JOIN Cost=62428 Card=26785 Bytes=2276725
    TABLE ACCESS FULL TBAP_ITEM [ANALYZED] Cost=62072 Card=26785 Bytes=2276725
    SORT JOIN Cost=1985 Card=89365 Bytes=2591585
    TABLE ACCESS FULL TBORDER_ACTION [ANALYZED] Cost=1511 Card=89365 Bytes=2591585
    SORT JOIN Cost=33 Card=3017 Bytes=78442
    TABLE ACCESS FULL TBCATALOG_ITEM [ANALYZED] Cost=4 Card=3017 Bytes=78442
    TABLE ACCESS BY INDEX ROWID TBORDER_ACTION_IMPL [ANALYZED] Cost=1 Card=1 Bytes=12
    INDEX UNIQUE SCAN TBORDER_ACTION_IMPL_PK [ANALYZED] Cost=1 Card=1 Bytes=
    TABLE ACCESS BY INDEX ROWID TBAP_ITEM [ANALYZED] Cost=1 Card=2972308 Bytes=71335392
    INDEX RANGE SCAN TBAP_ITEM_PK [ANALYZED] Cost=2 Card=2 Bytes=
    I am now taking the level 4 trace now.will post it once Its done. I found some "latchfree" timeouts while running it now...
    I also find that few cols refered in where clause doesn't have indexes...So I am going to discuss this with the developers. also I want modify the query too..as below.
    ELECT item.ap_id, item.ap_version_id, oa.customer_id,CI.CAPTION OFFER_ID, ITEM.BILL_START_DATE , ITEM.CTDB_CRE_DATETIME , oa.order_unit_id
    FROM tbap_item item,
    tbprice_plan pp,
    tborder_action oa,
    tborder_action_impl oaimpl,
         TBCATALOG_ITEM CI
    WHERE
    item.entity_type = 'amdocs.oms.sbcproduct.ApPricePlanImpl'
    AND item.status = 'AC'
    AND item.state IN ('AS', 'OR')
    AND item.ap_version_id = '0'
    AND pp.is_promote = '1'
    AND oaimpl.bypass_reason_id = 'MI'
    AND oa.xml_id IS NOT NULL
    AND item.item_def_id = pp.cid
    AND item.item_def_ver = pp.pcversion_id
    AND item.order_action_id = oa.order_unit_id
    AND oa.order_unit_id = oaimpl.order_unit_id
    AND CI.CID = ITEM.ITEM_DEF_ID
    AND CI.PCVERSION_ID = ITEM.ITEM_DEF_VER
    AND EXISTS (SELECT 1 FROM TBAP_ITEM TEMP WHERE
    TEMP.STATE IN ('AS' , 'OR') AND TEMP.STATUS ='AC' AND TEMP.AP_ID = ITEM.AP_ID AND TEMP.END_DATE > SYSDATE );
    Please suggest. what else I need to check to imporve the performace .
    Thanks in advace for your help and suggestions.

    here is formatted one:
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.14       0.19          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        8     58.21    4169.28    1663901    1699503         10         103
    total       10     58.36    4169.47    1663901    1699503         10         103
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    Parsing user id: 139
    Rows     Row Source Operation
        103  NESTED LOOPS SEMI
        158   NESTED LOOPS
       3613    MERGE JOIN
       3613     SORT JOIN
       3613      MERGE JOIN
    110996       SORT JOIN
    110996        MERGE JOIN
        195         SORT JOIN
        195          TABLE ACCESS FULL OBJ#(33959)
    110996         SORT JOIN
    820046          TABLE ACCESS FULL OBJ#(33563)
       3613       SORT JOIN
      89365        TABLE ACCESS FULL OBJ#(33538)
       3613     SORT JOIN
       3017      TABLE ACCESS FULL OBJ#(33889)
        158    TABLE ACCESS BY INDEX ROWID OBJ#(33534)
       3613     INDEX UNIQUE SCAN OBJ#(33645) (object id 33645)
        103   TABLE ACCESS BY INDEX ROWID OBJ#(33563)
        275    INDEX RANGE SCAN OBJ#(48320) (object id 48320)
    ********************************************************************************

  • SQL Query with a little bit more complicated WHERE clause performance issue

    Hello, I have some performance issue in this case:
    Very simplified query:
    SELECT COUNT(*) FROM Items
    WHERE
    ConditionA OR
    ConditionB OR
    ConditionC OR ...
    Simply I have to determine how many Items the user has access through some complicated conditions.
    When there is a large number of records (100,000+) in the Items table and say ~10 complicated conditions concatenated in WHERE clause, I get the result about 2 seconds in my case. The problem is when very few conditions are met, f.e. when I get only
    10 Items from 100,000.
    How can I improve the performace in this "Get my items" case?
    Additional information:
    the query is generated by EF 6.1
    MS SQL 2012 Express
    Here is the main part of the real SQL Execution Plan:

    Can you post table/index DDL?  Query?
    Sample query:
    exec sp_executesql N'SELECT
    [GroupBy1].[A1] AS [C1]
    FROM ( SELECT
    COUNT(1) AS [A1]
    FROM [dbo].[Tickets] AS [Extent1]
    LEFT OUTER JOIN [dbo].[Services] AS [Extent2] ON [Extent1].[ServiceId] = [Extent2].[Id]
    WHERE (@p__linq__0 = 1) OR ([Extent1].[SubmitterKey] = @p__linq__1) OR ([Extent1].[OperatorKey] = @p__linq__2) OR (([Extent1].[OperatorKey] IS NULL) AND (@p__linq__2 IS NULL)) OR ([Extent1].[SolverKey] = @p__linq__3) OR (([Extent1].[SolverKey] IS NULL) AND (@p__linq__3 IS NULL)) OR ([Extent1].[Incident2ndLineSupportKey] = @p__linq__4) OR (([Extent1].[Incident2ndLineSupportKey] IS NULL) AND (@p__linq__4 IS NULL)) OR ((@p__linq__5 = 1) AND ((1 = CAST( [Extent1].[TicketType] AS int)) OR ((@p__linq__6 = 1) AND (((2 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[IncidentManager] = @p__linq__7) OR (([Extent2].[IncidentManager] IS NULL) AND (@p__linq__7 IS NULL)))) OR ((3 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[ServiceRequestManager] = @p__linq__8) OR (([Extent2].[ServiceRequestManager] IS NULL) AND (@p__linq__8 IS NULL)))) OR ((4 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[ProblemManager] = @p__linq__9) OR (([Extent2].[ProblemManager] IS NULL) AND (@p__linq__9 IS NULL)))) OR ((5 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[ChangeManager] = @p__linq__10) OR (([Extent2].[ChangeManager] IS NULL) AND (@p__linq__10 IS NULL)))))) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceDeputyManagers] AS [Extent3]
    WHERE ([Extent1].[ServiceId] = [Extent3].[ServiceId]) AND ( CAST( [Extent3].[TicketType] AS int) = CAST( [Extent1].[TicketType] AS int)) AND ([Extent3].[UserProviderKey] = @p__linq__11)
    )))) OR ((2 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[AllowAccessToOtherOperatorsIncidents] = 1) OR ((201 = [Extent1].[TicketStateValue]) AND ([Extent2].[WfDisableIncidentTakeFromQueueAction] <> cast(1 as bit)))) AND ([Extent2].[Incident1stLineSupportLimitedAccess] <> cast(1 as bit))) OR ((3 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[AllowAccessToOtherOperatorsServiceRequests] = 1) OR ((301 = [Extent1].[TicketStateValue]) AND ([Extent2].[WfDisableServiceRequestTakeFromQueueAction] <> cast(1 as bit)))) AND ([Extent2].[ServiceRequestLimitedAccess] <> cast(1 as bit))) OR ((4 = CAST( [Extent1].[TicketType] AS int)) AND ([Extent2].[AllowAccessToOtherOperatorsProblems] = 1) AND ([Extent2].[ProblemLimitedAccess] <> cast(1 as bit))) OR ((5 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[AllowAccessToOtherOperatorsChanges] = 1) OR ((501 = [Extent1].[TicketStateValue]) AND ([Extent2].[WfDisableChangeTakeFromQueueAction] <> cast(1 as bit)))) AND ([Extent2].[ChangeLimitedAccess] <> cast(1 as bit))) OR ((2 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[AllowAccessToOtherOperatorsIncidents] = 1) OR ((201 = [Extent1].[TicketStateValue]) AND ([Extent2].[WfDisableIncidentTakeFromQueueAction] <> cast(1 as bit)))) AND (( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperators] AS [Extent4]
    WHERE ([Extent1].[ServiceId] = [Extent4].[ServiceId]) AND (2 = CAST( [Extent4].[TicketType] AS int)) AND ([Extent4].[UserProviderKey] = @p__linq__12) AND (1 = [Extent4].[SupportLine])
    )) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[OperatorGroupUsers] AS [Extent5]
    WHERE ([Extent5].[UserProviderKey] = @p__linq__13) AND ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperatorGroups] AS [Extent6]
    WHERE ([Extent6].[ServiceId] = [Extent1].[ServiceId]) AND (2 = CAST( [Extent6].[TicketType] AS int)) AND (1 = [Extent6].[SupportLine]) AND ([Extent6].[OperatorGroupId] = [Extent5].[OperatorGroupId])
    )))) OR ((2 = CAST( [Extent1].[TicketType] AS int)) AND ([Extent1].[IncidentFunctionEscalatedTo2ndLineSupport] = 1) AND ([Extent1].[Incident2ndLineSupportKey] IS NULL) AND (([Extent2].[Incident2ndLineSupportLimitedAccess] <> cast(1 as bit)) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperators] AS [Extent7]
    WHERE ([Extent1].[ServiceId] = [Extent7].[ServiceId]) AND (2 = CAST( [Extent7].[TicketType] AS int)) AND ([Extent7].[UserProviderKey] = @p__linq__14) AND (2 = [Extent7].[SupportLine])
    )) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[OperatorGroupUsers] AS [Extent8]
    WHERE ([Extent8].[UserProviderKey] = @p__linq__15) AND ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperatorGroups] AS [Extent9]
    WHERE ([Extent9].[ServiceId] = [Extent1].[ServiceId]) AND (2 = CAST( [Extent9].[TicketType] AS int)) AND (2 = [Extent9].[SupportLine]) AND ([Extent9].[OperatorGroupId] = [Extent8].[OperatorGroupId])
    )))) OR ((3 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[AllowAccessToOtherOperatorsServiceRequests] = 1) OR ((301 = CAST( [Extent1].[TicketState] AS int)) AND ([Extent2].[WfDisableServiceRequestTakeFromQueueAction] <> cast(1 as bit)))) AND (( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperators] AS [Extent10]
    WHERE ([Extent1].[ServiceId] = [Extent10].[ServiceId]) AND (3 = CAST( [Extent10].[TicketType] AS int)) AND ([Extent10].[UserProviderKey] = @p__linq__16)
    )) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[OperatorGroupUsers] AS [Extent11]
    WHERE ([Extent11].[UserProviderKey] = @p__linq__17) AND ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperatorGroups] AS [Extent12]
    WHERE ([Extent12].[ServiceId] = [Extent1].[ServiceId]) AND (3 = CAST( [Extent12].[TicketType] AS int)) AND ([Extent12].[OperatorGroupId] = [Extent11].[OperatorGroupId])
    )))) OR ((4 = CAST( [Extent1].[TicketType] AS int)) AND ([Extent2].[AllowAccessToOtherOperatorsProblems] = 1) AND (( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperators] AS [Extent13]
    WHERE ([Extent1].[ServiceId] = [Extent13].[ServiceId]) AND (4 = CAST( [Extent13].[TicketType] AS int)) AND ([Extent13].[UserProviderKey] = @p__linq__18)
    )) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[OperatorGroupUsers] AS [Extent14]
    WHERE ([Extent14].[UserProviderKey] = @p__linq__19) AND ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperatorGroups] AS [Extent15]
    WHERE ([Extent15].[ServiceId] = [Extent1].[ServiceId]) AND (4 = CAST( [Extent15].[TicketType] AS int)) AND ([Extent15].[OperatorGroupId] = [Extent14].[OperatorGroupId])
    )))) OR ((5 = CAST( [Extent1].[TicketType] AS int)) AND (([Extent2].[AllowAccessToOtherOperatorsChanges] = 1) OR ((501 = [Extent1].[TicketStateValue]) AND ([Extent2].[WfDisableChangeTakeFromQueueAction] <> cast(1 as bit)))) AND (( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperators] AS [Extent16]
    WHERE ([Extent1].[ServiceId] = [Extent16].[ServiceId]) AND (5 = CAST( [Extent16].[TicketType] AS int)) AND ([Extent16].[UserProviderKey] = @p__linq__20)
    )) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[OperatorGroupUsers] AS [Extent17]
    WHERE ([Extent17].[UserProviderKey] = @p__linq__21) AND ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[ServiceOperatorGroups] AS [Extent18]
    WHERE ([Extent18].[ServiceId] = [Extent1].[ServiceId]) AND (5 = CAST( [Extent18].[TicketType] AS int)) AND ([Extent18].[OperatorGroupId] = [Extent17].[OperatorGroupId])
    )))) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM [dbo].[TicketInvitations] AS [Extent19]
    WHERE ([Extent19].[TicketId] = [Extent1].[Id]) AND (([Extent19].[InvitedUserProviderKey] = @p__linq__22) OR (([Extent19].[InvitedUserProviderKey] IS NULL) AND (@p__linq__22 IS NULL)))
    )) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM (SELECT
    [Extent20].[CustomerId] AS [CustomerId]
    FROM [dbo].[CustomerUsers] AS [Extent20]
    WHERE ([Extent20].[UserProviderKey] = @p__linq__23) AND ([Extent20].[CanAccessOthersTickets] = 1)
    INTERSECT
    SELECT
    [Extent21].[CustomerId] AS [CustomerId]
    FROM [dbo].[CustomerUsers] AS [Extent21]
    WHERE [Extent21].[UserProviderKey] = [Extent1].[SubmitterKey]) AS [Intersect1]
    )) OR ( EXISTS (SELECT
    1 AS [C1]
    FROM (SELECT
    [Extent22].[InternalGroupId] AS [InternalGroupId]
    FROM [dbo].[InternalGroupUsers] AS [Extent22]
    WHERE ([Extent22].[UserProviderKey] = @p__linq__24) AND ([Extent22].[CanAccessOthersTickets] = 1)
    INTERSECT
    SELECT
    [Extent23].[InternalGroupId] AS [InternalGroupId]
    FROM [dbo].[InternalGroupUsers] AS [Extent23]
    WHERE [Extent23].[UserProviderKey] = [Extent1].[SubmitterKey]) AS [Intersect2]
    ) AS [GroupBy1]',N'@p__linq__0 bit,@p__linq__1 varchar(8000),@p__linq__2 varchar(8000),@p__linq__3 varchar(8000),@p__linq__4 varchar(8000),@p__linq__5 bit,@p__linq__6 bit,@p__linq__7 varchar(8000),@p__linq__8 varchar(8000),@p__linq__9 varchar(8000),@p__linq__10 varchar(8000),@p__linq__11 varchar(8000),@p__linq__12 varchar(8000),@p__linq__13 varchar(8000),@p__linq__14 varchar(8000),@p__linq__15 varchar(8000),@p__linq__16 varchar(8000),@p__linq__17 varchar(8000),@p__linq__18 varchar(8000),@p__linq__19 varchar(8000),@p__linq__20 varchar(8000),@p__linq__21 varchar(8000),@p__linq__22 varchar(8000),@p__linq__23 varchar(8000),@p__linq__24 varchar(8000)',@p__linq__0=0,@p__linq__1='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__2='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__3='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__4='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__5=1,@p__linq__6=0,@p__linq__7='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__8='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__9='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__10='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__11='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__12='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__13='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__14='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__15='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__16='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__17='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__18='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__19='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__20='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__21='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__22='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__23='31555851-b89d-4a15-bb05-5a6fd42f9552',@p__linq__24='31555851-b89d-4a15-bb05-5a6fd42f9552'
    Generated DDL for related tables: (indexes are primary on PKs and FKs)
    CREATE TABLE [dbo].[CustomerUsers](
    [UserProviderKey] [varchar](184) NOT NULL,
    [CustomerId] [int] NOT NULL,
    [CanAccessOthersTickets] [bit] NOT NULL,
    CONSTRAINT [PK_dbo.CustomerUsers] PRIMARY KEY CLUSTERED
    [UserProviderKey] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Table [dbo].[InternalGroupUsers] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[InternalGroupUsers](
    [UserProviderKey] [varchar](184) NOT NULL,
    [InternalGroupId] [int] NOT NULL,
    [CanAccessOthersTickets] [bit] NOT NULL,
    CONSTRAINT [PK_dbo.InternalGroupUsers] PRIMARY KEY CLUSTERED
    [UserProviderKey] ASC,
    [InternalGroupId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Table [dbo].[OperatorGroupUsers] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[OperatorGroupUsers](
    [UserProviderKey] [varchar](184) NOT NULL,
    [OperatorGroupId] [int] NOT NULL,
    CONSTRAINT [PK_dbo.OperatorGroupUsers] PRIMARY KEY CLUSTERED
    [UserProviderKey] ASC,
    [OperatorGroupId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Table [dbo].[ServiceDeputyManagers] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[ServiceDeputyManagers](
    [UserProviderKey] [varchar](184) NOT NULL,
    [ServiceId] [int] NOT NULL,
    [TicketType] [int] NOT NULL,
    CONSTRAINT [PK_dbo.ServiceDeputyManagers] PRIMARY KEY CLUSTERED
    [UserProviderKey] ASC,
    [ServiceId] ASC,
    [TicketType] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Table [dbo].[ServiceOperatorGroups] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[ServiceOperatorGroups](
    [ServiceId] [int] NOT NULL,
    [OperatorGroupId] [int] NOT NULL,
    [TicketTypeValue] [int] NOT NULL,
    [SupportLine] [int] NOT NULL,
    [TicketType] [int] NOT NULL,
    CONSTRAINT [PK_dbo.ServiceOperatorGroups] PRIMARY KEY CLUSTERED
    [ServiceId] ASC,
    [OperatorGroupId] ASC,
    [TicketTypeValue] ASC,
    [SupportLine] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    /****** Object: Table [dbo].[ServiceOperators] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[ServiceOperators](
    [UserProviderKey] [varchar](184) NOT NULL,
    [ServiceId] [int] NOT NULL,
    [TicketTypeValue] [int] NOT NULL,
    [SupportLine] [int] NOT NULL,
    [TicketType] [int] NOT NULL,
    CONSTRAINT [PK_dbo.ServiceOperators] PRIMARY KEY CLUSTERED
    [UserProviderKey] ASC,
    [ServiceId] ASC,
    [TicketTypeValue] ASC,
    [SupportLine] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Table [dbo].[Services] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[Services](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ParentId] [int] NULL,
    [Name] [nvarchar](256) NOT NULL,
    [Description] [nvarchar](max) NULL,
    [Disabled] [bit] NOT NULL,
    [NewTicketLimitedAccess] [bit] NOT NULL,
    [Incident1stLineSupportLimitedAccess] [bit] NOT NULL,
    [Incident2ndLineSupportLimitedAccess] [bit] NOT NULL,
    [ServiceRequestLimitedAccess] [bit] NOT NULL,
    [ProblemLimitedAccess] [bit] NOT NULL,
    [ServiceRequestManager] [varchar](184) NOT NULL,
    [IncidentManager] [varchar](184) NOT NULL,
    [ProblemManager] [varchar](184) NOT NULL,
    [Deleted] [bit] NOT NULL,
    [WfDisableIncidentAssignedState] [bit] NOT NULL,
    [WfDisableIncidentConfirmedState] [bit] NOT NULL,
    [WfDisableIncidentTakeFromQueueAction] [bit] NOT NULL,
    [WfDisableIncidentFinishSolutionAction] [bit] NOT NULL,
    [WfDisableServiceRequestAssignedState] [bit] NOT NULL,
    [WfDisableServiceRequestConfirmedState] [bit] NOT NULL,
    [WfDisableServiceRequestTakeFromQueueAction] [bit] NOT NULL,
    [WfDisableServiceRequestFinishSolutionAction] [bit] NOT NULL,
    [WfDisableServiceRequestPostponeAction] [bit] NOT NULL,
    [ChangeLimitedAccess] [bit] NOT NULL,
    [ChangeManager] [varchar](184) NOT NULL,
    [WfDisableChangeTakeFromQueueAction] [bit] NOT NULL,
    [WfDisableChangeAssignedState] [bit] NOT NULL,
    [WfDisableChangeStartPreparationAction] [bit] NOT NULL,
    [IsDepartment] [bit] NOT NULL,
    [InheritsFromDepartment] [bit] NOT NULL,
    [AllowSelectSolverBySubmitterForIncidents] [bit] NOT NULL,
    [AllowSelectSolverBySubmitterForServiceRequests] [bit] NOT NULL,
    [AllowSelectSolverBySubmitterForProblems] [bit] NOT NULL,
    [AllowSelectSolverBySubmitterForChanges] [bit] NOT NULL,
    [AllowAccessToOtherOperatorsIncidents] [bit] NOT NULL,
    [AllowAccessToOtherOperatorsServiceRequests] [bit] NOT NULL,
    [AllowAccessToOtherOperatorsProblems] [bit] NOT NULL,
    [AllowAccessToOtherOperatorsChanges] [bit] NOT NULL,
    [AllowChangeDeadlineForIncidents] [bit] NOT NULL,
    [AllowChangeDeadlineForServiceRequests] [bit] NOT NULL,
    [AllowChangeDeadlineForProblems] [bit] NOT NULL,
    [AllowChangeDeadlineForChanges] [bit] NOT NULL,
    [AllowSelectPriorityForServiceRequests] [bit] NOT NULL,
    [WfDisableIncidentCompletedState] [bit] NOT NULL,
    [WfDoIncidentCompleteActionBySubmittersMessage] [bit] NOT NULL,
    [WfDisableServiceRequestCompletedState] [bit] NOT NULL,
    [WfDoServiceRequestCompleteActionBySubmittersMessage] [bit] NOT NULL,
    CONSTRAINT [PK_dbo.Services] PRIMARY KEY CLUSTERED
    [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Table [dbo].[TicketInvitations] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[TicketInvitations](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [TicketId] [int] NOT NULL,
    [InitiatorUserProviderKey] [varchar](184) NULL,
    [InitiatorFullName] [nvarchar](max) NULL,
    [InvitedUserProviderKey] [varchar](184) NULL,
    [InvitedFullName] [nvarchar](max) NULL,
    [Type] [int] NOT NULL,
    [CreatedUTC] [datetime] NOT NULL,
    CONSTRAINT [PK_dbo.TicketInvitations] PRIMARY KEY CLUSTERED
    [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Table [dbo].[Tickets] Script Date: 7.5.2014 8:39:38 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[Tickets](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ParentId] [int] NULL,
    [ServiceId] [int] NULL,
    [ServiceMailboxId] [int] NULL,
    [TicketTypeValue] [int] NOT NULL,
    [TicketTypeIdREF] [int] NOT NULL,
    [SubmitterKey] [varchar](184) NOT NULL,
    [SubmitterFullName] [nvarchar](256) NULL,
    [CustomerId] [int] NULL,
    [SolverKey] [varchar](184) NULL,
    [SolverFullName] [nvarchar](256) NULL,
    [Subject] [nvarchar](max) NULL,
    [CreatedUTC] [datetime] NOT NULL,
    [Archived] [bit] NOT NULL,
    [MarkedAsSolvedUTC] [datetime] NULL,
    [ArchivedUTC] [datetime] NULL,
    [TicketSourceValue] [int] NOT NULL,
    [OperatorKey] [varchar](184) NULL,
    [DeadlineUTC] [datetime] NULL,
    [DeadlineLastNotificatedPercentage] [int] NULL,
    [UrgencyValue] [int] NULL,
    [ImpactValue] [int] NULL,
    [PriorityValue] [int] NULL,
    [TicketStateValue] [int] NOT NULL,
    [IncidentFunctionEscalatedTo2ndLineSupport] [bit] NOT NULL,
    [Incident2ndLineSupportKey] [varchar](184) NULL,
    [Incident2ndLineSupportFullName] [nvarchar](max) NULL,
    [TicketType] [int] NOT NULL,
    [Source] [int] NOT NULL,
    [TicketState] [int] NOT NULL,
    [Urgency] [int] NULL,
    [Impact] [int] NULL,
    [TicketSummaryState] [int] NOT NULL,
    [ResolutionText] [nvarchar](max) NULL,
    [ResolutionModifiedUTC] [datetime] NULL,
    [ResolutionEdited] [bit] NOT NULL,
    [ResolutionUserProviderKey] [varchar](184) NULL,
    [ResolutionFullName] [nvarchar](max) NULL,
    [TicketSubType] [int] NULL,
    [ChangeRiskProbabilityValue] [int] NULL,
    [ChangeImpactValue] [int] NULL,
    [ChangeRiskCategoryValue] [int] NULL,
    [RfcText] [nvarchar](max) NULL,
    [RfcModifiedUTC] [datetime] NULL,
    [RfcEdited] [bit] NOT NULL,
    [RfcUserProviderKey] [varchar](184) NULL,
    [RfcFullName] [nvarchar](max) NULL,
    [ManualDeadline] [bit] NOT NULL,
    [ContactInformation] [nvarchar](256) NULL,
    [Imported] [bit] NOT NULL,
    [ForceClosed] [bit] NOT NULL,
    CONSTRAINT [PK_dbo.Tickets] PRIMARY KEY CLUSTERED
    [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    /****** Object: Index [IX_CustomerId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_CustomerId] ON [dbo].[CustomerUsers]
    [CustomerId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_InternalGroupId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_InternalGroupId] ON [dbo].[InternalGroupUsers]
    [InternalGroupId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_OperatorGroupId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_OperatorGroupId] ON [dbo].[OperatorGroupUsers]
    [OperatorGroupId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_ServiceId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_ServiceId] ON [dbo].[ServiceDeputyManagers]
    [ServiceId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_OperatorGroupId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_OperatorGroupId] ON [dbo].[ServiceOperatorGroups]
    [OperatorGroupId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_ServiceId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_ServiceId] ON [dbo].[ServiceOperatorGroups]
    [ServiceId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_ServiceId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_ServiceId] ON [dbo].[ServiceOperators]
    [ServiceId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_ParentId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_ParentId] ON [dbo].[Services]
    [ParentId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_TicketId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_TicketId] ON [dbo].[TicketInvitations]
    [TicketId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    SET ANSI_PADDING ON
    GO
    /****** Object: Index [IX_TicketInvitations_InvitedUserProviderKey_TicketId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE UNIQUE NONCLUSTERED INDEX [IX_TicketInvitations_InvitedUserProviderKey_TicketId] ON [dbo].[TicketInvitations]
    [InvitedUserProviderKey] ASC,
    [TicketId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_CustomerId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_CustomerId] ON [dbo].[Tickets]
    [CustomerId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_ParentId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_ParentId] ON [dbo].[Tickets]
    [ParentId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_ServiceId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_ServiceId] ON [dbo].[Tickets]
    [ServiceId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_ServiceMailboxId] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_ServiceMailboxId] ON [dbo].[Tickets]
    [ServiceMailboxId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    SET ANSI_PADDING ON
    GO
    /****** Object: Index [IX_SolverFullName] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_SolverFullName] ON [dbo].[Tickets]
    [SolverFullName] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    SET ANSI_PADDING ON
    GO
    /****** Object: Index [IX_SolverKey] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_SolverKey] ON [dbo].[Tickets]
    [SolverKey] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    SET ANSI_PADDING ON
    GO
    /****** Object: Index [IX_SubmitterFullName] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_SubmitterFullName] ON [dbo].[Tickets]
    [SubmitterFullName] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    SET ANSI_PADDING ON
    GO
    /****** Object: Index [IX_SubmitterKey] Script Date: 7.5.2014 8:39:38 ******/
    CREATE NONCLUSTERED INDEX [IX_SubmitterKey] ON [dbo].[Tickets]
    [SubmitterKey] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    /****** Object: Index [IX_Tickets_TicketType_TicketTypeIdREF] Script Date: 7.5.2014 8:39:38 ******/
    CREATE UNIQUE NONCLUSTERED INDEX [IX_Tickets_TicketType_TicketTypeIdREF] ON [dbo].[Tickets]
    [TicketType] ASC,
    [TicketTypeIdREF] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[CustomerUsers] WITH CHECK ADD CONSTRAINT [FK_dbo.CustomerUsers_dbo.Customers_CustomerId] FOREIGN KEY([CustomerId])
    REFERENCES [dbo].[Customers] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[CustomerUsers] CHECK CONSTRAINT [FK_dbo.CustomerUsers_dbo.Customers_CustomerId]
    GO
    ALTER TABLE [dbo].[InternalGroupUsers] WITH CHECK ADD CONSTRAINT [FK_dbo.InternalGroupUsers_dbo.InternalGroups_InternalGroupId] FOREIGN KEY([InternalGroupId])
    REFERENCES [dbo].[InternalGroups] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[InternalGroupUsers] CHECK CONSTRAINT [FK_dbo.InternalGroupUsers_dbo.InternalGroups_InternalGroupId]
    GO
    ALTER TABLE [dbo].[OperatorGroupUsers] WITH CHECK ADD CONSTRAINT [FK_dbo.OperatorGroupUsers_dbo.OperatorGroups_OperatorGroupId] FOREIGN KEY([OperatorGroupId])
    REFERENCES [dbo].[OperatorGroups] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[OperatorGroupUsers] CHECK CONSTRAINT [FK_dbo.OperatorGroupUsers_dbo.OperatorGroups_OperatorGroupId]
    GO
    ALTER TABLE [dbo].[ServiceDeputyManagers] WITH CHECK ADD CONSTRAINT [FK_dbo.ServiceDeputyManagers_dbo.Services_ServiceId] FOREIGN KEY([ServiceId])
    REFERENCES [dbo].[Services] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[ServiceDeputyManagers] CHECK CONSTRAINT [FK_dbo.ServiceDeputyManagers_dbo.Services_ServiceId]
    GO
    ALTER TABLE [dbo].[ServiceOperatorGroups] WITH CHECK ADD CONSTRAINT [FK_dbo.ServiceOperatorGroups_dbo.OperatorGroups_OperatorGroupId] FOREIGN KEY([OperatorGroupId])
    REFERENCES [dbo].[OperatorGroups] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[ServiceOperatorGroups] CHECK CONSTRAINT [FK_dbo.ServiceOperatorGroups_dbo.OperatorGroups_OperatorGroupId]
    GO
    ALTER TABLE [dbo].[ServiceOperatorGroups] WITH CHECK ADD CONSTRAINT [FK_dbo.ServiceOperatorGroups_dbo.Services_ServiceId] FOREIGN KEY([ServiceId])
    REFERENCES [dbo].[Services] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[ServiceOperatorGroups] CHECK CONSTRAINT [FK_dbo.ServiceOperatorGroups_dbo.Services_ServiceId]
    GO
    ALTER TABLE [dbo].[ServiceOperators] WITH CHECK ADD CONSTRAINT [FK_dbo.ServiceOperators_dbo.Services_ServiceId] FOREIGN KEY([ServiceId])
    REFERENCES [dbo].[Services] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[ServiceOperators] CHECK CONSTRAINT [FK_dbo.ServiceOperators_dbo.Services_ServiceId]
    GO
    ALTER TABLE [dbo].[Services] WITH CHECK ADD CONSTRAINT [FK_dbo.Services_dbo.Services_ParentId] FOREIGN KEY([ParentId])
    REFERENCES [dbo].[Services] ([Id])
    GO
    ALTER TABLE [dbo].[Services] CHECK CONSTRAINT [FK_dbo.Services_dbo.Services_ParentId]
    GO
    ALTER TABLE [dbo].[TicketInvitations] WITH CHECK ADD CONSTRAINT [FK_dbo.TicketInvitations_dbo.Tickets_TicketId] FOREIGN KEY([TicketId])
    REFERENCES [dbo].[Tickets] ([Id])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[TicketInvitations] CHECK CONSTRAINT [FK_dbo.TicketInvitations_dbo.Tickets_TicketId]
    GO
    ALTER TABLE [dbo].[Tickets] WITH CHECK ADD CONSTRAINT [FK_dbo.Tickets_dbo.Customers_CustomerId] FOREIGN KEY([CustomerId])
    REFERENCES [dbo].[Customers] ([Id])
    GO
    ALTER TABLE [dbo].[Tickets] CHECK CONSTRAINT [FK_dbo.Tickets_dbo.Customers_CustomerId]
    GO
    ALTER TABLE [dbo].[Tickets] WITH CHECK ADD CONSTRAINT [FK_dbo.Tickets_dbo.ServiceMailboxes_ServiceMailboxId] FOREIGN KEY([ServiceMailboxId])
    REFERENCES [dbo].[ServiceMailboxes] ([Id])
    GO
    ALTER TABLE [dbo].[Tickets] CHECK CONSTRAINT [FK_dbo.Tickets_dbo.ServiceMailboxes_ServiceMailboxId]
    GO
    ALTER TABLE [dbo].[Tickets] WITH CHECK ADD CONSTRAINT [FK_dbo.Tickets_dbo.Services_ServiceId] FOREIGN KEY([ServiceId])
    REFERENCES [dbo].[Services] ([Id])
    GO
    ALTER TABLE [dbo].[Tickets] CHECK CONSTRAINT [FK_dbo.Tickets_dbo.Services_ServiceId]
    GO
    ALTER TABLE [dbo].[Tickets] WITH CHECK ADD CONSTRAINT [FK_dbo.Tickets_dbo.Tickets_ParentId] FOREIGN KEY([ParentId])
    REFERENCES [dbo].[Tickets] ([Id])
    GO
    ALTER TABLE [dbo].[Tickets] CHECK CONSTRAINT [FK_dbo.Tickets_dbo.Tickets_ParentId]
    GO

  • Help needed in tuning this query

    This is the SQL i would like to tune for performace...
    The table structure is given below.
    The table has about 2 million rows.
    From the second day onwards only around 10% of records will be between Load_Start_Time and Load_End_Time. Among these around 50% will have THAMES_URN_WITH_ROLE_SUFFIX as 'TP%'. At present there are unique and primary key indexes on THAMES_URN_WITH_ROLE_SUFFIX .
    I'm sure that we need a b-tree index on STG_UPDATE_DATE_TIME as it is the column with good selectivity.
    I'm primarily concerned about the substr, instr and reverese on THAMES_URN_WITH_ROLE_SUFFIX.
    Also pls. let me know if the order of predicates is right.
    Thanks in advance.
    SELECT TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN, TPD_STG_TL_SF_LEGAL_OWNER.UPDATE_SOURCE, TPD_STG_TL_SF_LEGAL_OWNER.SOURCE_EXTRACT_DATE_TIME, TPD_STG_TL_SF_LEGAL_OWNER.LEGAL_OWNERSHIP_ISSUE_IND, TPD_STG_TL_SF_LEGAL_OWNER.CONTACTABLE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ADMIN_CONTROL_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.BANKRUPTCY_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ASSIGNED_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.IN_TRUST_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.DIVORCE_CASE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.POA_COP_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.CLEANSING_STATUS, TPD_STG_TL_SF_LEGAL_OWNER.CATEGORY
    FROM
    TPD_STG_TL_SF_LEGAL_OWNER
    WHERE
    ((TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME > '$$Load_Start_Time'
    AND
    TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME <= '$$Load_End_Time')
    OR
    (TPD_STG_TL_SF_LEGAL_OWNER.TPDB_PROCESSED_IDENTIFIER != 'Y') )
    AND
    SUBSTR(TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX,1,2)='TP'
    AND
    SUBSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),INSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),'-',1)-1,1)!='S'
    ========================================
    CREATE TABLE TPD_STG_TL_SF_LEGAL_OWNER
    THAMES_URN VARCHAR2(35 BYTE) NOT NULL,
    UPDATE_SOURCE VARCHAR2(3 BYTE),
    SOURCE_EXTRACT_DATE_TIME DATE,
    LEGAL_OWNERSHIP_ISSUE_IND CHAR(1 BYTE),
    CONTACTABLE_INDICATOR CHAR(1 BYTE),
    ADMIN_CONTROL_INDICATOR CHAR(1 BYTE),
    BANKRUPTCY_INDICATOR CHAR(1 BYTE),
    ASSIGNED_INDICATOR CHAR(1 BYTE),
    IN_TRUST_INDICATOR CHAR(1 BYTE),
    DIVORCE_CASE_INDICATOR CHAR(1 BYTE),
    POA_COP_INDICATOR CHAR(1 BYTE),
    THAMES_URN_WITH_ROLE_SUFFIX VARCHAR2(39 BYTE),
    THAMES_LEGAL_OWNERSHIP_IND CHAR(1 BYTE),
    PRODUCT_HOLDING_ROLE_TYPE VARCHAR2(21 BYTE),
    OWNERSHIP_SPLIT_PERCENTAGE NUMBER(3),
    SOURCE_SYSTEM VARCHAR2(3 BYTE),
    TITLE VARCHAR2(50 BYTE),
    FIRST_NAME VARCHAR2(50 BYTE),
    MIDDLE_INITIAL VARCHAR2(50 BYTE),
    SURNAME VARCHAR2(50 BYTE),
    GENDER CHAR(1 BYTE),
    BIRTH_DATE DATE,
    DEATH_INDICATOR CHAR(1 BYTE),
    DEATH_RECORD_DATE DATE,
    NATIONAL_INSURANCE_NUMBER VARCHAR2(9 BYTE),
    GONE_AWAY_INDICATOR CHAR(1 BYTE),
    ADDRESS_LINE_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_3 VARCHAR2(50 BYTE),
    ADDRESS_LINE_4 VARCHAR2(50 BYTE),
    ADDRESS_LINE_5 VARCHAR2(50 BYTE),
    POST_CODE VARCHAR2(12 BYTE),
    COUNTRY VARCHAR2(50 BYTE),
    OVERSEAS_ADDRESS_INDICATOR CHAR(1 BYTE),
    ORGANISATION_NAME VARCHAR2(50 BYTE),
    TPDB_PROCESSED_IDENTIFIER CHAR(2 BYTE),
    CLEANSING_STATUS VARCHAR2(30 BYTE),
    CATEGORY VARCHAR2(50 BYTE),
    SCHEME_NAME VARCHAR2(50 BYTE),
    STG_CREATE_DATE_TIME DATE,
    STG_UPDATE_DATE_TIME DATE,
    LAST_UPDATED_DATE_TIME DATE
    TABLESPACE TPDBS01A_DATA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE UNIQUE INDEX TPD_STG_TL_SF_LEGAL_OWNER_PK ON TPD_STG_TL_SF_LEGAL_OWNER
    (THAMES_URN_WITH_ROLE_SUFFIX)
    LOGGING
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    NOPARALLEL;
    ALTER TABLE TPD_STG_TL_SF_LEGAL_OWNER ADD (
    CONSTRAINT TPD_STG_TL_SF_LEGAL_OWNER_PK
    PRIMARY KEY
    (THAMES_URN_WITH_ROLE_SUFFIX)
    USING INDEX
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    ));

    > If indexes don't help, is the only way to gain REAL
    performance gain on this type of query is to
    partition the table
    If a Full Table Scan on a table takes "too long" (and
    this is purely subjective - "too long" is different
    for every problem) and indexes can't help, and we
    need <100% of the rows, and if partitioning will give
    us the performance we desire, is it OK do it ? Also
    would STG_UPDATE_DATE_TIME be the best column to do a
    index partion ?
    For this type of query, partitioning on STG_UPDATE_DATE_TIME would be good.
    However, partitioning is not done just for one query. It has to fit in your total design. For example, if you are also doing queries with a predicate like <column with a local unique index but not the partition key> = <constant>, it would have to visit all partitions instead of just one, and those queries would take much longer to execute. You can make the index global, but there all kind of maintenance issues with that. In short: be careful about partitioning and think it through first.
    > But is it a good option to partition tables with
    total no. of rows between 2 million and 5 million ? I
    thought partitioning is better done for tables > 20
    million.
    Please throw some light on that.
    Generally, partitioning is done on bigger tables, yes. But it is not about some specific number of rows. You partition a table when all forecasted use of the table is known, so you can make a good judgement which usages will benefit, which ones won't be affected and which ones are likely to suffer. When the benefits outweigh the disadvantages, you partition...
    Above I had an example about queries that are going to suffer. Partitioning is beneficial for example when once in some period you'd have to delete A LOT of old rows. Or when you have some data warehousing queries that need like 10% of only the most recent data in a huge table.
    The decision is yours.
    Regards,
    Rob.

Maybe you are looking for

  • Querying data from the maintenance view.

    Hi Experts, Well, i need the STEXT field value from the maintanance view V_T591A created for the standard table T591A. Table T591A has the field Subtype but doesn't have the field Stext, which consists the description of the subtype. The Stext field

  • LaserJet M1212nf MFP ,Vista Home Premium SP2,printer driver

    Hello I have a HP Pavilion dv6700 Notebook PC and I have installed a LaserJet M1212 nf MFP multipurpose machine. I can send FAX ,I can scan,I can copy but  can not print as I get a message asking me to install the driver. When  I answer no, it opens

  • Please help: installing FP 10.3.183.90 on iMac 10.5.8

    Attempting to download Flash Player 10.3.189.90* on an iMac using Leopard (10.5.8); after multiple tries, have gotten to a point at which clicking the Install icon opens a window asking if I want to install (considering this a victory; something is h

  • Mac book pro automatically start to recovery

    I pushed in and held down the power button and then restarted the computer and it automatically went to the recovery options it will not start up normally please help

  • How can i remotely turn on location settings?

    Lost my phone in a field and I think location services are disabled. Is there any way i can remotely turn them on so i can use find my iphone to locate it?