Re: Query help please

From: Randolf Geist <>
Date: Wed, 18 Mar 2009 02:20:25 -0700 (PDT)
Message-ID: <>

On Mar 17, 9:37 pm, "bob123" <> wrote:
> How can I optimize this query (30 min) (

Your query has two potential issues:

  1. 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?
  2. 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:


Oracle related stuff blog:

SQLTools++ for Oracle (Open source Oracle GUI for Windows): Received on Wed Mar 18 2009 - 04:20:25 CDT

Original text of this message