﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Neil的备忘录-随笔分类-ORACLE</title><link>http://www.blogjava.net/zl4393753/category/37300.html</link><description>just do it</description><language>zh-cn</language><lastBuildDate>Fri, 12 Nov 2010 11:10:07 GMT</lastBuildDate><pubDate>Fri, 12 Nov 2010 11:10:07 GMT</pubDate><ttl>60</ttl><item><title>ORACLE 调整数据库内存</title><link>http://www.blogjava.net/zl4393753/archive/2010/11/11/337786.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Thu, 11 Nov 2010 03:03:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2010/11/11/337786.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/337786.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2010/11/11/337786.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/337786.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/337786.html</trackback:ping><description><![CDATA[<p>
<p>如何才能优化oracle的内存占用情况呢？为了开发的方便，想减少oracle平时占用的内存。下面就为您介绍一个通过调整oracle内存参数实现减少内存占用的方法，供您参考学习。</p>
<p>解决方法：</p>
<p>sqlplus &#8220;/ as sysdba" &nbsp;</p>
<p>&nbsp;create pfile='d:/cj.ora' from spfile; &nbsp;</p>
<p>然后去你的oracle安装目录</p>
<p>找一个init数据库名.ora这样一个文件</p>
<p>把几个oracle内存参数改小点</p>
<p>一个2G的内存是如下配置的：</p>
<p>*.sga_max_size=712M</p>
<p>*.large_pool_size=8M</p>
<p>*.shared_pool_size=250M</p>
<p>*.sort_area_size=0.5M</p>
<p>*.db_cache_size=350M</p>
<p>然后shutdown数据库</p>
<p>shutdown immediate; &nbsp;</p>
<p>&nbsp;create spfile from pfile='d:/cj2.ora'; &nbsp;</p>
<p>&nbsp;startup; &nbsp;</p>
<p>然后启动，就可以了。</p>
<p>以上就是调整oracle内存参数，减少数据库内存占用的方法介绍。</p>
</p>
<img src ="http://www.blogjava.net/zl4393753/aggbug/337786.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2010-11-11 11:03 <a href="http://www.blogjava.net/zl4393753/archive/2010/11/11/337786.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle 递归查询</title><link>http://www.blogjava.net/zl4393753/archive/2010/10/19/335526.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Tue, 19 Oct 2010 02:19:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2010/10/19/335526.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/335526.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2010/10/19/335526.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/335526.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/335526.html</trackback:ping><description><![CDATA[<span  style="font-family: Verdana, 宋体; font-size: 14px; line-height: 25px; ">1. 通过子节点向根节点追朔，语法：<br />
select * from da_tree start with id='195' connect by prior parentid=id;<br />
2.&nbsp;</span><span  style="font-family: Verdana, 宋体; font-size: 14px; line-height: 25px; ">通过根节点遍历子节点，语法：<br />
select * from da_tree start with parentid='21' connect by prior id=parentid;<br />
<br />
<span  style="line-height: 16px; font-size: 13px; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-size: 14px; line-height: 25px; ">oracle中的select语句可以用START WITH...CONNECT BY PRIOR子句实现递归查询，connect by 是结构化查询中用到的，其基本语法是：</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-size: 14px; line-height: 25px; ">Java代码</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-size: 14px; line-height: 25px; ">select * from tablename start with cond1&nbsp;connect by cond2&nbsp;where cond3;</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-size: 14px; line-height: 25px; ">简单说来是将一个树状结构存储在一张表里，比如一个表中存在两个字段:</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-size: 14px; line-height: 25px; ">id,parentid那么通过表示每一条记录的parent是谁，就可以形成一个树状结构。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-size: 14px; line-height: 25px; ">用上述语法的查询可以取得这棵树的所有记录。</p>
<div><br />
</div>
</span></span>
<img src ="http://www.blogjava.net/zl4393753/aggbug/335526.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2010-10-19 10:19 <a href="http://www.blogjava.net/zl4393753/archive/2010/10/19/335526.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Windows Vista下安装ORACLE10G需注意事项</title><link>http://www.blogjava.net/zl4393753/archive/2009/09/08/294275.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Tue, 08 Sep 2009 03:39:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/09/08/294275.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/294275.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/09/08/294275.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/294275.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/294275.html</trackback:ping><description><![CDATA[<span  style="font-family: Helvetica; font-size: 12px; border-collapse: collapse; color: #333333; line-height: 19px; ">首先、确保你有该文件夹的完全控制权。（修改：文件夹点右键&nbsp;<font color="yellowgreen" style="word-wrap: break-word; line-height: normal; ">属性-〉安全-〉高级-〉所有者-〉</font>改为自己。接着编辑自己的权限为完全控制）<br style="word-wrap: break-word; line-height: normal; " />
其次、将<font color="darkorange" style="word-wrap: break-word; line-height: normal; ">setup.exe</font>的兼容性改为<font color="sandybrown" style="word-wrap: break-word; line-height: normal; ">windows server 2003(server pack 1)。</font>就是右键<font color="orange" style="word-wrap: break-word; line-height: normal; ">属性-〉兼容性-〉兼容模式</font>中。<br style="word-wrap: break-word; line-height: normal; " />
接着、右键，以管理员身份运行。<br style="word-wrap: break-word; line-height: normal; " />
最后、会出现兼容性问题的提示框。选择<font color="darkorange" style="word-wrap: break-word; line-height: normal; ">运行程序</font>。</span>
<img src ="http://www.blogjava.net/zl4393753/aggbug/294275.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-09-08 11:39 <a href="http://www.blogjava.net/zl4393753/archive/2009/09/08/294275.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle - Rebuild The Temporary Tablespace</title><link>http://www.blogjava.net/zl4393753/archive/2009/03/12/259380.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Thu, 12 Mar 2009 09:15:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/03/12/259380.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/259380.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/03/12/259380.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/259380.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/259380.html</trackback:ping><description><![CDATA[<div>create temporary tablespace TEMP2 TEMPFILE '/home2/oracle/oradata/sysmon/temp02.dbf' SIZE 512M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED; --创建中转临时表空间</div>
<div>alter database default temporary tablespace temp2; --改变缺省临时表空间 为刚刚创建的新临时表空间temp2</div>
<div>drop tablespace temp including contents and datafiles;--删除原来临时表空间</div>
<div>create temporary tablespace TEMP TEMPFILE '/home2/oracle/oradata/sysmon/temp01.dbf' SIZE 512M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED; --重新创建临时表空间</div>
<div>alter database default temporary tablespace temp; --重置缺省临时表空间为新建的temp表空间</div>
<div>drop tablespace temp2 including contents and datafiles;--删除中转用临时表空间</div>
<img src ="http://www.blogjava.net/zl4393753/aggbug/259380.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-03-12 17:15 <a href="http://www.blogjava.net/zl4393753/archive/2009/03/12/259380.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Index Skip Scanning</title><link>http://www.blogjava.net/zl4393753/archive/2009/01/21/252219.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Wed, 21 Jan 2009 07:22:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/01/21/252219.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/252219.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/01/21/252219.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/252219.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/252219.html</trackback:ping><description><![CDATA[In previous releases a composite index could only be used if the first column, the leading edge, of the
index was referenced in the <code>WHERE</code> clause of a statement. In Oracle9i this restriction
is removed because the optimizer can perform skip scans to retrieve rowids for values that do not use the
prefix.<br />
<ul>
    <li><a href="http://oracle-base.com/articles/9i/IndexSkipScanning.php#HowItWorks">How It Works</a></li>
    <li><a href="http://oracle-base.com/articles/9i/IndexSkipScanning.php#Advantages">Advantages</a></li>
    <li><a href="http://oracle-base.com/articles/9i/IndexSkipScanning.php#Example">Example</a></li>
</ul>
<h2>How It Works</h2>
Rather than restricting the search path using a predicate from the statement, Skip Scans are initiated by probing
the index for distinct values of the prefix column. Each of these distinct values is then used as a starting point
for a regular index search. The result is several separate searches of a single index that, when combined, eliminate
the affect of the prefix column. Essentially, the index has been searched from the second level down.<br />
<br />
The optimizer uses statistics to decide if a skip scan would be more efficient than a full table scan.<br />
<h2>Advantages</h2>
This approach is advantageous because:<br />
<ul>
    <li>
    It reduces the number of indexes needed to support a range of queries. This increases
    performance by reducing index maintenance and decreases wasted space associated with multiple indexes.
    </li>
    <li>
    The prefix column should be the most discriminating and the most widely used in queries. These two conditions do
    not always go hand in hand which makes the decision difficult. In these situations skip scanning reduces
    the impact of makeing the "wrong" decision.
    </li>
</ul>
<h2>Example</h2>
First, create and populate a test table with a concatenated index.<br />
<blockquote>
<pre>CREATE TABLE test_objects AS<br />
SELECT * FROM all_objects;<br />
<br />
CREATE INDEX test_objects_i ON test_objects (owner, object_name, subobject_name);<br />
<br />
EXEC DBMS_STATS.gather_table_stats(USER, 'TEST_OBJECTS', cascade =&gt; TRUE);</pre>
</blockquote>
Next, run a query that hits the leading edge of the index. Notice the range scan on the index.<br />
<blockquote>
<pre>SQL&gt; SET AUTOTRACE ON<br />
SQL&gt; SELECT owner, object_name<br />
2  FROM   test_objects<br />
3  WHERE  owner       = 'SYS'<br />
4  AND    object_name = 'DBMS_OUTPUT';<br />
<br />
OWNER                          OBJECT_NAME<br />
------------------------------ ------------------------------<br />
SYS                            DBMS_OUTPUT<br />
<br />
1 row selected.<br />
<br />
<br />
Execution Plan<br />
----------------------------------------------------------<br />
Plan hash value: 3650344004<br />
<br />
-----------------------------------------------------------------------------------<br />
| Id  | Operation        | Name           | Rows  | Bytes | Cost (%CPU)| Time     |<br />
-----------------------------------------------------------------------------------<br />
|   0 | SELECT STATEMENT |                |     1 |    32 |     2   (0)| 00:00:01 |<br />
|*  1 |  INDEX RANGE SCAN| TEST_OBJECTS_I |     1 |    32 |     2   (0)| 00:00:01 |<br />
-----------------------------------------------------------------------------------</pre>
</blockquote>
Next, run a query that does not hit the leading edge of the index. Notice the index skip scan on the index.<br />
<blockquote>
<pre>SQL&gt; SET AUTOTRACE ON<br />
SQL&gt; SELECT owner, object_name<br />
2  FROM   test_objects<br />
3  WHERE  object_name = 'DBMS_OUTPUT';<br />
<br />
OWNER                          OBJECT_NAME<br />
------------------------------ ------------------------------<br />
PUBLIC                         DBMS_OUTPUT<br />
SYS                            DBMS_OUTPUT<br />
<br />
2 rows selected.<br />
<br />
<br />
Execution Plan<br />
----------------------------------------------------------<br />
Plan hash value: 1293870291<br />
<br />
-----------------------------------------------------------------------------------<br />
| Id  | Operation        | Name           | Rows  | Bytes | Cost (%CPU)| Time     |<br />
-----------------------------------------------------------------------------------<br />
|   0 | SELECT STATEMENT |                |     2 |    64 |    14   (0)| 00:00:01 |<br />
|*  1 |  INDEX SKIP SCAN | TEST_OBJECTS_I |     2 |    64 |    14   (0)| 00:00:01 |<br />
-----------------------------------------------------------------------------------</pre>
</blockquote>
Finally, clean up the test table.<br />
<blockquote>
<pre>DROP TABLE test_objects;</pre>
</blockquote>
For more information see:<br />
<ul>
    <li><a href="http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96533/optimops.htm#51553">Index Skip Scans</a></li>
</ul>
Hope this helps. Regards Tim...<br />
<br />
原文地址： <a href="http://oracle-base.com/articles/9i/IndexSkipScanning.php#HowItWorks">http://oracle-base.com/articles/9i/IndexSkipScanning.php#HowItWorks</a><br />
<img src ="http://www.blogjava.net/zl4393753/aggbug/252219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-01-21 15:22 <a href="http://www.blogjava.net/zl4393753/archive/2009/01/21/252219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle Update Join Syntax</title><link>http://www.blogjava.net/zl4393753/archive/2009/01/20/252061.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Tue, 20 Jan 2009 07:14:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/01/20/252061.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/252061.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/01/20/252061.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/252061.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/252061.html</trackback:ping><description><![CDATA[<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">update</span><span style="color: rgb(0, 0, 0);">&nbsp;<br />
(<br />
</span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);">&nbsp;a.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;da_page&nbsp;a,da_jbxx&nbsp;b,&nbsp;da_pic&nbsp;c&nbsp;<br />
</span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);">&nbsp;a.da_id</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);">b.id&nbsp;<br />
</span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);">&nbsp;a.pic_id</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);">c.id&nbsp;<br />
</span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);">&nbsp;a.ztdm&nbsp;</span><span style="color: rgb(128, 128, 128);">&gt;=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">020</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;<br />
</span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);">&nbsp;a.ztdm&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">060</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;<br />
</span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);">&nbsp;(a.shbz</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">0</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">or</span><span style="color: rgb(0, 0, 0);">&nbsp;a.shbz</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">R</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;<br />
</span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);">&nbsp;a.jsbz</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">N</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;<br />
</span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);">&nbsp;b.swjg_dm&nbsp;</span><span style="color: rgb(128, 128, 128);">like</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">14201%</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
)<br />
</span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);">&nbsp;jsbz</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">Y</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,shr_dm</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">14201000087</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);">&nbsp;rownum&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">10</span><span style="color: rgb(255, 0, 0);">'</span></div>
<img src ="http://www.blogjava.net/zl4393753/aggbug/252061.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-01-20 15:14 <a href="http://www.blogjava.net/zl4393753/archive/2009/01/20/252061.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Cost Control: Inside the Oracle Optimizer</title><link>http://www.blogjava.net/zl4393753/archive/2009/01/19/251923.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Mon, 19 Jan 2009 09:11:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/01/19/251923.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/251923.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/01/19/251923.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/251923.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/251923.html</trackback:ping><description><![CDATA[<p align="left">
<font style="font-size: 12pt;">
In Oracle we now see
<a href="http://www.dba-oracle.com/oracle11g/oracle_11g_extended_optimizer_statistics.htm">11g
extended optimizer statistics</a><span style="color: #000000;">, an
alternative to <em>dynamic_sampling</em> for estimating result set
sizes.</span></font></p>
<p><strong><font size="4">PART 2 - CBO Statistics</font></strong></p>
<p><span><span style="font-size: 12pt;">The
most important key to success with the CBO is to carefully define and
manage your statistics. In order for the CBO to make an intelligent
decision about the best execution plan for your SQL, it must
have&nbsp;information about the table and indexes that participate in the
query. When the CBO knows the size of the tables and the distribution,
cardinality, and selectivity of column values, the CBO can make an
informed decision and almost always generates the best execution plan.</span></span> </p>
<font style="font-size: 12pt;" face="Times New Roman">
<p>
As a review, the CBO gathers information from many sources, and he has
the lofty goal of using DBA-provided metadata to always make the "best"
execution plan decision:</p>
</font>
<font size="3">
<p align="center">
<img src="http://www.dba-oracle.com/images/oracle_cost_based_optimizer.jpg" border="0" width="600" height="444"  alt="" /></p>
</font>
<p><font face="Times New Roman">
<span style="font-style: italic;"><font size="1">Oracle uses data
from many sources to make an execution plan</font></span></font></p>
<p><span><span style="font-size: 12pt;">Let's examine the following areas of CBO
statistics and see how to gather top-quality statistics for the CBO
and how to create an appropriate CBO environment for your database.</span></span>
</p>
<p><span><span style="font-size: 12pt;">Getting top-quality statistics for the
CBO.</span></span><span style="font-size: 12pt;"><span> The choices of executions plans
made by the CBO are only as good as the statistics available to it.
The old-fashioned </span><tt>analyze table</tt><span>
and </span><tt>dbms_utility</tt><span> methods for
generating CBO statistics are obsolete and somewhat dangerous to SQL
performance. As we may know,&nbsp;the CBO uses object statistics to choose
the best execution plan for all SQL statements.</span> </span> </p>
<p><span style="font-size: 12pt;">The  </span>
<span style="font-size: 12pt;"><tt>dbms_stats</tt><span>
utility does a far better job in estimating statistics, especially for
large partitioned tables, and the better statistics result in faster
SQL execution plans. Here is a sample execution of </span><tt>
dbms_stats</tt> with the <tt>OPTIONS</tt><span>
clause:</span> </span> </p>
<pre>exec dbms_stats.gather_schema_stats( - <br />
ownname          =&gt; 'SCOTT', - <br />
options          =&gt; 'GATHER AUTO', - <br />
estimate_percent =&gt; dbms_stats.auto_sample_size, - <br />
method_opt       =&gt; 'for all columns size repeat', - <br />
degree           =&gt; 34 - <br />
)</pre>
<pre><font style="font-size: 12pt;" face="Times New Roman">Here is another dbms_stats example that creates histograms on all indexes columns:</font></pre>
<blockquote>
<pre>BEGIN<br />
dbms_stats.gather_schema_stats(<br />
ownname=&gt;'TPCC',<br />
METHOD_OPT=&gt;'FOR ALL INDEXED COLUMNS SIZE SKEWONLY',<br />
CASCADE=&gt;TRUE,<br />
ESTIMATE_PERCENT=&gt;100);<br />
END;<br />
/<br />
</pre>
</blockquote>
<p><span><span style="font-size: 12pt;">There are several values for the
</span> </span><span style="font-size: 12pt;"><tt>
OPTIONS</tt><span> parameter that we need to know
about:</span> </span> </p>
<ul>
    <li><tt><span style="font-size: 12pt;">GATHER_</span></tt><span style="font-size: 12pt;"><span> reanalyzes the
    whole schema</span> <br />
    &nbsp;</span></li>
    <li><tt><span style="font-size: 12pt;">GATHER EMPTY_</span></tt><span style="font-size: 12pt;"><span> only
    analyzes tables that have no existing statistics</span> <br />
    &nbsp;</span></li>
    <li><tt><span style="font-size: 12pt;">GATHER STALE_</span></tt><span style="font-size: 12pt;"><span> only
    reanalyzes tables with more than 10 percent modifications (inserts,
    updates,&nbsp;&nbsp; deletes)</span> <br />
    &nbsp;</span></li>
    <li><tt><span style="font-size: 12pt;">GATHER AUTO_</span></tt><span style="font-size: 12pt;"><span> will
    reanalyze objects that currently have no statistics and objects with
    stale statistics.&nbsp; Using </span><tt>GATHER AUTO</tt><span>
    is like combining </span><tt>GATHER STALE</tt><span>
    and </span><tt>GATHER EMPTY.</tt> </span> </li>
</ul>
<p><span><span style="font-size: 12pt;">Note that both
</span> </span><span style="font-size: 12pt;"><tt>GATHER STALE</tt><span>
and </span><tt>GATHER AUTO</tt><span> require
monitoring. If you issue the </span><tt>ALTER TABLE XXX MONITORING</tt><span>
command, Oracle tracks changed tables with the </span><tt>
dba_tab_modifications</tt><span> view. Below we see
that the exact number of inserts, updates and deletes are tracked
since the last analysis of statistics:</span> </span> </p>
<pre>SQL&gt; desc dba_tab_modifications;<br />
<br />
Name                Type<br />
--------------------------------<br />
TABLE_OWNER         VARCHAR2(30)<br />
TABLE_NAME          VARCHAR2(30)<br />
PARTITION_NAME      VARCHAR2(30)<br />
SUBPARTITION_NAME   VARCHAR2(30)<br />
INSERTS             NUMBER<br />
UPDATES             NUMBER<br />
DELETES             NUMBER<br />
TIMESTAMP           DATE<br />
TRUNCATED           VARCHAR2(3)<br />
</pre>
<p><span><span style="font-size: 12pt;">The most interesting of these options is the
</span>
</span><span style="font-size: 12pt;"><tt>GATHER STALE</tt><span> option. Because
all statistics will become stale&nbsp;&nbsp; quickly in a robust OLTP database, we
must remember the rule for </span><tt>GATHER STALE</tt><span>
is &gt; 10% row change&nbsp;&nbsp; (based on </span><tt>num_rows</tt><span>
at statistics collection time). Hence, almost every table except
read-only tables will be reanalyzed with the </span><tt>GATHER STALE</tt><span>
option, making the </span><tt>GATHER STALE</tt><span>
option best for systems that are&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; largely read-only. For example, if
only five percent of the database tables get significant updates, then
only&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; five percent of the tables will be reanalyzed with the </span>
<tt>GATHER STALE</tt> option. </span> </p>
<p><span><span style="font-size: 12pt;">Automating sample size with
</span> </span><span style="font-size: 12pt;"><tt>
<strong>dbms_stats.</strong></tt><span>The better the quality
of the statistics, the better the job that the&nbsp;&nbsp;&nbsp; CBO will do when
determining your execution plans. Unfortunately, doing a complete
analysis on a large&nbsp; database could take days, and most shops must
sample your database to get CBO statistics. The goal is to take a
large enough sample of the database to provide top-quality data for
the CBO.</span> </span> </p>
<p><span><span style="font-size: 12pt;">Now that we see how the
</span> </span><span style="font-size: 12pt;"><tt>
dbms_stats</tt><span> option works, let's see how to
specify an adequate sample size for </span><tt>dbms_stats.</tt> </span> </p>
<p><span><span style="font-size: 12pt;">In earlier releases, the DBA had to guess
what percentage of the database provided the best sample size and
sometimes underanalyzed the schema. Starting with Oracle9<em>i</em>
Database, the </span> </span><span style="font-size: 12pt;"><tt>estimate_percent</tt><span>
argument is a great way to allow Oracle's </span><tt>dbms_stats</tt><span>
to automatically estimate the "best" percentage of a segment&nbsp;to sample
when gathering statistics:</span> </span> </p>
<pre>estimate_percent =&gt; dbms_stats.auto_sample_size<br />
</pre>
<p><span><span style="font-size: 12pt;">After collecting automatic sample sizes, you
can verify the accuracy of the automatic statistics sampling by&nbsp;&nbsp;&nbsp; looking at the
</span> </span><span style="font-size: 12pt;"><tt>sample_size</tt><span>
column on any of these data dictionary views:</span> </span> </p>
<ul>
    <li><span style="font-size: 12pt;">DBA_ALL_TABLES</span> </li>
    <li><span style="font-size: 12pt;">DBA_INDEXES</span> </li>
    <li><span style="font-size: 12pt;">DBA_IND_PARTITIONS</span> </li>
    <li><span style="font-size: 12pt;">DBA_IND_SUBPARTITIONS</span> </li>
    <li><span style="font-size: 12pt;">DBA_OBJECT_TABLES</span> </li>
    <li><span style="font-size: 12pt;">DBA_PART_COL_STATISTICS</span> </li>
    <li><span style="font-size: 12pt;">DBA_SUBPART_COL_STATISTICS</span>
    </li>
    <li><span style="font-size: 12pt;">DBA_TABLES</span> </li>
    <li><span style="font-size: 12pt;">DBA_TAB_COLS</span> </li>
    <li><span style="font-size: 12pt;">DBA_TAB_COLUMNS</span> </li>
    <li><span style="font-size: 12pt;">DBA_TAB_COL_STATISTICS</span> </li>
    <li><span style="font-size: 12pt;">DBA_TAB_PARTITIONS</span> </li>
    <li><span style="font-size: 12pt;">DBA_TAB_SUBPARTITIONS</span> </li>
</ul>
<p><span><span style="font-size: 12pt;">Note that Oracle generally chooses a
</span> </span>
<span style="font-size: 12pt;">
<tt>sample_size</tt><span>
from 5 to 20 percent when using automatic sampling, depending on the
size of the tables and the distribution of column values. Remember, the
better the quality of&nbsp; your statistics, the better the decision of the
CBO.</span>
</span> </p>
<hr />
<p>Update:</p>
<p>
<font style="font-size: 12pt;">
In Oracle we now see
<a href="http://www.dba-oracle.com/oracle11g/oracle_11g_extended_optimizer_statistics.htm">11g
extended optimizer statistics</a><span style="color: #000000;">, an
alternative to <em>dynamic_sampling</em> for estimating result set
sizes.</span></font></p>
<hr />
<p><span>Now that we understand the value of CBO
statistics, let's look at ways that the CBO statistics are managed in
a successful Oracle shop.</span> </p>
<hr />
<p align="center">
<img src="http://www.dba-oracle.com/images/wise_rpt_ee_avg_io_files_doy.jpg" border="2" width="500" height="583"  alt="" /></p>
<p align="left"><font>The <a href="http://www.wise-oracle.com/">WISE
Oracle tool</a> is
the easiest way to analyze Oracle performance and WISE
allows you to spot hidden performance trends.</font></p>
<p align="left"><br />
</p>
<p align="left"><font>原文地址： <a href="http://www.dba-oracle.com/art_otn_cbo_p2.htm">http://www.dba-oracle.com/art_otn_cbo_p2.htm</a><br />
</font></p>
<img src ="http://www.blogjava.net/zl4393753/aggbug/251923.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-01-19 17:11 <a href="http://www.blogjava.net/zl4393753/archive/2009/01/19/251923.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Cost Based Optimizer (CBO) and Database Statistics</title><link>http://www.blogjava.net/zl4393753/archive/2009/01/19/251907.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Mon, 19 Jan 2009 08:00:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/01/19/251907.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/251907.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/01/19/251907.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/251907.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/251907.html</trackback:ping><description><![CDATA[Whenever a valid SQL statement is processed Oracle has to decide how to retrieve the necessary data. This decision can be
made using one of two methods:
<ul>
    <li>
    Rule Based Optimizer (RBO) - This method is used if the server has no internal statistics relating to the
    objects referenced by the statement. This method is no longer favoured by Oracle and will be desupported
    in future releases.
    </li>
    <li>
    Cost Based Optimizer (CBO) - This method is used if internal statistics are present. The CBO checks several
    possible execution plans and selects the one with the lowest cost, where cost relates to system resources.
    </li>
</ul>
If new objects are created, or the amount of data in the database changes the statistics will no longer represent the real
state of the database so the CBO decision process may be seriously impaired. The mechanisms and issues relating to maintenance
of internal statistics are explained below:<br />
<ul>
    <li><a href="http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#AnalyzeStatement">Analyze Statement</a></li>
    <li><a href="http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#DBMS_UTILITY">DBMS_UTILITY</a></li>
    <li><a href="http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#DBMS_STATS">DBMS_STATS</a></li>
    <li><a href="http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#SchedulingStats">Scheduling Stats</a></li>
    <li><a href="http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#TransferingStats">Transfering Stats</a></li>
    <li><a href="http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#Issues">Issues</a></li>
</ul>
<h2>Analyze Statement</h2>
The ANALYZE statement can be used to gather statistics for a specific
table, index or cluster. The statistics can be computed exactly, or
estimated
based on a specific number of rows, or a percentage of rows:<br />
<blockquote>
<pre>ANALYZE TABLE employees COMPUTE STATISTICS;<br />
ANALYZE INDEX employees_pk COMPUTE STATISTICS;<br />
<br />
ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 100 ROWS;<br />
ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 15 PERCENT;</pre>
</blockquote>
<h2>DBMS_UTILITY</h2>
The DBMS_UTILITY package can be used to gather statistics for a whole
schema or database. Both methods follow the same format as the analyze
statement:<br />
<blockquote>
<pre>EXEC DBMS_UTILITY.analyze_schema('SCOTT','COMPUTE');<br />
EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_rows =&gt; 100);<br />
EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_percent =&gt; 15);<br />
<br />
EXEC DBMS_UTILITY.analyze_database('COMPUTE');<br />
EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_rows =&gt; 100);<br />
EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_percent =&gt; 15);</pre>
</blockquote>
<h2>DBMS_STATS</h2>
The DBMS_STATS package was introduced in Oracle 8i and is Oracles preferred method of gathering object statistics.
Oracle list a number of benefits to using it including parallel execution, long term storage
of statistics and transfer of statistics between servers. Once again, it follows a similar format to the other methods:<br />
<blockquote>
<pre>EXEC DBMS_STATS.gather_database_stats;<br />
EXEC DBMS_STATS.gather_database_stats(estimate_percent =&gt; 15);<br />
<br />
EXEC DBMS_STATS.gather_schema_stats('SCOTT');<br />
EXEC DBMS_STATS.gather_schema_stats('SCOTT', estimate_percent =&gt; 15);<br />
<br />
EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES');<br />
EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES', estimate_percent =&gt; 15);<br />
<br />
EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK');<br />
EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK', estimate_percent =&gt; 15);</pre>
</blockquote>
This package also gives you the ability to delete statistics:<br />
<blockquote>
<pre>EXEC DBMS_STATS.delete_database_stats;<br />
EXEC DBMS_STATS.delete_schema_stats('SCOTT');<br />
EXEC DBMS_STATS.delete_table_stats('SCOTT', 'EMPLOYEES');<br />
EXEC DBMS_STATS.delete_index_stats('SCOTT', 'EMPLOYEES_PK');</pre>
</blockquote>
<h2>Scheduling Stats</h2>
Scheduling the gathering of statistics using DBMS_Job is the easiest way to make sure they are always up to date:<br />
<blockquote>
<pre>SET SERVEROUTPUT ON<br />
DECLARE<br />
l_job  NUMBER;<br />
BEGIN<br />
<br />
DBMS_JOB.submit(l_job,<br />
'BEGIN DBMS_STATS.gather_schema_stats(''SCOTT''); END;',<br />
SYSDATE,<br />
'SYSDATE + 1');<br />
COMMIT;<br />
DBMS_OUTPUT.put_line('Job: ' || l_job);<br />
END;<br />
/</pre>
</blockquote>
The above code sets up a job to gather statistics for SCOTT for the
current time every day. You can list the current jobs on the server
using the DBS_JOBS and DBA_JOBS_RUNNING views.<br />
<br />
Existing jobs can be removed using:<br />
<blockquote>
<pre>EXEC DBMS_JOB.remove(X);<br />
COMMIT;</pre>
</blockquote>
Where 'X' is the number of the job to be removed.<br />
<h2>Transfering Stats</h2>
It is possible to transfer statistics between servers allowing consistent execution plans between servers with varying
amounts of data. First the statistics must be collected into a statistics table. In the following examples the statistics
for the APPSCHEMA user are collected into a new table, STATS_TABLE, which is owned by DBASCHEMA:<br />
<blockquote>
<pre>  SQL&gt; EXEC DBMS_STATS.create_stat_table('DBASCHEMA','STATS_TABLE');<br />
SQL&gt; EXEC DBMS_STATS.export_schema_stats('APPSCHEMA','STATS_TABLE',NULL,'DBASCHEMA');</pre>
</blockquote>
This table can then be transfered to another server using your preferred method (Export/Import, SQLPlus Copy etc.) and
the stats imported into the data dictionary as follows:<br />
<blockquote>
<pre>  SQL&gt; EXEC DBMS_STATS.import_schema_stats('APPSCHEMA','STATS_TABLE',NULL,'DBASCHEMA');<br />
SQL&gt; EXEC DBMS_STATS.drop_stat_table('DBASCHEMA','STATS_TABLE');</pre>
</blockquote>
<h2>Issues</h2>
<ul>
    <li>Exclude dataload tables from your regular stats gathering,
    unless you know they will be full at the time that stats are gathered.</li>
    <li>I've found gathering stats for the SYS schema can make the system run slower, not faster.</li>
    <li>Gathering statistics can be very resource intensive for the server so avoid peak workload times or gather stale stats only.</li>
    <li>Even if scheduled, it may be necessary to gather fresh statistics after database maintenance or large data loads.</li>
</ul>
For more information see:<br />
<ul>
    <li><a href="http://www.oracle-base.com/articles/8i/RefreshingStaleStatistics8i.php">Refreshing Stale Statistics</a></li>
    <li><a href="http://download-west.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76936/dbms_sta.htm">DBMS_STATS</a></li>
    <li><a href="http://download-west.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76936/dbms_uti.htm">DBMS_UTILITY</a></li>
    <li><a href="http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a85397/statem8a.htm">ANALYZE</a></li>
</ul>
Hope this helps. Regards Tim...<br />
<br />
原文地址： <a href="http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#AnalyzeStatement">http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#AnalyzeStatement</a><br />
<img src ="http://www.blogjava.net/zl4393753/aggbug/251907.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-01-19 16:00 <a href="http://www.blogjava.net/zl4393753/archive/2009/01/19/251907.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE统计信息的导出、导入</title><link>http://www.blogjava.net/zl4393753/archive/2009/01/16/251599.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Fri, 16 Jan 2009 08:46:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/01/16/251599.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/251599.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/01/16/251599.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/251599.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/251599.html</trackback:ping><description><![CDATA[1\ 创建一个专用表保存各表的统计信息：<br />
exec dbms_stats.create_stat_table(''ks38'',''fys'');<br />
<br />
2\ 将各表的统计信息导入到ks38.fys表中；<br />
exec dbms_stats.export_table_stats(''ks38'',''tcl_cust_base_info'',null,''fys'');  <br />
---可以创建不是登陆用户下的表；如用system登陆，可以创建表到&#8216;ks38''用户下<br />
<br />
或将指定schema的统计信息导入到ks38.fys表中<br />
exec dbms_stats.export_schema_stats(''ks38'',''fys'');<br />
<br />
注：<br />
若将整个数据库的统计信息导出到某个表必须按以下方式做：<br />
1）用SYSDBA角色的用户登陆（如system)<br />
2) exec dbms_stat.create_stat_table(''system'',''tbl_name'');  ----记住：此处创建的表必须是登陆用户下的表。 <br />
3) exec dbms_stat.export_database_stats(''tbl_name'')<br />
<br />
****<br />
导出表状态、SCHEMA统计信息，保存导出信息的表的SCHEMA可以和登陆用户名不一致；另外导入统计信息的表和原表尽可能<br />
是同一schema下的<br />
导出整个数据库统计信息，保存导出信息的表的SCHEMA必须和登陆用户名一致，必须是DBA角色。<br />
<br />
3\ 查看统计信息是否导入：<br />
select * from ks38.fys;<br />
<br />
4\ 删除某张表的统计信息：<br />
exec dbms_stats.delete_table_stats(''ks38'',''tcl_cust_base_info'');<br />
<br />
5\ 查看统计信息是否被删除：<br />
select table_name ,to_char(LAST_ANALYZED,''yyyymmdd hh24:mi:ss'') <br />
from ALL_tables where lower(table_name) LIKE ''tcl_cust_%_info%'';<br />
<br />
6\ 导入先前导出的统计信息：<br />
exec dbms_stats.import_table_stats(''ks38'',''tcl_cust_base_info'',''fys'');<br />
注意：tcl_cust_base_info和fys都是在&#8217;ks38''用户下的表。<br />
<br />
原文地址： <a href="http://database.e800.com.cn/articles/2007/819/1187467720638726675_1.html">http://database.e800.com.cn/articles/2007/819/1187467720638726675_1.html</a><br />
 <img src ="http://www.blogjava.net/zl4393753/aggbug/251599.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-01-16 16:46 <a href="http://www.blogjava.net/zl4393753/archive/2009/01/16/251599.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分析用户所有表之后</title><link>http://www.blogjava.net/zl4393753/archive/2009/01/16/251592.html</link><dc:creator>Neil's NoteBook</dc:creator><author>Neil's NoteBook</author><pubDate>Fri, 16 Jan 2009 08:23:00 GMT</pubDate><guid>http://www.blogjava.net/zl4393753/archive/2009/01/16/251592.html</guid><wfw:comment>http://www.blogjava.net/zl4393753/comments/251592.html</wfw:comment><comments>http://www.blogjava.net/zl4393753/archive/2009/01/16/251592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zl4393753/comments/commentRss/251592.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zl4393753/services/trackbacks/251592.html</trackback:ping><description><![CDATA[随着Oracle对CBO的进一步增强和改进, 对表进行分析已经成为一种常用的调优的手段,
当发现某个表的相关SQL语句的执行计划有问题时, 首先会想是不是统计信息过旧的问题, 如果的确是过旧, 则对这个表进行分析,
以让Oracle重新选择准确的最优执行计划, 以达到调优的目标. 用不合适的方式对表进分析, 则会造成十分严重的后果,
如对一个用户下的所有表进行分析, 或一下子分析多个表. 看到网友的<a href="http://www.itpub.net/viewthread.php?tid=925555&amp;extra=&amp;page=1">一篇贴子</a>, 让我想起二年多前帮别人处理过的一个案例, 有位DBA对某用户下的所有表进行了分析.
<p>&nbsp; &nbsp; 基本情况是, IBM P570, 16CPU, 32GB内存, 24GB的SGA,
支持不了一个50G的9i数据库(OLTP类型), 二百个以内的会话. 在分析之前CPU利用率是50-70%左右, 在分析后则一直是100%.
面临这样的情况后, 由于没有做统计信息(Statistics)的备份, 因此无法恢复以前的情况, 首先做的是删除所有非分区表的统计信息,
对分区表做更精确的统计信息分析, 使之运行于RULE方式, 情况稍有好转, 但用户还是不能接受, 相信Oracle的CBO没有那么差,
因此性能问题的关键并不在于统计信息了. 在处理了以下几个问题之后, 成功地降底了CPU的利用率. </p>
<p>&nbsp; &nbsp; 1, 发现繁烦的<strong>并行进程</strong>, 发现一个几有几十MB大小的表, 它的并行度不为1, 因此导致了这个表上的一个执行比较繁烦SQL采用了并行处理, 将并行度改成1后,  CPU利用率降低了20%, 基本上恢复到了分析前的水准. </p>
<p>&nbsp; &nbsp; 2, 发现一个后台发票打印程序的SQL有太多的逻辑读, 对<strong>发票打印模式</strong>进行分析后,
建议将执行繁率从每10秒执行一次降底到1分钟执行一次, 因为从售货台到打印发票的地方取发票需要走1分钟左右. 再检查其SQL,
发现其中的日期条件默认是两年, 也就是要查最近两年的销售记录, 再找出没有打印过的记录进行处理,
通过询问销售人员有没有人会来要求打印两周以前的发票, 当然是很少的了, 后来将这个默认的日期条件改成了最近一个月. 做了这个改动后,
系统的CPU利用率下降到了50%. </p>
<p>&nbsp; &nbsp; 3, 接下来处理了一个库存查询有关的SQL, 对这个SQL本身没有作任何修改,
因为用户可以自定义条件(动态构造WHERE条件)进行查询, 发现很多用户只选了最少的条件进行过滤, 导致了这个SQL运行效率极低,
解决办法就是培训前台用户, 让他们使用这个功能时, 尽可能地提供比较准确的<strong>查询条件</strong>. 这样一来, CPU利用率下降到了35%左右. </p>
<p>&nbsp; &nbsp; 4, 调整了一些SQL后, 新的SQL又出现了, 这一次的问题是, 看这个SQL的执行计划,
居然用了INDEX合并(Combine), 在where条件中用到了两个列, 开发人员在这两个列上分别建了索引, 但从单个列的角度来看,
效率不高, 但一组合效率则很高, 因此用<strong>复合索引</strong>解决此事. CPU利用率再次小降5%. </p>
<p>&nbsp; &nbsp; 5, 后面又调了几个SQL, 这次是<strong>创建了几个新的索引</strong>, CPU的利用率已经下降到了20-25%, 目标完成. </p>
<p>&nbsp; &nbsp; 总地来说, 分析表从来都不是优先考虑的调优手段, 从个人角度来看, 只有发现Oracle在某个表上选择了错误的执行计划后, 才会对单个表进行分析(分析之前先做备份, 除非很确定), 然后观察, 再分析下一个表. <br />
</p>
<p><br />
</p>
原文地址：&nbsp;<a href="http://www.anysql.net/dba/after_analyze_whole_schema.html">http://www.anysql.net/dba/after_analyze_whole_schema.html</a>
<img src ="http://www.blogjava.net/zl4393753/aggbug/251592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zl4393753/" target="_blank">Neil's NoteBook</a> 2009-01-16 16:23 <a href="http://www.blogjava.net/zl4393753/archive/2009/01/16/251592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>