Estimating range of performance for a query

I wonder if this is an intractable problem:
Using information available from the data dictionary and from the tables referenced in a query, estimate actual minimum and maximum run times for a given query, predict performance for various combinations of realistic values for the variables that influence performance.
Variables would include:
what kinds of IO are used
how much of each type of IO is used
atpr - average time per read for various types of IO
data relationships - min/max/avg #child records per parent record
server caching - how many gets require IO
clustering factor of indexes
I think a related item would be client caching
continued rows - how many per N primary rows
Type of plan - initally I think perhaps all NL and all hash joins are simple starting points
Some of the variables are observable from target systems ( atpr, data relationships, clustering factor, .. ).
I know, the optimizer already does this.
I know, it's faster to just run test queries.
Repeated work with such ideas would cause refinement of the method and
eventually might result in reasonably accurate estimates and improved understanding
of the variables involved in query performance, the latter being more important
than the former.
Please tell me why this is a bad or good idea. I already mentioned a couple of counter-arguments above,
please don't bother elaborating on them unless you're shedding light and not flaming. I think this would be
somewhat like the index evaluation methods in Lahdenmaki/Leach's book, but more Oracle-centric.
Or maybe I'm kidding myself..

Justin Cave wrote:
Could you possibly invert the problem a bit and use some statistical process control techniques to set some baselines and to identify statements that are moving outside of their control limits?
For example, a control chart could be built for each SQL statement based on actual execution performance data in the AWR-- you just need to know the average and the standard deviation execution time for that which should be relatively easy to derive. You can then gather the performance data for every snapshot interval, add a new data point to the chart. There are a number of different sets of rules for determining a "signal" from this data as opposed to normal random variation. That would generally be a reasonable way for everyone to agree on what performance should really be expected for a SQL statement and it would be a good early warning system that "something has changed" when you see a particular query start to run consistently slower (or faster) than it had been. That, in turn, might lead to better discussions, i.e. "sql_id Y is starting to run more slowly than we were expecting based on prior testing because we just introduced Process X that is generating a pile of I/O in the same window your query runs in. We can adjust Y's baseline to incorporate this new reality. Or we can move when Y runs so that it isn't competing with X. Or we can try to optimize Y further. Or we can get the folks that own X and Y into a room and determine how to meet everyone's requirements". Particularly if your performance testing can identify issues in test before the new Process X code goes into prod.
JustinThose are interesting ideas. Better discussions would be a good thing.
Re inverting the problem from prediction to reaction:
I have done some work with the script at http://kerryosborne.oracle-guy.com/2008/10/unstable-plans/ which of course work only for as much AWR data as you keep. I've had mixed results. I haven't tried to set it up to alert me about problems or to monitor a specific set of sql_ids. I've found it to be useful when users/developers are complaining about general slowness but won't give you any useful details about what is slow.
Here are a few complicating factors re identifying significant divergences in query performance or resource use - There are queries that accept different inputs that rightly generate completely different workloads for the same query, e.g., a product/location/time query whose inputs allow wide variations in the selectivity for each of the dimensions. There are applications that never heard of a bind variable, and there are queries that rightly do not use bind variables ( yes, even in the age of sql injection ).
In general , aside from the usual Grid Control and Nagios alerts re CPU/Memory/IO thresholds, and some blocking-locks alert programs, it's up to our users/developers to report performance problems.
Re my original question - I'll admit I was pretty sleep deprived when I wrote it. Sleep deprivation isn't usually conducive to clear thinking, so it will be interesting to see how this all looks in a month. Still, given that so much testing is affected by previous test runs ( caching ), I thought it made sense to try to understand the worst-performing case for a given execution plan. It's not a good thing to find that the big query that was tested to death and gave users a certain expectation of run time runs in production on a system where the caches have been dominated for the last N hours by completely unrelated workloads, and that when the query runs every single block must be read from a spindle, giving the users a much slower query than was seen in test.
Maybe the best way to predict worst-case performance is to work from the v$ metrics from test, manipulating the metrics to simulate different amounts of caching and different IO rates, thus generating different estimates for run-time.

Similar Messages

  • OPtimizing Performance for Select query on NAST table

    Hi All,
       We are fetching a single record from NAST table. The table has around 10 Million Entries.
       The Select Query takes around 5-6 minutes to return.
       We are not using the Primary key completely. We are using only one field of the primary key.
        The field is also a part of the Index but we are not using all the fields in the index as well.
        We need to bring down the time. What can be the solution? I cant see any changes to the code, since its a single query and we cant use the Entire Primary key.
       Would creating an Index on the fields that we are concerned with help in this regard.
       Open to all solutions.
    Thanks in Advance,
    Imran

    Hi,
    Please check this thread
    http://sap.ittoolbox.com/documents/popular-q-and-a/specifying-the-index-to-be-used-2462
    For creating another secondary index in NAST whether basis will approve for this?
    aRs

  • OPtimizing Performance for Select query on huge table

    Hi All,
       We are fetching a single record from NAST table. The table has around 10 Million Entries.
       The Select Query takes around 5-6 minutes to return.
       We are not using the Primary key completely. We are using only one field of the primary key.
        The field is also a part of the Index but we are not using all the fields in the index as well.
        We need to bring down the time. What can be the solution? I cant see any changes to the code, since its a single query and we cant use the Entire Primary key.
       Would creating an Index on the fields that we are concerned with help in this regard.
       Open to all solutions.
    Thanks in Advance,
    Imran

    There are sometimes tricks you can use to get it to use the index more efficiently. If you let us know which fields you are using in the SELECT (all of them actually), we might be able to help.
    Or are you saying you can't change the code at all?
    Please don't create duplicate posts though.
    Rob
    Message was edited by:
            Rob Burbank

  • Performance tuning in 11g for said query

    Hello,
    I have the below query which needs to be tuned:
    SELECT DISTINCT a.emplid
    , a.upa_fiscal_year
    , b.balance_period
    , 0
    , a.descr
    , a.UPA_CURRENT_AMT
    , a.UPA_CURRENT_AMT2
    , a.UPA_CURRENT_AMT3
    , a.UPA_CURRENT_AMT4
      FROM ps_upa_eq_incal_vw a
      , ps_upa_eq_incal_vw b
    WHERE a.emplid = b.emplid
       AND a.UPA_FISCAL_YEAR = b.UPA_FISCAL_YEAR
       AND a.balance_period = (
    SELECT MAX(balance_period)
      FROM ps_upa_eq_incal_vw
    WHERE emplid = a.emplid
       AND upa_fiscal_year = a.upa_fiscal_year
       AND descr = a.descr
       AND balance_period <= b.balance_period)
       AND a.descr NOT IN (
    SELECT DISTINCT descr
      FROM ps_upa_eq_incal_vw
    WHERE emplid = b.emplid
       AND upa_fiscal_year = b.upa_fiscal_year
       AND balance_period = b.balance_period
       AND b.balance_period > a.balance_period )
      UNION
    SELECT emplid
    , upa_fiscal_year
    , balance_period
    , 1
    , 'Total'
    , SUM ( UPA_CURRENT_AMT )
    , SUM ( UPA_CURRENT_AMT2 )
    , SUM ( UPA_CURRENT_AMT3 )
    , SUM ( UPA_CURRENT_AMT4 )
      FROM (
    SELECT DISTINCT a.emplid emplid
    , a.upa_fiscal_year upa_fiscal_year
    , b.balance_period balance_period
    , a.descr
    , a.UPA_CURRENT_AMT UPA_CURRENT_AMT
    , a.UPA_CURRENT_AMT2 UPA_CURRENT_AMT2
    , a.UPA_CURRENT_AMT3 UPA_CURRENT_AMT3
    , a.UPA_CURRENT_AMT4 UPA_CURRENT_AMT4
      FROM ps_upa_eq_incal_vw a
      , ps_upa_eq_incal_vw b
    WHERE a.emplid = b.emplid
       AND a.UPA_FISCAL_YEAR = b.UPA_FISCAL_YEAR
       AND a.BALANCE_PERIOD = (
    SELECT MAX(balance_period)
      FROM ps_upa_eq_incal_vw
    WHERE emplid = a.emplid
       AND upa_fiscal_year = a.upa_fiscal_year
       AND descr = a.descr
       AND balance_period <= b.balance_period)
       AND a.descr NOT IN (
    SELECT DISTINCT descr
      FROM ps_upa_eq_incal_vw
    WHERE emplid = b.emplid
       AND upa_fiscal_year = b.upa_fiscal_year
       AND balance_period = b.balance_period
       AND b.balance_period > a.balance_period ) )
      GROUP BY emplid , upa_fiscal_year , balance_period;The EXPLAIN plan for this query is as under:
    Plan hash value: 3550380953
    | Id  | Operation                              | Name               | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                       |                    |    24 |  2784 |       |   429M (53)|999:59:59 |
    |   1 |  SORT UNIQUE                           |                    |    24 |  2784 |       |   429M (53)|999:59:59 |
    |   2 |   UNION-ALL                            |                    |       |       |       |            |          |
    |*  3 |    FILTER                              |                    |       |       |       |            |          |
    |   4 |     NESTED LOOPS                       |                    |   196M|    29G|       |   205M  (4)|685:32:54 |
    |   5 |      VIEW                              | PS_UPA_EQ_INCAL_VW |  4513K|   146M|       | 72281   (2)| 00:14:28 |
    |   6 |       HASH GROUP BY                    |                    |  4513K|   249M|   329M| 72281   (2)| 00:14:28 |
    |*  7 |        HASH JOIN                       |                    |  4513K|   249M|       |  8644   (4)| 00:01:44 |
    |   8 |         TABLE ACCESS FULL              | PS_UPA_EQ_TRCD_TBL |   513 | 14364 |       |     3   (0)| 00:00:01 |
    |*  9 |         TABLE ACCESS FULL              | PS_UPA_EQ_DC_BAL   |  4513K|   129M|       |  8592   (4)| 00:01:44 |
    |  10 |      VIEW PUSHED PREDICATE             | PS_UPA_EQ_INCAL_VW |     1 |   127 |       |    46   (5)| 00:00:01 |
    |  11 |       SORT GROUP BY                    |                    |    33 |  1914 |       |    46   (5)| 00:00:01 |
    |* 12 |        HASH JOIN                       |                    |    33 |  1914 |       |    45   (3)| 00:00:01 |
    |* 13 |         TABLE ACCESS FULL              | PS_UPA_EQ_TRCD_TBL |    32 |   896 |       |     3   (0)| 00:00:01 |
    |  14 |         TABLE ACCESS BY INDEX ROWID    | PS_UPA_EQ_DC_BAL   |    44 |  1320 |       |    41   (0)| 00:00:01 |
    |* 15 |          INDEX RANGE SCAN              | PS_UPA_EQ_DC_BAL   |    44 |       |       |     3   (0)| 00:00:01 |
    |* 16 |     FILTER                             |                    |       |       |       |            |          |
    |  17 |      HASH GROUP BY                     |                    |     1 |    53 |       |     8  (25)| 00:00:01 |
    |* 18 |       FILTER                           |                    |       |       |       |            |          |
    |* 19 |        HASH JOIN                       |                    |     4 |   212 |       |     7  (15)| 00:00:01 |
    |* 20 |         INDEX RANGE SCAN               | PS_UPA_EQ_DC_BAL   |     4 |   100 |       |     3   (0)| 00:00:01 |
    |* 21 |         TABLE ACCESS FULL              | PS_UPA_EQ_TRCD_TBL |    32 |   896 |       |     3   (0)| 00:00:01 |
    |  22 |     SORT AGGREGATE                     |                    |     1 |    91 |       |            |          |
    |  23 |      VIEW                              | PS_UPA_EQ_INCAL_VW |     1 |    91 |       |     6   (0)| 00:00:01 |
    |  24 |       SORT GROUP BY                    |                    |     1 |    58 |       |     6   (0)| 00:00:01 |
    |  25 |        NESTED LOOPS                    |                    |       |       |       |            |          |
    |  26 |         NESTED LOOPS                   |                    |     1 |    58 |       |     6   (0)| 00:00:01 |
    |  27 |          TABLE ACCESS BY INDEX ROWID   | PS_UPA_EQ_DC_BAL   |     2 |    60 |       |     4   (0)| 00:00:01 |
    |* 28 |           INDEX RANGE SCAN             | PS_UPA_EQ_DC_BAL   |     1 |       |       |     3   (0)| 00:00:01 |
    |* 29 |          INDEX UNIQUE SCAN             | PS_UPA_EQ_TRCD_TBL |     1 |       |       |     0   (0)| 00:00:01 |
    |* 30 |         TABLE ACCESS BY INDEX ROWID    | PS_UPA_EQ_TRCD_TBL |     1 |    28 |       |     1   (0)| 00:00:01 |
    |  31 |    HASH GROUP BY                       |                    |    12 |   852 |       |   214M  (5)|715:46:12 |
    |  32 |     VIEW                               |                    |    12 |   852 |       |   214M  (5)|715:46:12 |
    |  33 |      HASH UNIQUE                       |                    |    12 |  1932 |       |   214M  (5)|715:46:12 |
    |* 34 |       FILTER                           |                    |       |       |       |            |          |
    |  35 |        NESTED LOOPS                    |                    |   196M|    29G|       |   205M  (4)|685:32:54 |
    |  36 |         VIEW                           | PS_UPA_EQ_INCAL_VW |  4513K|   146M|       | 72281   (2)| 00:14:28 |
    |  37 |          HASH GROUP BY                 |                    |  4513K|   249M|   329M| 72281   (2)| 00:14:28 |
    |* 38 |           HASH JOIN                    |                    |  4513K|   249M|       |  8644   (4)| 00:01:44 |
    |  39 |            TABLE ACCESS FULL           | PS_UPA_EQ_TRCD_TBL |   513 | 14364 |       |     3   (0)| 00:00:01 |
    |* 40 |            TABLE ACCESS FULL           | PS_UPA_EQ_DC_BAL   |  4513K|   129M|       |  8592   (4)| 00:01:44 |
    |  41 |         VIEW PUSHED PREDICATE          | PS_UPA_EQ_INCAL_VW |     1 |   127 |       |    46   (5)| 00:00:01 |
    |  42 |          SORT GROUP BY                 |                    |    33 |  1914 |       |    46   (5)| 00:00:01 |
    |* 43 |           HASH JOIN                    |                    |    33 |  1914 |       |    45   (3)| 00:00:01 |
    |* 44 |            TABLE ACCESS FULL           | PS_UPA_EQ_TRCD_TBL |    32 |   896 |       |     3   (0)| 00:00:01 |
    |  45 |            TABLE ACCESS BY INDEX ROWID | PS_UPA_EQ_DC_BAL   |    44 |  1320 |       |    41   (0)| 00:00:01 |
    |* 46 |             INDEX RANGE SCAN           | PS_UPA_EQ_DC_BAL   |    44 |       |       |     3   (0)| 00:00:01 |
    |* 47 |        FILTER                          |                    |       |       |       |            |          |
    |  48 |         HASH GROUP BY                  |                    |     1 |    53 |       |     8  (25)| 00:00:01 |
    |* 49 |          FILTER                        |                    |       |       |       |            |          |
    |* 50 |           HASH JOIN                    |                    |     4 |   212 |       |     7  (15)| 00:00:01 |
    |* 51 |            INDEX RANGE SCAN            | PS_UPA_EQ_DC_BAL   |     4 |   100 |       |     3   (0)| 00:00:01 |
    |* 52 |            TABLE ACCESS FULL           | PS_UPA_EQ_TRCD_TBL |    32 |   896 |       |     3   (0)| 00:00:01 |
    |  53 |        SORT AGGREGATE                  |                    |     1 |    91 |       |            |          |
    |  54 |         VIEW                           | PS_UPA_EQ_INCAL_VW |     1 |    91 |       |     6   (0)| 00:00:01 |
    |  55 |          SORT GROUP BY                 |                    |     1 |    58 |       |     6   (0)| 00:00:01 |
    |  56 |           NESTED LOOPS                 |                    |       |       |       |            |          |
    |  57 |            NESTED LOOPS                |                    |     1 |    58 |       |     6   (0)| 00:00:01 |
    |  58 |             TABLE ACCESS BY INDEX ROWID| PS_UPA_EQ_DC_BAL   |     2 |    60 |       |     4   (0)| 00:00:01 |
    |* 59 |              INDEX RANGE SCAN          | PS_UPA_EQ_DC_BAL   |     1 |       |       |     3   (0)| 00:00:01 |
    |* 60 |             INDEX UNIQUE SCAN          | PS_UPA_EQ_TRCD_TBL |     1 |       |       |     0   (0)| 00:00:01 |
    |* 61 |            TABLE ACCESS BY INDEX ROWID | PS_UPA_EQ_TRCD_TBL |     1 |    28 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter( NOT EXISTS (SELECT 0 FROM SYSADM."PS_UPA_EQ_TRCD_TBL" "V",SYSADM."PS_UPA_EQ_DC_BAL" "J" WHERE
                  :B1>:B2 AND "J"."BALANCE_PERIOD"=:B3 AND "J"."UPA_FISCAL_YEAR"=:B4 AND "J"."EMPLID"=:B5 AND
                  ("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR "J"."UPA_INC_TYPE"='P') AND
                  "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR" AND "J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND
                  "V"."UPA_FISCAL_YEAR"=:B6 GROUP BY "J"."EMPLID","J"."UPA_FISCAL_YEAR","J"."BALANCE_PERIOD","V"."DESCR"
                  HAVING "V"."DESCR"=:B7) AND "A"."BALANCE_PERIOD"= (SELECT MAX("BALANCE_PERIOD") FROM  (SELECT "J"."EMPLID"
                  "EMPLID","J"."UPA_FISCAL_YEAR" "UPA_FISCAL_YEAR","J"."BALANCE_PERIOD" "BALANCE_PERIOD","V"."DESCR"
                  "DESCR",SUM(DECODE("J"."UPA_INC_TYPE",'D',"J"."UPA_CURRENT_AMT",0))
                  "UPA_CURRENT_AMT",SUM(DECODE("J"."UPA_INC_TYPE",'M',"J"."UPA_CURRENT_AMT",0))
                  "UPA_CURRENT_AMT2",SUM(DECODE("J"."UPA_INC_TYPE",'C',"J"."UPA_CURRENT_AMT",0))
                  "UPA_CURRENT_AMT3",SUM(DECODE("J"."UPA_INC_TYPE",'P',"J"."UPA_CURRENT_AMT",0)) "UPA_CURRENT_AMT4" FROM
                  SYSADM."PS_UPA_EQ_TRCD_TBL" "V",SYSADM."PS_UPA_EQ_DC_BAL" "J" WHERE "J"."BALANCE_PERIOD"<=:B8 AND
                  "J"."UPA_FISCAL_YEAR"=:B9 AND "J"."EMPLID"=:B10 AND ("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR
                  "J"."UPA_INC_TYPE"='M' OR "J"."UPA_INC_TYPE"='P') AND "V"."UPA_FISCAL_YEAR"=:B11 AND
                  "J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "V"."DESCR"=:B12 AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR"
                  GROUP BY "J"."EMPLID","J"."UPA_FISCAL_YEAR","J"."BALANCE_PERIOD","V"."DESCR") "PS_UPA_EQ_INCAL_VW"))
       7 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
       9 - filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      12 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
      13 - filter("V"."UPA_FISCAL_YEAR"="B"."UPA_FISCAL_YEAR")
      15 - access("J"."EMPLID"="B"."EMPLID" AND "J"."UPA_FISCAL_YEAR"="B"."UPA_FISCAL_YEAR")
           filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      16 - filter("V"."DESCR"=:B1)
      18 - filter(:B1>:B2)
      19 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
      20 - access("J"."EMPLID"=:B1 AND "J"."UPA_FISCAL_YEAR"=:B2 AND "J"."BALANCE_PERIOD"=:B3)
           filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      21 - filter("V"."UPA_FISCAL_YEAR"=:B1)
      28 - access("J"."EMPLID"=:B1 AND "J"."UPA_FISCAL_YEAR"=:B2 AND "J"."BALANCE_PERIOD"<=:B3)
           filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      29 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "V"."UPA_FISCAL_YEAR"=:B1)
           filter("J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
      30 - filter("V"."DESCR"=:B1)
      34 - filter( NOT EXISTS (SELECT 0 FROM SYSADM."PS_UPA_EQ_TRCD_TBL" "V",SYSADM."PS_UPA_EQ_DC_BAL" "J" WHERE
                  :B1>:B2 AND "J"."BALANCE_PERIOD"=:B3 AND "J"."UPA_FISCAL_YEAR"=:B4 AND "J"."EMPLID"=:B5 AND
                  ("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR "J"."UPA_INC_TYPE"='P') AND
                  "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR" AND "J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND
                  "V"."UPA_FISCAL_YEAR"=:B6 GROUP BY "J"."EMPLID","J"."UPA_FISCAL_YEAR","J"."BALANCE_PERIOD","V"."DESCR"
                  HAVING "V"."DESCR"=:B7) AND "A"."BALANCE_PERIOD"= (SELECT MAX("BALANCE_PERIOD") FROM  (SELECT "J"."EMPLID"
                  "EMPLID","J"."UPA_FISCAL_YEAR" "UPA_FISCAL_YEAR","J"."BALANCE_PERIOD" "BALANCE_PERIOD","V"."DESCR"
                  "DESCR",SUM(DECODE("J"."UPA_INC_TYPE",'D',"J"."UPA_CURRENT_AMT",0))
                  "UPA_CURRENT_AMT",SUM(DECODE("J"."UPA_INC_TYPE",'M',"J"."UPA_CURRENT_AMT",0))
                  "UPA_CURRENT_AMT2",SUM(DECODE("J"."UPA_INC_TYPE",'C',"J"."UPA_CURRENT_AMT",0))
                  "UPA_CURRENT_AMT3",SUM(DECODE("J"."UPA_INC_TYPE",'P',"J"."UPA_CURRENT_AMT",0)) "UPA_CURRENT_AMT4" FROM
                  SYSADM."PS_UPA_EQ_TRCD_TBL" "V",SYSADM."PS_UPA_EQ_DC_BAL" "J" WHERE "J"."BALANCE_PERIOD"<=:B8 AND
                  "J"."UPA_FISCAL_YEAR"=:B9 AND "J"."EMPLID"=:B10 AND ("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR
                  "J"."UPA_INC_TYPE"='M' OR "J"."UPA_INC_TYPE"='P') AND "V"."UPA_FISCAL_YEAR"=:B11 AND
                  "J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "V"."DESCR"=:B12 AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR"
                  GROUP BY "J"."EMPLID","J"."UPA_FISCAL_YEAR","J"."BALANCE_PERIOD","V"."DESCR") "PS_UPA_EQ_INCAL_VW"))
      38 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
      40 - filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      43 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
      44 - filter("V"."UPA_FISCAL_YEAR"="B"."UPA_FISCAL_YEAR")
      46 - access("J"."EMPLID"="B"."EMPLID" AND "J"."UPA_FISCAL_YEAR"="B"."UPA_FISCAL_YEAR")
           filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      47 - filter("V"."DESCR"=:B1)
      49 - filter(:B1>:B2)
      50 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
      51 - access("J"."EMPLID"=:B1 AND "J"."UPA_FISCAL_YEAR"=:B2 AND "J"."BALANCE_PERIOD"=:B3)
           filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      52 - filter("V"."UPA_FISCAL_YEAR"=:B1)
      59 - access("J"."EMPLID"=:B1 AND "J"."UPA_FISCAL_YEAR"=:B2 AND "J"."BALANCE_PERIOD"<=:B3)
           filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      60 - access("J"."UPA_EQ_INC_CD"="V"."UPA_EQ_INC_CD" AND "V"."UPA_FISCAL_YEAR"=:B1)
           filter("J"."UPA_FISCAL_YEAR"="V"."UPA_FISCAL_YEAR")
      61 - filter("V"."DESCR"=:B1)Any directions as to how to tune this query would be greatly appreciated!
    Thanks,
    Suddhasatwa

    looks like these two steps hurts the most (causing the NL join take forever - because of the 4,5M rows)
    |*  9 |         TABLE ACCESS FULL              | PS_UPA_EQ_DC_BAL   |  4513K|   129M|       |  8592   (4)| 00:01:44 |
    |* 40 |            TABLE ACCESS FULL           | PS_UPA_EQ_DC_BAL   |  4513K|   129M|       |  8592   (4)| 00:01:44 |
       9 - filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')
      40 - filter("J"."UPA_INC_TYPE"='C' OR "J"."UPA_INC_TYPE"='D' OR "J"."UPA_INC_TYPE"='M' OR
                  "J"."UPA_INC_TYPE"='P')do you have an index on PS_UPA_EQ_DC_BAL.UPA_INC_TYPE column?
    reducing the number of rows returned in this step would be critical to speed up the NL join

  • Help required for improving performance of the Query

    Hello SAP Techies,
    I have MRP Query which shows Inventory projection by Calendar Year/Month wise.
    There are 2 variables Plant and Material in free charateristics where it has been restricted by replacement of Query result .
    Another query is Control M Query which is based on multiprovider. Multiprovider is created on 5 cubes.
    The Query is taking 20 -15 Mins to get the result.
    Due to replacement path by query result for the 2 variables first the control M Query is excuted. Business wanted to see all those materials in MRP query which are allocated to base plant hence they designed the query to use replacement Path by Query result. So it will get all the materials and plants from the control M query and will find the Invetory projection for the same selection in MRP query.
    Is there any way I can improve the performance of the Query.
    Query performance has been discussed innumerable times in the forums and there is a lot of information on the blogs and the WIKI - please search the forums before posting and if the existing posts do no answer your question satisfactorily then please raise a new post - else almost all the answers you get will be rehashed versions of previous posts ( and in most cases without attribution to the original author )
    Edited by: Arun Varadarajan on Apr 19, 2011 9:23 PM

    Hi ,
    Please see if you can make these changes currently to the report . It will help in improving the performance of the query
    1. Select the right read mode.
        Reading data during navigation minimizes the impact on
         the application server resources because only data that
        the user requires will be retrieved.
    2. Leverage filters as much as possible. Using filters contributes to
       reducing the number of database reads and the size of the result set,
        hereby significantly improving query runtimes.
       Filters are especially valuable when associated with u201Cbig
        dimensionsu201D where there is a large number of characteristics such as
        customers and document numbers.
    3. Reduce RKFs in the query to as few as possible. Also, define
    calculated & RKFs on the Infoprovider level instead of locally within the query.
    Regards
    Garima

  • Performance for a Specific Query:

    Hi, i am using a multi-threaded java application to execute a stored procedure with bulks of data grouped in an array. I use oracle 9i and this is the SP definition:
    create or replace
    PROCEDURE IE_SP_SET_BANS_TO_RECLASSIFY(
    MIN_AMOUNT IN NUMBER ,
    MIN_PAY_ADJ_DATE IN DATE,
    RECLA_CANDIDATES IN IE_RECLA_CANDIDATE_TBL )
    AS
    BEGIN
    FOR idx IN 1.. RECLA_CANDIDATES.COUNT
    LOOP
    INSERT INTO IE_RESUMEN_RECLA
    SELECT BA.BAN,
    BA.BILL_CYCLE,
    BA.COL_NEXT_STEP_NO ,
    BA.COL_NEXT_STEP_DATE,
    BA.COL_WAIVER_IND ,
    BA.STATUS_ACTV_RSN_CODE ,
    BA.COL_ASSIGNED_COLL,
    BA.COL_PATH_CODE ,
    BA.COL_CATEGORY_NO ,
    BA.ACCOUNT_TYPE ,
    BA.ACCOUNT_SUB_TYPE ,
    ADJ.ENT_SEQ_NO,
    ADJ.ACTV_DATE,
    ADJ.ACTV_AMT,
    ADJ.SUBSCRIBER_NO,
    ' ' AS SOURCE,
    ADJ.DESIGNATION,
    'ADJ' AS IDENT
    FROM CDLAPPC.ADJUSTMENT ADJ
    INNER JOIN CDLAPPC.BILLING_ACCOUNT BA
    ON(BA.BAN = ADJ.BAN)
    WHERE ADJ.BAN = RECLA_CANDIDATES(idx).ban
    AND ADJ.BALANCE_IMPACT_CODE = 'I'
    AND TRUNC(ADJ.SYS_CREATION_DATE) >= MIN_PAY_ADJ_DATE
    AND NVL(ADJ.ACTV_AMT,0) >= MIN_AMOUNT
    AND ROWNUM = 1;
    IF(SQL%ROWCOUNT = 0) THEN
    INSERT INTO IE_RESUMEN_RECLA
    SELECT BA.BAN,
    BA.BILL_CYCLE,
    BA.COL_NEXT_STEP_NO ,
    BA.COL_NEXT_STEP_DATE,
    BA.COL_WAIVER_IND ,
    BA.STATUS_ACTV_RSN_CODE ,
    BA.COL_ASSIGNED_COLL,
    BA.COL_PATH_CODE ,
    BA.COL_CATEGORY_NO ,
    BA.ACCOUNT_TYPE ,
    BA.ACCOUNT_SUB_TYPE ,
    P.ENT_SEQ_NO,
    P.DEPOSIT_DATE,
    P.ORIGINAL_AMT,
    P.SUBSCRIBER_NO,
    P.SOURCE_ID,
    P.DESIGNATION,
    'PAY' AS IDENT
    FROM CDLAPPC.PAYMENT P
    INNER JOIN CDLAPPC.BILLING_ACCOUNT BA
    ON(BA.BAN = P.BAN)
    WHERE P.BAN = RECLA_CANDIDATES(idx).ban
    AND TRUNC(P.SYS_CREATION_DATE) >= MIN_PAY_ADJ_DATE
    AND NVL(P.ORIGINAL_AMT,0) >= MIN_AMOUNT
    AND ROWNUM = 1;
    END IF;
    END LOOP ;
    END IE_SP_SET_BANS_TO_RECLASSIFY;
    I want to improve it's efficiency but i still do not know how. But possible solutions are:
    -i know that a FORALL loop would improve my insert speed but in this case there is a condition so i don't know how to implement it in a forall.
    -I want to avoid doing the inner join with billing_account for the query but i do not know if providing the billing_account details in the input table would make it more efficient, is not a lot of data per row, but i am sending 10k rows per SP call, also i am not sure if there will be a lot of context switching with PL/SQL and SQL in case i do that.
    Any help would be appreciated, thanks.

    Some of the suggestions I can make for improving the Queries are
    1) Try using Indexed columns whereever possible , specially when you are joining tables. If there is no index on column that you are using to join ,then either try to use columns which have an index or create a new index on columns if required.
    2) Try to see the Explain Plan for the select statements you are uisng. If you are using TOAD, try to use the tool's feature to generate different possible combinations of queries with the least cost. You need to supply TOAD with the problematic SQL statement, it will automatically generate different combinations of SQL statements and then you can choose the one with the least cost or the one with the best Explain plan results.
    Hope this helps.
    Regards
    IQ

  • How to improve the query performance or tune query from Explain Plan

    Hi
    The following is my explain plan for sql query. (The plan is generated by Toad v9.7). How to fix the query?
    SELECT STATEMENT ALL_ROWSCost: 4,160 Bytes: 25,296 Cardinality: 204                                         
         8 NESTED LOOPS Cost: 3 Bytes: 54 Cardinality: 1                                    
              5 NESTED LOOPS Cost: 2 Bytes: 23 Cardinality: 1                               
                   2 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 13 Cardinality: 1                          
                        1 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                     
                   4 TABLE ACCESS BY INDEX ROWID TABLE AR.HZ_CUST_ACCOUNTS Cost: 1 Bytes: 10 Cardinality: 1                          
                        3 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.HZ_CUST_ACCOUNTS_U1 Cost: 1 Cardinality: 1                     
              7 TABLE ACCESS BY INDEX ROWID TABLE AR.HZ_PARTIES Cost: 1 Bytes: 31 Cardinality: 1                               
                   6 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.HZ_PARTIES_U1 Cost: 1 Cardinality: 1                          
         10 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                                    
              9 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                               
         15 NESTED LOOPS Cost: 2 Bytes: 29 Cardinality: 1                                    
              12 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                               
                   11 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                          
              14 TABLE ACCESS BY INDEX ROWID TABLE ONT.OE_ORDER_HEADERS_ALL Cost: 1 Bytes: 17 Cardinality: 1                               
                   13 INDEX RANGE SCAN INDEX (UNIQUE) ONT.OE_ORDER_HEADERS_U2 Cost: 1 Cardinality: 1                          
         21 FILTER                                    
              16 TABLE ACCESS FULL TABLE ONT.OE_TRANSACTION_TYPES_TL Cost: 2 Bytes: 1,127 Cardinality: 49                               
              20 NESTED LOOPS Cost: 2 Bytes: 21 Cardinality: 1                               
                   18 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                          
                        17 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                     
                   19 INDEX RANGE SCAN INDEX (UNIQUE) ONT.OE_ORDER_HEADERS_U2 Cost: 1 Bytes: 9 Cardinality: 1                          
         23 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                                    
              22 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                               
         45 NESTED LOOPS Cost: 4,160 Bytes: 25,296 Cardinality: 204                                    
              42 NESTED LOOPS Cost: 4,150 Bytes: 23,052 Cardinality: 204                               
                   38 NESTED LOOPS Cost: 4,140 Bytes: 19,992 Cardinality: 204                          
                        34 NESTED LOOPS Cost: 4,094 Bytes: 75,850 Cardinality: 925                     
                             30 NESTED LOOPS Cost: 3,909 Bytes: 210,843 Cardinality: 3,699                
                                  26 PARTITION LIST ALL Cost: 2,436 Bytes: 338,491 Cardinality: 14,717 Partition #: 29 Partitions accessed #1 - #18          
                                       25 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_AE_HEADERS Cost: 2,436 Bytes: 338,491 Cardinality: 14,717 Partition #: 29 Partitions accessed #1 - #18     
                                            24 INDEX SKIP SCAN INDEX XLA.XLA_AE_HEADERS_N1 Cost: 264 Cardinality: 1,398,115 Partition #: 29 Partitions accessed #1 - #18
                                  29 PARTITION LIST ITERATOR Cost: 1 Bytes: 34 Cardinality: 1 Partition #: 32           
                                       28 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_AE_LINES Cost: 1 Bytes: 34 Cardinality: 1 Partition #: 32      
                                            27 INDEX RANGE SCAN INDEX (UNIQUE) XLA.XLA_AE_LINES_U1 Cost: 1 Cardinality: 1 Partition #: 32
                             33 PARTITION LIST ITERATOR Cost: 1 Bytes: 25 Cardinality: 1 Partition #: 35                
                                  32 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_DISTRIBUTION_LINKS Cost: 1 Bytes: 25 Cardinality: 1 Partition #: 35           
                                       31 INDEX RANGE SCAN INDEX XLA.XLA_DISTRIBUTION_LINKS_N3 Cost: 1 Cardinality: 1 Partition #: 35      
                        37 PARTITION LIST SINGLE Cost: 1 Bytes: 16 Cardinality: 1 Partition #: 38                     
                             36 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_EVENTS Cost: 1 Bytes: 16 Cardinality: 1 Partition #: 39 Partitions accessed #2               
                                  35 INDEX UNIQUE SCAN INDEX (UNIQUE) XLA.XLA_EVENTS_U1 Cost: 1 Cardinality: 1 Partition #: 40 Partitions accessed #2          
                   41 PARTITION LIST SINGLE Cost: 1 Bytes: 15 Cardinality: 1 Partition #: 41                          
                        40 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_TRANSACTION_ENTITIES Cost: 1 Bytes: 15 Cardinality: 1 Partition #: 42 Partitions accessed #2                    
                             39 INDEX UNIQUE SCAN INDEX (UNIQUE) XLA.XLA_TRANSACTION_ENTITIES_U1 Cost: 1 Cardinality: 1 Partition #: 43 Partitions accessed #2               
              44 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_CODE_COMBINATIONS Cost: 1 Bytes: 11 Cardinality: 1                               
                   43 INDEX UNIQUE SCAN INDEX (UNIQUE) GL.GL_CODE_COMBINATIONS_U1 Cost: 1 Cardinality: 1

    damorgan wrote:
    Tuning is NOT about reducing the cost of i/o.
    i/o is only one of many contributors to cost and only one of many contributors to waits.
    Any time you would like to explore this further run this code:
    SELECT 1 FROM dual
    WHERE regexp_like(' ','^*[ ]*a');but not on a production box because you are going to experience an extreme tuning event with zero i/o.
    And when I say "extreme" I mean "EXTREME!"
    You've been warned.I think you just need a faster server.
    SQL> set autotrace traceonly statistics
    SQL> set timing on
    SQL> select 1 from dual
      2  where
      3  regexp_like   (' ','^*[ ]*a');
    no rows selected
    Elapsed: 00:00:00.00
    Statistics
              1  recursive calls
              0  db block gets
              0  consistent gets
              0  physical reads
              0  redo size
            243  bytes sent via SQL*Net to client
            349  bytes received via SQL*Net from client
              1  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              0  rows processedRepeated from an Oracle 10.2.0.x instance:
    SQL> SELECT DISTINCT SID FROM V$MYSTAT;
           SID
           310
    SQL> ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    Session altered.
    SQL> select 1 from dual
      2  where
      3  regexp_like   (' ','^*[ ]*a');The session is hung. Wait a little while and connect to the database using a different session:
    COLUMN STAT_NAME FORMAT A35 TRU
    SET PAGESIZE 200
    SELECT
      STAT_NAME,
      VALUE
    FROM
      V$SESS_TIME_MODEL
    WHERE
      SID=310;
    STAT_NAME                                VALUE
    DB time                                   9247
    DB CPU                                    9247
    background elapsed time                      0
    background cpu time                          0
    sequence load elapsed time                   0
    parse time elapsed                        6374
    hard parse elapsed time                   5997
    sql execute elapsed time                  2939
    connection management call elapsed        1660
    failed parse elapsed time                    0
    failed parse (out of shared memory)          0
    hard parse (sharing criteria) elaps          0
    hard parse (bind mismatch) elapsed           0
    PL/SQL execution elapsed time               95
    inbound PL/SQL rpc elapsed time              0
    PL/SQL compilation elapsed time              0
    Java execution elapsed time                  0
    repeated bind elapsed time                  48
    RMAN cpu time (backup/restore)               0Seems to be using a bit of time for the hard parse (hard parse elapsed time). Wait a little while, then re-execute the query:
    STAT_NAME                                VALUE
    DB time                                   9247
    DB CPU                                    9247
    background elapsed time                      0
    background cpu time                          0
    sequence load elapsed time                   0
    parse time elapsed                        6374
    hard parse elapsed time                   5997
    sql execute elapsed time                  2939
    connection management call elapsed        1660
    failed parse elapsed time                    0
    failed parse (out of shared memory)          0
    hard parse (sharing criteria) elaps          0
    hard parse (bind mismatch) elapsed           0
    PL/SQL execution elapsed time               95
    inbound PL/SQL rpc elapsed time              0
    PL/SQL compilation elapsed time              0
    Java execution elapsed time                  0
    repeated bind elapsed time                  48
    RMAN cpu time (backup/restore)               0The session is not reporting additional CPU usage or parse time.
    Let's check one of the session's statistics:
    SELECT
      SS.VALUE
    FROM
      V$SESSTAT SS,
      V$STATNAME SN
    WHERE
      SN.NAME='consistent gets'
      AND SN.STATISTIC#=SS.STATISTIC#
      AND SS.SID=310;
         VALUE
           163Not many consistent gets after 20+ minutes.
    Let's take a look at the plan:
    SQL> SELECT SQL_ID,CHILD_NUMBER FROM V$SQL WHERE SQL_TEXT LIKE 'select 1 from du
    al%';
    SQL_ID        CHILD_NUMBER
    04mpgrzhsv72w            0
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('04mpgrzhsv72w',0,'TYPICAL'))
    select 1 from dual where regexp_like   (' ','^*[ ]*a')
    NOTE: cannot fetch plan for SQL_ID: 04mpgrzhsv72w, CHILD_NUMBER: 0
          Please verify value of SQL_ID and CHILD_NUMBER;
          It could also be that the plan is no longer in cursor cache (check v$sql_p
    lan)No plan...
    Let's take a look at the 10053 trace file:
    Registered qb: SEL$1 0x19157f38 (PARSER)
      signature (): qb_name=SEL$1 nbfros=1 flg=0
        fro(0): flg=4 objn=258 hint_alias="DUAL"@"SEL$1"
    Predicate Move-Around (PM)
    PM: Considering predicate move-around in SEL$1 (#0).
    PM:   Checking validity of predicate move-around in SEL$1 (#0).
    CBQT: Validity checks failed for 7uqx4guu04x3g.
    CVM: Considering view merge in query block SEL$1 (#0)
    CBQT: Validity checks failed for 7uqx4guu04x3g.
    Subquery Unnest
    SU: Considering subquery unnesting in query block SEL$1 (#0)
    Set-Join Conversion (SJC)
    SJC: Considering set-join conversion in SEL$1 (#0).
    Predicate Move-Around (PM)
    PM: Considering predicate move-around in SEL$1 (#0).
    PM:   Checking validity of predicate move-around in SEL$1 (#0).
    PM:     PM bypassed: Outer query contains no views.
    FPD: Considering simple filter push in SEL$1 (#0)
    FPD:   Current where clause predicates in SEL$1 (#0) :
              REGEXP_LIKE (' ','^*[ ]*a')
    kkogcp: try to generate transitive predicate from check constraints for SEL$1 (#0)
    predicates with check contraints:  REGEXP_LIKE (' ','^*[ ]*a')
    after transitive predicate generation:  REGEXP_LIKE (' ','^*[ ]*a')
    finally:  REGEXP_LIKE (' ','^*[ ]*a')
    apadrv-start: call(in-use=592, alloc=16344), compile(in-use=37448, alloc=42256)
    kkoqbc-start
                : call(in-use=592, alloc=16344), compile(in-use=38336, alloc=42256)
    kkoqbc-subheap (create addr=000000001915C238)Looks like the query never had a chance to start executing - it is still parsing after 20 minutes.
    I am not sure that this is a good example - the query either executes very fast, or never has a chance to start executing. But, it might still make your point physical I/O is not always the problem when performance problems are experienced.
    Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Please help me to increase the performance of the query

    Hello
    I am not an oracle expert or developer and i have a problem to resolve.
    Below is the query and explaiation plan and seeking the help to improve the performance of the query.
    Our Analysis,
    The query runs good,takes less one minute and fetches the results but during peak time it takes 8 minutes
    Require anyone suggestion's to improve the query.
    The query is generated from the Microsft dll so we dont have SQL code and require some help on tuning the tables.
    If tuning the query improves then also fine please suggest for that also.
    Enviroment: Solaris 8
    DB : oracle 9i
    (SELECT vw.dispapptobjid, vw.custsiteobjid, vw.emplastname, vw.empfirstname,
    vw.scheduledonsite AS starttime, vw.appttype, vw.latestart,
    vw.endtime, vw.typetitle, vw.empobjid, vw.latitude, vw.longitude,
    vw.workduration AS DURATION, vw.dispatchtype, vw.availability
    FROM ora_appt_disp_view vw
    WHERE ( ( vw.starttime >=
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.starttime <
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    OR vw.endtime >
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.endtime <=
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    OR ( vw.starttime <=
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.endtime >=
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    UNION
    (SELECT 0 AS dispapptobjid, emp.emp_physical_site2site AS custsiteobjid,
    emp.last_name AS emplastname, emp.first_name AS empfirstname,
    TO_DATE ('1/1/3000', 'MM/DD/YYYY') AS starttime, 'E' AS appttype,
    NULL AS latestart, NULL AS endtime, '' AS typetitle,
    emp.objid AS empobjid, 0 AS latitude, 0 AS longitude, 0 AS DURATION,
    '' AS dispatchtype, 0 AS availability
    FROM table_employee emp, table_user usr
    WHERE emp.employee2user = usr.objid AND emp.field_eng = 1 AND usr.status = 1)
    ORDER BY empobjid, starttime, endtime DESC
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=HINT: ALL_ROWS          23 K          11312                     
    SORT UNIQUE          23 K     3 M     11140                     
    UNION-ALL                                        
    VIEW     ORA_APPT_DISP_VIEW     17 K     3 M     10485                     
    UNION-ALL                                        
    CONCATENATION                                        
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    HASH JOIN          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      1 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_SCHED_REPAIR     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    NESTED LOOPS          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      1 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_SCHED_REPAIR     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     EMPLOYEE_OBJINDEX     1                               
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    NESTED LOOPS          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      1 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_REQ_ETA     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     EMPLOYEE_OBJINDEX     1                               
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    NESTED LOOPS          16 K     2 M     5812                     
    HASH JOIN          16 K     2 M     5812                     
    HASH JOIN          16 K     2 M     5286                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     13 K     441 K     28                     
    HASH JOIN          16 K     1 M     5243                     
    TABLE ACCESS FULL     TABLE_SCHEDULE     991      11 K     2                     
    HASH JOIN OUTER          16 K     1 M     5240                     
    HASH JOIN OUTER          16 K     1 M     3866                     
    HASH JOIN OUTER          16 K     1 M     450                     
    HASH JOIN          16 K     1 M     44                     
    TABLE ACCESS FULL     TABLE_GBST_ELM     781      14 K     2                     
    TABLE ACCESS FULL     TABLE_APPOINTMENT     16 K     822 K     41                     
    INDEX FAST FULL SCAN     CASE_OBJINDEX     1 M     6 M     201                     
    TABLE ACCESS FULL     TABLE_SITE     967 K     11 M     3157                     
    TABLE ACCESS FULL     TABLE_ADDRESS     961 K     11 M     1081                     
    INDEX FAST FULL SCAN     SITE_OBJINDEX     967 K     5 M     221                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    HASH JOIN          6 K     272 K     51                     
    TABLE ACCESS FULL     TABLE_USER     6 K     51 K     21                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     6 K     220 K     28

    Hi,
    First-off, it appear that you are querying a view. I would redo the auery against the base table.
    Next, look at a function-based index for the DATE column. Here are my notes:
    http://www.dba-oracle.com/t_function_based_indexes.htm
    http://www.dba-oracle.com/oracle_tips_index_scan_fbi_sql.htm
    Also, make sure you are analyzed properly with dbms_stats:
    http://www.dba-oracle.com/art_builder_dbms_stats.htm
    And histograms, if appropriate:
    http://www.dba-oracle.com/art_builder_histo.htm
    Lasty, look at increasing hash_area_size or pga_aggregate_tagtet, depending on your table sizes:
    http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm
    Hope this helps. . . .
    Donald K. Burleson
    Oracle Press Author

  • Looking for a query to find first/last dates in overlapping dates...

    Hi,
    I'm looking for a query to find the first dates and last dates in a table conaining overlapping dates.
    I have a subscription table which has for each Customer start and end date for different subscriptions.
    I want to know the different ranges of date where there is subscriptions active.
    so if the table has this:
    CustID, Start date, end date
    1, 2008-01-01, 2012-06-06
    1 ,2009-01-01, 2011-01-01
    1, 2011-01-01, 2013-02-02
    1, 2013-01-01, 2013-08-08
    1, 2014-01-01, 2014-04-04
    I want to produce this result:
    custid, range start, range end
    1, 2008-01-01, 2013-08-08
    1, 2014-01-01, 2014-04-04
    the first row is the range identified from the 4 rows in my subscription table.
    thanks :)

    I think I found it...
    http://stackoverflow.com/questions/5213484/eliminate-and-reduce-overlapping-date-ranges
    let me try this method
    Hi,
    m writing to follow up with you on this post. Thanks for you posting a reply to share your workground. Was the problem resolved after performing the above link? If you are satisfied with the above solution, I’d like to mark this issue as "Answered".
    Please also feel free to unmark the issue, with any new findings or concerns you may have.
    Thanks,
    Sofiya Li
    If you have any feedback on our support, please click here.
    Sofiya Li
    TechNet Community Support

  • How to populate the ranges using FM for the SELECTs

    Hi,
    I am still working on the FM to create a generic extractor. I went through the debugger but I am still unable to determine how the ranges are populated. RSA3 always gives me zero values for the results.
    There is a RANGE statement in the sample FM and the following statements for SELECTs
      RANGES: L_R_CARRID  FOR SFLIGHT-CARRID,
              L_R_CONNID  FOR SFLIGHT-CONNID.
    and...
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CARRID'.
            MOVE-CORRESPONDING L_S_SELECT TO L_R_CARRID.
            APPEND L_R_CARRID.
          ENDLOOP.
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CONNID'.
            MOVE-CORRESPONDING L_S_SELECT TO L_R_CONNID.
            APPEND L_R_CONNID.
          ENDLOOP.
    My question is how is L_R_CONNID and L_R_CARRID populated with low and high values for the SELECT statements? I tried to find the DS 0SAPI_SFLIGHT_SIMPLE to run and see how it is set up but there is no such DS.
    Would someone take the time to say something about this in  several sentences? I have my own code and it seems that it is not populating the values for the SELECTs when I debug from RSA3 when I provide the low and high values.
    Would I normally populate the low and high values from the InfoPackage 'Data Selection' tab once I have implemented in BW or ready to test in BW? That would mean I have to choose those fields as selections from RSO2. Anyway, I think I have asked about this but I am hoping to get an answer to get this going...
    Appreciate any replies.

    Hi
    Here is an example of an extractor that uses
    both method's, if the InfoPackage selection exist's
    it overrides the TVARV selection (which is the default).
    FUNCTION ZBW_TC_FORECAST_SO_EXTRACTOR.
    ""Local interface:
    *"  IMPORTING
    *"     VALUE(I_REQUNR) TYPE  SBIWA_S_INTERFACE-REQUNR
    *"     VALUE(I_DSOURCE) TYPE  SBIWA_S_INTERFACE-ISOURCE OPTIONAL
    *"     VALUE(I_CHABASNM) TYPE  SBIWA_S_INTERFACE-CHABASNM OPTIONAL
    *"     VALUE(I_MAXSIZE) TYPE  SBIWA_S_INTERFACE-MAXSIZE OPTIONAL
    *"     VALUE(I_INITFLAG) TYPE  SBIWA_S_INTERFACE-INITFLAG OPTIONAL
    *"     VALUE(I_UPDMODE) TYPE  SBIWA_S_INTERFACE-UPDMODE OPTIONAL
    *"     VALUE(I_DATAPAKID) TYPE  SBIWA_S_INTERFACE-DATAPAKID OPTIONAL
    *"     VALUE(I_PRIVATE_MODE) OPTIONAL
    *"     VALUE(I_CALLMODE) TYPE  ROARCHD200-CALLMODE OPTIONAL
    *"  TABLES
    *"      I_T_SELECT TYPE  SBIWA_T_SELECT OPTIONAL
    *"      I_T_FIELDS TYPE  SBIWA_T_FIELDS OPTIONAL
    *"      E_T_DATA STRUCTURE  ZBW_TC_FORECASTING_EXT_STR OPTIONAL
    *"  EXCEPTIONS
    *"      NO_MORE_DATA
    *"      ERROR_PASSED_TO_MESS_HANDLER
    *"      HIERARCHY_NOT_FOUND
    Change History                                                      *
    Mod. #  |  Date    |  Developer     |  Description                  *
    *RD3K915762|06/21/2005| SRangaraj      | Change selection of open SO   *
             |          |                | data to include deleted matls *
             |          |                | and obsolete items too        *
    RD3K915888|06/29/2005| SRANGARAJ      | Add ext matl grp and lab offce
             |          |                | filters for data-selection    *
    The input parameter I_DATAPAKID is not supported yet !
    Auxiliary Selection criteria structure
      DATA: L_S_SELECT TYPE SBIWA_S_SELECT.
    Maximum number of lines for DB table
      STATICS L_MAXSIZE TYPE SBIWA_S_INTERFACE-MAXSIZE.
    Parameter I_PRIVATE_MODE:
    Some applications might want to use this function module for other
    purposes as well (e.g. data supply for OLTP reporting tools). If the
    processing logic has to be different in this case, use the optional
    parameter I_PRIVATE_MODE (not supplied by BIW !) to distinguish
    between BIW calls (I_PRIVATE_MODE = SPACE) and other calls
    (I_PRIVATE_MODE = X).
    If the message handling has to be different as well, define Your own
    messaging macro which interprets parameter I_PRIVATE_MODE. When
    called by BIW, it should use the LOG_WRITE macro, otherwise do what
    You want.
    Initialization mode (first call by SAPI) or data transfer mode
    (following calls) ?
      IF I_INITFLAG = SBIWA_C_FLAG_ON.
    Initialization: check input parameters
                    buffer input parameters
                    prepare data selection
    The input parameter I_DATAPAKID is not supported yet !
    Invalid second initialization call -> error exit
        IF NOT G_FLAG_INTERFACE_INITIALIZED IS INITIAL.
          IF 1 = 2. MESSAGE E008(R3). ENDIF.
          LOG_WRITE 'E'                    "message type
                    'R3'                   "message class
                    '008'                  "message number
                    ' '                    "message variable 1
                    ' '.                   "message variable 2
          RAISE ERROR_PASSED_TO_MESS_HANDLER.
        ENDIF.
    Check InfoSource validity
        CASE I_DSOURCE.
          WHEN 'ZBW_TC_SO_EXTRACT'.
          WHEN OTHERS.
            IF 1 = 2. MESSAGE E009(R3). ENDIF.
            LOG_WRITE 'E'                  "message type
                      'R3'                 "message class
                      '009'                "message number
                      I_DSOURCE            "message variable 1
                      ' '.                 "message variable 2
            RAISE ERROR_PASSED_TO_MESS_HANDLER.
        ENDCASE.
    Check for supported update mode
       CASE I_UPDMODE.
         WHEN 'F'.
         WHEN OTHERS.
           IF 1 = 2. MESSAGE E011(R3). ENDIF.
           LOG_WRITE 'E'                  "message type
                     'R3'                 "message class
                     '011'                "message number
                     I_UPDMODE            "message variable 1
                     ' '.                 "message variable 2
           RAISE ERROR_PASSED_TO_MESS_HANDLER.
       ENDCASE.
    Check for obligatory selection criteria
       READ TABLE I_T_SELECT INTO L_S_SELECT WITH KEY FIELDNM = 'PGMID'.
       IF SY-SUBRC <> 0.
         IF 1 = 2. MESSAGE E010(R3). ENDIF.
         LOG_WRITE 'E'                    "message type
                   'R3'                   "message class
                   '010'                  "message number
                   'PGMID'                "message variable 1
                   ' '.                   "message variable 2
         RAISE ERROR_PASSED_TO_MESS_HANDLER.
       ENDIF.
        APPEND LINES OF I_T_SELECT TO G_T_SELECT.
    Fill parameter buffer for data extraction calls
        G_S_INTERFACE-REQUNR    = I_REQUNR.
        G_S_INTERFACE-ISOURCE   = I_DSOURCE.
        G_S_INTERFACE-MAXSIZE   = I_MAXSIZE.
        G_S_INTERFACE-INITFLAG  = I_INITFLAG.
        G_S_INTERFACE-UPDMODE   = I_UPDMODE.
        G_S_INTERFACE-DATAPAKID = I_DATAPAKID.
        G_FLAG_INTERFACE_INITIALIZED = SBIWA_C_FLAG_ON.
    Fill field list table for an optimized select statement
    (in case that there is no 1:1 relation between InfoSource fields
    and database table fields this may be far from beeing trivial)
        APPEND LINES OF I_T_FIELDS TO G_T_FIELDS.
    Fill range tables for fixed InfoSources. In the case of generated
    InfoSources, the usage of a dynamical SELECT statement might be
    more reasonable. BIW will only pass down simple selection criteria
    of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
        LOOP AT G_T_SELECT INTO L_S_SELECT.
          CASE L_S_SELECT-FIELDNM.
            WHEN 'PRDHA'.
              WGF_PRDHA_LENGTH = STRLEN( L_S_SELECT-LOW ).
              IF WGF_PRDHA_LENGTH = 6.  "PARTIAL PRDHA
                 WGF_PRDHA = L_S_SELECT-LOW.
                 CONCATENATE WGF_PRDHA '%' INTO WGF_PRDHA.
              ELSEIF WGF_PRDHA_LENGTH = 12.  "FULL PRDHA
              MOVE-CORRESPONDING L_S_SELECT TO L_R_PRDHA.
              APPEND L_R_PRDHA.
              ENDIF.
            WHEN 'MATKL'.
              MOVE-CORRESPONDING L_S_SELECT TO L_R_MATKL.
              APPEND L_R_MATKL.
          ENDCASE.
        ENDLOOP.
    reset the index of where we are in the gt_header table
      g_tabix = 0.
      perform populate_default_variables.
      perform get_data.
      perform build_detail.
        EXIT.
      ENDIF.                 "Initialization mode or data extraction ?
    Data transfer: First Call      OPEN CURSOR + FETCH
                   Following Calls FETCH only
    First data package -> OPEN CURSOR
       IF G_COUNTER_DATAPAKID = 0.
    Determine number of database records to be read per FETCH statement
    from input parameter I_MAXSIZE. If there is a one to one relation
    between InfoSource table lines and database entries, this is trivial.
    In other cases, it may be impossible and some estimated value has to
    be determined.
      DESCRIBE TABLE LT_DATA LINES l_count.
      IF g_tabix GE l_count.
        RAISE no_more_data.
      ENDIF.
    *CLEAN UP THE OUTPUT TABLE
      refresh E_T_DATA.
      LOOP AT LT_DATA FROM G_TABIX INTO LS_DATA.
        APPEND LS_DATA TO E_T_DATA.
    Set global counter
        g_tabix = g_tabix + 1.
      ENDLOOP.
       G_COUNTER_DATAPAKID = G_COUNTER_DATAPAKID + 1.
    ENDIF.              "Initialization mode or data extraction ?
    ENDFUNCTION.
    Forms
    ***INCLUDE LZBW_TC_FORECAST_SO_EXTF01 .
    *&      Form  populate_default_variables
          text
    -->  p1        text
    <--  p2        text
    FORM populate_default_variables.
      data: wlf_name like tvarv-name.
      clear: R_prdh3[], wlf_name.
    *get the exclusion range from tvarv for the product hierarchy in
    *question
      concatenate 'ZBW_EXL_' WGF_PRDHA(6) INTO WLF_NAME.
    SELECT LOW FROM TVARV INTO R_prdh3-low WHERE
                                 NAME = WLF_NAME.
      move:  'I'    to R_prdh3-sign,
             'EQ'   to R_prdh3-option.
      append R_prdh3.
      clear R_prdh3.
    ENDSELECT.
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
    CLEAR L_R_LABOR[].
    SELECT LOW FROM TVARV INTO L_R_LABOR-Low WHERE
                                 NAME = 'ZBW_TC_FORECAST_LAB_OFF'.
      move:  'I'    to L_R_LABOR-sign,
             'EQ'   to L_R_LABOR-option.
      append L_R_LABOR.
      clear L_R_LABOR.
    ENDSELECT.
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
    ENDFORM.                    " populate_default_variables
    *&      Form  get_data
          text
    -->  p1        text
    <--  p2        text
    FORM get_data.
      data: wlf_lmeng like vbep-lmeng.
    *get all deliveries for date range for either a range of product hrchy
    *or a like value
      refresh int_records1.
      if wgf_prdha ne space.
        select ivbeln iposnr iKLMENG jvkorg i~werks
               imatnr imeins mprdha mmatkl
        from vbap as i
           INNER JOIN VBAK AS j
           ON ( jvbeln = ivbeln
                and j~vbtyp = 'C' )
           INNER JOIN vbuk AS k
           ON ( kvbeln = ivbeln
                and k~lfgsk <> 'C'
                and k~gbstk <> 'C' )
           INNER JOIN vbup AS l
           ON ( lvbeln = ivbeln and
                lposnr = iposnr
                and l~lfgsa <> 'C'
                and l~gbsta <> 'C' )
           INNER JOIN mara AS m
           ON ( mmatnr = imatnr
    {Start of insert by SRangaraj on June 21, 2005 >>RD3K915762
                and m~lvorm eq ' '
                and m~mstae ne '99'
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                and m~extwg = '080' )
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
           INNER JOIN marc AS n
           ON ( nmatnr = imatnr
                and nwerks = iwerks
                and n~lvorm eq ' ' )
    }End of insert by SRangaraj on June 21, 2005 >>RD3K915762
        into table int_records1 where ( i~abgru = '  '
                                     and i~klmeng > 0
                                     and m~prdha like wgf_prdha
                                     and m~matkl in l_r_matkl
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                                     and m~labor in l_r_labor ).
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
      elseif not l_r_prdha[] is initial and wgf_prdha = space.
        select ivbeln iposnr iKLMENG jvkorg i~werks
               imatnr imeins mprdha mmatkl
        from vbap as i
           INNER JOIN VBAK AS j
           ON ( jvbeln = ivbeln
                and j~vbtyp = 'C' )
           INNER JOIN vbuk AS k
           ON ( kvbeln = ivbeln
                and k~lfgsk <> 'C'
                and k~gbstk <> 'C' )
           INNER JOIN vbup AS l
           ON ( lvbeln = ivbeln and
                lposnr = iposnr
                and l~lfgsa <> 'C'
                and l~gbsta <> 'C' )
           INNER JOIN mara AS m
           ON ( mmatnr = imatnr
    {Start of insert by SRangaraj on June 21, 2005 >>RD3K915762
                and m~lvorm eq ' '
                and m~mstae ne '99'
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                and m~extwg = '080' )
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
           INNER JOIN marc AS n
           ON ( nmatnr = imatnr
                and nwerks = iwerks
                and n~lvorm eq ' ' )
    }End of insert by SRangaraj on June 21, 2005 >>RD3K915762
        into table int_records1 where ( i~abgru = '  '
                                     and i~klmeng > 0
                                     and m~prdha in l_r_prdha
                                     and m~matkl in l_r_matkl
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                                     and m~labor in l_r_labor ).
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
    endif.
        sort int_records1 by vbeln posnr.
        delete adjacent duplicates from int_records1 comparing
        vbeln posnr.
    *remove unnecessary records
        if not r_prdh3[] is initial.
        DELETE INT_RECORDS1 WHERE PRDHA+6(3) IN r_prdh3.
        endif.
    *get the schedule lines for all of the above records and
    *get the lowest schedule line date per so line item
         if not int_records1[] is initial.
         refresh int_records3.
         select vbeln posnr etenr mbdat into table int_records3
         from vbep for all entries in int_records1
                           where vbeln = int_records1-vbeln and
                                 posnr = int_records1-posnr and
                                 lmeng > 0.
         sort int_records3 by vbeln posnr etenr mbdat ascending.
         loop at int_Records1.
           loop at int_records3 where vbeln = int_records1-vbeln
                                  and posnr = int_records1-posnr.
             int_records1-mbdat = int_records3-mbdat.
             modify int_records1.
             exit.
            endloop.
         endloop.
         refresh int_records3. free int_records3.
         refresh int_records2.
    *get the deliveries and calculate the open quantities
        select vbelv posnv vbeln posnn rfmng plmin
                    from vbfa into table int_records2
                                  for all entries in int_Records1
                                  where vbelv = int_records1-vbeln
                                    and posnv = int_records1-posnr
                                    and VBTYP_N = 'J'. "Dels
    *calculate open quantities next
         loop at int_records1.
           clear wlf_lmeng.
           clear int_records2.
           loop at int_records2 where vbelv = int_records1-vbeln
                                    and posnv = int_records1-posnr.
           case int_records2-plmin.
             when '-'.
              wlf_lmeng = wlf_lmeng - int_records2-rfmng.
             when others.  "just add
              wlf_lmeng = wlf_lmeng + int_records2-rfmng.
            endcase.
           endloop.
           int_records1-klmeng = int_records1-klmeng - wlf_lmeng.
           int_records1-vbeln_dl = int_records2-vbeln.
           int_records1-posnr_dl = int_records2-posnn.
           modify int_records1.
        endloop.
        endif.
        delete int_records1 where klmeng le 0.
        refresh int_records2. free int_Records2.
    ENDFORM.                    " get_data
    *&      Form  build_detail
          text
    -->  p1        text
    <--  p2        text
    FORM build_detail.
        LOOP AT int_records1.
    *DO INDIVIDUAL MOVES - ITS FASTER THAN MOVE-CORRESPONDING
        move: int_records1-vkorg    to LS_DATA-VKORG,
              int_records1-werks    to LS_DATA-WERKS,
              int_records1-matnr    to LS_DATA-MATNR,
              int_records1-klmeng   to LS_DATA-KLMENG,
              int_records1-mbdat(6) to LS_DATA-YEARMONTH,
              int_records1-meins    TO LS_DATA-MEINS,
              int_records1-vbeln    TO LS_DATA-VGBEL,
              int_records1-posnr    TO LS_DATA-VGPOS,
              int_records1-vbeln_dl TO LS_DATA-VBELN,
              int_records1-posnr_dl TO LS_DATA-POSNR,
              int_records1-mbdat    to LS_DATA-WADAT_IST,
              int_records1-PRDHA    to LS_DATA-PRDHA,
              int_records1-matkl    to LS_DATA-MATKL.
        APPEND LS_DATA TO LT_DATA.
        clear: LS_DATA.
        ENDLOOP.
    ENDFORM.                    " build_detail

  • Bug in sqlserver 2014 long processing time in query optimizer for complex query. With compatibility set to 2012, everything is quick.

    Believe the bug to be related to the new cardinality estimator. In my case joining 7 tables it took 4 seconds to see the query execution plan, with 8 tables it took 1 minute and with 9 tables 15
    minutes! the actual processing of the query plan was sub second. (each table has only two records...)
    It looks as if there is a workload in the cardinality estimator that escalates as the number of tables and join columns increases.
    We have a number of these queries in our application and the bug is a showstopper for our customers. They will have to set compatibility level to 110 (sqlserver 2012) to run the app. Then they should
    probably not upgrade from 2012...
    Is this a known bug? What is the bug number? How can I follow the bug to see when it is fixed?
      Here is my testcase: (first building tables and data, and then the query with some comments. A version spending 15 minutes in the optimizer, takes 0 seconds to complete with the hint "option (QUERYTRACEON 9481) ".  we can't use this
    hint in the application because no dba will allow an application like ours to run as sysadmin...
    SCRIPT:
    -- Example has one table containing 25 rows. another containing 2 rows. 
    -- The one with two rows is joined in several times. 
    -- In the original query each of these joins were to separate tables. 
    -- I use this simplification because it makes it easier to build the testcase.
    ------------  CREATE TEST CASE   ----------
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[oleclient](
    [acc_f_agio] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_f_dag] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_notes_ap] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_notes_ar] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_per_cost] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_per_inc] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_reverse] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_undec_ap] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_undec_ar] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_vat_pay] [varchar](25) NOT NULL DEFAULT (' '),
    [attr_id_balance] [varchar](4) NOT NULL DEFAULT (' '),
    [bal_acc_v2] [varchar](25) NOT NULL DEFAULT (' '),
    [bal_acc_v3] [varchar](25) NOT NULL DEFAULT (' '),
    [balance_acc] [varchar](25) NOT NULL DEFAULT (' '),
    [bank_fee_acc] [varchar](25) NOT NULL DEFAULT (' '),
    [bflag] [int] NOT NULL DEFAULT ((0)),
    [client] [varchar](25) NOT NULL DEFAULT (' '),
    [client_name] [varchar](255) NOT NULL DEFAULT (' '),
    [comp_reg_no] [varchar](25) NOT NULL DEFAULT (' '),
    [compress_flag] [tinyint] NOT NULL DEFAULT ((0)),
    [country] [varchar](255) NOT NULL DEFAULT (' '),
    [country_code] [varchar](25) NOT NULL DEFAULT (' '),
    [cur_client] [varchar](25) NOT NULL DEFAULT (' '),
    [cur_item] [tinyint] NOT NULL DEFAULT ((0)),
    [cur_type] [varchar](25) NOT NULL DEFAULT (' '),
    [cur_type_tri] [varchar](25) NOT NULL DEFAULT (' '),
    [curr_period] [int] NOT NULL DEFAULT ((0)),
    [currency] [varchar](25) NOT NULL DEFAULT (' '),
    [currency_tri] [varchar](25) NOT NULL DEFAULT (' '),
    [currency_v2] [varchar](25) NOT NULL DEFAULT (' '),
    [currency_v3] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_acc_v2] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_acc_v3] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_account] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_chk_v2] [tinyint] NOT NULL DEFAULT ((0)),
    [diff_chk_v3] [tinyint] NOT NULL DEFAULT ((0)),
    [dim_v2_type] [varchar](25) NOT NULL DEFAULT (' '),
    [dim_v3_type] [varchar](25) NOT NULL DEFAULT (' '),
    [employer_id] [varchar](12) NOT NULL DEFAULT (' '),
    [header] [varchar](30) NOT NULL DEFAULT (' '),
    [header2] [varchar](30) NOT NULL DEFAULT (' '),
    [headquarter] [varchar](25) NOT NULL DEFAULT (' '),
    [language] [varchar](2) NOT NULL DEFAULT (' '),
    [last_update] [datetime] NOT NULL DEFAULT (CONVERT([datetime],'19000101 00:00:00:000',(9))),
    [leg_act_cli] [varchar](25) NOT NULL DEFAULT (' '),
    [max_inv_diff] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_inv_diff_v2] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_inv_diff_v3] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_pay_diff] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_pay_diff_v2] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_pay_diff_v3] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [municipal] [varchar](25) NOT NULL DEFAULT (' '),
    [overrun_pct] [decimal](28, 8) NOT NULL DEFAULT ((0.0)),
    [pay_client] [varchar](25) NOT NULL DEFAULT (' '),
    [pay_diff_acc_g] [varchar](25) NOT NULL DEFAULT (' '),
    [pay_diff_acc_l] [varchar](25) NOT NULL DEFAULT (' '),
    [pay_ref] [varchar](25) NOT NULL DEFAULT (' '),
    [period_no] [smallint] NOT NULL DEFAULT ((0)),
    [remind_ref] [varchar](20) NOT NULL DEFAULT (' '),
    [rev_vat_disc_ap] [tinyint] NOT NULL DEFAULT ((0)),
    [rev_vat_disc_ar] [tinyint] NOT NULL DEFAULT ((0)),
    [sys_setup_code] [varchar](2) NOT NULL DEFAULT (' '),
    [tax_office_no] [varchar](50) NOT NULL DEFAULT (' '),
    [tax_office_ref] [varchar](20) NOT NULL DEFAULT (' '),
    [tax_system] [varchar](25) NOT NULL DEFAULT (' '),
    [user_id] [varchar](25) NOT NULL DEFAULT (' '),
    [vat_reg_no] [varchar](25) NOT NULL DEFAULT (' '),
    [agrtid] [bigint] IDENTITY(1,1) NOT NULL,
    UNIQUE NONCLUSTERED 
    [agrtid] 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
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
      ('8081','8181',' ',' ','2442','1481','9998',' ',' ','1320',' ','9998',' ',' ','8110','0','UK','Agresso Demo UK','987654321012','0','United Kingdom','GB','UK','1','1','EU','200409','GBP','EUR','EUR','USD','9998','9998','9998','1','0','EU','$',' ','Agresso
    demo','Corporate Office','NO','EN','2004-09-27 12:39:00.000','UK',0.020,0.000,0.000,0.100,0.000,0.000,'0301',0.00000000,'UK','9998','9998','Jim Smith','12','Mike Anderson','0','0','EN','Bristol Brunel','V123/123',' ','JOSUTTON','123456789101');
    insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
       ('8060','8160',' ',' ','2960','1480','1490',' ',' ',' ',' ',' ',' ',' ','7770','0','N1','N1 - Énklient','971332421','0','Norway','NO','N1','0','1',' ','200701','NOK',' ','EUR',' ',' ',' ','9999','0','0','E',' ','971332421','Agresso Demo Norge (NO)','Agresso
    Demo Norge (NO)','NO','NO','2007-01-26 08:31:00.000','N1',0.050,0.000,0.000,0.500,0.000,0.000,'0301',5.00000000,'N1','9999','9999',' ','12',' ','0','0','NO',' ',' ',' ','SYSNO','971332421');
    insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
     ('900000','900000',' ',' ',' ',' ','900100',' ',' ',' ',' ',' ',' ',' ','470000','0','BE','DEMO Belgie',' ','0','Belgium','BE','BE','0','1',' ','200208','EUR',' ','USD','GBP',' ',' ','900100','0','0','2','3',' ',' ','Agresso Business World','BE','EN','2005-11-18
    17:07:00.000','BE',0.050,0.000,0.000,0.050,0.000,0.000,'2018',0.00000000,'BE','900100','900100',' ','12',' ','0','0','BT',' ',' ',' ','SYSBE','BE461149381');
      insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8030','8040',' ',' ','1250','2450','9998',' ',' ',' ',' ',' ',' ',' ','8060','0','A99','Seneca N.V. - Reporting / Intellagent',' ','0',' ','NL','A99','0','1',' ','201105','EUR',' ','USD',' ',' ',' ','9998','0','0','2',' ',' ','Seneca N.V. - Report / Intell','Seneca
    N.V. - Report / Intell','A01','EN','2011-05-19 12:19:59.000','A99',0.010,0.000,0.000,5.000,0.000,0.000,' ',0.00000000,'A99','9998','9998',' ','12',' ','0','0','EN',' ',' ',' ','SYSTEM',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('766000','666000','445860','445870','486000','487000',' ','445806','445807','445806',' ',' ','DEVISES',' ',' ','3','FR','Agresso Demo France',' ','0','France','FR','FR','1','1','1','200509','EUR','EUR',' ','FRF',' ','DEVISES','471000','0','1',' ','1',' ','Agresso
    demo France','Agresso demo France','FR','FR','2005-08-30 09:27:00.000','FR',0.100,0.000,0.500,10.000,0.000,0.000,'92',0.00000000,'FR',' ',' ',' ','12',' ','0','0','FR',' ',' ',' ','SYSFR','FR12345678');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ','9999',' ',' ',' ',' ',' ',' ',' ',' ','0','AU','Agresso Australia','123456789','0','Australia','AU','AU','0','1',' ','200708','AUD',' ',' ',' ',' ',' ','9999','0','0',' ',' ',' ','Agresso demo Australia','Corporate Office','AU','AU','2007-04-19
    12:40:00.000','AU',0.000,0.000,0.000,0.000,0.000,0.000,' ',0.00000000,'AU','9999','9999',' ','12',' ','0','0','AU',' ',' ',' ','SYSAU','123456789')
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8060','8160',' ',' ','2960','1480','1490',' ',' ',' ',' ',' ',' ',' ','7770','0','NO','Agresso Demo Norge (NO)','971332425','0','Norway','NO','NO','0','1',' ','201401','NOK',' ','EUR',' ',' ',' ','9999','0','0','E',' ','971332425','Agresso Demo Norge (NO)','Agresso
    Demo Norge (NO)','NO','NO','2014-01-11 12:34:54.000','NO',0.050,0.000,0.000,0.500,0.000,0.000,'0301',5.00000000,'NO','9999','9999',' ','12',' ','0','0','NO',' ',' ',' ','SYSNO','971332425');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('9999','9999',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','9999','0','SF','Agresso Demo SF',' ','0','Finland','SF','SF','0',' ',' ','0','FIM',' ',' ',' ',' ',' ','9999','0','0',' ',' ',' ','Agresso Demo','Hovedkontoret','SF','SE','1996-01-18 03:25:00.000','SF',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'SF','9999','9999',' ','12',' ','0','0','SF',' ',' ',' ','SYSTEM',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','US','Agresso Demo Corp.',' ','0',' ','US','US','1',' ',' ','199702','USD',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ','Agresso Demo Corp.','Headquarter','US','US','1997-01-21 02:45:00.000','US',0.020,0.000,0.000,5.000,0.000,0.000,'
    ',0.00000000,'US',' ',' ','John Smith','12','Elsa Beskow','0','0','EN',' ',' ',' ','SYSNO',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8081','8181',' ',' ','2442','1481','9998',' ',' ','1320',' ','9998',' ',' ','8110','0','EN','Agresso Demo','987654321012','0','United Kingdom','GB','EN','1','1','EU','201401','GBP','EUR','EUR','USD','9998','9998','9998','1','0','EU','$',' ','Agresso demo','Corporate
    Office','NO','EN','2014-01-06 10:20:58.000','EN',0.020,0.010,0.000,0.100,0.000,0.000,'0301',0.00000000,'EN','9998','9998','Jim Smith','12','Mike Anderson','0','0','EN',' ',' ',' ','SYSEN','123456789101');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','10','Test company 10 (for multiclient)',' ','0',' ','GB','EN','0','1',' ','200801','GBP',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ','Test company 10 (multiclient)','Test company 10 (multiclient)','EN','EN','2008-05-07
    10:57:51.000','EN',0.010,0.000,0.000,1.000,0.000,0.000,' ',0.00000000,'EN',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','SYSEN',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('4840','6880',' ',' ','1900','3900',' ','1410','3810','3810',' ','9998','9998',' ',' ','1','DE','D3 Demo Fibu/Projekt/Logistik','1277777001','0',' ','DE','DE','1','1','1','200204','EUR','EUR','USD','DEM','9998','9998','9998','1','1','2','1',' ','Agresso Demo
    Fibu/Pr/Log','Agresso Demo Fibu/Pr/Log','DE','DE','2002-04-03 17:28:00.000','DE',0.050,0.000,0.000,5.000,0.000,0.000,' ',0.00000000,'DE','4720','4720',' ','12',' ','0','0','DE','Finanzamt München II',' ',' ','SYSDE','DE888999777');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','PF','Performance test company',' ','0',' ','GB','PF','0','1',' ','200910','GBP',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','PF','EN','2009-10-14 15:49:10.000','PF',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'PF',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','SYSEN',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','01','RD Reporting Team - Test Client 01',' ','0',' ','NO','01','0',' ',' ','201101',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','01','EN','2013-10-22 13:29:46.000','01',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'01',' ',' ',' ','12','Vidar Bjørnson','0','0','EN',' ',' ',' ','REPDEV',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','02','RD Reporting Team - Test Client 02',' ','0',' ','NO','02','0',' ',' ','201101',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','01','EN','2013-10-22 13:30:11.000','02',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'02',' ',' ',' ','12','Vidar Bjørnson','0','0','EN',' ',' ',' ','REPDEV',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','03','RD Reporting Team - Test Client 03',' ','0',' ','NO','03','0',' ',' ','201101',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','01','EN','2013-10-22 13:30:47.000','03',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'01',' ',' ',' ','12','Vidar Bjørnson','0','0','EN',' ',' ',' ','REPDEV',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','9998',' ',' ',' ','0','FP','FIN PROC Test Project','321456987','0',' ','NO','FP','0','1','1','201206','EUR','EUR','USD','USD','9998','9998',' ','1','1','2','2',' ','FIN PROC Test Project','FIN PROC Test Project','FP','EN','2012-09-24
    10:43:27.000','FP',0.000,0.000,0.000,0.000,0.000,0.000,' ',0.00000000,'FP',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','FRODE','321456987MVA');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','DM','Agresso Deployment Manager',' ','0',' ','NO','DM','0',' ',' ','201301',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','DM','EN','2013-11-06 13:55:17.000','DM',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'DM',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','SYSEN',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('3960','7960',' ',' ','1790','2990','2991',' ',' ',' ',' ',' ',' ',' ','6570','0','S1','Agresso Demo Client S1','556558-7893','0','Sweden','SE','S1','1','1',' ','200401','SEK',' ','NOK','EUR','8322','8321','3740','1','1','3','6','5565587893',' ','Utbildningsföretaget
    AB','SE','SE','2005-02-10 22:04:00.000','S1',0.500,0.000,0.000,0.500,0.000,0.000,' ',0.00000000,'S1','3740','3740','Anna Kronstam','12','Thomas Jelf','0','0','SE',' ',' ',' ','SYSEN','SE556558789301');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('3960','7960',' ',' ','1790','2990','2991',' ',' ',' ',' ',' ',' ',' ','6570','0','S2','Agresso Demo Client S2','556558-7893','0','Sweden','SE','S2','1','1',' ','200202','SEK',' ','NOK','EUR','8322','8321','3740','1','1','3','6','5565587893',' ','Utbildningsföretaget
    AB','SE','SE','2005-01-17 13:20:00.000','S2',0.500,0.000,0.000,0.500,0.000,0.000,' ',0.00000000,'S2','3740','3740','Anna Kronstam','12','Thomas Jelf','0','0','SE',' ',' ',' ','SYSSE','SE556558789301');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('910156','910166',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','NL','DEMO Nederland','KVK9937465','0','Holland','NL','NL','0','1',' ','200708','EUR',' ',' ',' ',' ',' ','999999','0','0',' ',' ',' ','Global Trada N.V.','Global Trada N.V.','NL','NL','2007-08-15
    13:41:00.000','NL',50000.000,0.000,0.000,50000.000,0.000,0.000,'3994 DB',0.00000000,'NL','470720','470720',' ','12',' ','0','0','NL',' ',' ',' ','ROB','NL009404296B01');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('4664','4730',' ',' ','4755',' ',' ',' ',' ',' ',' ',' ',' ',' ','4755','0','DK','Agresso Demo Denmark',' ','0','Denmark','DK','DK','0','1',' ','0','DKK',' ',' ',' ',' ',' ',' ','0','0',' ',' ','0123456789','Agresso Denmark','Agresso Denmark','DK','DK','2005-10-14
    08:40:00.000','DK',0.100,0.000,0.000,0.100,0.000,0.000,' ',0.00000000,'DK',' ',' ',' ','12',' ','0','0','DK',' ',' ',' ','SYSDK',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('76800','66800',' ',' ','48000','48500','99999','47201','47701',' ',' ',' ',' ',' ','66910','1','SP','Agresso Spain',' ','0','Spain','ES','SP','0','1','1','200804','EUR','EUR','GBP',' ',' ',' ','99999','0','0','2',' ',' ','Agresso DEMO S.A','Agresso DEMO S.A','SP','ES','2008-04-07
    14:01:38.000','SP',0.010,0.000,0.000,0.010,0.000,0.000,' ',0.50000000,'SP','99999','99999','Dpto.Aministración','12','Dpto.Riesgos','0','0','ES','00007307','18ru0456',' ','SYSES','B18389742');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('3960','7960',' ',' ','1790','2990','2991',' ',' ',' ',' ','8439',' ',' ','6570','0','SE','UTBILDNINGSFÖRETAGET AB','2021001235','0',' ','SE','SE','0','1',' ','200707','SEK',' ','EUR',' ','8439',' ','3740','1','0','2',' ',' ','Masterföretaget AB','Masterföretaget
    AB','SE','SE','2008-06-09 12:38:43.000','SE',0.500,0.000,0.000,0.500,0.000,0.000,'STLM',0.05000000,'SE','3740','3740',' ','12',' ','0','0','SE',' ','Stockholm',' ','SYSEN','SE202100123501');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8081','8181',' ',' ','2442','1481','9998','1301','1307','1320',' ','9998',' ',' ','8110','1','IT','IT - Client',' ','0','Italy','IT','IT','1','EU','EU','200601','EUR','EUR','EUR','USD','9998','9998','9998','1','0','EU','$','CODE SIA','Agresso demo Italia','Corporate
    Office','IT','IT','2006-09-28 08:46:00.000','IT',0.020,0.000,0.000,0.100,0.000,0.000,'0301',0.00000000,'IT','9998','9998','Jim Smith','12','Mike Anderson','0','0','IT','Tax authority province','Auto-no011299',' ','SYSEN','11465420153');
    go
    CREATE UNIQUE NONCLUSTERED INDEX [aioleclient1] ON [dbo].[oleclient]
    [client] 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)
    GO
    CREATE TABLE [dbo].[Htable1](
    [amount] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [cur_amount] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [value_2] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [value_3] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [currency] [varchar](25) NOT NULL DEFAULT (' '),
    [client] [varchar](25) NOT NULL DEFAULT (' '),
    [asset_id] [varchar](25) NOT NULL DEFAULT (' '),
    [depr_book_id] [varchar](25) NOT NULL DEFAULT (' '),
    [input_id] [bigint] NOT NULL DEFAULT ((0)),
    [amount_type] [char](25) NOT NULL DEFAULT (' '),
    [reval_year] [int] NOT NULL DEFAULT ((0)),
    [trans_seq] [int] NOT NULL DEFAULT ((0)),
    [sequence_no] [int] NOT NULL DEFAULT ((0)),
    [at_trans_date] [datetime] NOT NULL DEFAULT (CONVERT([datetime],'19000101',(112))),
    [agrtid] [bigint] IDENTITY(1,1) NOT NULL,
    UNIQUE NONCLUSTERED 
    [agrtid] 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
    INSERT INTO Htable1 (at_trans_date,amount,amount_type,asset_id,client,cur_amount,currency,depr_book_id,input_id,reval_year,sequence_no,trans_seq,value_2,value_3) 
     VALUES ('20140603' ,0.00000000,'GLN','BM','EN',0.00000000,'GBP','BUSINESS',563,0,29,0,0.00000000,0.00000000 ) 
    GO
    INSERT INTO Htable1 (at_trans_date,amount,amount_type,asset_id,client,cur_amount,currency,depr_book_id,input_id,reval_year,sequence_no,trans_seq,value_2,value_3) 
     VALUES ('20140603' ,0.00000000,'GLN','BM','EN',0.00000000,'GBP','BUSINESS',563,0,30,0,0.00000000,0.00000000 ) 
    GO
    --=================================================================================
    -- The following query takes 15 minutes on my computer to give an execution plan. Fetching the data takes no additional time.
    -- removing one table (CACHED88) from the query brings the time down to 59 seconds.
    -- removing one more (CACHED87) brings it down to 4 seconds.
    -- adding the hint "option (QUERYTRACEON 9481)" to the first case, brings it down from 15 minutes to less than one second!
    SELECT 
           CACHED83.amount - ( CACHED76.amount + CACHED75.amount + CACHED85.amount + CACHED86.amount + CACHED87.amount + CACHED88.amount) AS amount, 
           CACHED83.amount - ( CACHED76.amount + CACHED75.amount + CACHED85.amount + CACHED86.amount + CACHED87.amount + CACHED88.amount) AS cur_amount, 
           c.currency    
    FROM 
           Htable1   tab1 , 
           Htable1   CACHED83 , 
           Htable1   CACHED76 ,
           Htable1   CACHED75 ,
           Htable1   CACHED85 ,
           Htable1   CACHED86 ,
           Htable1   CACHED87 ,
           Htable1   CACHED88 ,
           oleclient c  
    WHERE 
           tab1.client = c.client AND
           tab1.amount_type = 'GLN' AND 
           tab1.asset_id     = CACHED83.asset_id AND 
           tab1.depr_book_id = CACHED83.depr_book_id AND        
           tab1.client       = CACHED83.client AND 
           tab1.input_id     = CACHED83.input_id AND 
           tab1.reval_year   = CACHED83.reval_year AND     
           tab1.trans_seq    = CACHED83.trans_seq AND 
           tab1.sequence_no  = CACHED83.sequence_no AND 
           tab1.asset_id     = CACHED76.asset_id AND  
           tab1.depr_book_id = CACHED76.depr_book_id AND 
           tab1.client       = CACHED76.client AND 
           tab1.input_id     = CACHED76.input_id AND  
           tab1.reval_year   = CACHED76.reval_year AND 
           tab1.trans_seq    = CACHED76.trans_seq AND 
           tab1.sequence_no  = CACHED76.sequence_no AND 
           tab1.asset_id     = CACHED75.asset_id AND 
           tab1.depr_book_id = CACHED75.depr_book_id AND 
           tab1.client       = CACHED75.client AND      
           tab1.input_id     = CACHED75.input_id AND 
           tab1.reval_year   = CACHED75.reval_year AND 
           tab1.trans_seq    = CACHED75.trans_seq AND       
           tab1.sequence_no  = CACHED75.sequence_no AND 
           tab1.asset_id     = CACHED85.asset_id AND 
           tab1.depr_book_id = CACHED85.depr_book_id AND        
           tab1.client       = CACHED85.client AND 
           tab1.input_id     = CACHED85.input_id AND 
           tab1.reval_year   = CACHED85.reval_year AND     
           tab1.trans_seq    = CACHED85.trans_seq AND 
           tab1.sequence_no  = CACHED85.sequence_no AND 
           tab1.asset_id     = CACHED86.asset_id AND 
           tab1.depr_book_id = CACHED86.depr_book_id AND 
           tab1.client       = CACHED86.client AND 
           tab1.input_id     = CACHED86.input_id AND  
           tab1.reval_year   = CACHED86.reval_year AND 
           tab1.trans_seq    = CACHED86.trans_seq AND 
           tab1.sequence_no  = CACHED86.sequence_no AND  
           tab1.asset_id     = CACHED87.asset_id AND 
           tab1.depr_book_id = CACHED87.depr_book_id AND 
           tab1.client       = CACHED87.client AND      
           tab1.input_id     = CACHED87.input_id AND 
           tab1.reval_year   = CACHED87.reval_year AND 
           tab1.trans_seq    = CACHED87.trans_seq AND       
           tab1.sequence_no  = CACHED87.sequence_no  AND  
           tab1.asset_id     = CACHED88.asset_id AND 
           tab1.depr_book_id = CACHED88.depr_book_id AND 
           tab1.client       = CACHED88.client AND      
           tab1.input_id     = CACHED88.input_id AND 
           tab1.reval_year   = CACHED88.reval_year AND 
           tab1.trans_seq    = CACHED88.trans_seq AND       
           tab1.sequence_no  = CACHED88.sequence_no  
    --  option (QUERYTRACEON 9481)         

    Reading "What's new in Sql Server 2014" (http://msdn.microsoft.com/en-us/library/bb510411.aspx#CE). I see that  it says:
    New Design for Cardinality Estimation
    The cardinality estimation logic, called the cardinality estimator, is re-designed in SQL Server 2014 to improve the quality of query plans, and therefore to improve query performance. The new cardinality estimator incorporates assumptions and algorithms
    that work well on modern OLTP and data warehousing workloads. It is based on in-depth cardinality estimation research on modern workloads, and our learnings over the past 15 years of improving the SQL Server cardinality estimator. Feedback from customers shows
    that while most queries will benefit from the change or remain unchanged, a small number might show regressions compared to the previous cardinality estimator. For performance tuning and testing recommendations, seeCardinality
    Estimation (SQL Server).
    I states that a "small number of queries might show regressions". To mee the regression is a showstopper and seems to have to do with complexity. I found one query reported by Juha Salo (bug 893758) that possibly could have to do with the same thing.
    It is a query with many joins. Simplifying the query by removing one of the joins, makes it work fine. The query documented in his report does not need any setup as it is a query on system tables as sys.indexes and sys.index_columns.
    I quote:
    There is a huge difference in performance for the following query between compatibility level 120 and the lower levels:
    dbcc dropcleanbuffers
    SELECT i.NAME
    FROM sys.indexes i
    INNER JOIN sys.index_columns k ON i.object_id = k.object_id
    AND i.index_id = k.index_id
    INNER JOIN sys.objects o ON i.object_id = o.object_id
    AND k.object_id = o.object_id
    INNER JOIN sys.index_columns k1 ON i.object_id = k1.object_id
    AND i.index_id = k1.index_id
    AND k1.key_ordinal = 1
    INNER JOIN sys.index_columns k2 ON i.object_id = k2.object_id
    AND i.index_id = k2.index_id
    AND k2.key_ordinal = 2
    INNER JOIN sys.index_columns k3 ON i.object_id = k3.object_id
    AND i.index_id = k3.index_id
    AND k3.key_ordinal = 3
    INNER JOIN sys.index_columns k4 ON i.object_id = k4.object_id
    AND i.index_id = k4.index_id
    AND k4.key_ordinal = 4
    INNER JOIN sys.index_columns k5 ON i.object_id = k5.object_id
    AND i.index_id = k5.index_id
    AND k5.key_ordinal = 5
    INNER JOIN sys.index_columns k6 ON i.object_id = k6.object_id
    AND i.index_id = k6.index_id
    AND k6.key_ordinal = 6
    INNER JOIN sys.index_columns k7 ON i.object_id = k7.object_id
    AND i.index_id = k7.index_id
    AND k7.key_ordinal = 7
    INNER JOIN sys.columns c1 ON o.object_id = c1.object_id
    AND k1.column_id = c1.column_id
    INNER JOIN sys.columns c2 ON o.object_id = c2.object_id
    AND k2.column_id = c2.column_id
    INNER JOIN sys.columns c3 ON o.object_id = c3.object_id
    AND k3.column_id = c3.column_id
    INNER JOIN sys.columns c4 ON o.object_id = c4.object_id
    AND k4.column_id = c4.column_id
    INNER JOIN sys.columns c5 ON o.object_id = c5.object_id
    AND k5.column_id = c5.column_id
    INNER JOIN sys.columns c6 ON o.object_id = c6.object_id
    AND k6.column_id = c6.column_id
    INNER JOIN sys.columns c7 ON o.object_id = c7.object_id
    AND k7.column_id = c7.column_id
    Can be run in any database. In our case we have a legacy database with almost 10 000 (ten thousand) tables. In that kind of database the query just freezes fully utilizing a single cpu core.
    If compatibility level is switched to 110 then query performs as it should.

  • Any room for improvement for this query? Explain Plan attached.

    Is there any room for improvement for this query? Table stats are up-to-date. Any suggestions Query rewrite, addition of indexes,...etc ??
    select sum(CONF
                 when (cd.actl_qty - cd.total_alloc_qty - lsd.Q < 0) then
                  0
                 else
                  cd.actl_qty - cd.total_alloc_qty - lsd.Q
               end)
      from (select sum(reqd_qty) as Q, ITEM_ID as ITEM
              from SHIP_DTL SD
             where exists (select 1
                      from CONF_dtl
                     where CONF_nbr = '1'
                       and ITEM_id = SD.ITEM_id)
             group by ITEM_id) lsd,
           CONF_dtl cd
    where lsd.ITEM = cd.ITEM_id
       and cd.CONF_nbr = '1'Total number of rows in the tables involved
    select count(*) from CONF_DTL;
      COUNT(*)
       1785889
    select count(*) from shp_dtl;
      COUNT(*)
        286675
      Explain Plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 2325658044
    | Id  | Operation                           | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                    |                    |     1 |    39 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE                     |                    |     1 |    39 |            |          |
    |   2 |   VIEW                              |                    |     1 |    39 |     4  (25)| 00:00:01 |
    |   3 |    HASH GROUP BY                    |                    |     1 |   117 |     4  (25)| 00:00:01 |
    |   4 |     TABLE ACCESS BY INDEX ROWID     | SHIP_DTL           |     1 |    15 |     1   (0)| 00:00:01
    |   5 |      NESTED LOOPS                   |                    |     1 |   117 |     3   (0)| 00:00:01 |
    |   6 |       MERGE JOIN CARTESIAN          |                    |     1 |   102 |     2   (0)| 00:00:01 |
    |   7 |        TABLE ACCESS BY INDEX ROWID  | CONF_DTL           |     1 |    70 |     1   (0)| 00:00:01 |
    |*  8 |         INDEX RANGE SCAN            | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
    |   9 |        BUFFER SORT                  |                    |     1 |    32 |     1   (0)| 00:00:01 |
    |  10 |         SORT UNIQUE                 |                    |     1 |    32 |     1   (0)| 00:00:01 |
    |  11 |          TABLE ACCESS BY INDEX ROWID| CONF_DTL           |     1 |    32 |     1   (0)| 00:00:01 |
    |* 12 |           INDEX RANGE SCAN          | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
    |* 13 |       INDEX RANGE SCAN              | SHIP_DTL_IND_6 |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       8 - access("CD"."CONF_NBR"='1')
      12 - access("CONF_NBR"='1')
      13 - access("ITEM_ID"="SD"."ITEM_ID")
           filter("ITEM_ID"="CD"."ITEM_ID")

    Citizen_2 wrote:
    Is there any room for improvement for this query? Table stats are up-to-date. Any suggestions Query rewrite, addition of indexes,...etc ??You say that the table stats are up-to-date, but is the following assumption of the optimizer correct:
    select count(*)
    from CONF_dtl
    where CONF_nbr = '1';Does this query return a count of 1? I doubt that, but that's what Oracle estimates in the EXPLAIN PLAN output. Based on that assumption you get a cartesian join between the two CONF_DTL table instances, and the result - which is still expected to be one row at most - is then joined to the SHIP_DTL table using a NESTED LOOP.
    If above assumption is incorrect, the number of rows generated by the cartesian join can be tremendous rendering the NESTED LOOP operation quite inefficient.
    You can verify this by using the DBMS_XPLAN.DISPLAY_CURSOR function together with the GATHER_PLAN_STATISTICS hint, if you're already on 10g or later.
    For more information regarding the DISPLAY_CURSOR function, see e.g. here: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
    It will show you the actual cardinalities compared to the estimated cardinalities.
    If the estimate of the optimizer is incorrect, you should find out why. There still might be some issues with the statistics, since this is most obvious reason for incorrect estimates.
    Are your index statistics up-to-date?
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Performance of the query incresed to 1 hour 15 mins....

    the view is working, but the performance of the query is horrible.
    Our pull time has increased from 25 minutes to 1 hour and 15 minutes.

    Can you please advice me the same solution pplies for prodction box also...
    Production database details::::
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The query in production database::::
    SELECT                                                      /*+ALL_ROWS*/
      2             a  .lcl_id AS Ora_Order,                            --Order_Number,
      3                a.closed_date AS Closed_Date,
      4                a.modified_date AS Modified_Date,
      5                a.received_date AS Received_Date,
      6                a.status AS Status,
      7                b.seq AS Ora_Line,                                 --Line_Number
      8                b.sub_seq AS Ora_sub_line,
      9                c.seq AS Unit_Number,
    10                SUBSTR (c.olig_group_id, INSTR (c.olig_group_id,
    11                                                '.',
    12                                                -1,
    13                                                1)
    14                                         + 1)
    15                   AS shipment_number,
    16                c.tag AS Tag,
    17                c.special_tag AS Customer_Tag,
    18                h.fmly_serial_id AS Serial_Number,
    19                d.allocation_timestamp AS Alloc_Date,
    20                MIN (f.closed_timestamp) AS First_Event_On_Floor,
    21                -- CALIBRATION
    22                MAX (DECODE (f.uutt_mstr_id, 1, f.closed_timestamp, NULL))
    23                   AS Calibration_Date,
    24                -- PACKAGING
    25                MAX (DECODE (f.uutt_mstr_id, 50, f.closed_timestamp, NULL))
    26                   AS Package_Date,
    27                -- CAPS KITTING
    28                MAX(DECODE (
    29                       f.uutt_mstr_id,
    30                       100,
    31                       DECODE (f.stnd_seq, 2024961, f.closed_timestamp, NULL)
    32                    ))
    33                   AS Caps_Kitting_Date,
    34                lastprodsn.pm_mstr_id AS Tagged_Model,
    35                b.CEP AS ETO_Number,
    36                j.VALUE AS Product_Options,
    37                a.PO AS PO_Number,
    38                --       lastprodsn.uut_glbl_id                                     as LastProdSN_UUT_Glbl_ID  -- replaced on 3/31/2011 BJACK
    39                MAX (DECODE (f.uutt_mstr_id, 2, f.glbl_id, NULL))
    40                   AS LastProdSN_UUT_Glbl_ID
    41          FROM   ssc.ordr_hdrs a,                 -- glbl_id = sales order number
    42                ssc.ordr_lns b,          -- oh_glbl_id = SO #, SEQ = line number
    43                ssc.ordr_ln_itms c, -- ol_oh_glbl_id = SO #, ol_seq = line #, seq = unit #, olig_group_id = shipment #
    44                ssc.omar_track_maps d, -- for tracking id, holds the allocation timestamp
    45                (SELECT   x.uut_glbl_id,
    46                          x.oli_ol_oh_glbl_id,
    47                          x.oli_ol_seq,
    48                          x.oli_ol_sub_seq,
    49                          x.oli_seq,
    50                          x.sm_glbl_id,
    51                          x.pm_mstr_id
    52                   FROM      ssc.serial_prod_uut_maps x
    53                          JOIN
    54                             (  SELECT   oli_ol_oh_glbl_id,
    55                                         oli_ol_seq,
    56                                         oli_ol_sub_seq,
    57                                         oli_seq,
    58                                         MAX (uut_glbl_id) Max_oli_uut_glbl_id
    59                                  FROM   ssc.serial_prod_uut_maps
    60                              GROUP BY   oli_ol_oh_glbl_id,
    61                                         oli_ol_seq,
    62                                         oli_ol_sub_seq,
    63                                         oli_seq) MAXOLIUUT
    64                          ON MAXOLIUUT.Max_oli_uut_glbl_id = x.uut_glbl_id
    65                             AND MAXOLIUUT.oli_ol_oh_glbl_id =
    66                                   x.oli_ol_oh_glbl_id
    67                             AND MAXOLIUUT.oli_ol_seq = x.oli_ol_seq
    68                             AND MAXOLIUUT.oli_ol_sub_seq = x.oli_ol_sub_seq
    69                             AND MAXOLIUUT.oli_seq = x.oli_seq) lastprodsn, -- find latest uut for OLI (assumes UUT ids are in sequence so max is latest; needed to deal with SN or product chgs for OLI)
    70                ssc.serial_prod_uut_maps e, -- go get all UUT IDs for the OLI's latest product number and serial number
    71                ssc.uuts f, -- go get UUT details for all of the good OLI-product-SNs
    72                ssc.uut_params g, -- go get the package void parameter (so can exclude them)
    73                ssc.serial_mstrs h,        -- go get serial number for the SN id
    74                ssc.ORDR_LN_PARAMS j        -- go get options for product number
    75        WHERE                   -- join a to b sales orders to sales order lines
    76             a      .glbl_id = b.oh_glbl_id
    77                AND -- join b to c to get sales order line items (units for a line item)
    78                   b.oh_glbl_id = c.ol_oh_glbl_id
    79                AND b.seq = c.ol_seq
    80                AND b.sub_seq = c.ol_sub_seq
    81                AND -- join c to d to get allocation date if available (outer join)
    82                   c.otm_track_id = d.track_id(+)
    83                AND                                      -- join c to lastprodsn
    84                   c.ol_oh_glbl_id = lastprodsn.oli_ol_oh_glbl_id(+)
    85                AND c.ol_seq = lastprodsn.oli_ol_seq(+)
    86                AND c.ol_sub_seq = lastprodsn.oli_ol_sub_seq(+)
    87                AND c.seq = lastprodsn.oli_seq(+)
    88                AND -- join lastprodsn to k to get serial number for last product/serial number processed
    89                   lastprodsn.sm_glbl_id = h.glbl_id(+)
    90                AND -- join lastprodsn to e to go get all the UUT ids for this OLI + Product # + Serial #
    91                   lastprodsn.oli_ol_oh_glbl_id = e.oli_ol_oh_glbl_id(+)
    92                AND lastprodsn.oli_ol_seq = e.oli_ol_seq(+)
    93                AND lastprodsn.oli_ol_sub_seq = e.oli_ol_sub_seq(+)
    94                AND lastprodsn.oli_seq = e.oli_seq(+)
    95                AND lastprodsn.pm_mstr_id = e.pm_mstr_id(+)
    96                AND lastprodsn.sm_glbl_id = e.sm_glbl_id(+)
    97                AND --join e to f to get UUT details for the good OLI-Product-SN combos
    98                   e.uut_glbl_id = f.glbl_id(+)
    99                AND                   -- join f to g to get the voided parameter
    100                   f.glbl_id = g.uut_glbl_id(+)
    101                AND -- join c to j to get the option codes for the product number (parameter 2070)
    102                   c.ol_oh_glbl_id = j.ol_oh_glbl_id(+)
    103                AND c.ol_seq = j.ol_seq(+)
    104                AND c.ol_sub_seq = j.ol_sub_seq(+)
    105                AND c.seq = j.seq(+)
    106                AND j.par_mstr_id(+) = 2070
    107                AND j.VALUE(+) IS NOT NULL
    108                AND                                   -- un-voided packages only
    109                   g.par_mstr_id(+) = 1003
    110                AND (g.uut_glbl_id IS NULL OR g.VALUE = 'N')
    111   /*             AND                      -- 1003 = package void status parameter
    112                   g.VALUE(+) = 'N' */
    113     GROUP BY   a.lcl_id,
    114                b.seq,
    115                b.sub_seq,
    116                c.seq,
    117                c.olig_group_id,
    118                a.closed_date,
    119                a.modified_date,
    120                a.received_date,
    121                a.status,
    122                c.tag,
    123                c.special_tag,
    124                h.fmly_serial_id,
    125                d.allocation_timestamp,
    126                lastprodsn.pm_mstr_id,
    127                b.CEP,
    128                j.VALUE,
    129                a.PO
    130             /
    SQL>=================
    explain plan:::
    | Id  | Operation                        | Name                 | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                 |                      | 82182 |    29M|       |   160K  (2)| 00:32:09 |
    |   1 |  HASH GROUP BY                   |                      | 82182 |    29M|    30M|   160K  (2)| 00:32:09 |
    |   2 |   NESTED LOOPS OUTER             |                      | 82182 |    29M|       |   154K  (2)| 00:30:51 |
    |   3 |    NESTED LOOPS OUTER            |                      | 82182 |    26M|       |   145K  (2)| 00:29:12 |
    |*  4 |     HASH JOIN                    |                      | 82182 |    23M|    10M|   137K  (2)| 00:27:33 |
    |   5 |      TABLE ACCESS FULL           | ORDR_HDRS            |   159K|  8716K|       |   397   (4)| 00:00:05 |
    |*  6 |      HASH JOIN                   |                      | 89664 |    20M|    15M|   135K  (2)| 00:27:09 |
    |   7 |       TABLE ACCESS FULL          | ORDR_LNS             |   506K|  9882K|       |   688   (5)| 00:00:09 |
    |*  8 |       HASH JOIN RIGHT OUTER      |                      | 89424 |    19M|    17M|   133K  (2)| 00:26:39 |
    |   9 |        TABLE ACCESS FULL         | OMAR_TRACK_MAPS      |   567K|    10M|       |   725   (5)| 00:00:09 |
    |* 10 |        FILTER                    |                      |       |       |       |            |          |
    |* 11 |         HASH JOIN RIGHT OUTER    |                      | 89424 |    17M|  4440K|   130K  (2)| 00:26:09 |
    |* 12 |          TABLE ACCESS FULL       | UUT_PARAMS           |   133K|  2869K|       |  3608   (7)| 00:00:44 |
    |* 13 |          HASH JOIN RIGHT OUTER   |                      |  3244K|   563M|    85M| 96934   (3)| 00:19:24 |
    |  14 |           TABLE ACCESS FULL      | UUTS                 |  2247K|    60M|       |  4893   (4)| 00:00:59 |
    |* 15 |           HASH JOIN RIGHT OUTER  |                      |  3244K|   476M|   239M| 62078   (3)| 00:12:25 |
    |  16 |            TABLE ACCESS FULL     | SERIAL_PROD_UUT_MAPS |  3639K|   197M|       |  6481   (4)| 00:01:18 |
    |* 17 |            HASH JOIN RIGHT OUTER |                      |  3244K|   300M|       | 26716   (4)| 00:05:21 |
    |  18 |             VIEW                 |                      |     1 |    48 |       | 18639   (4)| 00:03:44 |
    |* 19 |              FILTER              |                      |       |       |       |            |          |
    |  20 |               HASH GROUP BY      |                      |     1 |    85 |       | 18639   (4)| 00:03:44 |
    |* 21 |                HASH JOIN         |                      |   308K|    25M|    40M| 18587   (4)| 00:03:44 |
    |* 22 |                 TABLE ACCESS FULL| SERIAL_PROD_UUT_MAPS |  1060K|    28M|       |  6520   (5)| 00:01:19 |
    |* 23 |                 TABLE ACCESS FULL| SERIAL_PROD_UUT_MAPS |  1060K|    57M|       |  6520   (5)| 00:01:19 |
    |  24 |             TABLE ACCESS FULL    | ORDR_LN_ITMS         |  3244K|   151M|       |  8011   (4)| 00:01:37 |
    |* 25 |     TABLE ACCESS BY INDEX ROWID  | ORDR_LN_PARAMS       |     1 |    35 |       |     1   (0)| 00:00:01 |
    |* 26 |      INDEX RANGE SCAN            | OLP_OL_FK_I          |     1 |       |       |     1   (0)| 00:00:01 |
    |  27 |    TABLE ACCESS BY INDEX ROWID   | SERIAL_MSTRS         |     1 |    37 |       |     1   (0)| 00:00:01 |
    |* 28 |     INDEX RANGE SCAN             | SM_PK                |     1 |       |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - access("A"."GLBL_ID"="B"."OH_GLBL_ID")
       6 - access("B"."OH_GLBL_ID"="C"."OL_OH_GLBL_ID" AND "B"."SEQ"="C"."OL_SEQ" AND
                  "B"."SUB_SEQ"="C"."OL_SUB_SEQ")
       8 - access("C"."OTM_TRACK_ID"="D"."TRACK_ID"(+))
      10 - filter("G"."UUT_GLBL_ID" IS NULL OR "G"."VALUE"='N')
      11 - access("F"."GLBL_ID"="G"."UUT_GLBL_ID"(+))
      12 - filter("G"."PAR_MSTR_ID"(+)=1003)
      13 - access("E"."UUT_GLBL_ID"="F"."GLBL_ID"(+))
      15 - access("LASTPRODSN"."OLI_OL_OH_GLBL_ID"="E"."OLI_OL_OH_GLBL_ID"(+) AND
                  "LASTPRODSN"."OLI_OL_SEQ"="E"."OLI_OL_SEQ"(+) AND "LASTPRODSN"."OLI_OL_SUB_SEQ"="E"."OLI_OL_SUB_SEQ"(+)
                  AND "LASTPRODSN"."OLI_SEQ"="E"."OLI_SEQ"(+) AND "LASTPRODSN"."PM_MSTR_ID"="E"."PM_MSTR_ID"(+) AND
                  "LASTPRODSN"."SM_GLBL_ID"="E"."SM_GLBL_ID"(+))
      17 - access("C"."OL_OH_GLBL_ID"="LASTPRODSN"."OLI_OL_OH_GLBL_ID"(+) AND
                  "C"."OL_SEQ"="LASTPRODSN"."OLI_OL_SEQ"(+) AND "C"."OL_SUB_SEQ"="LASTPRODSN"."OLI_OL_SUB_SEQ"(+) AND
                  "C"."SEQ"="LASTPRODSN"."OLI_SEQ"(+))
      19 - filter("X"."UUT_GLBL_ID"=MAX("UUT_GLBL_ID"))
      21 - access("OLI_OL_OH_GLBL_ID"="X"."OLI_OL_OH_GLBL_ID" AND "OLI_OL_SEQ"="X"."OLI_OL_SEQ" AND
                  "OLI_OL_SUB_SEQ"="X"."OLI_OL_SUB_SEQ" AND "OLI_SEQ"="X"."OLI_SEQ")
      22 - filter("OLI_OL_OH_GLBL_ID" IS NOT NULL AND "OLI_OL_SEQ" IS NOT NULL AND "OLI_SEQ" IS NOT NULL AND
                  "OLI_OL_SUB_SEQ" IS NOT NULL)
      23 - filter("X"."OLI_OL_OH_GLBL_ID" IS NOT NULL AND "X"."OLI_OL_SEQ" IS NOT NULL AND "X"."OLI_SEQ" IS
                  NOT NULL AND "X"."OLI_OL_SUB_SEQ" IS NOT NULL)
      25 - filter("J"."PAR_MSTR_ID"(+)=2070 AND "J"."VALUE"(+) IS NOT NULL AND "C"."SEQ"="J"."SEQ"(+))
      26 - access("C"."OL_OH_GLBL_ID"="J"."OL_OH_GLBL_ID"(+) AND "C"."OL_SEQ"="J"."OL_SEQ"(+) AND
                  "C"."OL_SUB_SEQ"="J"."OL_SUB_SEQ"(+))
      28 - access("LASTPRODSN"."SM_GLBL_ID"="H"."GLBL_ID"(+))
    SQL>mod. action : adding tags , is that so difficult ?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

  • Tuning tricks for the query.

    Hi Everyone,
    This is my DB version @ production.
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production                         
    CORE 10.2.0.4.0 Production                                       
    TNS for Linux: Version 10.2.0.4.0 - Production                 
    NLSRTL Version 10.2.0.4.0 - Production
    We have a query, which is running more than 3 mins at production as we have 40 millions active records for almost 2 million active patients.
    So clearly the active record percentage is 98. We have indexes on all required field values last date of computed statistics was 1st Jan 2014.
    But we are unable achieve the performance from the query. If we are making it tightly coupled with parent - child relationship, then it's generating cost
    value more than 2 million. So we tried some sub-queries but still the cost value is in million. Please do have a look at the query and suggest me something where
    I can meliorate this. We can't go change DB structure straight away right now. So what needs to be done here? Please suggest something.
    Query:-
    select distinct
            (select p.last_name || ', ' || p.first_name
              from patient p
             where p.patient_id = loc.patient_id) as patient_name,
           (select p.external_id
              from patient p
             where p.patient_id = loc.patient_id) as external_id,
           (select p.spectra_mrn
            from patient p
            where p.patient_id = loc.patient_id) as spectra_mrn,
           ord.requisition_number as requisition_number,
           f.facility_name as facility_name,
           f.facility_id as facility_id,
           (select fad.account_type as modality
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as modality,
           (select fad.account_number as account_number
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as account_number,
           (select fad.hlab_num as hlab_num
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as hlab_num,
           loc.order_draw_dt as draw_dt,
           c.corporation_name as corporation_name,
           c.corporation_acronym as acronym,
           loc.patient_id,
           loct.test_id
      from lab_order_occ loc,
           lab_order_occ_test loct,
           facility f,
           corporation c,
           order_requisition_header ord
    where loc.lab_order_occ_id = loct.lab_order_occ_id
       and loc.facility_id = f.facility_id
       and f.corporation_id = c.corporation_id
       and ord.patient_id = loc.patient_id
       and ord.facility_id = loc.facility_id
       and ord.draw_dt = loc.order_draw_dt
       and loc.order_draw_dt between trunc(sysdate) - 7 and trunc(sysdate)
       and loc.status = 'A'
       and loc.msg_sent_to_lab_yn = 'Y'
       and loct.status <> 'R'
       and loct.test_id in (
                       select test_id
                         from test_required
                        where required_test_code in (
                                                     select test_code
                                                       from interface_adt_aoe_master))
        and              
          (select count(*) from interface_adt_aoe_master where source_system = corporation_acronym
          and test_code = (select test_code from test where test_id=(select aoe_test_id from lab_order_occ_test_aoe where lab_order_occ_test_id= loct.lab_order_occ_test_id)))
          !=
          (select count(*) from EMR_ADTAOE_DTL where patient_id = loc.patient_id and facility_id = loc.facility_id and (
              (test_id = (select aoe_test_id from lab_order_occ_test_aoe where lab_order_occ_test_id= loct.lab_order_occ_test_id) and trunc(draw_date) like trunc(loc.order_draw_dt))
                or (test_id = (select aoe_test_id from lab_order_occ_test_aoe where LAB_ORDER_OCC_TEST_ID= loct.lab_order_occ_test_id) and trunc(draw_date)= trunc(to_date('12-31-2999','mm-dd-yyyy')))
            and STATUS = 'Y'  and ANSWER is not null)
    Execution Plan @ QAT environment
    explain plan succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                          
    Plan hash value: 2140167730                                                                                                                                                                                                                                                                                
    | Id  | Operation                             | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                   
    |   0 | SELECT STATEMENT                      |                                |   399 | 59451 |  6293   (1)| 00:01:16 |                                                                                                                                                                                   
    |   1 |  TABLE ACCESS BY INDEX ROWID          | PATIENT                        |     1 |    21 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |*  2 |   INDEX UNIQUE SCAN                   | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |   3 |  TABLE ACCESS BY INDEX ROWID          | PATIENT                        |     1 |    11 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |*  4 |   INDEX UNIQUE SCAN                   | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |   5 |  TABLE ACCESS BY INDEX ROWID          | PATIENT                        |     1 |    12 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |*  6 |   INDEX UNIQUE SCAN                   | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |   7 |  NESTED LOOPS                         |                                |     1 |    43 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |   8 |   NESTED LOOPS                        |                                |     1 |    29 |     4   (0)| 00:00:01 |                                                                                                                                                                                   
    |   9 |    NESTED LOOPS                       |                                |     1 |    19 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 10 |     INDEX UNIQUE SCAN                 | PATIENT_PK                     |     1 |     5 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 11 |     INDEX RANGE SCAN                  | PATIENT_FACILITY_MOD_IX_01     |     1 |    14 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |  12 |    TABLE ACCESS BY INDEX ROWID        | FACILITY_ACCOUNT_MODALITY      |     1 |    10 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 13 |     INDEX UNIQUE SCAN                 | FACILITY_ACCOUNT_MODALITY_PK   |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  14 |   TABLE ACCESS BY INDEX ROWID         | FACILITY_ACCOUNT_DETAIL        |     1 |    14 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 15 |    INDEX UNIQUE SCAN                  | FACILITY_ACCOUNT_DETAIL_PK     |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  16 |  NESTED LOOPS                         |                                |     1 |    40 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |  17 |   NESTED LOOPS                        |                                |     1 |    29 |     4   (0)| 00:00:01 |                                                                                                                                                                                   
    |  18 |    NESTED LOOPS                       |                                |     1 |    19 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 19 |     INDEX UNIQUE SCAN                 | PATIENT_PK                     |     1 |     5 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 20 |     INDEX RANGE SCAN                  | PATIENT_FACILITY_MOD_IX_01     |     1 |    14 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |  21 |    TABLE ACCESS BY INDEX ROWID        | FACILITY_ACCOUNT_MODALITY      |     1 |    10 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 22 |     INDEX UNIQUE SCAN                 | FACILITY_ACCOUNT_MODALITY_PK   |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  23 |   TABLE ACCESS BY INDEX ROWID         | FACILITY_ACCOUNT_DETAIL        |     1 |    11 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 24 |    INDEX UNIQUE SCAN                  | FACILITY_ACCOUNT_DETAIL_PK     |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  25 |  NESTED LOOPS                         |                                |     1 |    42 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |  26 |   NESTED LOOPS                        |                                |     1 |    29 |     4   (0)| 00:00:01 |                                                                                                                                                                                   
    |  27 |    NESTED LOOPS                       |                                |     1 |    19 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 28 |     INDEX UNIQUE SCAN                 | PATIENT_PK                     |     1 |     5 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 29 |     INDEX RANGE SCAN                  | PATIENT_FACILITY_MOD_IX_01     |     1 |    14 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |  30 |    TABLE ACCESS BY INDEX ROWID        | FACILITY_ACCOUNT_MODALITY      |     1 |    10 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 31 |     INDEX UNIQUE SCAN                 | FACILITY_ACCOUNT_MODALITY_PK   |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  32 |   TABLE ACCESS BY INDEX ROWID         | FACILITY_ACCOUNT_DETAIL        |     1 |    13 |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 33 |    INDEX UNIQUE SCAN                  | FACILITY_ACCOUNT_DETAIL_PK     |     1 |       |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  34 |  HASH UNIQUE                          |                                |   399 | 59451 |  6293   (1)| 00:01:16 |                                                                                                                                                                                   
    |* 35 |   FILTER                              |                                |       |       |            |          |                                                                                                                                                                                   
    |* 36 |    FILTER                             |                                |       |       |            |          |                                                                                                                                                                                   
    |* 37 |     HASH JOIN                         |                                |   399 | 59451 |  6285   (1)| 00:01:16 |                                                                                                                                                                                   
    |  38 |      TABLE ACCESS FULL                | CORPORATION                    |   291 | 11640 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |  39 |      NESTED LOOPS                     |                                |   399 | 43491 |  6282   (1)| 00:01:16 |                                                                                                                                                                                   
    |* 40 |       HASH JOIN                       |                                |  2113 |   216K|  6281   (1)| 00:01:16 |                                                                                                                                                                                   
    |  41 |        TABLE ACCESS FULL              | TEST_REQUIRED                  |  1184 | 10656 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 42 |        TABLE ACCESS BY INDEX ROWID    | LAB_ORDER_OCC_TEST             |     8 |   144 |     5   (0)| 00:00:01 |                                                                                                                                                                                   
    |  43 |         NESTED LOOPS                  |                                |  1345 |   126K|  6276   (1)| 00:01:16 |                                                                                                                                                                                   
    |* 44 |          HASH JOIN                    |                                |   170 | 13260 |  5425   (1)| 00:01:06 |                                                                                                                                                                                   
    |* 45 |           HASH JOIN                   |                                |   170 |  8670 |  5403   (1)| 00:01:05 |                                                                                                                                                                                   
    |* 46 |            TABLE ACCESS BY INDEX ROWID| LAB_ORDER_OCC                  | 12775 |   336K|   569   (1)| 00:00:07 |                                                                                                                                                                                   
    |* 47 |             INDEX SKIP SCAN           | LAB_ORDER_OCC_IX_07            |  2218 |       |    13   (8)| 00:00:01 |                                                                                                                                                                                   
    |* 48 |            TABLE ACCESS BY INDEX ROWID| ORDER_REQUISITION_HEADER       | 56952 |  1334K|  4833   (1)| 00:00:58 |                                                                                                                                                                                   
    |* 49 |             INDEX SKIP SCAN           | ORDER_REQUISITION_HEADER_IX_04 |  4905 |       |  1707   (1)| 00:00:21 |                                                                                                                                                                                   
    |  50 |           TABLE ACCESS FULL           | FACILITY                       |  4252 |   112K|    22   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 51 |          INDEX RANGE SCAN             | LAB_ORDER_OCC_TEST_IX_01       |     8 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 52 |       INDEX RANGE SCAN                | INTERFACE_ADT_AOE_MASTER_IX_01 |     1 |     4 |     0   (0)| 00:00:01 |                                                                                                                                                                                   
    |  53 |    SORT AGGREGATE                     |                                |     1 |    12 |            |          |                                                                                                                                                                                   
    |* 54 |     TABLE ACCESS BY INDEX ROWID       | INTERFACE_ADT_AOE_MASTER       |     1 |    12 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 55 |      INDEX RANGE SCAN                 | INTERFACE_ADT_AOE_MASTER_IX_01 |     4 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |  56 |       TABLE ACCESS BY INDEX ROWID     | TEST                           |     1 |     9 |     2   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 57 |        INDEX UNIQUE SCAN              | TEST_PK                        |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 58 |         INDEX RANGE SCAN              | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |  59 |      SORT AGGREGATE                   |                                |     1 |    29 |            |          |                                                                                                                                                                                   
    |* 60 |       FILTER                          |                                |       |       |            |          |                                                                                                                                                                                   
    |* 61 |        TABLE ACCESS BY INDEX ROWID    | EMR_ADTAOE_DTL                 |     1 |    29 |    30   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 62 |         INDEX RANGE SCAN              | EMR_ADTAOE_DTL_IX_01           |   174 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 63 |        INDEX RANGE SCAN               | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    |* 64 |         INDEX RANGE SCAN              | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                   
    Query Block Name / Object Alias (identified by operation id):                                                                                                                                                                                                                                              
       1 - SEL$2        / P@SEL$2                                                                                                                                                                                                                                                                              
       2 - SEL$2        / P@SEL$2                                                                                                                                                                                                                                                                              
       3 - SEL$3        / P@SEL$3                                                                                                                                                                                                                                                                              
       4 - SEL$3        / P@SEL$3                                                                                                                                                                                                                                                                              
       5 - SEL$4        / P@SEL$4                                                                                                                                                                                                                                                                              
       6 - SEL$4        / P@SEL$4                                                                                                                                                                                                                                                                              
       7 - SEL$5                                                                                                                                                                                                                                                                                               
      10 - SEL$5        / P@SEL$5                                                                                                                                                                                                                                                                              
      11 - SEL$5        / PFM@SEL$5                                                                                                                                                                                                                                                                            
      12 - SEL$5        / FAM@SEL$5                                                                                                                                                                                                                                                                            
      13 - SEL$5        / FAM@SEL$5                                                                                                                                                                                                                                                                            
      14 - SEL$5        / FAD@SEL$5                                                                                                                                                                                                                                                                            
      15 - SEL$5        / FAD@SEL$5                                                                                                                                                                                                                                                                            
      16 - SEL$6                                                                                                                                                                                                                                                                                               
      19 - SEL$6        / P@SEL$6                                                                                                                                                                                                                                                                              
      20 - SEL$6        / PFM@SEL$6                                                                                                                                                                                                                                                                            
      21 - SEL$6        / FAM@SEL$6                                                                                                                                                                                                                                                                            
      22 - SEL$6        / FAM@SEL$6                                                                                                                                                                                                                                                                            
      23 - SEL$6        / FAD@SEL$6                                                                                                                                                                                                                                                                            
      24 - SEL$6        / FAD@SEL$6                                                                                                                                                                                                                                                                            
      25 - SEL$7                                                                                                                                                                                                                                                                                               
      28 - SEL$7        / P@SEL$7                                                                                                                                                                                                                                                                              
      29 - SEL$7        / PFM@SEL$7                                                                                                                                                                                                                                                                            
      30 - SEL$7        / FAM@SEL$7                                                                                                                                                                                                                                                                            
      31 - SEL$7        / FAM@SEL$7                                                                                                                                                                                                                                                                            
      32 - SEL$7        / FAD@SEL$7                                                                                                                                                                                                                                                                            
      33 - SEL$7        / FAD@SEL$7                                                                                                                                                                                                                                                                            
      34 - SEL$AA3B83ED                                                                                                                                                                                                                                                                                        
      38 - SEL$AA3B83ED / C@SEL$1                                                                                                                                                                                                                                                                              
      41 - SEL$AA3B83ED / TEST_REQUIRED@SEL$8                                                                                                                                                                                                                                                                  
      42 - SEL$AA3B83ED / LOCT@SEL$1                                                                                    

    Hi Karthick,
    Thanks for the response. The suggestion is really good. But we have some tables accessed like "lab_order_occ" which size is more than 8GB also having no partitions. If I'll ask for altering DB structure, this will be finalized not less than 6 months. Please do have a look at the plan now. It's generating more cost.
    explain plan succeeded.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                         
    Plan hash value: 2523654849                                                                                                                                                                                                                                                                               
    | Id  | Operation                               | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                
    |   0 | SELECT STATEMENT                        |                                |  1057 |   293K| 25324   (2)| 00:05:04 |                                                                                                                                                                                
    |*  1 |  FILTER                                 |                                |       |       |            |          |                                                                                                                                                                                
    |*  2 |   HASH JOIN RIGHT SEMI                  |                                |  1057 |   293K| 25317   (2)| 00:05:04 |                                                                                                                                                                                
    |   3 |    VIEW                                 | VW_NSO_1                       |   224 |  2912 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |*  4 |     FILTER                              |                                |       |       |            |          |                                                                                                                                                                                
    |   5 |      NESTED LOOPS                       |                                |   224 |  2912 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |   6 |       TABLE ACCESS FULL                 | TEST_REQUIRED                  |  1184 | 10656 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |*  7 |       INDEX RANGE SCAN                  | INTERFACE_ADT_AOE_MASTER_IX_01 |     1 |     4 |     0   (0)| 00:00:01 |                                                                                                                                                                                
    |*  8 |    TABLE ACCESS BY INDEX ROWID          | LAB_ORDER_OCC_TEST             |     8 |   144 |     5   (0)| 00:00:01 |                                                                                                                                                                                
    |   9 |     NESTED LOOPS                        |                                |  1345 |   355K| 25311   (2)| 00:05:04 |                                                                                                                                                                                
    |* 10 |      HASH JOIN                          |                                |   170 | 43010 | 24460   (2)| 00:04:54 |                                                                                                                                                                                
    |  11 |       TABLE ACCESS FULL                 | CORPORATION                    |   291 | 11640 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |* 12 |       HASH JOIN                         |                                |   170 | 36210 | 24457   (2)| 00:04:54 |                                                                                                                                                                                
    |  13 |        NESTED LOOPS OUTER               |                                |   170 | 31620 | 24434   (2)| 00:04:54 |                                                                                                                                                                                
    |* 14 |         HASH JOIN                       |                                |   170 | 14960 |  5403   (1)| 00:01:05 |                                                                                                                                                                                
    |* 15 |          TABLE ACCESS BY INDEX ROWID    | LAB_ORDER_OCC                  | 12775 |   598K|   569   (1)| 00:00:07 |                                                                                                                                                                                
    |* 16 |           INDEX SKIP SCAN               | LAB_ORDER_OCC_IX_07            |  2218 |       |    13   (8)| 00:00:01 |                                                                                                                                                                                
    |* 17 |          TABLE ACCESS BY INDEX ROWID    | ORDER_REQUISITION_HEADER       | 56952 |  2224K|  4833   (1)| 00:00:58 |                                                                                                                                                                                
    |* 18 |           INDEX SKIP SCAN               | ORDER_REQUISITION_HEADER_IX_04 |  4905 |       |  1707   (1)| 00:00:21 |                                                                                                                                                                                
    |  19 |         VIEW PUSHED PREDICATE           |                                |     1 |    98 |   112   (2)| 00:00:02 |                                                                                                                                                                                
    |* 20 |          HASH JOIN                      |                                |    93 |  8835 |   112   (2)| 00:00:02 |                                                                                                                                                                                
    |* 21 |           HASH JOIN                     |                                |    93 |  6231 |    56   (2)| 00:00:01 |                                                                                                                                                                                
    |* 22 |            HASH JOIN                    |                                |    93 |  5301 |    48   (3)| 00:00:01 |                                                                                                                                                                                
    |  23 |             NESTED LOOPS                |                                |    68 |  2924 |    44   (0)| 00:00:01 |                                                                                                                                                                                
    |  24 |              TABLE ACCESS BY INDEX ROWID| PATIENT                        |     1 |    34 |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 25 |               INDEX UNIQUE SCAN         | PATIENT_PK                     |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                
    |  26 |              TABLE ACCESS BY INDEX ROWID| LAB_ORDER_OCC                  |    68 |   612 |    42   (0)| 00:00:01 |                                                                                                                                                                                
    |* 27 |               INDEX RANGE SCAN          | LAB_ORDER_OCC_IX_02            |    53 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 28 |             INDEX RANGE SCAN            | PATIENT_FACILITY_MOD_IX_01     |   111 |  1554 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |  29 |            TABLE ACCESS FULL            | FACILITY_ACCOUNT_MODALITY      |  9159 | 91590 |     8   (0)| 00:00:01 |                                                                                                                                                                                
    |  30 |           TABLE ACCESS FULL             | FACILITY_ACCOUNT_DETAIL        |  7266 |   198K|    55   (0)| 00:00:01 |                                                                                                                                                                                
    |  31 |        TABLE ACCESS FULL                | FACILITY                       |  4252 |   112K|    22   (0)| 00:00:01 |                                                                                                                                                                                
    |* 32 |      INDEX RANGE SCAN                   | LAB_ORDER_OCC_TEST_IX_01       |     8 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |  33 |   SORT AGGREGATE                        |                                |     1 |    12 |            |          |                                                                                                                                                                                
    |* 34 |    TABLE ACCESS BY INDEX ROWID          | INTERFACE_ADT_AOE_MASTER       |     1 |    12 |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 35 |     INDEX RANGE SCAN                    | INTERFACE_ADT_AOE_MASTER_IX_01 |     4 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                
    |  36 |      TABLE ACCESS BY INDEX ROWID        | TEST                           |     1 |     9 |     2   (0)| 00:00:01 |                                                                                                                                                                                
    |* 37 |       INDEX UNIQUE SCAN                 | TEST_PK                        |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                
    |* 38 |        INDEX RANGE SCAN                 | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |  39 |     SORT AGGREGATE                      |                                |     1 |    29 |            |          |                                                                                                                                                                                
    |* 40 |      FILTER                             |                                |       |       |            |          |                                                                                                                                                                                
    |* 41 |       TABLE ACCESS BY INDEX ROWID       | EMR_ADTAOE_DTL                 |     1 |    29 |    30   (0)| 00:00:01 |                                                                                                                                                                                
    |* 42 |        INDEX RANGE SCAN                 | EMR_ADTAOE_DTL_IX_01           |   174 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                
    |* 43 |       INDEX RANGE SCAN                  | LAB_ORDER_OCC_TEST_AOE_PK      |     1 |    10 |     3   (0)| 00:00:01 |                                                                                                                                                                                
    Query Block Name / Object Alias (identified by operation id):                                                                                                                                                                                                                                             
       1 - SEL$19EEE7EA                                                                                                                                                                                                                                                                                       
       3 - SEL$9DB3EFF9 / VW_NSO_1@SEL$19EEE7EA                                                                                                                                                                                                                                                               
       4 - SEL$9DB3EFF9                                                                                                                                                                                                                                                                                       
       6 - SEL$9DB3EFF9 / TEST_REQUIRED@SEL$3                                                                                                                                                                                                                                                                 
       7 - SEL$9DB3EFF9 / INTERFACE_ADT_AOE_MASTER@SEL$4                                                                                                                                                                                                                                                      
       8 - SEL$19EEE7EA / LOCT@SEL$1                                                                                                                                                                                                                                                                          
      11 - SEL$19EEE7EA / C@SEL$1                                                                                                                                                                                                                                                                             
      15 - SEL$19EEE7EA / LOC@SEL$1                                                                                                                                                                                                                                                                           
      16 - SEL$19EEE7EA / LOC@SEL$1                                                                                                                                                                                                                                                                           
      17 - SEL$19EEE7EA / ORD@SEL$1                                                                                                                                                                                                                                                                           
      18 - SEL$19EEE7EA / ORD@SEL$1                                                                                                                                                                                                                                                                           
      19 - SEL$639F1A6F / P@SEL$1                                                                                                                                                                                                                                                                             
      20 - SEL$639F1A6F                                                                                                                                                                                                                                                                                       
      24 - SEL$639F1A6F / P@SEL$2                                                                                                                                                                                                                                                                             
      25 - SEL$639F1A6F / P@SEL$2                                                                                                                                                                                                                                                                             
      26 - SEL$639F1A6F / LOC@SEL$2                                                                                                                                                                                                                                                                           
      27 - SEL$639F1A6F / LOC@SEL$2                                                                                                                                                                                                                                                                           
      28 - SEL$639F1A6F / PFM@SEL$2                                                                                                                                                                                                                                                                           
      29 - SEL$639F1A6F / FAM@SEL$2                                                                                                                                                                                                                                                                           
      30 - SEL$639F1A6F / FAD@SEL$2                                                                                                                                                                                                                                                                           
      31 - SEL$19EEE7EA / F@SEL$1                                                                                                                                                                                                                                                                             
      32 - SEL$19EEE7EA / LOCT@SEL$1                                                                                                                                                                                                                                                                          
      33 - SEL$5                                                                                                                                                                                                                                                                                              
      34 - SEL$5        / INTERFACE_ADT_AOE_MASTER@SEL$5                                                                                                                                                                                                                                                      
      35 - SEL$5        / INTERFACE_ADT_AOE_MASTER@SEL$5                                                                                                                                                                                                                                                      
      36 - SEL$6        / TEST@SEL$6                                                                                                                                                                                                                                                                          
      37 - SEL$6        / TEST@SEL$6                                                                                                                                                                                                                                                                          
      38 - SEL$7        / LAB_ORDER_OCC_TEST_AOE@SEL$7                                                                                                                                                                                                                                                        
      39 - SEL$8                                                                                                                                                                                                                                                                                              
      41 - SEL$8        / EMR_ADTAOE_DTL@SEL$8                                                                                                                                                                                                                                                                
      42 - SEL$8        / EMR_ADTAOE_DTL@SEL$8                                                                                                                                                                                                                                                                
      43 - SEL$9        / LAB_ORDER_OCC_TEST_AOE@SEL$9                                                                                                                                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                       
       1 - filter( (SELECT /*+ */ COUNT(*) FROM "KORUS2XPROD_OWN"."INTERFACE_ADT_AOE_MASTER"                                                                                                                                                                                                                  
                  "INTERFACE_ADT_AOE_MASTER" WHERE "TEST_CODE"= (SELECT /*+ */ "TEST_CODE" FROM "KORUS2XPROD_OWN"."TEST" "TEST"                                                                                                                                                                               
                  WHERE "TEST_ID"= (SELECT /*+ */ "AOE_TEST_ID" FROM "KORUS2XPROD_OWN"."LAB_ORDER_OCC_TEST_AOE"                                                                                                                                                                                               
                  "LAB_ORDER_OCC_TEST_AOE" WHERE "LAB_ORDER_OCC_TEST_ID"=:B1)) AND "SOURCE_SYSTEM"=:B2)<> (SELECT /*+ */ COUNT(*)                                                                                                                                                                             
                  FROM "KORUS2XPROD_OWN"."EMR_ADTAOE_DTL" "EMR_ADTAOE_DTL" WHERE "TEST_ID"= (SELECT /*+ */ "AOE_TEST_ID" FROM                                                                                                                                                                                 
                  "KORUS2XPROD_OWN"."LAB_ORDER_OCC_TEST_AOE" "LAB_ORDER_OCC_TEST_AOE" WHERE "LAB_ORDER_OCC_TEST_ID"=:B3) AND                                                                                                                                                                                  
                  "PATIENT_ID"=:B4 AND "FACILITY_ID"=:B5 AND "STATUS"='Y' AND (TO_CHAR(TRUNC(INTERNAL_FUNCTION("DRAW_DATE"))) LIKE                                                                                                                                                                            
                  TO_CHAR(TRUNC(:B6)) OR TRUNC(INTERNAL_FUNCTION("DRAW_DATE"))=TO_DATE(' 2999-12-31 00:00:00', 'syyyy-mm-dd                                                                                                                                                                                   
                  hh24:mi:ss')) AND "ANSWER" IS NOT NULL))                                                                                                                                                                                                                                                    
       2 - access("LOCT"."TEST_ID"="$nso_col_1")                                                                                                                                                                                                                                                              
       4 - filter(TRUNC(SYSDATE@!)-7<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                                                       
       7 - access("REQUIRED_TEST_CODE"="TEST_CODE")                                                                                                                                                                                                                                                           
       8 - filter("LOCT"."STATUS"<>'R')                                                                                                                                                                                                                                                                       
      10 - access("F"."CORPORATION_ID"="C"."CORPORATION_ID")                                                                                                                                                                                                                                                  
      12 - access("LOC"."FACILITY_ID"="F"."FACILITY_ID")                                                                                                                                                                                                                                                      
      14 - access("ORD"."PATIENT_ID"="LOC"."PATIENT_ID" AND "ORD"."FACILITY_ID"="LOC"."FACILITY_ID" AND                                                                                                                                                                                                       
                  "ORD"."DRAW_DT"="LOC"."ORDER_DRAW_DT")                                                                                                                                                                                                                                                      
      15 - filter("LOC"."PATIENT_ID" IS NOT NULL AND "LOC"."MSG_SENT_TO_LAB_YN"='Y')                                                                                                                                                                                                                          
      16 - access("LOC"."ORDER_DRAW_DT">=TRUNC(SYSDATE@!)-7 AND "LOC"."STATUS"='A' AND                                                                                                                                                                                                                        
                  "LOC"."ORDER_DRAW_DT"<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                                                    
           filter("LOC"."STATUS"='A')                                                                                                                                                                                                                                                                         
      17 - filter("ORD"."PATIENT_ID" IS NOT NULL)                                                                                                                                                                                                                                                             
      18 - access("ORD"."DRAW_DT">=TRUNC(SYSDATE@!)-7 AND "ORD"."DRAW_DT"<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                  
           filter("ORD"."DRAW_DT">=TRUNC(SYSDATE@!)-7 AND "ORD"."DRAW_DT"<=TRUNC(SYSDATE@!))                                                                                                                                                                                                                  
      20 - access("FAM"."FACILITY_ACCOUNT_DETAIL_ID"="FAD"."FACILITY_ACCOUNT_DETAIL_ID")                                                                                                                                                                                                                      
      21 - access("PFM"."FACILITY_ACCOUNT_MODALITY_ID"="FAM"."FACILITY_ACCOUNT_MODALITY_ID")                                                                                                                                                                                                                  
      22 - access("PFM"."FACILITY_ID"="LOC"."FACILITY_ID")                                                                                                                                                                                                                                                    
      25 - access("P"."PATIENT_ID"="LOC"."PATIENT_ID")                                                                                                                                                                                                                                                        
      27 - access("LOC"."PATIENT_ID"="LOC"."PATIENT_ID")           

  • Hpw to tune the performance of following query?

    Hi all,
               I want a particular set of G/L acct nos for the list of billing documents that i have in an internal table ie. pt_vbrk. I am using table BSIS.However ,when i use the following query it is taking  very very long time .I even tried using LOOP...ENDLOOP statement.Can anyone tell me how to enhance the performance of the query?Thanks in advance.
    i = 0.
    loop at pt_vbrk.
    i = i + 1.
    endloop.
    while j <= i.
    read table pt_vbrk index j.
    select single hkont  from bsis into  corresponding fields of
    pt_vbrk where
    ( hkont = '0013100000' or hkont = '0013105000'
    or hkont = '0013110000' or hkont = '0013112000'
    or hkont = '0013115000' or hkont = '0013120000'
    or hkont = '0013125000' or hkont = '0013135500'
    or hkont = '0013140000' or hkont = '0013145000'
    or hkont = '0013155000' or hkont = '0013165000'
    or hkont = '0013175000' or hkont = '0013170000' )
    and belnr = pt_vbrk-belnr and  gjahr = pt_vbrk-gjahr   . "#EC CI_NOFIRST
    modify pt_vbrk from pt_vbrk index j.
    j = j + 1.
    endwhile.
    Moderator message - Moved to the correct forum
    Edited by: Rob Burbank on Sep 22, 2009 9:06 AM

    Try the following approach.
    TYPES: BEGIN OF ty_bsis,
             bukrs TYPE bsis-bukrs,
             hkont TYPE bsis-hkont,
             augdt TYPE bsis-augdt,
             augbl TYPE bsis-augbl,
             zuonr TYPE bsis-zuonr,
             gjahr TYPE bsis-gjahr,
             belnr TYPE bsis-belnr,
             buzei TYPE bsis-buzei,
           END OF ty_bsis.
    DATA: w_bsis     TYPE                 ty_bsis ,
          w_index    TYPE                 sy-tabix,
          t_bsis     TYPE SORTED TABLE OF ty_bsis
            WITH NON-UNIQUE KEY bukrs belnr gjahr ,
          t_vbrk_tmp LIKE        TABLE OF pt_vbrk .
    RANGES: r_hkont FOR bsis-hkont.
    IF NOT pt_vbrk[] IS INITIAL.
      REFRESH r_hkont.
      r_hkont-sign   = 'I'.
      r_hkont-option = 'EQ'.
      r_hkont-low = '0013100000'.
      APPEND r_hkont.
      r_hkont-low = '0013105000'.
      APPEND r_hkont.
      r_hkont-low = '0013110000'.
      APPEND r_hkont.
      r_hkont-low = '0013112000'.
      APPEND r_hkont.
      r_hkont-low = '0013115000'.
      APPEND r_hkont.
      r_hkont-low = '0013120000'.
      APPEND r_hkont.
      r_hkont-low = '0013125000'.
      APPEND r_hkont.
      r_hkont-low = '0013135500'.
      APPEND r_hkont.
      r_hkont-low = '0013140000'.
      APPEND r_hkont.
      r_hkont-low = '0013145000'.
      APPEND r_hkont.
      r_hkont-low = '0013155000'.
      APPEND r_hkont.
      r_hkont-low = '0013165000'.
      APPEND r_hkont.
      r_hkont-low = '0013175000'.
      APPEND r_hkont.
      r_hkont-low = '0013170000'.
      APPEND r_hkont.
      t_vbrk_tmp[] = pt_vbrk[].
      SORT t_vbrk_tmp BY bukrs gjahr belnr.
      DELETE ADJACENT DUPLICATES FROM t_vbrk_tmp
        COMPARING bukrs gjahr belnr.
      SELECT bukrs
             hkont
             augdt
             augbl
             zuonr
             gjahr
             belnr
             buzei
        FROM bsis
        INTO TABLE t_bsis
        FOR ALL ENTRIES IN t_vbrk_tmp
        WHERE bukrs EQ t_vbrk_tmp-bukrs
        AND   hkont IN r_hkont
        AND   gjahr EQ t_vbrk_tmp-gjahr
        AND   belnr EQ t_vbrk_tmp-belnr.
      IF sy-subrc EQ 0.
        LOOP AT pt_vbrk.
          w_index = sy-tabix.
          READ TABLE t_bsis INTO w_bsis
            WITH KEY bukrs = pt_vbrk-bukrs
                     belnr = pt_vbrk-belnr
                     gjahr = pt_vbrk-gjahr
                     TRANSPORTING
                       hkont.
          IF sy-subrc EQ 0.
            pt_vbrk-hkont = w_bsis-hkont.
            MODIFY pt_vbrk INDEX w_index
              TRANSPORTING
                hkont.
          ENDIF.
        ENDIF.
      ENDIF.

Maybe you are looking for

  • Iphone 4 says I have no storage available even though I do

    (I have an iphone 4; 6.4G) So lately I've been running out on space. I had about 600 pics, 32 songs, and 18 apps that I have downloaded. Normally I'll be able to delete some pictures or something and I'll have enough storage again. But now I have 400

  • Using Java Webservices provided by xRPM 4.0 in PPM 5.0

    Hi, We have developed some custom WD ABAP applications in PPM 4.5 which were using Java webservices provided by xRPM 4.0 to get the UI context. The details are provided in the document https://websmp109.sap-ag.de/~sapidb/012006153200000315412008E/How

  • RFC and CURP for Mexican vendors

    Hello, I would appreciate you can provide any comments  about Master data for Mexican customers/vendors. In Mexico companies and organizations have a Tax registration number called RFC which is ABC680504BV1 which contains 12 length characters The fie

  • Seed mailbox database copy through replication network (DAG members on different subnets in different sites)

    Good afternoon I currently operate a two node DAG in our primary site supporting one mailbox database. I plan to introduce a third DAG node in our datacenter which is in a different Active Directory site. Both current DAG members replicate over a ded

  • CONVERTING DATE FORMAT

    HI FRNDS,        i have a problem with converting my DATE format from my flat file to the BW system the date in the flat files may be in these formats                         '12-jan-1992'                           '12/01/1992'