Slow query on aggregate.

Hello Experts,
We have very specific issue on query performance. We have a query which uses to execute within 3 minutes.  We have created Aggregates on the following cube and the same query partially uses the aggregate and cube.  The particular query after creating the new aggregate taking more than 25 minutes to execute.
If we switch-off the aggregate and execute the query, the following query takes only 3 minutes.  The query uses Count Function in few formulas.  Can you please suggest, is there any option for particular query to ignore Aggregate and use only infocube.
Regards
Christopher Francis

Hi Francis,
First of all this is not a common issue seen across SAP System.
According to your issue...exceution time on aggregate is more than on cube.
According to my analysis what could be the reason ..is that the characterstics on which you made the aggregate would have different.
example : you want to create aggregate on cust_no..but aggregate might have created on different characterstic..suppose prod_no
so When query hits the aggrgate it doesnot find any record of cust_no and  again search in the cube.
so it takes more time for serching aggreagate as well as in the cube.
that is why i think it may  be taking more time..for execution on aggregate.
please check your required characterstics..on which you have created aggregate.
Regards,
Sidhartha

Similar Messages

  • Very Slow Query with CTE inner join

    I have 2 tables (heavily simplified here to show relevant columns):
    CREATE TABLE tblCharge
    (ChargeID int NOT NULL,
    ParentChargeID int NULL,
    ChargeName varchar(200) NULL)
    CREATE TABLE tblChargeShare
    (ChargeShareID int NOT NULL,
    ChargeID int NOT NULL,
    TotalAmount money NOT NULL,
    TaxAmount money NULL,
    DiscountAmount money NULL,
    CustomerID int NOT NULL,
    ChargeShareStatusID int NOT NULL)
    I have a very basic View to Join them:
    CREATE VIEW vwBASEChargeShareRelation as
    Select c.ChargeID, ParentChargeID, s.CustomerID, s.TotalAmount, isnull(s.TaxAmount, 0) as TaxAmount, isnull(s.DiscountAmount, 0) as DiscountAmount
    from tblCharge c inner join tblChargeShare s
    on c.ChargeID = s.ChargeID Where s.ChargeShareStatusID < 3
    GO
    I then have a view containing a CTE to get the children of the Parent Charge:
    ALTER VIEW [vwChargeShareSubCharges] AS
    WITH RCTE AS
    SELECT ParentChargeId, ChargeID, 1 AS Lvl, ISNULL(TotalAmount, 0) as TotalAmount, ISNULL(TaxAmount, 0) as TaxAmount,
    ISNULL(DiscountAmount, 0) as DiscountAmount, CustomerID, ChargeID as MasterChargeID
    FROM vwBASEChargeShareRelation Where ParentChargeID is NULL
    UNION ALL
    SELECT rh.ParentChargeID, rh.ChargeID, Lvl+1 AS Lvl, ISNULL(rh.TotalAmount, 0), ISNULL(rh.TaxAmount, 0), ISNULL(rh.DiscountAmount, 0) , rh.CustomerID
    , rc.MasterChargeID
    FROM vwBASEChargeShareRelation rh
    INNER JOIN RCTE rc ON rh.PArentChargeID = rc.ChargeID and rh.CustomerID = rc.CustomerID
    Select MasterChargeID as ChargeID, CustomerID, Sum(TotalAmount) as TotalCharged, Sum(TaxAmount) as TotalTax, Sum(DiscountAmount) as TotalDiscount
    from RCTE
    Group by MasterChargeID, CustomerID
    GO
    So far so good, I can query this view and get the total cost for a line item including all children.
    The problem occurs when I join this table. The query:
    Select t.* from vwChargeShareSubCharges t
    inner join
    tblChargeShare s
    on t.CustomerID = s.CustomerID
    and t.MasterChargeID = s.ChargeID
    Where s.ChargeID = 1291094
    Takes around 30 ms to return a result (tblCharge and Charge Share have around 3.5 million records).
    But the query:
    Select t.* from vwChargeShareSubCharges t
    inner join
    tblChargeShare s
    on t.CustomerID = s.CustomerID
    and t.MasterChargeID = s.ChargeID
    Where InvoiceID = 1045854
    Takes around 2 minutes to return a result - even though the only charge with that InvoiceID is the same charge as the one used in the previous query.
    The same thing occurs if I do the join in the same query that the CTE is defined in.
    I ran the execution plan for each query. The first (fast) query looks like this:
    The second(slow) query looks like this:
    I am at a loss, and my skills at decoding execution plans to resolve this are lacking.
    I have separate indexes on tblCharge.ChargeID, tblCharge.ParentChargeID, tblChargeShare.ChargeID, tblChargeShare.InvoiceID, tblChargeShare.ChargeShareStatusID
    Any ideas? Tested on SQL 2008R2 and SQL 2012

    >> The database is linked [sic] to an established app and the column and table names can't be changed. <<
    Link? That is a term from pointer chains and network databases, not SQL. I will guess that means the app came back in the old pre-RDBMS days and you are screwed. 
    >> I am not too worried about the money field [sic], this is used for money and money based calculations so the precision and rounding are acceptable at this level. <<
    Field is a COBOL concept; columns are totally different. MONEY is how Sybase mimics the PICTURE clause that puts currency signs, commas, period, etc in a COBOL money field. 
    Using more than one operation (multiplication or division) on money columns will produce severe rounding errors. A simple way to visualize money arithmetic is to place a ROUND() function calls after 
    every operation. For example,
    Amount = (Portion / total_amt) * gross_amt
    can be rewritten using money arithmetic as:
    Amount = ROUND(ROUND(Portion/total_amt, 4) * 
    gross_amt, 4)
    Rounding to four decimal places might not seem an 
    issue, until the numbers you are using are greater 
    than 10,000. 
    BEGIN
    DECLARE @gross_amt MONEY,
     @total_amt MONEY,
     @my_part MONEY,
     @money_result MONEY,
     @float_result FLOAT,
     @all_floats FLOAT;
     SET @gross_amt = 55294.72;
     SET @total_amt = 7328.75;
     SET @my_part = 1793.33;
     SET @money_result = (@my_part / @total_amt) * 
    @gross_amt;
     SET @float_result = (@my_part / @total_amt) * 
    @gross_amt;
     SET @Retult3 = (CAST(@my_part AS FLOAT)
     / CAST( @total_amt AS FLOAT))
     * CAST(FLOAT, @gross_amt AS FLOAT);
     SELECT @money_result, @float_result, @all_floats;
    END;
    @money_result = 13525.09 -- incorrect
    @float_result = 13525.0885 -- incorrect
    @all_floats = 13530.5038673171 -- correct, with a -
    5.42 error 
    >> The keys are ChargeID(int, identity) and ChargeShareID(int, identity). <<
    Sorry, but IDENTITY is not relational and cannot be a key by definition. But it sure works just like a record number in your old COBOL file system. 
    >> .. these need to be int so that they are assigned by the database and unique. <<
    No, the data type of a key is not determined by physical storage, but by logical design. IDENTITY is the number of a parking space in a garage; a VIN is how you identify the automobile. 
    >> What would you recommend I use as keys? <<
    I do not know. I have no specs and without that, I cannot pull a Kabbalah number from the hardware. Your magic numbers can identify Squids, Automobile or Lady Gaga! I would ask the accounting department how they identify a charge. 
    >> Charge_Share_Status_ID links [sic] to another table which contains the name, formatting [sic] and other information [sic] or a charge share's status, so it is both an Id and a status. <<
    More pointer chains! Formatting? Unh? In RDBMS, we use a tiered architecture. That means display formatting is in a presentation layer. A properly created table has cohesion – it does one and only one data element. A status is a state of being that applies
    to an entity over a period time (think employment, marriage, etc. status if that is too abstract). 
    An identifier is based on the Law of Identity from formal logic “To be is to be something in particular” or “A is A” informally. There is no entity here! The Charge_Share_Status table should have the encoded values for a status and perhaps a description if
    they are unclear. If the list of values is clear, short and static, then use a CHECK() constraint. 
    On a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, this is literally that silly and wrong. 
    >> I understand what a CTE is; is there a better way to sum all children for a parent hierarchy? <<
    There are many ways to represent a tree or hierarchy in SQL.  This is called an adjacency list model and it looks like this:
    CREATE TABLE OrgChart 
    (emp_name CHAR(10) NOT NULL PRIMARY KEY, 
     boss_emp_name CHAR(10) REFERENCES OrgChart(emp_name), 
     salary_amt DECIMAL(6,2) DEFAULT 100.00 NOT NULL,
     << horrible cycle constraints >>);
    OrgChart 
    emp_name  boss_emp_name  salary_amt 
    ==============================
    'Albert'    NULL    1000.00
    'Bert'    'Albert'   900.00
    'Chuck'   'Albert'   900.00
    'Donna'   'Chuck'    800.00
    'Eddie'   'Chuck'    700.00
    'Fred'    'Chuck'    600.00
    This approach will wind up with really ugly code -- CTEs hiding recursive procedures, horrible cycle prevention code, etc.  The root of your problem is not knowing that rows are not records, that SQL uses sets and trying to fake pointer chains with some
    vague, magical non-relational "id".  
    This matches the way we did it in old file systems with pointer chains.  Non-RDBMS programmers are comfortable with it because it looks familiar -- it looks like records and not rows.  
    Another way of representing trees is to show them as nested sets. 
    Since SQL is a set oriented language, this is a better model than the usual adjacency list approach you see in most text books. Let us define a simple OrgChart table like this.
    CREATE TABLE OrgChart 
    (emp_name CHAR(10) NOT NULL PRIMARY KEY, 
     lft INTEGER NOT NULL UNIQUE CHECK (lft > 0), 
     rgt INTEGER NOT NULL UNIQUE CHECK (rgt > 1),
      CONSTRAINT order_okay CHECK (lft < rgt));
    OrgChart 
    emp_name         lft rgt 
    ======================
    'Albert'      1   12 
    'Bert'        2    3 
    'Chuck'       4   11 
    'Donna'       5    6 
    'Eddie'       7    8 
    'Fred'        9   10 
    The (lft, rgt) pairs are like tags in a mark-up language, or parens in algebra, BEGIN-END blocks in Algol-family programming languages, etc. -- they bracket a sub-set.  This is a set-oriented approach to trees in a set-oriented language. 
    The organizational chart would look like this as a directed graph:
                Albert (1, 12)
        Bert (2, 3)    Chuck (4, 11)
                       /    |   \
                     /      |     \
                   /        |       \
                 /          |         \
            Donna (5, 6) Eddie (7, 8) Fred (9, 10)
    The adjacency list table is denormalized in several ways. We are modeling both the Personnel and the Organizational chart in one table. But for the sake of saving space, pretend that the names are job titles and that we have another table which describes the
    Personnel that hold those positions.
    Another problem with the adjacency list model is that the boss_emp_name and employee columns are the same kind of thing (i.e. identifiers of personnel), and therefore should be shown in only one column in a normalized table.  To prove that this is not
    normalized, assume that "Chuck" changes his name to "Charles"; you have to change his name in both columns and several places. The defining characteristic of a normalized table is that you have one fact, one place, one time.
    The final problem is that the adjacency list model does not model subordination. Authority flows downhill in a hierarchy, but If I fire Chuck, I disconnect all of his subordinates from Albert. There are situations (i.e. water pipes) where this is true, but
    that is not the expected situation in this case.
    To show a tree as nested sets, replace the nodes with ovals, and then nest subordinate ovals inside each other. The root will be the largest oval and will contain every other node.  The leaf nodes will be the innermost ovals with nothing else inside them
    and the nesting will show the hierarchical relationship. The (lft, rgt) columns (I cannot use the reserved words LEFT and RIGHT in SQL) are what show the nesting. This is like XML, HTML or parentheses. 
    At this point, the boss_emp_name column is both redundant and denormalized, so it can be dropped. Also, note that the tree structure can be kept in one table and all the information about a node can be put in a second table and they can be joined on employee
    number for queries.
    To convert the graph into a nested sets model think of a little worm crawling along the tree. The worm starts at the top, the root, makes a complete trip around the tree. When he comes to a node, he puts a number in the cell on the side that he is visiting
    and increments his counter.  Each node will get two numbers, one of the right side and one for the left. Computer Science majors will recognize this as a modified preorder tree traversal algorithm. Finally, drop the unneeded OrgChart.boss_emp_name column
    which used to represent the edges of a graph.
    This has some predictable results that we can use for building queries.  The root is always (left = 1, right = 2 * (SELECT COUNT(*) FROM TreeTable)); leaf nodes always have (left + 1 = right); subtrees are defined by the BETWEEN predicate; etc. Here are
    two common queries which can be used to build others:
    1. An employee and all their Supervisors, no matter how deep the tree.
     SELECT O2.*
       FROM OrgChart AS O1, OrgChart AS O2
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND O1.emp_name = :in_emp_name;
    2. The employee and all their subordinates. There is a nice symmetry here.
     SELECT O1.*
       FROM OrgChart AS O1, OrgChart AS O2
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND O2.emp_name = :in_emp_name;
    3. Add a GROUP BY and aggregate functions to these basic queries and you have hierarchical reports. For example, the total salaries which each employee controls:
     SELECT O2.emp_name, SUM(S1.salary_amt)
       FROM OrgChart AS O1, OrgChart AS O2,
            Salaries AS S1
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND S1.emp_name = O2.emp_name 
       GROUP BY O2.emp_name;
    4. To find the level and the size of the subtree rooted at each emp_name, so you can print the tree as an indented listing. 
    SELECT O1.emp_name, 
       SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt 
       THEN O2.sale_amt ELSE 0.00 END) AS sale_amt_tot,
       SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt 
       THEN 1 ELSE 0 END) AS subtree_size,
       SUM(CASE WHEN O1.lft BETWEEN O2.lft AND O2.rgt
       THEN 1 ELSE 0 END) AS lvl
      FROM OrgChart AS O1, OrgChart AS O2
     GROUP BY O1.emp_name;
    5. The nested set model has an implied ordering of siblings which the adjacency list model does not. To insert a new node, G1, under part G.  We can insert one node at a time like this:
    BEGIN ATOMIC
    DECLARE rightmost_spread INTEGER;
    SET rightmost_spread 
        = (SELECT rgt 
             FROM Frammis 
            WHERE part = 'G');
    UPDATE Frammis
       SET lft = CASE WHEN lft > rightmost_spread
                      THEN lft + 2
                      ELSE lft END,
           rgt = CASE WHEN rgt >= rightmost_spread
                      THEN rgt + 2
                      ELSE rgt END
     WHERE rgt >= rightmost_spread;
     INSERT INTO Frammis (part, lft, rgt)
     VALUES ('G1', rightmost_spread, (rightmost_spread + 1));
     COMMIT WORK;
    END;
    The idea is to spread the (lft, rgt) numbers after the youngest child of the parent, G in this case, over by two to make room for the new addition, G1.  This procedure will add the new node to the rightmost child position, which helps to preserve the idea
    of an age order among the siblings.
    6. To convert a nested sets model into an adjacency list model:
    SELECT B.emp_name AS boss_emp_name, E.emp_name
      FROM OrgChart AS E
           LEFT OUTER JOIN
           OrgChart AS B
           ON B.lft
              = (SELECT MAX(lft)
                   FROM OrgChart AS S
                  WHERE E.lft > S.lft
                    AND E.lft < S.rgt);
    7. To find the immediate parent of a node: 
    SELECT MAX(P2.lft), MIN(P2.rgt)
      FROM Personnel AS P1, Personnel AS P2
     WHERE P1.lft BETWEEN P2.lft AND P2.rgt 
       AND P1.emp_name = @my_emp_name;
    I have a book on TREES & HIERARCHIES IN SQL which you can get at Amazon.com right now. It has a lot of other programming idioms for nested sets, like levels, structural comparisons, re-arrangement procedures, etc. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Slow Query Using index. Fast with full table Scan.

    Hi;
    (Thanks for the links)
    Here's my question correctly formated.
    The query:
    SELECT count(1)
    from ehgeoconstru  ec
    where ec.TYPE='BAR' 
    AND ( ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') )  
    and deathdate is null
    and substr(ec.strgfd, 1, length('[CIMText')) <> '[CIMText'Runs on 32 seconds!
    Same query, but with one extra where clause:
    SELECT count(1)
    from ehgeoconstru  ec
    where ec.TYPE='BAR' 
    and  ( (ec.contextVersion = 'REALWORLD')     --- ADDED HERE
    AND ( ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') ) ) 
    and deathdate is null
    and substr(ec.strgfd, 1, length('[CIMText')) <> '[CIMText'This runs in 400 seconds.
    It should return data from one table, given the conditions.
    The version of the database is Oracle9i Release 9.2.0.7.0
    These are the parameters relevant to the optimizer:
    SQL> show parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     1
    optimizer_features_enable            string      9.2.0
    optimizer_index_caching              integer     99
    optimizer_index_cost_adj             integer     10
    optimizer_max_permutations           integer     2000
    optimizer_mode                       string      CHOOSE
    SQL> Here is the output of EXPLAIN PLAN for the first fast query:
    PLAN_TABLE_OUTPUT
    | Id  | Operation                     |  Name               | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |                         |           |       |       |
    |   1 |  SORT AGGREGATE       |                         |           |       |       |
    |*  2 |   TABLE ACCESS FULL   | EHCONS            |       |       |       |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       2 - filter(SUBSTR("EC"."strgfd",1,8)<>'[CIMText' AND "EC"."DEATHDATE"
                  IS NULL AND "EC"."BIRTHDATE"<=TO_DATE('2009-10-06 11:52:12', 'yyyy
    -mm-dd
                  hh24:mi:ss') AND "EC"."TYPE"='BAR')
    Note: rule based optimizationHere is the output of EXPLAIN PLAN for the slow query:
    PLAN_TABLE_OUTPUT
       |       |
    |   1 |  SORT AGGREGATE              |                             |       |
       |       |
    |*  2 |   TABLE ACCESS BY INDEX ROWID| ehgeoconstru      |       |
       |       |
    |*  3 |    INDEX RANGE SCAN          | ehgeoconstru_VSN  |       |
       |       |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    2 - filter(SUBSTR("EC"."strgfd",1,8)<>'[CIMText' AND "EC"."DEATHDATE" IS
    NULL AND "EC"."TYPE"='BAR')
    PLAN_TABLE_OUTPUT
       3 - access("EC"."CONTEXTVERSION"='REALWORLD' AND "EC"."BIRTHDATE"<=TO_DATE('2
    009-10-06
                  11:52:12', 'yyyy-mm-dd hh24:mi:ss'))
           filter("EC"."BIRTHDATE"<=TO_DATE('2009-10-06 11:52:12', 'yyyy-mm-dd hh24:
    mi:ss'))
    Note: rule based optimizationThe TKPROF output for this slow statement is:
    TKPROF: Release 9.2.0.7.0 - Production on Tue Nov 17 14:46:32 2009
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Trace file: gen_ora_3120.trc
    Sort options: prsela  exeela  fchela 
    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 count(1)
    from ehgeoconstru  ec
    where ec.TYPE='BAR'
    and  ( (ec.contextVersion = 'REALWORLD')
    AND ( ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') ) )
    and deathdate is null
    and substr(ec.strgfd, 1, length('[CIMText')) <> '[CIMText'
    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        2      0.00     538.12     162221    1355323          0           1
    total        4      0.00     538.12     162221    1355323          0           1
    Misses in library cache during parse: 0
    Optimizer goal: CHOOSE
    Parsing user id: 153 
    Rows     Row Source Operation
          1  SORT AGGREGATE
      27747   TABLE ACCESS BY INDEX ROWID OBJ#(73959)
    2134955    INDEX RANGE SCAN OBJ#(73962) (object id 73962)
    alter session set sql_trace=true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.02          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        1      0.00       0.02          0          0          0           0
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer goal: CHOOSE
    Parsing user id: 153 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      2      0.00       0.02          0          0          0           0
    Fetch        2      0.00     538.12     162221    1355323          0           1
    total        5      0.00     538.15     162221    1355323          0           1
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        2  user  SQL statements in session.
        0  internal SQL statements in session.
        2  SQL statements in session.
    Trace file: gen_ora_3120.trc
    Trace file compatibility: 9.02.00
    Sort options: prsela  exeela  fchela 
           2  sessions in tracefile.
           2  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           2  SQL statements in trace file.
           2  unique SQL statements in trace file.
          94  lines in trace file.Edited by: PauloSMO on 17/Nov/2009 4:21
    Edited by: PauloSMO on 17/Nov/2009 7:07
    Edited by: PauloSMO on 17/Nov/2009 7:38 - Changed title to be more correct.

    Although your optimizer_mode is choose, it appears that there are no statistics gathered on ehgeoconstru. The lack of cost estimate and estimated row counts from each step of the plan, and the "Note: rule based optimization" at the end of both plans would tend to confirm this.
    Optimizer_mode choose means that if statistics are gathered then it will use the CBO, but if no statistics are present in any of the tables in the query, then the Rule Based Optimizer will be used. The RBO tends to be index happy at the best of times. I'm guessing that the index ehgeoconstru_VSN has contextversion as the leading column and also includes birthdate.
    You can either gather statistics on the table (if all of the other tables have statistics) using dbms_stats.gather_table_stats, or hint the query to use a full scan instead of the index. Another alternative would be to apply a function or operation against the contextversion to preclude the use of the index. something like this:
    SELECT COUNT(*)
    FROM ehgeoconstru  ec
    WHERE ec.type='BAR' and 
          ec.contextVersion||'' = 'REALWORLD'
          ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') and
          deathdate is null and
          SUBSTR(ec.strgfd, 1, LENGTH('[CIMText')) <> '[CIMText'or perhaps UPPER(ec.contextVersion) if that would not change the rows returned.
    John

  • SharePoint 2010 Slow query duration when setting metadata on folder

    I'm getting "Slow Query Duration" when I programmatically set a default value for a default field to apply to documents at a specified location on a SP 2010 library.
    It has nothing to do with performance most probably as I'm getting this working with a folder within a library with only a 1 document on a UAT environment. Front-end: AMD Opteron 6174 2.20GHz x 2 + 8gb RAM, Back-end: AMD Opteron 6174 2.20GHz x 2 + 16gb
    RAM.
    The specific line of code causing this is:
    folderMetadata.SetFieldDefault(createdFolder, fieldData.Field.InternalName, thisFieldTextValue);
    What SP says:
    02/17/2014 16:29:03.24 w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa42 Monitorable A large block of literal text was sent to sql. This can result in blocking in sql and excessive memory use on the front end. Verify that no binary parameters are
    being passed as literals, and consider breaking up batches into smaller components. If this request is for a SharePoint list or list item, you may be able to resolve this by reducing the number of fields.
    02/17/2014 16:29:03.24 w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa43 High Slow Query Duration: 254.705556153086
    02/17/2014 16:29:03.26 w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High Slow Query StackTrace-Managed: at Microsoft.SharePoint.Utilities.SqlSession.OnPostExecuteCommand(SqlCommand command, SqlQueryData monitoringData) at Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand
    command, CommandBehavior behavior, SqlQueryData monitoringData, Boolean retryForDeadLock) at Microsoft.SharePoint.SPSqlClient.ExecuteQueryInternal(Boolean retryfordeadlock) at Microsoft.SharePoint.SPSqlClient.ExecuteQuery(Boolean retryfordeadlock) at Microsoft.SharePoint.Library.SPRequestInternalClass.PutFile(String
    bstrUrl, String bstrWebRelativeUrl, Object punkFile, Int32 cbFile, Object punkFFM, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Obje...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High ...ct varProperties, String bstrCheckinComment, Byte partitionToCheck, Int64 fragmentIdToCheck, String bstrCsvPartitionsToDelete, String bstrLockIdMatch, String bstEtagToMatch,
    Int32 lockType, String lockId, Int32 minutes, Int32 fRefreshLock, Int32 bValidateReqFields, Guid gNewDocId, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage, String& pEtagReturn, Byte& piLevel, Int32& pbIgnoredReqProps) at Microsoft.SharePoint.Library.SPRequest.PutFile(String
    bstrUrl, String bstrWebRelativeUrl, Object punkFile, Int32 cbFile, Object punkFFM, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties,
    String bstrCheckinComment, Byte partitionToCheck, Int64 fragmentIdToCheck...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High ..., String bstrCsvPartitionsToDelete, String bstrLockIdMatch, String bstEtagToMatch, Int32 lockType, String lockId, Int32 minutes, Int32 fRefreshLock, Int32 bValidateReqFields,
    Guid gNewDocId, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage, String& pEtagReturn, Byte& piLevel, Int32& pbIgnoredReqProps) at Microsoft.SharePoint.SPFile.SaveBinaryStreamInternal(Stream file, String checkInComment, Boolean checkRequiredFields,
    Boolean autoCheckoutOnInvalidData, Boolean bIsMigrate, Boolean bIsPublish, Boolean bForceCreateVersion, String lockIdMatch, SPUser modifiedBy, DateTime timeLastModified, Object varProperties, SPFileFragmentPartition partitionToCheck, SPFileFragmentId fragmentIdToCheck,
    SPFileFragmentPartition[] partitionsToDelete, Stream formatMetadata, String etagToMatch, Boolea...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High ...n bSyncUpdate, SPLockType lockType, String lockId, TimeSpan lockTimeout, Boolean refreshLock, Boolean requireWebFilePermissions, Boolean failIfRequiredCheckout, Boolean
    validateReqFields, Guid newDocId, SPVirusCheckStatus& virusCheckStatus, String& virusCheckMessage, String& etagReturn, Boolean& ignoredRequiredProps) at Microsoft.SharePoint.SPFile.SaveBinary(Stream file, Boolean checkRequiredFields, Boolean
    createVersion, String etagMatch, String lockIdMatch, Stream fileFormatMetaInfo, Boolean requireWebFilePermissions, String& etagNew) at Microsoft.SharePoint.SPFile.SaveBinary(Byte[] file) at Microsoft.Office.DocumentManagement.MetadataDefaults.Update()
    at TWINSWCFAPI.LibraryManager.CreatePathFromFolderCollection(String fullPathUrl, SPListItem item, SPWeb web, Dictionary2...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High ... folderToCreate, Boolean setDefaultValues, Boolean mainFolder) at TWINSWCFAPI.LibraryManager.CreatePathFromFolderCollection(String fullPathUrl, List1 resultDataList,
    SPListItem item, SPWeb web, Boolean setDefaultValues, Boolean mainFolder) at TWINSWCFAPI.LibraryManager.CreateExtraFolders(List1
    pathResultDataList, List1 resultDataList, String fullPathUrl, SPWeb web, SPListItem item, Boolean setDefaultValues) at TWINSWCFAPI.LibraryManager.CreateFolders(SPWeb web, List1
    pathResultDataList, SPListItem item, String path, Boolean setDefaultValues) at TWINSWCFAPI.LibraryManager.MoveFileAfterMetaChange(SPListItem item) at TWINSWCFAPI.DocMetadataChangeEventReceiver.DocMetadataChangeEventReceiver.FileDocument(SPWeb web, SPListItem
    listItem) at TWINSWCFAPI.DocMetadataChang...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High ...eEventReceiver.DocMetadataChangeEventReceiver.ItemCheckedIn(SPItemEventProperties properties) at Microsoft.SharePoint.SPEventManager.RunItemEventReceiver(SPItemEventReceiver
    receiver, SPUserCodeInfo userCodeInfo, SPItemEventProperties properties, SPEventContext context, String receiverData) at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, SPUserCodeInfo userCodeInfo, Object properties, SPEventContext
    context, String receiverData) at Microsoft.SharePoint.SPEventManager.<>c__DisplayClassc1.b__6() at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param) at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](SPUserToken
    userToken, Gu...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High ...id tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel) at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](Byte[]
    userTokenBytes, Guid tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel) at Microsoft.SharePoint.SPEventManager.HandleEventCallback[ReceiverType,PropertiesType](Object callbackData) at Microsoft.SharePoint.Utilities.SPThreadPool.WaitCallbackWrapper(Object
    state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.Run(ExecutionContext
    execu...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database fa44 High ...tionContext, ContextCallback callback, Object state) at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
    02/17/2014 16:29:03.26 w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database tzku High ConnectionString: 'Data Source=PFC-SQLUAT-202;Initial Catalog=TWINSDMS_LondonDivision_Content;Integrated Security=True;Enlist=False;Asynchronous Processing=False;Connect
    Timeout=15' ConnectionState: Open ConnectionTimeout: 15
    02/17/2014 16:29:03.26 w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database tzkv High SqlCommand: 'DECLARE @@iRet int;BEGIN TRAN EXEC @@iRet = proc_WriteChunkToAllDocStreams @wssp0, @wssp1, @wssp2, @wssp3, @wssp4, @wssp5, @wssp6;IF @@iRet <> 0 GOTO
    done; DECLARE @@S uniqueidentifier; DECLARE @@W uniqueidentifier; DECLARE @@DocId uniqueidentifier; DECLARE @@DoclibRowId int; DECLARE @@Level tinyint; DECLARE @@DocUIVersion int;DECLARE @@IsCurrentVersion bit; DECLARE @DN nvarchar(256); DECLARE @LN nvarchar(128);
    DECLARE @FU nvarchar(260); SET @DN=@wssp7;SET @@iRet=0; ;SET @LN=@wssp8;SET @FU=@wssp9;SET @@S=@wssp10;SET @@W=@wssp11;SET @@DocUIVersion = 512;IF @@iRet <> 0 GOTO done; ;SET @@Level =@wssp12; EXEC @@iRet = proc_UpdateDocument @@S, @@W, @DN, @LN, @wssp13,
    @wssp14, @wssp15, @wssp16, @wssp17, @wssp18, @wssp19, @wssp20, @wssp21, @wssp22, @wssp23, @wssp24, @wssp25, @wssp26,...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database tzkv High ... @wssp27, @wssp28, @wssp29, @wssp30, @wssp31, @wssp32, @wssp33, @wssp34, @wssp35, @wssp36, @wssp37, @wssp38, @wssp39, @wssp40, @wssp41, @wssp42, @wssp43, @wssp44, @wssp45,
    @wssp46, @wssp47, @wssp48, @wssp49, @wssp50, @wssp51, @@DocId OUTPUT, @@Level OUTPUT , @@DoclibRowId OUTPUT,@wssp52 OUTPUT,@wssp53 OUTPUT,@wssp54 OUTPUT,@wssp55 OUTPUT ; IF @@iRet <> 0 GOTO done; EXEC @@iRet = proc_TransferStream @@S, @@DocId, @@Level,
    @wssp56, @wssp57, @wssp58; IF @@iRet <> 0 GOTO done; EXEC proc_AL @@S,@DN,@LN,@@Level,0,N'London/Broking/Documents/E/E _ E Foods Corporation',N'2012',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,1,N'London/Broking/Documents/E',N'E _ E Foods Corporation',72,85,83,1,N'';EXEC
    proc_AL @@S,@DN,@LN,@@Level,2,N'London/Broking/Documents/E/E _ E Foods Corporation',N'2013',72,85,...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database tzkv High ...83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,3,N'London/Broking/Documents/E/E _ E Foods Corporation/2013',N'QA11G029601',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,4,N'London/Broking/Documents/K',N'Konig
    _ Reeker',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,5,N'London/Broking/Documents/K/Konig _ Reeker',N'2012',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,6,N'London/Broking/Documents/K/Konig _ Reeker/2012',N'QA12E013201',72,85,83,1,N'';EXEC proc_AL
    @@S,@DN,@LN,@@Level,7,N'London/Broking/Documents/K/Konig _ Reeker/2012',N'A12EL00790',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,8,N'London/Broking/Documents/K/Konig _ Reeker/2012',N'A12DA00720',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,9,N'London/Broking/Documents/K/Konig
    _ Reeker/2012',N'A12DC00800',72,85,83,1,N'';EXEC proc...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database tzkv High ..._AL @@S,@DN,@LN,@@Level,10,N'London/Broking/Documents/A',N'Ace European Group Limited',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,11,N'London/Broking/Documents/A/Ace
    European Group Limited',N'2012',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,12,N'London/Broking/Documents/A/Ace European Group Limited/2012',N'JXB88435',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,13,N'London/Broking/Documents/A/Ace European Group
    Limited/2012/JXB88435/Closings',N'PRM 1',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,14,N'London/Broking/Documents/A/Ace European Group Limited/2012/JXB88435/Closings',N'PRM 2',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,15,N'London/Broking/Documents/C',N'C
    Moore-Gordon',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,16,N'London/Broking/Documents/C/C Moore-Gordo...
    02/17/2014 16:29:03.26* w3wp.exe (0x10D0) 0x0DB0 SharePoint Foundation Database tzkv High ...n',N'2012',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,17,N'London/Broking/Documents/C/C Moore-Gordon/2012',N'QY13P700201',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,18,N'London/Broking/Documents/C/C
    Moore-Gordon',N'2013',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,19,N'London/Broking/Documents/C/C Moore-Gordon/2013',N'Y13PF07010',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,20,N'London/Broking/Documents/A/Ace European Group Limited/2012/JXB88435/Closings',N'ARP
    7',72,85,83,1,N'';EXEC proc_AL @@S,@DN,@LN,@@Level,21,N'London/Broking/Documents/A/Ace European Group Limited/2012/JXB88435/Closings',N'ARP 8',72,85,83,1,N'';EXEC proc_AL . . .
    Thanks in advance A

    SharePoint and SQL Server installed on same server or how is the setup?
    i would start to enable the developer dashboard, analyze the report of the developer dashboard...
    you will see if any webpart, or page or sql server query taking too much time.
    http://www.sharepoint-journey.com/developer-dashboard-in-sharepoint-2013.html
    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

  • Query with aggregates over collection of trans. instances throws an error

    Hi, I'm executing a query with aggregates an it throws an exception with the following message "Queries with aggregates or projections using variables currently cannot be executed in-memory. Either set the javax.jdo.option.IgnoreCache property to true, set IgnoreCache to true for this query,
    set the kodo.FlushBeforeQueries property to true, or execute the query before changing any instances in the transaction.
    The offending query was on type "class Pago" with filter "productosServicios.contains(item)".
    The class Pago has the field productosServicios which is a List of Pago$ItemMonto, the relevant code is :
    KodoQuery query = (KodoQuery)pm.newQuery(Pago.class,
    pagos);
    where pagos is a list of transient instances of type Pago.
    query.declareVariables("Pago$ItemMonto item");
    query.setFilter("productosServicios.contains(item)");
    query.setGrouping("item.id");
    query.setResult("item.id as idProductoServicio,
    sum(montoTotal) as montoTotal");
    query.setResultClass(PagoAgrupado.class);
    where the class PagoAgrupado has the corresponding fields idProductoServicio and montoTotal.
    In other words, I want to aggregate the id field of class ItemMonto over the instances contained in the productosServicios field of class Pago.
    I have set to true the ignoreCache and kodo.FlushBeforeQueries flags in the kodo.properties file and in the instances of the pm and the query but it has not worked, what can be wrong?.
    I'm using Kodo 3.2.4, MySQL 5.0
    Thanks,
    Jaime.
    Message was edited by:
    jdelajaraf

    Thanks, you nailed it! I tried comparing the two files myself, but Bridge told me that the 72.009 dpi document was 72 dpi.
    I have no idea why the resolution mess things up, but as long as I know how to avoid the bug, things are grand!

  • Slow query execution time

    Hi,
    I have a query which fetches around 100 records from a table which has approximately 30 million records. Unfortunately, I have to use the same table and can't go ahead with a new table.
    The query executes within a second from RapidSQL. The problem I'm facing is it takes more than 10 minutes when I run it through the Java application. It doesn't throw any exceptions, it executes properly.
    The query:
    SELECT aaa, bbb, SUM(ccc), SUM(ddd), etc
    FROM MyTable
    WHERE SomeDate= date_entered_by_user  AND SomeString IN ("aaa","bbb")
    GROUP BY aaa,bbbI have an existing clustered index on SomeDate and SomeString fields.
    To check I replaced the where clause with
    WHERE SomeDate= date_entered_by_user  AND SomeString = "aaa"No improvements.
    What could be the problem?
    Thank you,
    Lobo

    It's hard for me to see how a stored proc will address this problem. I don't think it changes anything. Can you explain? The problem is slow query execution time. One way to speed up the execution time inside the RDBMS is to streamline the internal operations inside the interpreter.
    When the engine receives a command to execute a SQL statement, it does a few things before actually executing the statement. These things take time. First, it checks to make sure there are no syntax errors in the SQL statement. Second, it checks to make sure all of the tables, columns and relationships "are in order." Third, it formulates an execution plan. This last step takes the most time out of the three. But, they all take time. The speed of these processes may vary from product to product.
    When you create a stored procedure in a RDBMS, the processes above occur when you create the procedure. Most importantly, once an execution plan is created it is stored and reused whenever the stored procedure is ran. So, whenever an application calls the stored procedure, the execution plan has already been created. The engine does not have to anaylze the SELECT|INSERT|UPDATE|DELETE statements and create the plan (over and over again).
    The stored execution plan will enable the engine to execute the query faster.
    />

  • Find a slow query

    Hi all,
    I have two questions about the SQL tuning:
    There are many open sessions for an Oracle database,
    (1) How to find the session that runs a slow query?
    (2) How to locate / find this slow query so that the query can be tuned?
    Thanks a lot.

    Hi,
    (1) How to find the session that runs a slow query?This can be coming up from the wait events that the sessions are waiting for.So you can check V$session_wait to see that which are the sessions which are waiting for some thing to happen and for that reason have become slow.Also you can take the advantage of ASH in 10g to tell you the same if you want to drill down your search for last few minutes.
    (2) How to locate / find this slow query so that the query can be tuned?IF you read Optimizing OralcePerformance, this is the first thing that Carry asks to address and take extreme caution in doing it.Ask the user that which business process is slow.It will vary depending upon the business.There is nothing called ,"we are slow" and there is no such thing that "tune it all".We have to tune the main area or the maximum benefit giving area only.Ask the user which query/report he is running which he wants to get optimized.You can also take advantage or statspack/AWR report to go for the particular query depending upon the wait event.If you know the query than trace the query to see what is happening.I shall suggest 10046 trace forthe query as its more wider and imparts mch more info as compared to tkprof but you can pick what you want/like.
    HTH
    Aman....

  • How does u find whether query touches aggregates or not?

    Hi gurus
         How does u find whether query touches aggregates or not?
    Thanks in advance
    Raj

    Hi Rajaiah.
    You can test this from TA RSRT -> Execute and debug -> Display aggregate found.
    Hope it helps.
    BR
    Stefan

  • Stumbled on the slow query, Can any one look into it, Y it is so slow

    I just stumbled on the slow query . Can any one please guess why this querie is so slow, do i need to change anything in it
    Pid=32521 Tid=2884070320 03/26/2011 07:54:19.176 - Cursor wm09_2_49107 took 27996 ms elapsed time and 27995 ms db time for 1 fetches. sql string:
    SELECT ALLOC_INVN_DTL.ALLOC_INVN_DTL_ID, ALLOC_INVN_DTL.WHSE, ALLOC_INVN_DTL.SKU_ID, ALLOC_INVN_DTL.INVN_TYPE, ALLOC_INVN_DTL.PROD_STAT, ALLOC_INVN_DTL.BATCH_NBR, ALLOC_INVN_DTL.SKU_ATTR_1, ALLOC_INVN_DTL.SKU_ATTR_2, ALLOC_INVN_DTL.SKU_ATTR_3, ALLOC_INVN_DTL.SKU_ATTR_4, ALLOC_INVN_DTL.SKU_ATTR_5, ALLOC_INVN_DTL.CNTRY_OF_ORGN, ALLOC_INVN_DTL.ALLOC_INVN_CODE, ALLOC_INVN_DTL.CNTR_NBR, ALLOC_INVN_DTL.TRANS_INVN_TYPE, ALLOC_INVN_DTL.PULL_LOCN_ID, ALLOC_INVN_DTL.INVN_NEED_TYPE, ALLOC_INVN_DTL.TASK_TYPE, ALLOC_INVN_DTL.TASK_PRTY, ALLOC_INVN_DTL.TASK_BATCH, ALLOC_INVN_DTL.ALLOC_UOM, ALLOC_INVN_DTL.ALLOC_UOM_QTY, ALLOC_INVN_DTL.QTY_PULLD, ALLOC_INVN_DTL.FULL_CNTR_ALLOCD, ALLOC_INVN_DTL.ORIG_REQMT, ALLOC_INVN_DTL.QTY_ALLOC, ALLOC_INVN_DTL.DEST_LOCN_ID, ALLOC_INVN_DTL.TASK_GENRTN_REF_CODE, ALLOC_INVN_DTL.TASK_GENRTN_REF_NBR, ALLOC_INVN_DTL.TASK_CMPL_REF_CODE, ALLOC_INVN_DTL.TASK_CMPL_REF_NBR, ALLOC_INVN_DTL.ERLST_START_DATE_TIME, ALLOC_INVN_DTL.LTST_START_DATE_TIME, ALLOC_INVN_DTL.LTST_CMPL_DATE_TIME, ALLOC_INVN_DTL.NEED_ID, ALLOC_INVN_DTL.STAT_CODE, ALLOC_INVN_DTL.CREATE_DATE_TIME, ALLOC_INVN_DTL.MOD_DATE_TIME, ALLOC_INVN_DTL.USER_ID, ALLOC_INVN_DTL.PKT_CTRL_NBR, ALLOC_INVN_DTL.REQD_INVN_TYPE, ALLOC_INVN_DTL.REQD_PROD_STAT, ALLOC_INVN_DTL.REQD_BATCH_NBR, ALLOC_INVN_DTL.REQD_SKU_ATTR_1, ALLOC_INVN_DTL.REQD_SKU_ATTR_2, ALLOC_INVN_DTL.REQD_SKU_ATTR_3, ALLOC_INVN_DTL.REQD_SKU_ATTR_4, ALLOC_INVN_DTL.REQD_SKU_ATTR_5, ALLOC_INVN_DTL.REQD_CNTRY_OF_ORGN, ALLOC_INVN_DTL.PKT_SEQ_NBR, ALLOC_INVN_DTL.CARTON_NBR, ALLOC_INVN_DTL.CARTON_SEQ_NBR, ALLOC_INVN_DTL.PIKR_NBR, ALLOC_INVN_DTL.PULL_LOCN_SEQ_NBR, ALLOC_INVN_DTL.DEST_LOCN_SEQ_NBR, ALLOC_INVN_DTL.TASK_CMPL_REF_NBR_SEQ, ALLOC_INVN_DTL.SUBSTITUTION_FLAG, ALLOC_INVN_DTL.MISC_ALPHA_FIELD_1, ALLOC_INVN_DTL.MISC_ALPHA_FIELD_2, ALLOC_INVN_DTL.MISC_ALPHA_FIELD_3, ALLOC_INVN_DTL.CD_MASTER_ID FROM ALLOC_INVN_DTL WHERE ( ( ( ( ( ( ALLOC_INVN_DTL.TASK_CMPL_REF_CODE = :1 ) AND ( ALLOC_INVN_DTL.TASK_CMPL_REF_NBR = :2 ) ) AND ( ALLOC_INVN_DTL.SKU_ID = :3 ) ) AND ( ALLOC_INVN_DTL.CNTR_NBR = :4 ) ) AND ( ALLOC_INVN_DTL.STAT_CODE < 1 ) ) AND ( ALLOC_INVN_DTL.PULL_LOCN_ID IS NULL ) )
    input variables
    1: Address(0xabe74300) Length(0) Type(8) "2" - No Indicator
    2: Address(0x8995474) Length(0) Type(8) "PERP014119" - No Indicator
    3: Address(0xab331f1c) Length(0) Type(8) "MB57545217" - No Indicator
    4: Address(0xab31e32c) Length(0) Type(8) "T0000000000000078257" - No Indicator

    784786 wrote:
    I just stumbled on the slow query . Can any one please guess why this querie is so slow, do i need to change anything in it
    Pid=32521 Tid=2884070320 03/26/2011 07:54:19.176 - Cursor wm09_2_49107 took 27996 ms elapsed time and 27995 ms db time for 1 fetches. sql string:
    SELECT ALLOC_INVN_DTL.ALLOC_INVN_DTL_ID, ALLOC_INVN_DTL.WHSE, ALLOC_INVN_DTL.SKU_ID, ALLOC_INVN_DTL.INVN_TYPE, ALLOC_INVN_DTL.PROD_STAT, ALLOC_INVN_DTL.BATCH_NBR, ALLOC_INVN_DTL.SKU_ATTR_1, ALLOC_INVN_DTL.SKU_ATTR_2, ALLOC_INVN_DTL.SKU_ATTR_3, ALLOC_INVN_DTL.SKU_ATTR_4, ALLOC_INVN_DTL.SKU_ATTR_5, ALLOC_INVN_DTL.CNTRY_OF_ORGN, ALLOC_INVN_DTL.ALLOC_INVN_CODE, ALLOC_INVN_DTL.CNTR_NBR, ALLOC_INVN_DTL.TRANS_INVN_TYPE, ALLOC_INVN_DTL.PULL_LOCN_ID, ALLOC_INVN_DTL.INVN_NEED_TYPE, ALLOC_INVN_DTL.TASK_TYPE, ALLOC_INVN_DTL.TASK_PRTY, ALLOC_INVN_DTL.TASK_BATCH, ALLOC_INVN_DTL.ALLOC_UOM, ALLOC_INVN_DTL.ALLOC_UOM_QTY, ALLOC_INVN_DTL.QTY_PULLD, ALLOC_INVN_DTL.FULL_CNTR_ALLOCD, ALLOC_INVN_DTL.ORIG_REQMT, ALLOC_INVN_DTL.QTY_ALLOC, ALLOC_INVN_DTL.DEST_LOCN_ID, ALLOC_INVN_DTL.TASK_GENRTN_REF_CODE, ALLOC_INVN_DTL.TASK_GENRTN_REF_NBR, ALLOC_INVN_DTL.TASK_CMPL_REF_CODE, ALLOC_INVN_DTL.TASK_CMPL_REF_NBR, ALLOC_INVN_DTL.ERLST_START_DATE_TIME, ALLOC_INVN_DTL.LTST_START_DATE_TIME, ALLOC_INVN_DTL.LTST_CMPL_DATE_TIME, ALLOC_INVN_DTL.NEED_ID, ALLOC_INVN_DTL.STAT_CODE, ALLOC_INVN_DTL.CREATE_DATE_TIME, ALLOC_INVN_DTL.MOD_DATE_TIME, ALLOC_INVN_DTL.USER_ID, ALLOC_INVN_DTL.PKT_CTRL_NBR, ALLOC_INVN_DTL.REQD_INVN_TYPE, ALLOC_INVN_DTL.REQD_PROD_STAT, ALLOC_INVN_DTL.REQD_BATCH_NBR, ALLOC_INVN_DTL.REQD_SKU_ATTR_1, ALLOC_INVN_DTL.REQD_SKU_ATTR_2, ALLOC_INVN_DTL.REQD_SKU_ATTR_3, ALLOC_INVN_DTL.REQD_SKU_ATTR_4, ALLOC_INVN_DTL.REQD_SKU_ATTR_5, ALLOC_INVN_DTL.REQD_CNTRY_OF_ORGN, ALLOC_INVN_DTL.PKT_SEQ_NBR, ALLOC_INVN_DTL.CARTON_NBR, ALLOC_INVN_DTL.CARTON_SEQ_NBR, ALLOC_INVN_DTL.PIKR_NBR, ALLOC_INVN_DTL.PULL_LOCN_SEQ_NBR, ALLOC_INVN_DTL.DEST_LOCN_SEQ_NBR, ALLOC_INVN_DTL.TASK_CMPL_REF_NBR_SEQ, ALLOC_INVN_DTL.SUBSTITUTION_FLAG, ALLOC_INVN_DTL.MISC_ALPHA_FIELD_1, ALLOC_INVN_DTL.MISC_ALPHA_FIELD_2, ALLOC_INVN_DTL.MISC_ALPHA_FIELD_3, ALLOC_INVN_DTL.CD_MASTER_ID FROM ALLOC_INVN_DTL WHERE ( ( ( ( ( ( ALLOC_INVN_DTL.TASK_CMPL_REF_CODE = :1 ) AND ( ALLOC_INVN_DTL.TASK_CMPL_REF_NBR = :2 ) ) AND ( ALLOC_INVN_DTL.SKU_ID = :3 ) ) AND ( ALLOC_INVN_DTL.CNTR_NBR = :4 ) ) AND ( ALLOC_INVN_DTL.STAT_CODE < 1 ) ) AND ( ALLOC_INVN_DTL.PULL_LOCN_ID IS NULL ) )
    input variables
    1: Address(0xabe74300) Length(0) Type(8) "2" - No Indicator
    2: Address(0x8995474) Length(0) Type(8) "PERP014119" - No Indicator
    3: Address(0xab331f1c) Length(0) Type(8) "MB57545217" - No Indicator
    4: Address(0xab31e32c) Length(0) Type(8) "T0000000000000078257" - No IndicatorWithout more information I cannot tell you why it is slow, but I can certainly tell you why it is impossible to read.
    Just because sql allows unformatted query text does not mean it is a good idea. Why not bring some sanity to this for your own sake, not to mention that of people from whom you are expecting to actually read and analyze this mess. I wish someone could explain to me why people write these long stream-of-consciousness queries.
    When posting to this forum you should use the code tags to bracket your code and preserve the formatting. Then the code should actually be formatted:
    SELECT
         ALLOC_INVN_DTL.ALLOC_INVN_DTL_ID,
         ALLOC_INVN_DTL.WHSE,
         ALLOC_INVN_DTL.SKU_ID,
         ALLOC_INVN_DTL.INVN_TYPE,
         ALLOC_INVN_DTL.PROD_STAT,
         ALLOC_INVN_DTL.BATCH_NBR,
         ALLOC_INVN_DTL.SKU_ATTR_1,
         ALLOC_INVN_DTL.SKU_ATTR_2,
         ALLOC_INVN_DTL.SKU_ATTR_3,
         ALLOC_INVN_DTL.SKU_ATTR_4,
         ALLOC_INVN_DTL.SKU_ATTR_5,
         ALLOC_INVN_DTL.CNTRY_OF_ORGN,
         ALLOC_INVN_DTL.ALLOC_INVN_CODE,
         ALLOC_INVN_DTL.CNTR_NBR,
         ALLOC_INVN_DTL.TRANS_INVN_TYPE,
         ALLOC_INVN_DTL.PULL_LOCN_ID,
         ALLOC_INVN_DTL.INVN_NEED_TYPE,
         ALLOC_INVN_DTL.TASK_TYPE,
         ALLOC_INVN_DTL.TASK_PRTY,
         ALLOC_INVN_DTL.TASK_BATCH,
         ALLOC_INVN_DTL.ALLOC_UOM,
         ALLOC_INVN_DTL.ALLOC_UOM_QTY,
         ALLOC_INVN_DTL.QTY_PULLD,
         ALLOC_INVN_DTL.FULL_CNTR_ALLOCD,
         ALLOC_INVN_DTL.ORIG_REQMT,
         ALLOC_INVN_DTL.QTY_ALLOC,
         ALLOC_INVN_DTL.DEST_LOCN_ID,
         ALLOC_INVN_DTL.TASK_GENRTN_REF_CODE,
         ALLOC_INVN_DTL.TASK_GENRTN_REF_NBR,
         ALLOC_INVN_DTL.TASK_CMPL_REF_CODE,
         ALLOC_INVN_DTL.TASK_CMPL_REF_NBR,
         ALLOC_INVN_DTL.ERLST_START_DATE_TIME,
         ALLOC_INVN_DTL.LTST_START_DATE_TIME,
         ALLOC_INVN_DTL.LTST_CMPL_DATE_TIME,
         ALLOC_INVN_DTL.NEED_ID,
         ALLOC_INVN_DTL.STAT_CODE,
         ALLOC_INVN_DTL.CREATE_DATE_TIME,
         ALLOC_INVN_DTL.MOD_DATE_TIME,
         ALLOC_INVN_DTL.USER_ID,
         ALLOC_INVN_DTL.PKT_CTRL_NBR,      
         ALLOC_INVN_DTL.REQD_INVN_TYPE,      
         ALLOC_INVN_DTL.REQD_PROD_STAT,
         ALLOC_INVN_DTL.REQD_BATCH_NBR,
         ALLOC_INVN_DTL.REQD_SKU_ATTR_1,
         ALLOC_INVN_DTL.REQD_SKU_ATTR_2,
         ALLOC_INVN_DTL.REQD_SKU_ATTR_3,
         ALLOC_INVN_DTL.REQD_SKU_ATTR_4,
         ALLOC_INVN_DTL.REQD_SKU_ATTR_5,
         ALLOC_INVN_DTL.REQD_CNTRY_OF_ORGN,
         ALLOC_INVN_DTL.PKT_SEQ_NBR,
         ALLOC_INVN_DTL.CARTON_NBR,
         ALLOC_INVN_DTL.CARTON_SEQ_NBR,
         ALLOC_INVN_DTL.PIKR_NBR,
         ALLOC_INVN_DTL.PULL_LOCN_SEQ_NBR,
         ALLOC_INVN_DTL.DEST_LOCN_SEQ_NBR,
         ALLOC_INVN_DTL.TASK_CMPL_REF_NBR_SEQ,
         ALLOC_INVN_DTL.SUBSTITUTION_FLAG,
         ALLOC_INVN_DTL.MISC_ALPHA_FIELD_1,
         ALLOC_INVN_DTL.MISC_ALPHA_FIELD_2,
         ALLOC_INVN_DTL.MISC_ALPHA_FIELD_3,
         ALLOC_INVN_DTL.CD_MASTER_ID
    FROM ALLOC_INVN_DTL
    WHERE (
                 ( ALLOC_INVN_DTL.TASK_CMPL_REF_CODE = :1
                    AND ( ALLOC_INVN_DTL.TASK_CMPL_REF_NBR = :2
                  AND ( ALLOC_INVN_DTL.SKU_ID = :3
                AND ( ALLOC_INVN_DTL.CNTR_NBR = :4
              AND ( ALLOC_INVN_DTL.STAT_CODE < 1
            AND ( ALLOC_INVN_DTL.PULL_LOCN_ID IS NULL
          )Now, since you are only selecting from one table, there is no need to clutter up the query by qualifying every column name with the table name. Let's simplify with this:
    SELECT
         ALLOC_INVN_DTL_ID,
         WHSE,
         SKU_ID,
         INVN_TYPE,
         PROD_STAT,
         BATCH_NBR,
         SKU_ATTR_1,
         SKU_ATTR_2,
         SKU_ATTR_3,
         SKU_ATTR_4,
         SKU_ATTR_5,
         CNTRY_OF_ORGN,
         ALLOC_INVN_CODE,
         CNTR_NBR,
         TRANS_INVN_TYPE,
         PULL_LOCN_ID,
         INVN_NEED_TYPE,
         TASK_TYPE,
         TASK_PRTY,
         TASK_BATCH,
         ALLOC_UOM,
         ALLOC_UOM_QTY,
         QTY_PULLD,
         FULL_CNTR_ALLOCD,
         ORIG_REQMT,
         QTY_ALLOC,
         DEST_LOCN_ID,
         TASK_GENRTN_REF_CODE,
         TASK_GENRTN_REF_NBR,
         TASK_CMPL_REF_CODE,
         TASK_CMPL_REF_NBR,
         ERLST_START_DATE_TIME,
         LTST_START_DATE_TIME,
         LTST_CMPL_DATE_TIME,
         NEED_ID,
         STAT_CODE,
         CREATE_DATE_TIME,
         MOD_DATE_TIME,
         USER_ID,
         PKT_CTRL_NBR,      
         REQD_INVN_TYPE,      
         REQD_PROD_STAT,
         REQD_BATCH_NBR,
         REQD_SKU_ATTR_1,
         REQD_SKU_ATTR_2,
         REQD_SKU_ATTR_3,
         REQD_SKU_ATTR_4,
         REQD_SKU_ATTR_5,
         REQD_CNTRY_OF_ORGN,
         PKT_SEQ_NBR,
         CARTON_NBR,
         CARTON_SEQ_NBR,
         PIKR_NBR,
         PULL_LOCN_SEQ_NBR,
         DEST_LOCN_SEQ_NBR,
         TASK_CMPL_REF_NBR_SEQ,
         SUBSTITUTION_FLAG,
         MISC_ALPHA_FIELD_1,
         MISC_ALPHA_FIELD_2,
         MISC_ALPHA_FIELD_3,
         CD_MASTER_ID
    FROM ALLOC_INVN_DTL
    WHERE (
                 ( TASK_CMPL_REF_CODE = :1
                    AND ( TASK_CMPL_REF_NBR = :2
                  AND ( SKU_ID = :3
                AND ( CNTR_NBR = :4
              AND ( STAT_CODE < 1
            AND ( PULL_LOCN_ID IS NULL
          )And finally, your WHERE clause is a simple string of AND conditions, there was no need to complicate it with all of the nested parentheses. Much simpler:
    WHERE ALLOC_INVN_DTL.TASK_CMPL_REF_CODE = :1
       AND  ALLOC_INVN_DTL.TASK_CMPL_REF_NBR = :2
       AND  ALLOC_INVN_DTL.SKU_ID = :3
       AND  ALLOC_INVN_DTL.CNTR_NBR = :4
       AND  ALLOC_INVN_DTL.STAT_CODE < 1
       AND  ALLOC_INVN_DTL.PULL_LOCN_ID IS NULL
               None of the above makes a whit of difference in your query performance, but if you worked in my office, I would make you clean it up before I even attempted to do a performance analysis.
    Edited by: EdStevens on Mar 26, 2011 2:14 PM

  • Query on Aggregate

    Hi Gurus,
    I am into archiving, and my question is we have an infocube with some aggregates, So i want to know how queries are created for the aggregates and how it is accessible, as per my knowledge, the query defined to the infocube for which aggregates exists, is this the same query which also gets the results for the aggregates according to the query definition.
      My question if i change or do anything with the infocube, does it affect the aggregates. Can anyone please let me know on this, and when it is possible to query the aggregates separately. Query can be created only for a particular aggregated cube. Can anyone please let me on this.
    Thanks,
    Hem

    Hello Hem,
    it is completely transparent to the user if and which aggregates are used when executing a query. Only in debug mode (transaction RSRT) you can force the system to use (or not use) an aggregate.
    If you make changes to the InfoCube, you might have to rebuild the aggregates. Reasons among others
    - If you add or change any key figure
    - If you change a characteristic that's used in the aggregate
    - If you change a hierarchy that is used in the aggregate
    Regards,
    Marc
    SAP NetWeaver RIG

  • Slow query against seg$ - Oracle 10g

    Hi,
    Our AWR report shows the following slow query, 3 minutes per execution,
    select file#, block# from seg$ where type# = 3 and ts# = :1
    This query isn't from our application for sure. Does anyone know what backgroud jobs or processes may execute this query?
    Thanks.

    user632535 wrote:
    Hi,
    Our AWR report shows the following slow query, 3 minutes per execution,
    select file#, block# from seg$ where type# = 3 and ts# = :1
    This query isn't from our application for sure. Does anyone know what backgroud jobs or processes may execute this query?
    It looks like the type of thing the SMON would run to clear up temporary segments after a process has done a rebuild, move, drop or similar. One reason why it might be slow is if you have a very large number of objects in a given tablespace that is subject to a lot of drops, creates etc. (E.g. a tablespace holding a complicated composite partitioned object with lots of indexes that goes through a frequent cycle of add/drop partition).
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    "The temptation to form premature theories upon insufficient data is the bane of our profession."
    Sherlock Holmes (Sir Arthur Conan Doyle) in "The Valley of Fear".

  • Slow Query: Join rows from table A with first match in table B

    Hi,
    I have been struggling with this for days. It is very slow:
    With table with 4.5 mio records it took over 2h.
    Records with anType 2 and 3 4 mio.
    Records with anType 1 and 4 500,000
    Different acWarehouse values: 20
    Different acIdent values: 9799
    Could this be written in any other way so that it would be faster.
    anId | acWarehouse | acIdent | anType | anQty | anTotalQuantity
    1| WarehouseA | IdentA | 1 | 100 | 100
    2| WarehouseA | IdentA | 1 | 100 | 200
    3| WarehouseA | IdentA | 1 | 100 | 300
    4| WarehouseA | IdentA | 1 | 100 | 400
    5| WarehouseA | IdentA | 2 | -100 | 100
    6| WarehouseA | IdentA | 2 | -100 | 200
    7| WarehouseA | IdentA | 2 | -100 | 300
    8| WarehouseA | IdentA | 2 | -100 | 400
    Result should be:
    anId | anEdge_Transaction_Id | anQuantity
    5| 1| 100
    6| 2 | 100
    7| 3 | 100
    8| 4 | 100
    Table definition:
    CREATE TABLE iPA_Transaction
         ANID     NUMBER(9,0) -- PRIMARY KEY
    ,     ACWAREHOUSE     VARCHAR2(30 CHAR)
    ,     ACIDENT     VARCHAR2(16 CHAR)
    ,     ANTYPE     NUMBER(1)
    ,     ANQTY     NUMBER(19,4)
    ,     ANTOTALQUANTITY NUMBER(19,4) -- RUNNING TOTAL
    ALTER TABLE iPA_Transaction ADD CONSTRAINT PK_Transaction PRIMARY KEY (anId);
    CREATE INDEX IX_Transaction_TEST4 ON iPA_Transaction(acIdent,acWarehouse,anType,anTotalQuantity);
    CREATE TYPE edge_transaction_data AS OBJECT (
         anId NUMBER(9,0)
    ,     anEdge_Transaction_Id NUMBER(9,0)
    ,     anQuantity NUMBER(19,4)
    CREATE TYPE edge_transaction AS TABLE OF edge_transaction_data;
    /Query:
         SELECT
              iPA_Transaction.anId
         ,     first_transaction.anEdge_Transaction_Id
         ,     first_transaction.anQuantity
         FROM
              iPA_Transaction
              INNER JOIN TABLE(
                   CAST(
                        MULTISET(
                             SELECT
                                  iPA_Transaction.anId
                             ,     MIN(transaction_stock.anId) KEEP (DENSE_RANK FIRST ORDER BY transaction_stock.anTotalQuantity) AS anEdge_Transaction_Id
                             ,     MIN(transaction_stock.anTotalQuantity) KEEP (DENSE_RANK FIRST ORDER BY transaction_stock.anTotalQuantity) AS anTotalQuantity
                             FROM
                                  iPA_Transaction transaction_stock
                             WHERE
                                  transaction_stock.anType IN (1,4)
                             AND transaction_stock.acIdent = iPA_Transaction.acIdent
                             AND transaction_stock.acWarehouse = iPA_Transaction.acWarehouse
                             AND transaction_stock.anTotalQuantity > (iPA_Transaction.antotalquantity + iPA_Transaction.anqty)
                        ) AS edge_transaction
              ) first_transaction ON (iPA_Transaction.anId = first_transaction.anId)
         WHERE
              iPA_Transaction.anType IN (2,3)
         ;-- EXECUTION PLAN
    PLAN_TABLE_OUTPUT
    Plan hash value: 1731335374
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 6634 | 362K| 107M (1)|357:36:32 |
    | 1 | NESTED LOOPS | | 6634 | 362K| 107M (1)|357:36:32 |
    |* 2 | TABLE ACCESS FULL | IPA_TRANSACTION | 3946K| 203M| 15004 (1)| 00:03:01 |
    |* 3 | COLLECTION ITERATOR SUBQUERY FETCH| | 1 | 2 | 27 (0)| 00:00:01 |
    | 4 | VIEW | | 1 | 39 | 6 (0)| 00:00:01 |
    | 5 | SORT AGGREGATE | | 1 | 50 | | |
    | 6 | INLIST ITERATOR | | | | | |
    | 7 | TABLE ACCESS BY INDEX ROWID | IPA_TRANSACTION | 1 | 50 | 6 (0)| 00:00:01 |
    |* 8 | INDEX RANGE SCAN | IX_TRANSACTION_TEST4 | 1 | | 5 (0)| 00:00:01 |
    Query Block Name / Object Alias (identified by operation id):
    1 - SEL$80EA2A9E
    2 - SEL$80EA2A9E / IPA_TRANSACTION@SEL$1
    3 - SEL$80EA2A9E / KOKBF$@SEL$2
    4 - SEL$4 / KOKSDML$@SEL$540AC7B0
    5 - SEL$4
    7 - SEL$4 / TRANSACTION_STOCK@SEL$4
    8 - SEL$4 / TRANSACTION_STOCK@SEL$4
    Predicate Information (identified by operation id):
    2 - filter("IPA_TRANSACTION"."ANTYPE"=2 OR "IPA_TRANSACTION"."ANTYPE"=3)
    3 - filter("IPA_TRANSACTION"."ANID"=SYS_OP_ATG(VALUE(KOKBF$),1,2,2))
    8 - access("TRANSACTION_STOCK"."ACIDENT"=:B1 AND "TRANSACTION_STOCK"."ACWAREHOUSE"=:B2 AND
    ("TRANSACTION_STOCK"."ANTYPE"=1 OR "TRANSACTION_STOCK"."ANTYPE"=4) AND
    "TRANSACTION_STOCK"."ANTOTALQUANTITY">:B3+:B4 AND "TRANSACTION_STOCK"."ANTOTALQUANTITY" IS NOT NULL)
    Column Projection Information (identified by operation id):
    1 - (#keys=0) "IPA_TRANSACTION"."ANID"[NUMBER,22],
    "IPA_TRANSACTION"."ACWAREHOUSE"[VARCHAR2,120], "IPA_TRANSACTION"."ACIDENT"[VARCHAR2,64],
    "IPA_TRANSACTION"."ANTYPE"[NUMBER,22], "IPA_TRANSACTION"."ANQTY"[NUMBER,22],
    "IPA_TRANSACTION"."ANTOTALQUANTITY"[NUMBER,22], VALUE(A0)[96]
    2 - "IPA_TRANSACTION"."ANID"[NUMBER,22], "IPA_TRANSACTION"."ACWAREHOUSE"[VARCHAR2,120],
    "IPA_TRANSACTION"."ACIDENT"[VARCHAR2,64], "IPA_TRANSACTION"."ANTYPE"[NUMBER,22],
    "IPA_TRANSACTION"."ANQTY"[NUMBER,22], "IPA_TRANSACTION"."ANTOTALQUANTITY"[NUMBER,22]
    3 - VALUE(A0)[96]
    4 - "KOKSDML$"."KOKSDML$_C00000"[NUMBER,22], "KOKSDML$"."ANEDGE_TRANSACTION_ID"[NUMBER,22],
    "KOKSDML$"."ANTOTALQUANTITY"[NUMBER,22]
    5 - (#keys=0) MIN("TRANSACTION_STOCK"."ANTOTALQUANTITY") KEEP (DENSE_RANK FIRST ORDER BY
    "TRANSACTION_STOCK"."ANTOTALQUANTITY")[22], MIN("TRANSACTION_STOCK"."ANID") KEEP (DENSE_RANK FIRST
    ORDER BY "TRANSACTION_STOCK"."ANTOTALQUANTITY")[22]
    6 - "TRANSACTION_STOCK".ROWID[ROWID,10], "TRANSACTION_STOCK"."ANID"[NUMBER,22],
    "TRANSACTION_STOCK"."ACWAREHOUSE"[VARCHAR2,120], "TRANSACTION_STOCK"."ACIDENT"[VARCHAR2,64],
    "TRANSACTION_STOCK"."ANTYPE"[NUMBER,22], "TRANSACTION_STOCK"."ANTOTALQUANTITY"[NUMBER,22]
    7 - "TRANSACTION_STOCK".ROWID[ROWID,10], "TRANSACTION_STOCK"."ANID"[NUMBER,22],
    "TRANSACTION_STOCK"."ACWAREHOUSE"[VARCHAR2,120], "TRANSACTION_STOCK"."ACIDENT"[VARCHAR2,64],
    "TRANSACTION_STOCK"."ANTYPE"[NUMBER,22], "TRANSACTION_STOCK"."ANTOTALQUANTITY"[NUMBER,22]
    8 - "TRANSACTION_STOCK".ROWID[ROWID,10], "TRANSACTION_STOCK"."ACIDENT"[VARCHAR2,64],
    "TRANSACTION_STOCK"."ACWAREHOUSE"[VARCHAR2,120], "TRANSACTION_STOCK"."ANTYPE"[NUMBER,22],
    "TRANSACTION_STOCK"."ANTOTALQUANTITY"[NUMBER,22]
    Edited by: 939464 on 08-Jun-2012 02:30
    Edited by: 939464 on 08-Jun-2012 02:32
    Edited by: 939464 on 08-Jun-2012 02:36
    Edited by: 939464 on 08-Jun-2012 04:39

    Additional to what has just been said by Hoek, which I also quote, I feel this could be a problem similar to the one posted here.
    [url:https://forums.oracle.com/forums/thread.jspa?threadID=2387388]SQL - Which positive covered the negative?
    Could you please let us know a bit more about the logic of the output?
    1) Do you want to know which transaction with positive quantity cover the current transaction with negative quantity?
    2) How does it need to be partitioned?
    3) Are the quantity always equal for corresponding transaction?
    If I just look at your data I can do something really simple but it might be not what you need.
    CREATE TABLE iPA_Transaction
    ANID NUMBER(9,0) -- PRIMARY KEY
    , ACWAREHOUSE VARCHAR2(30 CHAR)
    , ACIDENT VARCHAR2(16 CHAR)
    , ANTYPE NUMBER(1)
    , ANQTY NUMBER(19,4)
    , ANTOTALQUANTITY NUMBER(19,4) -- RUNNING TOTAL
    ALTER TABLE iPA_Transaction ADD CONSTRAINT PK_Transaction PRIMARY KEY (anId);
    CREATE INDEX IX_Transaction_TEST4 ON iPA_Transaction(acIdent,acWarehouse,anType,anTotalQuantity);
    INSERT INTO iPA_Transaction VALUES(1, 'WarehouseA', 'IdentA', 1 , 100, 100);
    INSERT INTO iPA_Transaction VALUES(2, 'WarehouseA', 'IdentA', 1 , 100, 200);
    INSERT INTO iPA_Transaction VALUES(3, 'WarehouseA', 'IdentA', 1 , 100, 300);
    INSERT INTO iPA_Transaction VALUES(4, 'WarehouseA', 'IdentA', 1 , 100, 400);
    INSERT INTO iPA_Transaction VALUES(5, 'WarehouseA', 'IdentA', 2 , -100, 100);
    INSERT INTO iPA_Transaction VALUES(6, 'WarehouseA', 'IdentA', 2 , -100, 200);
    INSERT INTO iPA_Transaction VALUES(7, 'WarehouseA', 'IdentA', 2 , -100, 300);
    INSERT INTO iPA_Transaction VALUES(8, 'WarehouseA', 'IdentA', 2 , -100, 400);
    SELECT a.anid, b.anid anedge_transaction_id, -a.anqty anqty
      FROM ipa_transaction a, ipa_transaction b
    WHERE     a.acwarehouse = b.acwarehouse
           AND a.acident = b.acident
           AND a.antype IN (2, 4)
           AND b.antype IN (1, 4)
           AND a.antotalquantity = b.antotalquantity;
          ANID ANEDGE_TRANSACTION_ID      ANQTY
             5                     1        100
             6                     2        100
             7                     3        100
             8                     4        100
    {code}
    Try to give additional details.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Slow query times with "contains" and "or"

    We're running Oracle 9.2.0.4 on RHEL 3
    I have a simple table - "docinfo". I've create a multicolumn Text index for docinfo called "repoidx". I have five cases below with the fourth one being the most difficult to understand. I have a primary key for "docinfo" but do nott have any additional indexes on "docinfo" right now because we're still testing the design. I'm curious about what is magical about using "or" plus "contains" in the same query (case 4).
    [case 1 - simple like]
    select count(docid)
    from sa.docinfo
    where
    author like '%smith%'
    Elapsed: 00:00:00.02
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1468 Card=1 Bytes=15)
    1 0 SORT (AGGREGATE)
    2 1 TABLE ACCESS (FULL) OF 'DOCINFO' (Cost=1468 Card=12004 Bytes=180060)
    [case 2 - simple contains]
    select count(docid)
    from sa.docinfo
    where contains(repoidx,'facts')>0
    Elapsed: 00:00:01.00
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3905 Card=1 Bytes=12)
    1 0 SORT (AGGREGATE)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'DOCINFO' (Cost=3905 Card=21278 Bytes=255336)
    3 2 DOMAIN INDEX OF 'IDX_DOCINFO_REPOIDX' (Cost=3549)
    [case 3 - simple like _and_ simple contains]
    select count(docid)
    from sa.docinfo
    where
    contains(repoidx,'facts')>0
    and
    author like '%smith%'
    Elapsed: 00:00:00.02
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3905 Card=1 Bytes= 23)
    1 0 SORT (AGGREGATE)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'DOCINFO' (Cost=3905 Card=1064 Bytes=24472)
    3 2 DOMAIN INDEX OF 'IDX_DOCINFO_REPOIDX' (Cost=3549)
    [case 4 - simple like _or_ simple contains]
    select count(docid)
    from sa.docinfo
    where
    contains(repoidx,'facts')>0
    or
    author like '%smith%'
    Elapsed: 00:01:37.02
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1468 Card=1 Bytes= 23)
    1 0 SORT (AGGREGATE)
    2 1 TABLE ACCESS (FULL) OF 'DOCINFO' (Cost=1468 Card=32218 Bytes=741014)
    [case 5 - simple like union simple contains]
    select count(docid)
    from sa.docinfo
    where
    contains(repoidx,'facts')>0
    union
    select count(docid)
    from sa.docinfo
    where
    author like '%smith%'
    Elapsed: 00:00:00.04
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=5581 Card=2 Bytes= 27)
    1 0 SORT (UNIQUE) (Cost=5581 Card=2 Bytes=27)
    2 1 UNION-ALL
    3 2 SORT (AGGREGATE) (Cost=4021 Card=1 Bytes=12)
    4 3 TABLE ACCESS (BY INDEX ROWID) OF 'DOCINFO' (Cost=3905 Card=21278 Bytes=255336)
    5 4 DOMAIN INDEX OF 'IDX_DOCINFO_REPOIDX' (Cost=3549)
    6 2 SORT (AGGREGATE) (Cost=1560 Card=1 Bytes=15)
    7 6 TABLE ACCESS (FULL) OF 'DOCINFO' (Cost=1468 Card=12004 Bytes=180060)

    Case 1:
    There is no index on author and it would not be able to use one if there was, due to the leading %, so it does a full table scan, which is still quick, since that is all there is to the query.
    Case 2:
    It has an index on repoidx, so it uses it and it is quick.
    Case 3:
    It has an index on repoidx, so it uses it. Since "and" is used, both conditions must be met. It has quckly obtained the results that match the first condition using the index, so it only has to check those rows, not every row in the table, to see if they also match the second condition.
    Case 4:
    Either condition may be met. It does not have an index on author, so it cannot use an index for that conditiion. Either condition can be met and it cannot duplicate the rows where both conditions are met, so it cannot use the results of one condition to check the other. So, it has to do a full table scan, in order to check every row for either condition, so it is slow.
    Case 5:
    select count (docid)
    from   docinfo
    where  contains (repoidx, 'facts') > 0
    union
    select count (docid)
    from   docinfo
    where  author like '%smith%';is not the same as:
    select count (docid)
    from   (select docid
            from   docinfo
            where  contains (repoidx, 'facts') > 0
            union
            select docid
            from   docinfo
            where  author like '%smith%');which is the same as case 4 and therefore just as slow. Your case 5 is just taking the union of 2 numbers, which could result in one row or two rows, depending on whether the numbers happen to match or not. Consider the following:
    scott@ORA92> SELECT job, empno
      2  FROM   emp
      3  /
    JOB            EMPNO
    CLERK           7369
    SALESMAN        7499
    SALESMAN        7521
    MANAGER         7566
    SALESMAN        7654
    MANAGER         7698
    MANAGER         7782
    ANALYST         7788
    PRESIDENT       7839
    SALESMAN        7844
    CLERK           7876
    CLERK           7900
    ANALYST         7902
    CLERK           7934
    14 rows selected.
    scott@ORA92> SELECT job, COUNT (empno)
      2  FROM   emp
      3  GROUP  BY job
      4  /
    JOB       COUNT(EMPNO)
    ANALYST              2
    CLERK                4
    MANAGER              3
    PRESIDENT            1
    SALESMAN             4
    scott@ORA92> SELECT COUNT (empno)
      2  FROM   emp
      3  WHERE  job = 'SALESMAN'
      4  /
    COUNT(EMPNO)
               4
    scott@ORA92> SELECT COUNT (empno)
      2  FROM   emp
      3  WHERE  job = 'CLERK'
      4  /
    COUNT(EMPNO)
               4
    scott@ORA92> SELECT COUNT (empno)
      2  FROM   emp
      3  WHERE  job = 'SALESMAN'
      4  UNION
      5  SELECT COUNT (empno)
      6  FROM   emp
      7  WHERE  job = 'CLERK'
      8  /
    COUNT(EMPNO)
               4
    scott@ORA92> -- the above is the same as:
    scott@ORA92> SELECT 4 FROM DUAL
      2  UNION
      3  SELECT 4 FROM DUAL
      4  /
             4
             4
    scott@ORA92> -- it is not the same as:
    scott@ORA92> SELECT COUNT (empno)
      2  FROM   (SELECT empno
      3            FROM   emp
      4            WHERE  job = 'SALESMAN'
      5            UNION
      6            SELECT empno
      7            FROM   emp
      8            WHERE  job = 'CLERK')
      9  /
    COUNT(EMPNO)
               8
    scott@ORA92> -- if the numbers are different, you get 2 rows:
    scott@ORA92> SELECT COUNT (empno)
      2  FROM   emp
      3  WHERE  job = 'ANALYST'
      4  UNION
      5  SELECT COUNT (empno)
      6  FROM   emp
      7  WHERE  job = 'MANAGER'
      8  /
    COUNT(EMPNO)
               2
               3
    scott@ORA92> -- the above is the same as:
    scott@ORA92> SELECT 2 FROM DUAL
      2  UNION
      3  SELECT 3 FROM DUAL
      4  /
             2
             2
             3
    scott@ORA92> -- it is not the same as:
    scott@ORA92> SELECT COUNT (empno)
      2  FROM   (SELECT empno
      3            FROM   emp
      4            WHERE  job = 'ANALYST'
      5            UNION
      6            SELECT empno
      7            FROM   emp
      8            WHERE  job = 'MANAGER')
      9  /
    COUNT(EMPNO)
               5

  • Querying on aggregates created on Virtual Cube

    Hello,
    I have implemented a virtual InfoProvider with Services.When I create queries directly on the Virtual Infoprovider the query runs fine and I see the report.
    As per my requirement I create an aggregate on the Virtual Infoprovider .Then I define a query on the aggregate .But when I execute this query I get the following errors :
    Error reading the data of InfoProvider AG4
    An exception with the type CX_SY_REF_IS_INITIAL occurred, but was neither handled locally, nor declared in a RAISING clause
    Dereferencing of the NULL reference.
    Would appreciate any assistance on this topic.
    Thanks
    Priyadarshi

    Yes it is possible to create aggregates on Virtual cubes.
    I will be grateful if hope anybody who is aware of the method of aggreagate creation and who has faced similar issues comes forward and throws some light on what could be the error.
    Thanks

  • Very Slow Query due to Bitmap Conversion

    I have a strange problem with the performance of a spatial query. If I perform a 'SELECT non_geom_column FROM my_table WHERE complicated_join_query' the result comes back sub-second. However, when I replace the column selected with geometry and perform 'SELECT geom_column FROM my_table WHERE same_complicated_join_query' the response takes over a minute.
    The issue is that in the second case, despite the identical where clause, the explain plan is significantly different. In the 'select geom_column' query there is a BITMAP CONVERSION (TO ROWIDS) which accounts for all of the extra time, where as in the 'select other_column' query that conversion is replaced with TABLE ACCESS (BY INDEX ROWID) which is near instant.
    I have tried putting in some hints, although I do not have much experience with hints, and have also tried nesting the query in various sub-selects. Whatever I try I can not persuade the explain plan to drop the bitmap conversion when I select the geometry column. The full query and an explanation of that query are below. I have run out of things to try, so any help or suggestions at all would be much appreciated.
    Regards,
    Chris
    Explanation and query
    My application allows users to select geometries from a map image through clicking, dragging a box and various other means. The image is then refreshed - highlighting geometries based on the query with which I am having trouble. The user is then able to deselect any of those highlighted geometries, or append others with additional clicks or dragged selections.
    If there are 2 (or any even number of) clicks within the same geometry then that geometry is deselected. Alternatively the geometry could have been selected through an intersection with a dragged box, and then clicked in to deselect - again an even number of selections. Any odd number of selections (i.e. selecting, deselecting, then selecting again) would result in the geometry being selected.
    The application can not know if the multiple user clicks are in the same geometry, as it simply has an image to work with, so all it does is pass all the clicks so far to the database to deal with.
    My query therefore does each spatial point or rectangle query in turn and then appends the unique key for the rows each returned to a list. After performing all of the queries it groups the list by the key and the groups with an odd total are 'selected'. To do this logic in a single where clause I have ended up with nested select statements that are joined with union all commands.
    The query is therefore..
    SELECT
    --the below column (geometry) makes it very slow...replacing it with any non-spatial column takes less than 1/100 of the time - that is my problem!
    geometry
    FROM
    my_table
    WHERE
    primary_key IN
    SELECT primary_key FROM
    SELECT primary_key FROM my_table WHERE
    sdo_relate(geometry, mdsys.sdo_geometry(2003, 81989, NULL, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array( rectangle co-ords )), 'mask=anyinteract') = 'TRUE'
    UNION ALL SELECT primary_key FROM my_table WHERE
    sdo_relate(geometry, mdsys.sdo_geometry(2001, 81989, sdo_point_type( point co-ords , NULL), NULL, NULL), 'mask=anyinteract') = 'TRUE'
    --potentially more 'union all select...' here
    GROUP BY primary_key HAVING mod(count(*),2) = 1     
    AND
    --the below is the bounding rectangle of the whole image to be returned
    sdo_filter(geometry, mdsys.sdo_geometry(2003, 81989, NULL, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array( outer rectangle co-ords )), 'mask=anyinteract') = 'TRUE'

    Hi
    Thanks for the reply. After a lot more googling- it turns out this is a general Oracle problem and is not solely related to use of the GEOMETRY column. It seems that sometimes, the Oracle optimiser makes an arbitrary decision to do bitmap conversion. No amount of hints will get it to change its mind !
    One person reported a similarly negative change after table statistic collection had run.
    Why changing the columns being retrieved should change the execution path, I do not know.
    We have a numeric primary key which is always set to a positive value. When I added "AND primary_key_column > 0" (a pretty pointless clause) the optimiser changed the way it works and we got it working fast again.
    Chris

Maybe you are looking for