Very Slow Query with CTE inner join

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

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

Similar Messages

  • Set READ UNCOMMITED for a query with a table join (Ver 12.5. and 15.5)

    Hi all,
    this is an example of how to set the READ UNCOMMITED isolation level for a simple query:
    select col_a from mytable at isolation 0
    What about a query with an equi-join?
    Is it:
    select col_a
    from mytable t1, mytable t2
    at isolation 0
    I am sorry for the simple question, I did not find a auitable example in the documentation.
    Best Regards
    Arthur

    Yeah, the docs aren't very good at providing a robust set of examples so you've gotta:
    1 - review the command syntax and then
    2 - try a few examples until you find the format that works
    1 - From the ASE 15.5 Commands reference manual we find the following syntax:
    =========================
    select ::=
              select [all | distinct]
              [top unsigned_integer]
              select_list
              [into_clause]
              [from_clause]
              [where_clause]
              [group_by_clause]
              [having_clause]
              [order_by_clause]
              [compute_clause]
              [read_only_clause]
              [isolation_clause]
              [browse_clause]
              [plan_clause]
    =========================
    This shows us that the isolation clause is attached at the 'end' of the query as a query-level specifier (along with the 'group by', 'order by' and 'having' clauses).
    From this syntax I'd say your proposed query looks correct so ...
    2 - Try running your example to see if you get a syntax error ("When in doubt, try it out!"), eg:
    =========================
    select s.name,c.name
    from sysobjects s, syscolumns c
    where s.id = c.id
    at isolation 0
    go
    name
    sysobjects
    sysobjects
    sysobjects
    ... snip ...
    =========================

  • Very slow connection with Mifi 4510L??

    I'm hoping someone here can give some guidance. I am having very slow connection with the 4510L we just got. Via test on speedtest.net I'm seeing download speed of .17 MBPS at times it was so slow the test was not completing. I normally have 1 or 2 bars on the mifi unit and have seen up to 3 at times. I drove into town and see the same range (1 to 3 bars). I have yet to see the 4G light come on except for prior to activation (would light solid green at times) since activating I have only seen the violet light for 3G.
    Verizon advertises full service both around our city (Richmond, VA) and at my more remote location in Hanover. I have been through the recommended resets and nothing seems to improve the connection speed. Could the unit itself be defective? Also, I've noticed when I go to a location website it thinks I am in Pennsylvania when I am in Virginia. Could the Mifi be trying to connect to a signal in that location for some reason (was refurbished device)
    Thanks for any help you can offer,
    Brian

    I was having problems but upgrading to 2.28 seems to have helped me in addition to a few other changes I made based on this review of the 4510L
    http://www.anandtech.com/show/4500/novatel-wireless-mifi-4510l-review-the-best-4g-lte-wifi-hotspot/4
    1) "selecting WPA2 Personal/PSK (AES)"
    2) "manually selecting a channel (instead of Auto) fixes almost all the instability problems"
    (I'm not sure if it actually worked as the diagnostics always shows channel 0 no matter what I picked.  I did try a couple before one - or the myriad of other things I tried - seemed to make a difference - at least for now - fingers crossed)
    3) "allowing for one to select between each network mode manually, so you can force 4G LTE, EVDO, 1xRTT, or all of the above. This is incredibly useful if you’re right at the cutoff for 4G LTE SINR"  (that's WWAN Preferred Mode LTE only for me)
    4) I also changed my 802.11 Mode to just one mode that works on both computers at my house
    5) I am also careful to turn it off when I am done with it and take it off the charger for the night as well.
    It is my only internet service due to my semiremote location (no cable etc) and when I first got it as a replacement for my dependable 2200 I was about to pull all my hair out.  I was "forced" into it because due to antenna issues on a local tower that supplies my 3G signal my 2200 wasn't even able to load my gmail account.  Verizon very helpful on that - call us if its still an issue in a "few weeks"!  However, when I inquired about the antenna's effect on a 4G signal, an intelligent tech was able to tell me that it was not the tower I would be getting a 4G signal off of - odd but I didn't question that possibility.
    It runs very very warm but I suspect having it on the charger and using it almost all day is part of that.  At first I was wondering if heat was part of the problem - going so far as to have it sitting on an ice pack to test that theory.  Of course then I had to wonder if maybe I was freezing it -lol.  I am careful to turn it off when I am done with it and take it off the charger for the night as well.
    I've been on it most of the day and it seems to be behaving well - so fingers crossed

  • Very Slow Query due to Bitmap Conversion

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

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

  • Stuck on how to improve very slow query without any admin rights

    Hello All,
    I am using the code below to query a very large data table (RH) and a few other joined tables. I am trying to improve the query but I do not have any admin rights and have no idea how to get diagnostic info on how the query is being executed. Apologies for the system specific and probably not easy to read code but I do not have a generic version that anyone could run, and no admin rights so I can not create tables.
    The main part of the code below (subquery R) takes about 10 minutes to run (3 minutes without the date parameters) and the full code (with the two analytic functions on top) below takes an eye watering 30 minutes to run and this is only a subquery of a much larger query so I really need to get this running more quickly. All I want to do is place a cap on the dates, get partitioned row numbers and a lead row value on one of the fields. I really am stuck on how to get this query more efficient. Am I counting things multiple times unnecessarily? How can I make this quicker? Am I committing some cardinal programming sin in using analytic functions on subqueries?
    Apologies for the vaugueness of this code and my questions but I am totally clueless about diagnostics and basically have very limited system access so I'm stuck as to where to go or to look.
    Very grateful for any advice,
    Jon
    SELECT R.*
    , ROW_NUMBER( ) OVER( PARTITION BY R.RTBLE_ID ORDER BY R.EFF_DT DESC, R.CHG_DT DESC ) RN
    , LEAD(R.RTNG_CD,1,0) OVER( PARTITION BY R.RTBLE_ID ORDER BY R.EFF_DT DESC, R.CHG_DT DESC ) RTNG_CD_PREV
    FROM ( SELECT RH.RTNG_ID
    , RH.RTBLE_ID
    , RA.RTNG_ACTN_DESC
    , TYP.RTNG_TYP_DESC
    , RH.RTNG_CD_ID
    , RC.RTNG_CD
    , RH.EFF_DT
    , RH.CHG_DT
    , RAL.RTNG_ALRT_TYP_ID
    , RAL.EFF_DT ALRT_EFF_DT
    , RAL.CHG_DT ALRT_CHG_DT
    , RH.PRV_FLG
    FROM FTCH_RTNG.RTNG_HIST RH
    , FTCH_RTNG.RTNG_ALRT_HIST RAL
    , FII_CORE.RTNG_ACTN RA
    , FTCH_RTNG.RTNG_TYP TYP
    , FII_CORE.RTNG_CD RC
    WHERE RH.RTNG_ACTN_ID = RA.RTNG_ACTN_ID
    AND RH.RTNG_TYP_ID = TYP.RTNG_TYP_ID
    AND RH.RTNG_TYP_ID = RC.RTNG_TYP_ID
    AND RH.RTNG_CD_ID = RC.RTNG_CD_ID
    AND RH.RTNG_ID = RAL.RTNG_ID (+)
    AND RH.DELETE_FLG = 'N'
    AND RH.EFF_DT < TRUNC(CURRENT_DATE,'MM')
    AND RAL.EFF_DT < TRUNC(CURRENT_DATE,'MM')
    )R
    -----

    Thanks so much for replying blueforg, and for pointing out the code markup.
    Our server is in the US and we run our code from London, so it is the local time I am interested in, CURRENT_DATE is merely there to get that and as you suggest is not a column. I want my cap to the first of whatever month I run the code on so I'm happy with that bit of the code (so 1 Oct if I run it today). I'm just surprised at how slow my code becomes when I try and restrict the dates and get the row numbers and next row values.
    This code is actually a subquery used in a much bigger query that I am trying to tidy up and make more efficient. The RN is important as I will eventually be filtering for RN = 1. I didn't post the full query as it is huge,badly written (by me) and and particular to our databases so I'm tackling bits one at a time to cut down on confusion. I'll repost with the RN=1 and the code markup ;)
    I also restricting the RH table directly (SELECT * FROM FTCH_RTNG.RTNG_HIST RH WHERE RH.EFF_DT < TRUNC(CURRENT_DATE,'MM')) and moving the analytic functions into the R subquery but that is very slow as well. I heard that temporary tables are efficient? I'm assuming that with my rubbish priveleges I will not be able to do that. I don't want to take any chances of messing anything up either!
    Jon
    SELECT RT.* FROM
      ( SELECT  R.*
              , ROW_NUMBER( ) OVER( PARTITION BY R.RTBLE_ID ORDER BY R.EFF_DT DESC, R.CHG_DT DESC ) RN    
              , LEAD(R.RTNG_CD,1,0) OVER( PARTITION BY R.RTBLE_ID ORDER BY R.EFF_DT DESC, R.CHG_DT DESC ) RTNG_CD_PREV
        FROM  ( SELECT  RH.RTNG_ID    
                      , RH.RTBLE_ID    
                      , RA.RTNG_ACTN_DESC    
                      , TYP.RTNG_TYP_DESC    
                      , RH.RTNG_CD_ID    
                      , RC.RTNG_CD    
                      , RH.EFF_DT  
                      , RH.CHG_DT 
                      , RAL.RTNG_ALRT_TYP_ID    
                      , RAL.EFF_DT ALRT_EFF_DT    
                      , RAL.CHG_DT ALRT_CHG_DT
                      , RH.PRV_FLG    
                FROM    FTCH_RTNG.RTNG_HIST RH
                      , FTCH_RTNG.RTNG_ALRT_HIST RAL
                      , FII_CORE.RTNG_ACTN RA    
                      , FTCH_RTNG.RTNG_TYP TYP    
                      , FII_CORE.RTNG_CD RC    
                WHERE RH.RTNG_ACTN_ID = RA.RTNG_ACTN_ID    
                AND RH.RTNG_TYP_ID = TYP.RTNG_TYP_ID    
                AND RH.RTNG_TYP_ID = RC.RTNG_TYP_ID    
                AND RH.RTNG_CD_ID = RC.RTNG_CD_ID    
                AND RH.RTNG_ID = RAL.RTNG_ID (+)    
                AND RH.DELETE_FLG = 'N'
                AND RH.EFF_DT < TRUNC(CURRENT_DATE,'MM')
                AND RAL.EFF_DT < TRUNC(CURRENT_DATE,'MM')
                                                          )R  )RT
    WHERE RT.RN = 1-----

  • Query with FULL OUTER JOIN , help pleaseeeeeeeeeeee...

    Hi everyone,
    I'm trying to write a query for a report in Oracle SQL, but i just can't figure out how to do it.
    I'm using Oracle 10g release 1.0 database and i execute my queris in SQL* PLUS ( eventually i'm gonna use them in Oracle Report Builder ) .
    here's what i have:
    i have four tables that are used for our inventory application. lets call them INCOMMING , INCOMMING_ITEMS , OUTGOING , OUTGOING_ITEMS.
    as you may have guessed , INCOMMING_ITEMS is the detail table for INCOMMING ( joined by IID column) and also OUTGOING_ITEMS is the detail table for OUTGOING ( joined by OID column ).
    here is the structure of them :
    INCOMMING
    IID varchar2
    CDATE date
    INCOMMING_ITEM
    IID varchar2
    PART_NO number
    QTY number
    OUTGOING
    OID varchar2
    CDATE date
    OUTGOING_ITEM
    OID varchar2
    PART_NO number
    QTY number
    now , the query i want, should return part_no , cdate , sum of OUTGOING qty , sum of INCOMMING qty .
    the result of the query should be sth like this :
    part_no     cdate     O_qty     I_qty
    100     01/05/06     10     0
    100     01/05/07     20     60
    200     01/06/02     0     50
    300     01/06/02     30     40
    this means that for some dates and for some parts, i may not have INCOMMING or OUTGOING data, but if at least one of the 2 last columns has a non-zero data, i should show the row ( like the first and third rows of my example result), and if both have data for the same PART_NO and the same CDATE, both should be showed in the same row. ( like the second row in my example result)
    i tried so much and came up with several huge and also time consuming queries, but then i read abt FULL OUTER JOIN somewhere and tried using that. here is what i came up with :
    SELECT
    PART_NO , CDATE , sum(II.QTY) I_QTY , SUM (OI.QTY) O_QTY
    FROM
         (OUTGOING O INNER JOIN OUTGOING_ITEM OI USING ( OID ) )
    FULL OUTER JOIN
         (INCOMMING I INNER JOIN INCOMMING_ITEM II USING ( IID ) )
    ON ( I.CDATE = O.CDATE AND II.PART_NO = OI.PART_NO)
    WHERE
    I.CDATE = :PARAMETER1
    AND O.CDATE = :PARAMETER1
    GROUP BY
    PART_NO , CDATE
    this query is short and fast , but the results r not what i expected. i mean, although i have used FULL OUTER JOIN in the query , but the results i get r sth like this :
    part_no     cdate     O_qty     I_qty
    100     01/05/07     20     60
    300     01/06/02     30     40
    which means only the rows that has both values are returned.
    any change i make to this query would make the SQL* PLUS hang , like when i use the cartesian product of two large tables, so i guess my changes wheren't in the right direction.
    i think its possible to write this query using FULL OUTER JOIN syntax, but i just can't find it.
    Can anybody pleaseeeeeeeeeeeee help me?
    thanx in advance,
    Maryam.

    Note: I wrote this on the fly -- hope there is no syntax errors, otherwise forgive me -- but you get the idea..
    select
    fromUnionAll.cdate, fromUnionAll.part_no,
    sum(fromUnionAll.O_qty) O_qty,
    sum(fromUnionAll.I_qty) I_qty
    from
    select
    iinner.cdate, iinner.part_no, 0 O_qty, iinner.I_qty
    from
    select
    i.cdate, ii.part_no,
    /* added the case only for the extreme case when there is
    no record anywhere for the given CDATE in INCOMMING_item */
    sum( ( case when ii.qty is not null then ii.qty else 0 end) ) I_qty
    from
    incomming i,
    incomming_item ii
    where
    i.iid = ii.iid (+)
    group by i.cdate, ii.part_no
    ) iinner
    union all
    select
    oinner.cdate, oinner.part_no, oinner.O_qty, 0 I_qty
    from
    select
    o.cdate, oi.part_no,
    /* added the case only for the extreme case when there is
    no record anywhere for the given CDATE in OUTGOING_item */
    sum( ( case when oi.qty is not null then oi.qty else 0 end) ) O_qty
    from
    outgoing o,
    outgoing_item oi
    where
    o.oid = oi.oid (+)
    group by o.cdate, oi.part_no
    ) oinner
    ) fromUnionAll
    group by fromUnionAll.cdate, fromUnionAll.part_no;
    --Samson                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 2.4GHZ clients very slow speeds with AP3600

    5508 WLC (7.5.102)
    AP36021
    We currently have a test WiFi SSID setup that uses basic mac filtering on our WLC's
    WLAN is configured with WPA and WPA2 L2 Security with WPA Policy and WPA2 Encryption.
    For some reason we seem to be getting very slow speeds on clients with 2.4GHZ
    for example speedtest.net I get 70mg upload and 65mg download on 5GHZ devices and about 1-3mg download and 1mg upload for 2.4GZ devices!
    AP36021 are dual band with 4 channels (2 x 2.4Ghz and 2 x 5Ghz)
    fyi - There are no dropped packets on the client stats via Prime mgmt that use 2.4GHZ
    Any ideas here?

    Foreign Primary WLC (let me know if you need the Anchor controller ouput as well)
    We have 3 ports configured  as 0/12 trunked
    interface GigabitEthernet0/12
    description + WLC ****
    switchport access vlan 999
    switchport trunk encapsulation dot1q
    switchport trunk native vlan 999
    switchport trunk allowed vlan 10,30,40
    switchport mode trunk
    switchport nonegotiate
    load-interval 30
    no cdp enable
    channel-group 3 mode on
    spanning-tree portfast
    end
    Building configuration...
    Current configuration : 330 bytes
    interface Port-channel3
    description + WLC ****
    switchport access vlan 999
    switchport trunk encapsulation dot1q
    switchport trunk native vlan 999
    switchport trunk allowed vlan 10,30,40
    switchport mode trunk
    switchport nonegotiate
    logging event trunk-status
    logging event bundle-status
    load-interval 30
    end
    AP switch port config
    Building configuration...
    Current configuration : 617 bytes
    interface GigabitEthernet4/32
    description AP36021
    switchport
    switchport access vlan 30
    switchport mode access
    switchport voice vlan 20
    load-interval 30
    speed auto 10 100
    wrr-queue bandwidth 5 90 5
    wrr-queue queue-limit 5 80 5
    wrr-queue random-detect min-threshold 2 70 100 100 100 100 100 100 100
    wrr-queue random-detect min-threshold 3 70 100 100 100 100 100 100 100
    wrr-queue random-detect max-threshold 2 100 100 100 100 100 100 100 100
    wrr-queue cos-map 2 1 0 1 2 4
    wrr-queue cos-map 3 1 3 6 7
    no snmp trap link-status
    mls qos trust cos
    no mdix auto
    spanning-tree portfast
    end
    show wlan 4
    WLAN Identifier.................................. 4
    Profile Name..................................... WLKPV
    Network Name (SSID).............................. WLKPV
    Status........................................... Enabled
    MAC Filtering.................................... Enabled
    Broadcast SSID................................... Enabled
    AAA Policy Override.............................. Disabled
    Network Admission Control
    Client Profiling Status
        Radius Profiling ............................ Disabled
         DHCP ....................................... Disabled
         HTTP ....................................... Disabled
        Local Profiling ............................. Disabled
         DHCP ....................................... Disabled
         HTTP ....................................... Disabled
      Radius-NAC State............................... Disabled
      SNMP-NAC State................................. Disabled
      Quarantine VLAN................................ 0
    Maximum number of Associated Clients............. 0
    Maximum number of Clients per AP Radio........... 200
    --More-- or (q)uit
    Number of Active Clients......................... 21
    Exclusionlist Timeout............................ 60 seconds
    Session Timeout.................................. 7200 seconds
    User Idle Timeout................................ Disabled
    Sleep Client..................................... disable
    Sleep Client Timeout............................. 12 hours
    User Idle Threshold.............................. 0 Bytes
    NAS-identifier................................... hellotest
    CHD per WLAN..................................... Enabled
    Webauth DHCP exclusion........................... Disabled
    Interface........................................ new-byod
    Multicast Interface.............................. Not Configured
    WLAN IPv4 ACL.................................... unconfigured
    WLAN IPv6 ACL.................................... unconfigured
    WLAN Layer2 ACL.................................. unconfigured
    mDNS Status...................................... Enabled
    mDNS Profile Name................................ default-mdns-profile
    DHCP Server...................................... Default
    DHCP Address Assignment Required................. Disabled
    Static IP client tunneling....................... Disabled
    PMIPv6 Mobility Type............................. none
        PMIPv6 MAG Profile........................... Unconfigured
        PMIPv6 Default Realm......................... Unconfigured
    --More-- or (q)uit
        PMIPv6 NAI Type.............................. Hexadecimal
    Quality of Service............................... Silver
    Per-SSID Rate Limits............................. Upstream      Downstream
    Average Data Rate................................   0             0
    Average Realtime Data Rate.......................   0             0
    Burst Data Rate..................................   0             0
    Burst Realtime Data Rate.........................   0             0
    Per-Client Rate Limits........................... Upstream      Downstream
    Average Data Rate................................   0             0
    Average Realtime Data Rate.......................   0             0
    Burst Data Rate..................................   0             0
    Burst Realtime Data Rate.........................   0             0
    Scan Defer Priority.............................. 4,5,6
    Scan Defer Time.................................. 100 milliseconds
    WMM.............................................. Allowed
    WMM UAPSD Compliant Client Support............... Disabled
    Media Stream Multicast-direct.................... Disabled
    CCX - AironetIe Support.......................... Enabled
    CCX - Gratuitous ProbeResponse (GPR)............. Disabled
    CCX - Diagnostics Channel Capability............. Disabled
    Dot11-Phone Mode (7920).......................... Disabled
    Wired Protocol................................... None
    Passive Client Feature........................... Disabled
    --More-- or (q)uit
    Peer-to-Peer Blocking Action..................... Disabled
    Radio Policy..................................... All
    DTIM period for 802.11a radio.................... 1
    DTIM period for 802.11b radio.................... 1
    Radius Servers
       Authentication................................ Global Servers
       Accounting.................................... Global Servers
          Interim Update............................. Disabled
          Framed IPv6 Acct AVP ...................... Prefix
       Dynamic Interface............................. Disabled
       Dynamic Interface Priority.................... wlan
    Local EAP Authentication......................... Disabled
    Security
       802.11 Authentication:........................ Open System
       FT Support.................................... Disabled
       Static WEP Keys............................... Disabled
       802.1X........................................ Disabled
       Wi-Fi Protected Access (WPA/WPA2)............. Enabled
          WPA (SSN IE)............................... Disabled
          WPA2 (RSN IE).............................. Enabled
             TKIP Cipher............................. Disabled
             AES Cipher.............................. Enabled
    --More-- or (q)uit
          Auth Key Management
             802.1x.................................. Disabled
             PSK..................................... Enabled
             CCKM.................................... Disabled
             FT-1X(802.11r).......................... Disabled
             FT-PSK(802.11r)......................... Disabled
             PMF-1X(802.11w)......................... Disabled
             PMF-PSK(802.11w)........................ Disabled
          FT Reassociation Timeout................... 20
          FT Over-The-DS mode........................ Enabled
          GTK Randomization.......................... Disabled
          SKC Cache Support.......................... Disabled
          CCKM TSF Tolerance......................... 1000
       WAPI.......................................... Disabled
       Wi-Fi Direct policy configured................ Disabled
       EAP-Passthrough............................... Disabled
       CKIP ......................................... Disabled
       Web Based Authentication...................... Disabled
       Web-Passthrough............................... Disabled
       Conditional Web Redirect...................... Disabled
       Splash-Page Web Redirect...................... Disabled
       Auto Anchor................................... Enabled
       FlexConnect Local Switching................... Disabled
    --More-- or (q)uit
       flexconnect Central Dhcp Flag................. Disabled
       flexconnect nat-pat Flag...................... Disabled
       flexconnect Dns Override Flag................. Disabled
       flexconnect PPPoE pass-through................ Disabled
       flexconnect local-switching IP-source-guar.... Disabled
       FlexConnect Vlan based Central Switching ..... Disabled
       FlexConnect Local Authentication.............. Disabled
       FlexConnect Learn IP Address.................. Enabled
       Client MFP.................................... Optional
       PMF........................................... Disabled
       PMF Association Comeback Time................. 1
       PMF SA Query RetryTimeout..................... 200
       Tkip MIC Countermeasure Hold-down Timer....... 60
    AVC Visibilty.................................... Disabled
    AVC Profile Name................................. None
    Flow Monitor Name................................ None
    Split Tunnel (Printers).......................... Disabled
    Call Snooping.................................... Disabled
    Roamed Call Re-Anchor Policy..................... Disabled
    SIP CAC Fail Send-486-Busy Policy................ Enabled
    SIP CAC Fail Send Dis-Association Policy......... Disabled
    KTS based CAC Policy............................. Disabled
    Assisted Roaming Prediction Optimization......... Disabled
    --More-- or (q)uit
    802.11k Neighbor List............................ Disabled
    802.11k Neighbor List Dual Band.................. Disabled
    Band Select...................................... Disabled
    Load Balancing................................... Disabled
    Multicast Buffer................................. Disabled
    Mobility Anchor List
    WLAN ID     IP Address            Status
    4           10.x.x.x          Up
    4           10.x.x.x         Up
    802.11u........................................ Disabled
    MSAP Services.................................. Disabled

  • Query with lots of JOINS

    Below is a query I recieved from a customer who currently has SqlServer. I was also provided the tables with data and the output. However, I am not getting the same output when I run this in Oracle (9i). Could somebody take a look and "translate" the joins into a WHERE clause
    SELECT TOP 100 PERCENT
           Local_Name.Level_CMD           AS CMD_CD,
           Local_Code_3.SUB_CMD           AS SUB_CMD_CD,
           Local_Sub_Name.SUBCMD_ABBR     AS SUB_CMD_NAME,
           Local_Code_4.DETAIL_CMD        AS DETAIL_CMD_CD,
           Local_Det_Name.DETAIL_CMD_ABBR AS DETAIL_CMD_NAME,
           Local_Code_1.Bat               AS Bat_Desc,
           Local_Code_5.Name_Ind          AS Bat_NAME,
           Local_Code_2.Desc              AS End_Name_Desc
      FROM Local_Sub_Name RIGHT OUTER JOIN
           Local_Name     RIGHT OUTER JOIN
           Local_Det_Name RIGHT OUTER JOIN
           Local_Cmd_Cd   INNER JOIN
           Local_Cmd_Cd Local_Code_2 ON Local_Cmd_Cd.Desc = Local_Code_2.Desc INNER JOIN
           Local_Cmd_Cd Local_Code_3 ON Local_Cmd_Cd.Desc = Local_Code_3.Desc INNER JOIN
           Local_Cmd_Cd Local_Code_4 ON Local_Cmd_Cd.Desc = Local_Code_4.Desc INNER JOIN
           Local_Cmd_Cd Local_Code_1 ON Local_Cmd_Cd.Desc = Local_Code_1.Desc INNER JOIN
           Local_Cmd_Cd Local_Code_5 ON Local_Code_1.Bat  = Local_Code_5.Desc ON
           Local_Det_Name.DETAIL_CMD = Local_Code_4.DETAIL_CMD ON
           Local_Name.Level_CMD      = Local_Cmd_Cd.Level_CMD ON
           Local_Sub_Name.SUB_CMD    = Local_Code_3.SUB_CMDThe problem I'm having with the query, is it returns a null for Local_Sub_Name.SUBCMD_ABBR in Oracle but returns a value for SqlServer.

    This could be caused by trailing spaces on one of the SUB_CMD columns. In SQL Server, trailing spaces are ignored when comparing two strings.
    For example, in SQL Server, 'abc' == 'abc '
    In Oracle, as we all know, for two strings two be equal, they must match exactly.
    You might try changing:
    Local_Sub_Name.SUB_CMD = Local_Code_3.SUB_CMD
    to
    TRIM(Local_Sub_Name.SUB_CMD) = TRIM(Local_Code_3.SUB_CMD)
    and see if this changes your results.

  • Query with CTE solution - Predecessor

    Well, my problem started with the following challenge:
    I have a table where
    I have a field I call 'JOB'and
    the otherI call 'predecessor'. Predecessor, as the name says, is
    the father of JOB beside him, for example:
    JOB - PREDECESSOR - POSITION
      A   -    '       '        -   NULL 
      B   -      A             -   NULL
    'A' is the root job, the first one..
    and 'B' is just below the
    'A', then 'A' is father of 'B'.
    I has the following Query, I have the followingquery,where my
    query defines a table where there are
    random insertions.I want to
    organize it in an order from the first job
    to be executed. I created
    a CTE but it doesnt work for this order,but I was wondering
    if you can optimize it to organize
    my table correctly.
    CREATE
    TABLE CTRL_M2
    Job
    varchar(50),
    Antecessor
    varchar(50),
    Posicao
    int
    insert
    into CTRL_M2
    values
    ('B',
    'A',
    null)
    insert
    into CTRL_M2
    values
    ('C',
    'B',
    null)
    insert
    into CTRL_M2
    values
    ('B',
    'AB',
    null)
    insert
    into CTRL_M2
    values
    ('XB',
    'A',
    null)
    insert
    into CTRL_M2
    values
    ('XC',
    'A',
    null)
    insert
    into CTRL_M2
    values
    ('E',
    'D',
    null)
    insert
    into CTRL_M2
    values
    ('ZB',
    null)
    insert
    into CTRL_M2
    values
    ('ZA',
    null)
    insert
    into CTRL_M2
    values
    ('D',
    'C',
    null)
    insert
    into CTRL_M2
    values
    ('A',
    null)
    insert
    into CTRL_M2
    values
    ('AB',
    null)
    select
    from CTRL_M2
    with
    CTE as
    SELECT s.Job,
    s.Antecessor,
    Posicao
    =
    CASE
    WHEN s.Antecessor
    like
    THEN 1
    END
    FROM CTRL_M2 s
    UNION
    ALL
    SELECT s.Job,
    s.Antecessor,
    Posicao
    =
    CASE
    WHEN s.Antecessor
    like
    THEN 1
    END
    FROM CTRL_M2 s
    join cte
    as x
    on x.Job
    = s.Antecessor
    WHERE s.Antecessor
    is
    not
    null
    select
    distinct Job,
    Antecessor,Posicao
    from CTE
    order
    by Posicao
    DESC 

    Hi, Jayakumaur.
    I tried but I noticed that
    still does not solve my problem. Here's why:
    I
    insert that order:
    insert into CTRL_M2 values ('B', 'A', null)
    insert into CTRL_M2 values ('C', 'B', null)
    insert into CTRL_M2 values ('B', 'AB', null)
    insert into CTRL_M2 values ('XB', 'A', null)
    insert into CTRL_M2 values ('XC', 'A', null)
    insert into CTRL_M2 values ('E', 'D', null)
    insert into CTRL_M2 values ('ZB', '-', null)
    insert into CTRL_M2 values ('ZA', '-', null)
    insert into CTRL_M2 values ('D', 'C', null)
    insert into CTRL_M2 values ('A', '-', null)
    insert into CTRL_M2 values ('AB', '-', null)
    As you can see, my table is totally out of order.
    When I used your
    CTE, I had
    the following result:
    JOB - PREDECESSOR - POSITION
    A    -    '-'      -      1
    AB    -    '-'      -      1
    B    -    A     -      0
    B    -    AB      -      0
    C    -    B     -      0
    D    -    C      -      0
    E    -    D      -      0
    XC    -    A      -      0
    XB  -    A      -      0
    ZA  -    '-'      -      1
    ZB  -    '-'      -      1
    The last four
    jobs are out of
    order.The last two
    should be first to be
    run as they have no
    predecessors.The two
    above them should be
    well above
    the job because they have
    'A' as a predecessor, so
    could not be in
    the end.

  • Issue with the inner join on EKKO and EKPO.

    Dear All,
    The report using this join takes a long time to execute.
    Does this inner join have an issue?
    Do i need to code this in a different way for lesser execution time?
    Please give me your inputs.
    SELECT
            a~ebeln
            b~ebelp
            a~bukrs
            a~bstyp
            a~bsart
            a~ekorg
            a~ekgrp
            a~kdatb
            a~kdate
            FROM ekko AS a JOIN ekpo AS b
            ON aebeln = bebeln
            INTO TABLE t_ekpo
            WHERE
            a~bukrs EQ p_bukrs
            AND a~bstyp EQ c_k
            AND a~bsart IN s_bsart
            AND a~ekorg IN s_ekorg
            AND a~ekgrp IN s_ekgrp
            AND a~kdate GE s_fdate-low
            AND a~loekz EQ space
            AND b~loekz EQ space.
    Regards,
    SuryaD.

    Index EKKO~D consists top-down of BSTYP and BEDAT. BSTYP is already an EQ-condition in your selection, but not very selective (many rows with the same value). So including BEDAT should help in efficiently reducing the data that needs to be scanned for finding the relevant rows. However, just a new optional S_BEDAT select option that can be left empty by the user would not help, you must force a narrow selection (one month, one week, even one day? the less the better).
    This is just a quick guess from my side, there might be other options that occur to you once you have analysed the available indexes. Sometimes alternative tables could be the solution, and even less sometimes introducing a new secondary index for a standard table might be the last option (takes up space and adds processing time to insert/update/delete operations).
    Thomas

  • Very slow working with eps files over new network

    Please help!!!
    Our IT has recently upgraded us from a OSX server to a 2 Terabyte SNAP SERVER 520.
    I am using the only INTEL Mac in the department (we have another 10+ G5 PPCs running 10.4), and the only one using OSX 10.5. Since changing to the new server, I am also the only one with several file saving/opening issues.
    I believe this is a network issue.
    It is with mostly ADOBE products and we all know they will not support, working over the network. Due to the volume of files, I simply cannot drag files to my HD, and work locally. It is not practical. I also know that we have not had any issues in the past, and don't see why I can't get to the root of the problem.
    **The most obvious issue is Illustrator .eps files.**
    I can open and save .ai files in good time both locally, and over the network. There is no difference either way. HOWEVER, if it is an .eps file working over the network is not practical. I get the spinning wheel for about 2 minutes each time I open, save, or make a change. It is VERY slow. Working on eps files locally is fine (about the same speed as .ai files), but as soon as it hits the server, it is painfully slow to do anything.
    Additionally, when saving Photoshop, Illustrator, InDesign AND Quark 7 files (direct to the network), I am regularly getting "Could not save because write access was not granted", or "Could not save becasue unexpected end-of-file was encountered", or "Could not save because the file is already in use or as left open" type errors.
    I simply then click 'OK', and then hit save again, and it either gives me the same message, or it goes into 'save as' mode which lets me save the file (same name, and same location, but the original file has disappeared).
    I am connected to the server IP address through afp:// but have also tried cifs://. IT have removed all access to the server through smb://, so I cannot try this.
    ANY help is appreciated.

    With regard to the EPS issue, I think I may have found the source of the problem for SMB users: the Suitcase Fusion plug-in.
    Did you make any progress on these issues?

  • Select List or Radio Buttons query with multiple tables join

    Hello,
    I'm having a problem creating a select list or a radio group item.
    I need to display the emp_first_name in the select list but have the return value of the order_id in the select list or radio buttons item.
    The tables are as follow:
    emp_table
    emp_id
    emp_first_name
    emp_last_name
    etc...
    orders_table
    order_id
    order_name
    emp_id
    etc...
    I need to display the emp_name from emp_table in the select list but return the order_id from the orders_table as the return value.
    How can I do this?
    Any help would be greatly appreciated.
    Thanks.
    Regards,
    NJ

    Hi NJ,
    Try:
    select e.emp_first_name d,
    o.order_id r
    from orders_table o
    inner join emp_table e on o.emp_id = e.emp_id
    order by 1You may have an issue with an emp_id being used for more than one order and, therefore, the employee's name appearing more than once in the list?
    Andy

  • Query with multiple outer joins

    I had a doubt with whether the following kind of query is valid with multiple outer-joins. The format of the query is something like this:-
    select A.col1, B.col2
    from table1 A, table2 B, table3 C where
    A.col3=B.col4(+) and B.col5=C.col6(+)
    This would mean the follwoing with regard to outer-joins in the query.
    1) fetch records with col3 in table A matching or not matching col4 in table B
    2) fetch records with col5 in table B matching or not matching col6 in table C
    So, this query is valid?
    I hope, my question is clear.
    Please, help in solving the doubt.
    regards

    This is valid and it works fine

  • Very slow query on xml db objects

    Hi, I'm a dba (new to xml db) trying to diagnose some very slow queries against xml tables. The following takes 2 + hours to return a count of ~700,000 records. We have some that take 10-15 hours.
    select count(*)
    from MEDTRONICCRM a, table(xmlsequence(extract(value(a),'/MedtronicCRM/Counters/
    Histogram'))) b ,
    table(xmlsequence(extract(value(b),'/Histogram/Row'))) c, table(xmlsequence(extract(value(c),'/Row/Column'))) d
    The explain plan from a tkprof looks like this:
    Rows Row Source Operation
    1 SORT AGGREGATE (cr=1586294 r=27724 w=0 time=334399181 us)
    761020 NESTED LOOPS (cr=1586294 r=27724 w=0 time=6285597846 us)
    209395 NESTED LOOPS (cr=1586294 r=27724 w=0 time=1294406875 us)
    16864 NESTED LOOPS (cr=1586294 r=27724 w=0 time=188247898 us)
    544 TABLE ACCESS FULL OBJ#(26985) (cr=1993 r=548 w=0 time=171380 us)
    16864 COLLECTION ITERATOR PICKLER FETCH (cr=0 r=0 w=0 time=82831582 us)
    209395 COLLECTION ITERATOR PICKLER FETCH (cr=0 r=0 w=0 time=939691917 us)
    761020 COLLECTION ITERATOR PICKLER FETCH (cr=0 r=0 w=0 time=3399611143 us)
    I noticed the following statemnt in a previous thread:
    "Indexing is not the answer here... The problem is the storage model. You are current storing all of the collections as serialized lobs. This means that all manipluation of the collection is done in memory. We need to store the collections as nested tables to get peformant queries on them. You do this by using the store VARRAY as table clause to control which collections are stored as nested tables. "
    Could this be the problem? How do I tell which storage model we are using.
    Thanks ,
    Heath Henjum

    With 10g I get the following
    SQL> begin
    2 dbms_xmlschema.registerSchema
    3 (
    4 schemaURL => '&3',
    5 schemaDoc => xdbURIType('/home/&1/xsd/&4').getClob(),
    6 local => TRUE,
    7 genTypes => TRUE,
    8 genBean => FALSE,
    9 genTables => &5
    10 );
    11 end;
    12 /
    old 4: schemaURL => '&3',
    new 4: schemaURL => 'MedtronicCRM.xsd',
    old 5: schemaDoc => xdbURIType('/home/&1/xsd/&4').getClob(),
    new 5: schemaDoc => xdbURIType('/home/OTNTEST/xsd/MedtronicCRM.xsd').getClob(),
    old 9: genTables => &5
    new 9: genTables => TRUE
    begin
    ERROR at line 1:
    ORA-31154: invalid XML document
    ORA-19202: Error occurred in XML processing
    LSX-00175: a complex base within "simpleContent" must have simple content
    ORA-06512: at "XDB.DBMS_XMLSCHEMA_INT", line 17
    ORA-06512: at "XDB.DBMS_XMLSCHEMA", line 26
    ORA-06512: at line 2
    SQL> quit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
    With the Partitioning, OLAP and Data Mining options

  • Confusion in Select query having a inner join on single table

    Hi,
    I was going through coding and came a accross a select query which has a inner join on a single table. I am getting confused while analysing this . Please someone can help me analysing this query.
    select
            m~MATERIAL
            s~NUMERATOR s~DENOMINTR
            m~GROSS_WT  m~UNIT_OF_WT
          into table itab
          from ( table1as s
           inner join table1 as m
           on  m~MATERIAL = s~MATERIAL
          and m~MAT_UNIT = 'CS'
          and m~SOURSYSTEM = s~SOURSYSTEM )
          where s~MAT_UNIT = 'EA'
             and s~SOURSYSTEM = 'LD'
             and s~OBJVERS = 'A'
             and s~MATERIAL IN ( Select mat_sales
                from Table2  group by mat_sales ).
    Thank you
    Kusuma

    I don't see any use of the INNER JOIN here.
    But what's the meaning of the last selection clause?
    s~MATERIAL IN ( Select mat_sales
                from Table2  group by mat_sales ).
    Is that native SQL or something?
    Pushpraj

Maybe you are looking for