Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Why is this simple query taking forever?
On Mar 1, 10:57 am, "ame..._at_iwc.net" <ame..._at_iwc.net> wrote:
> On Feb 28, 6:59 pm, "Mark D Powell" <Mark.Pow..._at_eds.com> wrote:
> > Where is the SQL and explain plan for the 45 minute query?
> > When was the last time statistics were collected on each object? You
> > might want to update the statistics and then recheck the plan for the
> > poorly performing query?
>
> > HTH -- Mark D Powell
>
> The top query is the 45 minute query. You see the explain plan right
> below it........
I had trouble following the original post also. Let's see if we can
unwind the logic of the main SQL query that takes 45 minutes to
complete:
* Main SQL calls LAST_SUBSCR_CODE PL/SQL function (context switch) for
every row returned (dep=0 in a 10046 trace)
* LAST_SUBSCR_CODE calls LAST_SUBSCR_DATE potentially for every row
in CUSTOMER_ORDER, LAST_SUBSCR_CODE hits the same tables as the main
SQL statement (dep=1 in a 10046 trace)
* LAST_SUBSCR_DATE hits three of the same tables as the main SQL
statement (dep=2 in a 10046 trace)
Main SQL calls LAST_SUBSCR_STATUS_TMP PL/SQL function (context switch)
for every row returned (dep=0 in a 10046 trace)
* LAST_SUBSCR_STATUS_TMP calls LAST_SUBSCR_DATE_TMP potentially for
every row in CUSTOMER_ORDER, LAST_SUBSCR_STATUS_TMP hits three of the
same tables used by the main SQL statement (dep=1 in a 10046 trace)
* LAST_SUBSCR_DATE_TMP hits three of the same tables as the main
SQL statement (dep=2 in a 10046 trace)
(dep=0 in a 10046 trace)
SELECT
P.SUBPRODUCT_ID,
NS.NEWSLETTER_NAME, NS.FREQUENCY, NS.FORMAT,
AND NS.NEWSLETTER_ID = 208 AND CO.CUSTOMER_ID = 1068733494 AND CO.ORDER_DATE = LAST_SUBSCR_DATE(1068733494, 208);
LAST_SUBSCR_DATE (dep=2 in a 10046 trace)
So, where might the problems be? You cannot look at the explain plan for each SQL statement in isolation. How many times are you scanning the tables (or indexes for the tables): CUSTOMER_ORDER, ORDER_LINE, PRODUCT, NEWSLETTER_SUBSCRIPTION? How much CPU time are you losing due to excessive context switches?
Suggestions:
* See if you can accomplish some or all of the above using analytical
functions.
* Unwind the logic to accomplish everything in a single SQL statement.
Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.
Received on Thu Mar 01 2007 - 11:06:29 CST