Re: Query help please
Date: Wed, 18 Mar 2009 02:20:25 -0700 (PDT)
On Mar 17, 9:37 pm, "bob123" <bob..._at_gmail.com> wrote:
> How can I optimize this query (30 min) (22.214.171.124)
Your query has two potential issues:
- The cardinality estimates are way off. You're getting back 71k rows but the optimizer estimates a single row at most. The issue starts with the access to the table PFMQ_MESSAGESTATUS. The predicate "ms.status = 64" is estimated to return only a single row from that table. Is that estimate correct? If not, you need to find out, why it is incorrect? In what state are your table/index stats? Have gathered statistics on both, if yes, how?
- The SELECT MAX()... nested subquery is potentially executed for each row of the result set. Since the Oracle runtime engine has a powerful optimization for such filter operations it might not be the problem, but you could try to use analytic functions (e.g. SELECT FROM ...( , RANK() OVER (PARTITION BY MS.ID ORDER BY MS.STATUSREVISIONNUMBER DESC) as rnk) WHERE RNK = 1) or join the SELECT MAX() to the query instead of using a subquery.
You should trace your statement to find out where the bottleneck is, either 1. or 2. or both.
You can follow my blog post how to do that, it shows you step-by-step instructions: http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
Oracle related stuff blog: