Advertisement

09.23.2008 at 02:42PM PDT, ID: 23756728
[x]
Attachment Details

URGENT  -  ORACLE query with sort is slow, contains functions

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0
Tags:

ORACLE, 10g

I am interested to find ways to improve query response time when working with database calculations, especially when sorting must be used.

I have functions I wrote in PL/SQL for returning some calculations ...LOW val, HIGH val, and a SUM val (LOW + HIGH)

i have a separate function for each.  my database is composed of a number of projects for my company and in each project, we need to calculate a LOW, HIGH, and SUM value for each ...the rows in the TABLE_C table are used across projects so the query is a little more complex.   so....I first found all C.ID that are used on the project  (project id = '1081' in this example query)   then ...for those C.ID, I am trying to return the calculated LOW, HIGH, SUM functions.  this query is taking about 12 seconds to complete.  if I remove the ORDER BY at the end of the query......it returns the result in ~5seconds.....which is manageable.....    So, is there a different way for me to structure this query so I can avoid these long query times.  I can move the sorting to javascript, but don't know anything about how to do that.  am I doing something wrong in my structure....and is there a way for me to calculate the sum of LOW and HIGH ....without recalculating low and hi?   that would cut my query time in half alone.  i just feel like my query is very slow because I am sorting on a calculated field.  please help!!


SELECT C.ID,
P.FIELD_P1,
C.FIELD_C1
C.FIELD_C2,
FXN.CCSL(C.ID) AS LOW,
FXN.CCSU(C.ID) AS HI,
(FXN.CCSL(C.ID) + FXN.CCSU(C.ID)) AS SUM_VALS
FROM TABLE_C C, TABLE_P P
WHERE C.P_ID = P.ID  AND (C.ID IN
    (SELECT
            DISTINCT SCC.ID
            FROM TABLE_S S, TABLE_SCC SCC
            WHERE S.ID = SCC.S_ID AND (S.PROJECT_ID = '1081')))
ORDER BY SUM_VALS DESC
Answered By: sdstuber
Expert Since: 10/06/2003
Accepted Solutions: 1846
Computer Expertise: Advanced
sdstuber has been an Expert for 5 years 3 months, during which he has posted 7484 comments and answered 1846 questions. sdstuber is just one of 761 experts in the Oracle 10.x Zone. 3 experts collaborated on this answer, which was graded an "A" by the asker.
 
 
20081119-EE-VQP-47 / EE_QW_2_20070628