Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Sql Tuning Thoughts?

RE: Sql Tuning Thoughts?

From: Cary Millsap <cary.millsap_at_hotsos.com>
Date: Fri, 23 Jan 2004 09:14:25 -0800
Message-ID: <F001.005DDFCC.20040123091425@fatcity.com>


Content-Type: text/plain;
 charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Tracy,  

Take a look at the thing calling this 43,814 times. Can this query be used as an inline view for the thing using this query's result set? If so, then you'll eliminate 87,629 database calls.  

As Tom Kyte says, "Tune the QUESTION, not the query."  

Cary Millsap
Hotsos Enterprises, Ltd.
http://www.hotsos.com
Nullius in verba

Upcoming events:
- Performance <http://www.hotsos.com/training/PD101.html> Diagnosis
101: 1/27 Atlanta
- SQL Optimization 101: 2/16 Dallas

-----Original Message-----
Tracy Rahmlow
Sent: Thursday, January 22, 2004 11:24 AM To: Multiple recipients of list ORACLE-L  

This statement is from a batch program within a pl/sql procedure. (Also, I have many similar ones within the process) The policy table has approximately 6.2 million rows. The procedure is to incrementally(daily) build an extract table from multiple tables. The extract table is then used for reporting purposes. The statement performs well per policy, however it is being executed 43,000+ times. Is there a design option available to me to reduce the number of executions and be more scaleable? I am considering the creation of an index to incorporate both the policy_number and the pol_eff_date hopefully eliminating the table access.

We are currently on 8.1.7.



SELECT MIN(P.POL_EFF_DATE)
FROM
 PHXADM.POLICY P WHERE P.POLICY_NUMBER = :b1

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ----------



Parse 1 0.00 0.01 0 0 0 0
Execute 43814 1.95 1.57 0 0 0 0
Fetch 43814 55.88 599.11 408248 568098 0 43814
------- ------ -------- ---------- ---------- ---------- ----------

total 87629 57.83 600.69 408248 568098 0 43814

Misses in library cache during parse: 1 Optimizer goal: CHOOSE
Parsing user id: 547 (RPTADM) (recursive depth: 1)

Rows Execution Plan

-------  --------------------------------------------------- 
      0  SELECT STATEMENT   GOAL: CHOOSE 
      0   SORT (AGGREGATE) 
      0    TABLE ACCESS   GOAL: ANALYZED (BY INDEX ROWID) OF 'POLICY' 
      0     INDEX   GOAL: ANALYZED (RANGE SCAN) OF 'POLICY_PK' (UNIQUE) 

American Express made the following
annotations on 01/22/2004 10:24:24 AM





"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."





------=_NextPart_000_0357_01C3E1A1.DD2EEC50 Content-Type: text/html;
 charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<html>

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii">

<meta name=3DGenerator content=3D"Microsoft Word 10 (filtered)">

<style>
<!--
 /* Font Definitions */
 @font-face

	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}

 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
p
	{margin-right:0in;
	margin-left:0in;
	font-size:12.0pt;
	font-family:"Times New Roman";}
tt
	{font-family:"Courier New";}
span.EmailStyle19
	{font-family:Arial;
	color:navy;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}

-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:
  10.0pt;font-family:Arial;color:navy'>Tracy</span></font><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial; color:navy'>,</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Take a look at the thing calling = this 43,814
times. Can this query be used as an inline view for the thing using this = query&#8217;s
result set? If so, then you&#8217;ll eliminate 87,629 database = calls.</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>As Tom Kyte says, &#8220;Tune the QUESTION, not the query.&#8221;</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<div>

<p><b><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:10.0pt;
font-family:Arial;color:navy;font-weight:bold'>Cary = Millsap</span></font></b><font
size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:10.0pt;font-family:Arial; color:navy'><br>
Hotsos Enterprises, Ltd.<br>
<a href=3D"http://www.hotsos.com">http://www.hotsos.com</a><br> <em><i><font face=3DArial><span style=3D'font-family:Arial'>Nullius in = verba</span></font></i></em><br>
<br>
Upcoming events:<br>
- <a href=3D"http://www.hotsos.com/training/PD101.html">Performance
Diagnosis&nbsp;101</a>: 1/27 Atlanta<br>
- SQL Optimization&nbsp;101: 2/16 Dallas<br>

</div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 = face=3DTahoma><span
style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original = Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> = ml-errors_at_fatcity.com
[mailto:ml-errors_at_fatcity.com] <b><span style=3D'font-weight:bold'>On = Behalf Of </span></b>Tracy
Rahmlow<br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Thursday, January = 22, 2004
11:24 AM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> Multiple recipients = of list
ORACLE-L<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> Sql Tuning = Thoughts?</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 = face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 = face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'><br>
</span></font><tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>This
statement is from a batch program within a pl/sql procedure. (Also, I = have many
similar ones within the process) &nbsp;The policy table has = approximately 6.2
million rows. &nbsp;The procedure is to incrementally(daily) build an = extract
table from multiple tables. &nbsp;The extract table is then used for = reporting
purposes. The statement performs well per policy, however it is being = executed
43,000+ times. &nbsp;Is there a design option available to me to reduce = the
number of executions and be more scaleable? &nbsp; &nbsp;I am = considering the
creation of an index to incorporate both the policy_number and the = pol_eff_date
hopefully eliminating the table access. &nbsp;</span></font></tt> <br> <br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>We are
currently on 8.1.7.</span></font></tt> <br>

<br>
<br>
<tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>**********************************************=
*****************************************</span></font></tt>
<br>
<br>

<br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>SELECT
MIN(P.POL_EFF_DATE) &nbsp; </span></font></tt><br> <tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>FROM</span></font></tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>&nbsp;PHXADM.POLICY P &nbsp;WHERE P.POLICY_NUMBER =3D :b1</span></font></tt> <br>
<br>
<br>
<tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>call &nbsp;
&nbsp; count &nbsp; &nbsp; &nbsp; cpu &nbsp; &nbsp;elapsed &nbsp; &nbsp; = &nbsp;
disk &nbsp; &nbsp; &nbsp;query &nbsp; &nbsp;current &nbsp; &nbsp; &nbsp; &nbsp;rows</span></font></tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>-------
------ &nbsp;-------- ---------- ---------- ---------- ----------
&nbsp;----------</span></font></tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>Parse &nbsp;
&nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp; 0.01 =
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; =
&nbsp;
&nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
0</span></font></tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>Execute
&nbsp;43814 &nbsp; &nbsp; &nbsp;1.95 &nbsp; &nbsp; &nbsp; 1.57 &nbsp; =
&nbsp;
&nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; =
&nbsp;
&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0</span></font></tt> =
<br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>Fetch &nbsp;
&nbsp;43814 &nbsp; &nbsp; 55.88 &nbsp; &nbsp; 599.11 &nbsp; &nbsp; = 408248
&nbsp; &nbsp; 568098 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; = &nbsp;
43814</span></font></tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>------- ------
&nbsp;-------- ---------- ---------- ---------- ---------- =
&nbsp;----------</span></font></tt>

<br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>total &nbsp;
&nbsp;87629 &nbsp; &nbsp; 57.83 &nbsp; &nbsp; 600.69 &nbsp; &nbsp; = 408248
&nbsp; &nbsp; 568098 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; = &nbsp;
43814</span></font></tt> <br>
<br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>Misses in
library cache during parse: 1</span></font></tt> <br> <tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>Optimizer
goal: CHOOSE</span></font></tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>Parsing user
id: 547 &nbsp;(RPTADM) &nbsp; (recursive depth: 1)</span></font></tt> =
<br>
<br>
<tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>Rows &nbsp;
&nbsp; Execution Plan</span></font></tt> <br> <tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>-------
&nbsp;---------------------------------------------------</span></font></=
tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>&nbsp;
&nbsp; &nbsp; 0 &nbsp;SELECT STATEMENT &nbsp; GOAL: = CHOOSE</span></font></tt> <br>
<tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>&nbsp;
&nbsp; &nbsp; 0 &nbsp; SORT (AGGREGATE)</span></font></tt> <br> <tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>&nbsp;
&nbsp; &nbsp; 0 &nbsp; &nbsp;TABLE ACCESS &nbsp; GOAL: ANALYZED (BY = INDEX
ROWID) OF 'POLICY'</span></font></tt> <br> <tt><font size=3D2 face=3D"Courier New"><span = style=3D'font-size:10.0pt'>&nbsp;
&nbsp; &nbsp; 0 &nbsp; &nbsp; INDEX &nbsp; GOAL: ANALYZED (RANGE SCAN) = OF
'POLICY_PK' (UNIQUE)</span></font></tt> </p>

<p style=3D'margin-left:.5in'><font size=3D3 face=3D"Times New = Roman"><span
style=3D'font-size:12.0pt'>American Express made the following<br> annotations on 01/22/2004 10:24:24 AM<br>

-------------------------------------------------------------------------=
-----<br>
*************************************************************************=
*****<br>
<br>
&quot;This message and any attachments are solely for the intended = recipient
and may contain confidential or privileged information. If you are not = the
intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. = If you
have received this communication in error, please notify us by reply = e-mail and
immediately and permanently delete this message and any attachments. = Thank
you.&quot;<br>
<br>
*************************************************************************=
*****<br>
<br>
<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D</span></font></p>

</div>

</body>

</html>

------=_NextPart_000_0357_01C3E1A1.DD2EEC50--

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Cary Millsap
  INET: cary.millsap_at_hotsos.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Fri Jan 23 2004 - 11:14:25 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US