﻿<?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-Calvin's Tech Space-随笔分类-Oracle</title><link>http://www.blogjava.net/lihao336/category/41453.html</link><description>成于坚忍，毁于浮躁</description><language>zh-cn</language><lastBuildDate>Wed, 27 Oct 2010 22:05:16 GMT</lastBuildDate><pubDate>Wed, 27 Oct 2010 22:05:16 GMT</pubDate><ttl>60</ttl><item><title>如何用一条sql语句删除表中所相同的记录</title><link>http://www.blogjava.net/lihao336/archive/2010/03/23/316377.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Tue, 23 Mar 2010 14:47:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2010/03/23/316377.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/316377.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2010/03/23/316377.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/316377.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/316377.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.blogjava.net/lihao336/archive/2010/03/23/316377.html'>阅读全文</a><img src ="http://www.blogjava.net/lihao336/aggbug/316377.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2010-03-23 22:47 <a href="http://www.blogjava.net/lihao336/archive/2010/03/23/316377.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu9.04下安装Oracle11g</title><link>http://www.blogjava.net/lihao336/archive/2010/03/02/314215.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Mon, 01 Mar 2010 16:18:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2010/03/02/314215.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/314215.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2010/03/02/314215.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/314215.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/314215.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.blogjava.net/lihao336/archive/2010/03/02/314215.html'>阅读全文</a><img src ="http://www.blogjava.net/lihao336/aggbug/314215.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2010-03-02 00:18 <a href="http://www.blogjava.net/lihao336/archive/2010/03/02/314215.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle索引——位图索引</title><link>http://www.blogjava.net/lihao336/archive/2009/09/20/295756.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 20 Sep 2009 09:03:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/20/295756.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/295756.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/20/295756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/295756.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/295756.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;Oracle索引——位图索引位图索引（bitmap index）是从Oracle7.3版本开始引入的。目前Oracle企业版和个人版都支持位图索引，但标准版不支持。位图索引是为数据仓库/即席查询环境设计的，在此所有查询要求的数据在系统实现时根本不知道。位图索引特别不适用于OLTP系统，如果系统中的数据会由多个并发会话频繁地更新，这种系统也不适用位图索引。位图索引是这样一...&nbsp;&nbsp;<a href='http://www.blogjava.net/lihao336/archive/2009/09/20/295756.html'>阅读全文</a><img src ="http://www.blogjava.net/lihao336/aggbug/295756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-20 17:03 <a href="http://www.blogjava.net/lihao336/archive/2009/09/20/295756.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle索引——B树索引</title><link>http://www.blogjava.net/lihao336/archive/2009/09/20/295755.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 20 Sep 2009 08:46:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/20/295755.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/295755.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/20/295755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/295755.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/295755.html</trackback:ping><description><![CDATA[<div class="Section0" style="layout-grid:  15.6pt none">
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt">&nbsp;</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">两种使用<font face="Times New Roman">B</font><font face="SimSun">树在列上建立索引的情况：</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 21pt; text-indent: -21pt"><span style="font-size: 10.5pt; font-family: 'Wingdings'; mso-spacerun: 'yes'">l&nbsp;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">索引用于访问表中的行：通过读索引来访问表中的行。此时你希望访问表中很少的一部分行（只占一个很小的百分比）。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 21pt; text-indent: -21pt"><span style="font-size: 10.5pt; font-family: 'Wingdings'; mso-spacerun: 'yes'">l&nbsp;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">索引用于回答一个查询：索引包含了足够的信息来回答整个查询，我根本不用去访问表。在这种情况下，索引则用作一个&#8220;较瘦&#8220;版本的表，即通过查询索引就能找到查询结果，在这种情况下，可以通过处理标准<font face="Times New Roman">100%</font><font face="SimSun">的数据，而不像第一种情况中只能访问少量的数据。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: justify"><br />
<span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: bold; font-size: 14pt; font-family: 'SimSun'; mso-spacerun: 'yes'">为什么在通过索引访问表时如果数据量比较大的话，使用索引反而会降低性能？</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">一般来讲，</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">B*<font face="SimSun">树索引会放在频繁使用查询谓词的列上</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">，而且我们希望从表中只返回少量的数据（只占很小的百分比），或者最终用户请求立即得到反馈。在一个瘦（<font face="Times New Roman">thin</font><font face="SimSun">）表（也就是说，只有很少的几个列，或者列很小）上，这个百分比可能相当小。使用这个索引的查询应该只获取表中</font><font face="Times New Roman">2%</font><font face="SimSun">～</font><font face="Times New Roman">3%</font><font face="SimSun">（或者更少）的行。在一个胖（</font><font face="Times New Roman">fat</font><font face="SimSun">）表中（也就是说，这个表有很多列，或者列很宽），百分比则可能会上升到表的</font><font face="Times New Roman">20%</font><font face="SimSun">～</font><font face="Times New Roman">25%</font><font face="SimSun">。以上建议不一定直接适用于每一个人；这个比例并不直观，但很精确。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">索引按索引键的顺序存储。索引会按键的有序顺序进行访问。索引指向的块则随机地存储在堆中。因此，我们通过索引访问表时，会执行大量分散、随机的<font face="Times New Roman">I/O</font><font face="SimSun">。这里&#8220;分散&#8220;（</font><font face="Times New Roman">scattered</font><font face="SimSun">）是指，索引会告诉我们读取块</font><font face="Times New Roman">1</font><font face="SimSun">，然后是块</font><font face="Times New Roman">1000</font><font face="SimSun">、块</font><font face="Times New Roman">205</font><font face="SimSun">、块</font><font face="Times New Roman">321</font><font face="SimSun">、块</font><font face="Times New Roman">1</font><font face="SimSun">、块</font><font face="Times New Roman">1032</font><font face="SimSun">、块</font><font face="Times New Roman">1</font><font face="SimSun">，等等，它不会要求我们按一种连续的方式读取块</font><font face="Times New Roman">1</font><font face="SimSun">、然后是块</font><font face="Times New Roman">2</font><font face="SimSun">，接着是块</font><font face="Times New Roman">3</font><font face="SimSun">（原因在与表中的每一行并没有按照索引键的顺序存储在堆中，否则不会出现这种情况）。我们将以一种非常随意的方式读取和重新读取块。这种块</font><font face="Times New Roman">I/O</font><font face="SimSun">可能非常慢。</font></span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">下面来看这样一个简化的例子，假设我们通过索引读取一个瘦表，而且要读取表中<font face="Times New Roman">20%</font><font face="SimSun">的行。若这个表中有</font><font face="Times New Roman">100,000</font><font face="SimSun">行，其中的</font><font face="Times New Roman">20%</font><font face="SimSun">就是</font><font face="Times New Roman">2,0000</font><font face="SimSun">行。如果行大小约为</font><font face="Times New Roman">80</font><font face="SimSun">字节，在一个块大小为</font><font face="Times New Roman">8KB</font><font face="SimSun">的数据库中，每个块上则有大约</font><font face="Times New Roman">100</font><font face="SimSun">行。这说明，这个表有大约</font><font face="Times New Roman">1000</font><font face="SimSun">个块。了解了这些情况，计算起来就非常容易了。我们要通过索引读取</font><font face="Times New Roman">20,000</font><font face="SimSun">行；这说明，大约是</font><font face="Times New Roman">20,000</font><font face="SimSun">个</font><font face="Times New Roman">TABLE&nbsp;&nbsp;ACCESS&nbsp;&nbsp;BY&nbsp;&nbsp;ROWID</font><font face="SimSun">操作。为此要处理</font><font face="Times New Roman">20,000</font><font face="SimSun">个表块来执行这个查询。不过，整个表才有大约</font><font face="Times New Roman">1000</font><font face="SimSun">个块！</font></span><span style="font-size: 10.5pt; background: rgb(255,255,0); font-family: 'SimSun'; mso-spacerun: 'yes'">因而最后会平均把表中的每一个块读取和处理<font face="Times New Roman">20</font><font face="SimSun">次</font></span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">（效果就是缓存的命中率很低，缓存的相邻块的数据没有用到）</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">。&nbsp;即使把行的大小提高一个数量级，达到每行<font face="Times New Roman">800</font><font face="SimSun">字节，这样每块有</font><font face="Times New Roman">11.</font><font face="SimSun">行，现在表中就有</font><font face="Times New Roman">11.,000</font><font face="SimSun">个块。要通过索引访问</font><font face="Times New Roman">20,000</font><font face="SimSun">行，仍要求我们把每一个块平均读取</font><font face="Times New Roman">2</font><font face="SimSun">次。</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">在这种情况下，全表扫描就比使用索引高效得多，因为每个块只会命中一次。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">如果查询使用这个索引来访问数据，效率都不会高，除非对于<font face="Times New Roman">800</font><font face="SimSun">字节的行，平均只访问表中不到</font><font face="Times New Roman">5%</font><font face="SimSun">的数据，因为这样一来，就只会访问大约</font><font face="Times New Roman">5,000</font><font face="SimSun">个块，如果是</font><font face="Times New Roman">80</font><font face="SimSun">字节的行，则访问的数据应当只占更小的百分比，大约</font><font face="Times New Roman">0.5%</font><font face="SimSun">或更少（这就是为什么在一次查询中一个&#8220;胖表&#8221;的数据获取百分比比一个&#8220;瘦表&#8221;相对高的原因）。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">因此，根本原因是因为缓存命中率降低，出现了大量随机分散的<font face="Times New Roman">I/O</font><font face="SimSun">操作。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<br />
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">物理组织对索引效率的影响</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">此外，数据在磁盘上如何物理组织，对上述过程也会有显著影响。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">表会很自然地按主键顺序聚簇（因为数据或多或少就是已这种属性增加的）。当然，它不一定严格按照键聚簇（要想做到这一点，必须使用一个<font face="Times New Roman">IOT</font><font face="SimSun">），但是，一般来讲，主键值彼此接近的行的物理位置也会&#8220;靠&#8220;在一起。如果发出以下查询：</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">select&nbsp;*&nbsp;from&nbsp;T&nbsp;where&nbsp;primary_key&nbsp;between&nbsp;:x&nbsp;and&nbsp;:y<font face="SimSun">；</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">你想要的行通常就位于同样的块上。在这种情况下，即使要访问大量的行（占很大的百分比），索引区间扫描可能也很有用。原因在于：</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">我们需要读取和重新读取的数据库块很可能会被缓存，因为数据共同放置在同一个位置（<font face="Times New Roman">co-located</font><font face="SimSun">）</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">。另一方面，如果行并非共同存储在一个位置上，使用这个索引对性能来讲可能就是灾难性的。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<br />
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">聚簇因子</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">接下来，我们来看<font face="Times New Roman">Oracle</font><font face="SimSun">所用的一些信息。我们要特别查看</font><font face="Times New Roman">USER_INDEXES</font><font face="SimSun">视图中的</font><font face="Times New Roman">CLUSTERING_FACTOR</font><font face="SimSun">列。</font><font face="Times New Roman">Oracle&nbsp;reference</font><font face="SimSun">手册指出了这个列有以下含义：</font></span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">根据索引的值指示表中行的有序程度：</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">如果这个值与块数接近，则说明表相当有序，得到了很好的组织，在这种情况下，同一个叶子块中的索引条目可能指向同一个数据块上的行。</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;<font face="SimSun">如果这个值与行数接近，表的次序可能就是非常随机的。在这种情况下，同一个叶子块上的索引条目不太可能指向同一个数据块上的行。</font></span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">可以把聚簇因子（<font face="Times New Roman">clusteringfactor</font><font face="SimSun">）看作是通过索引读取整个表时对表执行的逻辑</font><font face="Times New Roman">I/O</font><font face="SimSun">次数。也就是说，</font><font face="Times New Roman">CLUSTERING_FACTOR</font><font face="SimSun">指示了表相对于索引本身的有序程度，查看这些索引时，会看到以下结果：</font></span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">ops$tkyte@ORA10G&gt;&nbsp;select&nbsp;a.index_name,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">2&nbsp;b.num_rows,</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">3&nbsp;b.blocks,</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">4&nbsp;a.clustering_factor</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">5&nbsp;from&nbsp;user_indexes&nbsp;a,&nbsp;user_tables&nbsp;b</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">6&nbsp;where&nbsp;&nbsp;index_name&nbsp;in&nbsp;('COLOCATED_PK',&nbsp;'DISORGANIZED_PK'&nbsp;)</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">7&nbsp;and&nbsp;a.table_name&nbsp;=&nbsp;b.table_name</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">8&nbsp;/</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">INDEX_NAME&nbsp;&nbsp;NUM_ROWS&nbsp;&nbsp;BLOCKS&nbsp;&nbsp;CLUSTERING_FACTOR</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">---------------&nbsp;&nbsp; ----------&nbsp; ---------- -----------------</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">COLOCATED_PK&nbsp; 100000&nbsp; 1252 1190</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">DISORGANIZED_PK&nbsp; 100000&nbsp; 1219 99932</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">所以数据库说：&#8220;如果通过索引<font face="Times New Roman">COLOCATED_PK</font><font face="SimSun">从头到尾地读取</font><font face="Times New Roman">COLOCATED</font><font face="SimSun">表中的每一行，就要执行</font><font face="Times New Roman">1190</font><font face="SimSun">次</font><font face="Times New Roman">I/O</font><font face="SimSun">。不过，如果我们对</font><font face="Times New Roman">DISORGANIZED</font><font face="SimSun">表做同样的事情，则会对这个表执行</font><font face="Times New Roman">99,932</font><font face="SimSun">次</font><font face="Times New Roman">I/O</font><font face="SimSun">&#8220;。之所以存在这么大的区别，原因在于，</font></span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">当<font face="Times New Roman">Oracle</font><font face="SimSun">对索引结构执行区间扫描时，如果它发现索引中的下一行几乎总与前一行在同一个数据库块上，就不会再执行另一个</font><font face="Times New Roman">I/O</font><font face="SimSun">从缓冲区缓存中获得表块。它已经有表块的一个句柄，只需直接使用就可以了。不过，如果下一行不在同一个块上，就会释放当前的这个块，而执行另一个</font><font face="Times New Roman">I/O</font><font face="SimSun">从缓冲区缓存获取要处理的下一个块</font></span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">。因此，在我们对索引执行区间扫描时，<font face="Times New Roman">COLOCATED_PK</font><font face="SimSun">索引会发现下一行几乎总于前一行在同一个块上。</font><font face="Times New Roman">DISORGANIZED_PK</font><font face="SimSun">索引发现的情况则恰好相反。</font></span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">以上讨论的关键点是，索引并不一定总是合适的访问方法。优化器也许选择不使用索引，而且如前面的例子所示，这种选择可能很正确。影响优化器是否使用索引的因素有很多，包括物理数据布局。因此，你可能会矫枉过正，力图重建所有的表来使所有索引有一个好的聚簇因子，但是在大多数情况下这可能只会浪费时间。只有当你在对表中的大量数据（所占百分比很大）执行索引区间扫描时，这才会产生影响。另外必须记住，对于一个表来说，一般只有一个索引能有合适的聚簇因子！表中的行可能只以一种方式排序。在前面所示的例子中，如果<font face="Times New Roman">Y</font><font face="SimSun">列上还有一个索引，这个索引在</font><font face="Times New Roman">COLOCATED</font><font face="SimSun">表中可能就不能很好地聚簇，而在</font><font face="Times New Roman">DISORGANIZED</font><font face="SimSun">表中则恰好相反。如果你认为数据物理聚簇很重要，可以考虑使用一个</font><font face="Times New Roman">IOT</font><font face="SimSun">、</font><font face="Times New Roman">B*</font><font face="SimSun">树聚簇，或者在连续地重建表时考虑散列聚簇。</font></span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<br />
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: bold; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">B*<font face="SimSun">树索引小结</font></span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">什么时候建立索引，在哪些列上建立索引，你的设计中必须注意这些问题。索引并不一定就意味着更快的访问；实际上你会发现，在许多情况下，如果<font face="Times New Roman">Oracle</font><font face="SimSun">使用索引，反而会使性能下降。</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">这实际上两个因素的一个函数，其中一个因素是通过索引需要访问表中多少数据（占多大的百分比），另一个因素是数据如何布局。</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">如果能完全使用索引&#8220;回答问题&#8220;（而不用表），那么访问大量的行（占很大的百分比）就是有意义的，因为这样可以避免读表所带来的额外的分散<font face="Times New Roman">I/O</font><font face="SimSun">。如果使用索引来访问表，可能就要确保只处理整个表中的很少一部分（只占很小的百分比）。</font></span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">应该在应用的设计期间考虑索引的设计和实现，而不要事后才想起来（我就经常见到这种情况）。如果对如何访问数据做了精心的计划和考虑，大多数情况下就能清楚地知道需要什么索引。</span><span style="font-weight: normal; font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
</div>
<!--endfragment-->
<img src ="http://www.blogjava.net/lihao336/aggbug/295755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-20 16:46 <a href="http://www.blogjava.net/lihao336/archive/2009/09/20/295755.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle索引——索引类型</title><link>http://www.blogjava.net/lihao336/archive/2009/09/20/295750.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 20 Sep 2009 07:06:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/20/295750.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/295750.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/20/295750.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/295750.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/295750.html</trackback:ping><description><![CDATA[<div class="Section0" style="layout-grid:  15.6pt none">
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><br />
&nbsp;&nbsp;&nbsp;&nbsp;Oracle&nbsp;<font face="SimSun">提供了多种不同类型的索引以供使用。简单地说，&nbsp;</font><font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">中包括如下索引：</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 14pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;B*&nbsp;<font face="SimSun">树索引</font></span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">这些是我所说的&nbsp;<font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">传统&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">索引。到目前为止，这是&nbsp;</font><font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">和大多数其他数据库中最常用的索引。&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树的构造类似于二叉树，能根据键提供一行或一个行集的快速访问，通常只需很少的读操作就能找到正确的行。不过，需要注意重要的一点，&nbsp;</font><font face="Times New Roman">&#8221;&nbsp;B*&nbsp;</font><font face="SimSun">树&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">中的&nbsp;</font><font face="Times New Roman">&#8221;&nbsp;B&nbsp;&#8220;&nbsp;</font><font face="SimSun">不代表二叉（&nbsp;</font><font face="Times New Roman">binary&nbsp;</font><font face="SimSun">），而代表平衡（&nbsp;</font><font face="Times New Roman">b&nbsp;alanced&nbsp;</font><font face="SimSun">）。</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树索引并不是一颗二叉树，这一点在介绍如何在磁盘上物理地存储&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树时就会了解到。&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树索引有以下子类型：</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">索引组织表（&nbsp;<font face="Times New Roman">index&nbsp;organized&nbsp;table&nbsp;</font><font face="SimSun">）：索引组织表以&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树结构存储。</font></span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Times New Roman'; mso-spacerun: 'yes'">堆表的数据行是以一种无组织的方式存储的（只要有可用的空间，就可以放数据），而&nbsp;<font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">与之不同，&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">中的数据要按主键的顺序存储和排序</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">。对应用来说，&nbsp;<font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">表现得与&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">常规&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">表并无二致；需要使用&nbsp;</font><font face="Times New Roman">SQL&nbsp;</font><font face="SimSun">来正确地访问&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">。&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">对信息获取、空间系统和&nbsp;</font><font face="Times New Roman">OLAP&nbsp;</font><font face="SimSun">应用最为有用。&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">在上一章已经详细地讨论过。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">B*<font face="SimSun">树聚簇索引（&nbsp;</font><font face="Times New Roman">B*tree&nbsp;cluster&nbsp;index&nbsp;</font><font face="SimSun">）这些是传统&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树索引的一个变体（只是稍有变化）。&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树聚簇索引用于对聚簇键建立索引（见第&nbsp;</font><font face="Times New Roman">11.&nbsp;</font><font face="SimSun">章中&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">索引聚簇表&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">一节），所以这一章不再讨论。在传统&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树中&nbsp;，键都指向一行；而&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树聚簇不同，</font></span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Times New Roman'; mso-spacerun: 'yes'">一个聚簇键会指向一个块，其中包含与这个聚簇键相关的多行</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">。</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">降序索引（&nbsp;<font face="Times New Roman">descending&nbsp;index&nbsp;</font><font face="SimSun">）：降序索引允许数据在索引结构中按&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">从大到小&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">的顺序（降序）排序，而不是按&nbsp;</font><font face="Times New Roman">&#8221;&nbsp;</font><font face="SimSun">从小到大&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">的顺序（升序）排序。我们会解释为什么降序索引很重要，并说明降序索引如何工作。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">反向键索引（&nbsp;<font face="Times New Roman">reverse&nbsp;key&nbsp;index&nbsp;</font><font face="SimSun">）：这也是&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树索引，只不过键中的字节会&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">反转&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">。利用反向键索引，如果索引中填充的是递增的值，索引条目在索引中可以得到更均匀的分布。例如，如果使用一个序列来生成主键，这个序列将生成诸如&nbsp;</font><font face="Times New Roman">987500&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">987501&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">987502&nbsp;</font><font face="SimSun">等值。这些值是顺序的，所以倘若使用一&nbsp;个传统的&nbsp;</font><font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树索引，这些值就可能放在同一个右侧块上，这就加剧了对这一块的竞争。利用反向键，&nbsp;</font><font face="Times New Roman">Oracl&nbsp;e</font><font face="SimSun">则会逻辑地对&nbsp;</font><font face="Times New Roman">205789&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">105789&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">005789&nbsp;</font><font face="SimSun">等建立索引。&nbsp;</font><font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">将数据放在索引中之前，将先&nbsp;把所存储数据的字节反转，这样原来可能在索引中相邻放置的值在字节反转之后就会相距很远。通过反转字节，对索引的插入就会分布到多个块上。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 14pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;位图索引（&nbsp;<font face="Times New Roman">bitmap&nbsp;index&nbsp;</font><font face="SimSun">）</font></span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">在一颗&nbsp;<font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树中，通常索引条目和行之间存在一种一对一的关系：一个&nbsp;索引条目就指向一行。</font></span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Times New Roman'; mso-spacerun: 'yes'">而对于位图索引，一个索引条目则使用一个位图同时指向多行。位图索引适用于高度重复而且通常只读的数据（高度重复是指相对于表中的总行数，数据只有很少的几个不同值）</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">。考虑在一&nbsp;个有&nbsp;<font face="Times New Roman">100&nbsp;</font><font face="SimSun">万行的表中，每个列只有&nbsp;</font><font face="Times New Roman">3&nbsp;</font><font face="SimSun">个可取值：&nbsp;</font><font face="Times New Roman">Y&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">N&nbsp;</font><font face="SimSun">和&nbsp;</font><font face="Times New Roman">NULL&nbsp;</font><font face="SimSun">。举例来说，如果你需要频繁地统计多少行有值</font><font face="Times New Roman">Y&nbsp;</font><font face="SimSun">，这就很适合建立位图索引。不过并不是说如果这个表中某一列有&nbsp;</font><font face="Times New Roman">11.000&nbsp;</font><font face="SimSun">个不同的值就不能建立位图索引，这一列当然也可以建立&nbsp;位图索引。在一个&nbsp;</font><font face="Times New Roman">OLTP&nbsp;</font><font face="SimSun">数据库中，由于存在</font></span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Times New Roman'; mso-spacerun: 'yes'">并发性</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">相关的问题，所以不能考虑使用位图索引（后面我们就会讨论这一点）。注意，位图索引要求使用&nbsp;<font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">企业版或个人版。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">位图联结索引（&nbsp;<font face="Times New Roman">bitmap&nbsp;join&nbsp;index&nbsp;</font><font face="SimSun">）：这为索引结构（而不是表）中的数据提供了一种逆规范化的&nbsp;方法。例如，请考虑简单的&nbsp;</font><font face="Times New Roman">EMP&nbsp;</font><font face="SimSun">和&nbsp;</font><font face="Times New Roman">DEPT&nbsp;</font><font face="SimSun">表。有人可能会问这样一个问题：&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">多少人在位于波士顿的部门工作&nbsp;？</font><font face="Times New Roman">&#8220;&nbsp;EMP&nbsp;</font><font face="SimSun">有一个指向&nbsp;</font><font face="Times New Roman">DEPT&nbsp;</font><font face="SimSun">的外键，要想统计&nbsp;</font><font face="Times New Roman">LOC&nbsp;</font><font face="SimSun">值为&nbsp;</font><font face="Times New Roman">Boston&nbsp;</font><font face="SimSun">的部门中的员工人数，通常必须完成表联结，将&nbsp;</font><font face="Times New Roman">LOC&nbsp;</font><font face="SimSun">列联结至&nbsp;</font><font face="Times New Roman">EMP&nbsp;</font><font face="SimSun">记录来回答这个问题。通过使用位图联结索引，则可以在&nbsp;</font><font face="Times New Roman">EMP&nbsp;</font><font face="SimSun">表上对&nbsp;</font><font face="Times New Roman">LOC&nbsp;</font><font face="SimSun">列建立索引&nbsp;。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-weight: bold; font-size: 14pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">基于函数的索引（&nbsp;<font face="Times New Roman">function-based&nbsp;index&nbsp;</font><font face="SimSun">）</font></span><span style="font-weight: bold; font-size: 14pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">这些就是&nbsp;<font face="Times New Roman">B*&nbsp;</font><font face="SimSun">树索引或位图索引，它将一个函数计算得到的结果存储在行的列中，而不是存储列数据本身。可以把基于函数的索引看作一个虚拟列（或派生列）上的索引，换句话说，这个列并不物理存储在表中。基于函数的索引可以用于加快形如&nbsp;</font><font face="Times New Roman">SELECT&nbsp;*&nbsp;FROM&nbsp;T&nbsp;W&nbsp;HERE</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">FUNCTION(DATABASE_COLUMN)&nbsp;=&nbsp;SAME_VALUE&nbsp;<font face="SimSun">这样的查询，因为值&nbsp;</font><font face="Times New Roman">FUNCTION(DATABASE_COLUMN)&nbsp;</font><font face="SimSun">已经提前计算并存储在索引中。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-weight: bold; font-size: 14pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">应用域索引（&nbsp;<font face="Times New Roman">application&nbsp;domain&nbsp;index&nbsp;</font><font face="SimSun">）</font></span><span style="font-weight: bold; font-size: 14pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">应用域索引是你自己构建和存储的索引，可能存储在<font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">中，也可能在&nbsp;</font><font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">之外。你要告诉优化器索引的选择性如何，以及执行的开销有多大，优化器则会根据你提供的信息来决定是否使用你的索引。&nbsp;</font><font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">文本索引就是应用域索引的一个例子；你也可&nbsp;以使用构建&nbsp;</font><font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">文本索引所用的工具来建立自己的索引。需要指出，这里创建的&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">索引&nbsp;</font><font face="Times New Roman">&#8220;&nbsp;</font><font face="SimSun">不需要使用传统的索引结构。例如，&nbsp;</font><font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">文本索引就使用了一组表来实现其索引概念。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
</div>
<!--endfragment-->
  <img src ="http://www.blogjava.net/lihao336/aggbug/295750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-20 15:06 <a href="http://www.blogjava.net/lihao336/archive/2009/09/20/295750.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用临时表删除Oracle重复数据</title><link>http://www.blogjava.net/lihao336/archive/2009/09/16/295285.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Wed, 16 Sep 2009 04:48:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/16/295285.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/295285.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/16/295285.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/295285.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/295285.html</trackback:ping><description><![CDATA[<div class="Section0" style="layout-grid:  15.6pt none">
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">在对数据库进行操作过程中我们可能会遇到这种情况，表中的数据可能重复出现，使我们对数据库的操作过程中带来很多的不便，那么怎么删除这些重复没有用的数据呢<font face="Times New Roman">?</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　重复数据删除技术可以提供更大的备份容量，实现更长时间的数据保留，还能实现备份数据的持续验证，提高数据恢复服务水平，方便实现数据容灾等。&nbsp;重复的数据可能有这样两种情况，第一种时表中只有某些字段一样，第二种是两行记录完全一样。<font face="Times New Roman">Oracle</font><font face="SimSun">数据库重复数据删除技术有如下优势：更大的备份容量、数据能得到持续验证、有更高的数据恢复服务水平、方便实现备份数据的容灾。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　一、删除部分字段重复数据</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　先来谈谈如何查询重复的数据吧。</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　下面语句可以查询出那些数据是重复的：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　</span><span style="font-size: 10.5pt; color: rgb(0,0,255); font-family: 'Times New Roman'; mso-spacerun: 'yes'">select&nbsp;<font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2,count(*)&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">group&nbsp;by&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;having&nbsp;count(*)&nbsp;&gt;&nbsp;1</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　将上面的<font face="Times New Roman">&gt;</font><font face="SimSun">号改为</font><font face="Times New Roman">=</font><font face="SimSun">号就可以查询出没有重复的数据了。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　想要删除这些重复的数据，可以使用下面语句进行删除</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">delete&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">a&nbsp;where&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;in</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">(select&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2,count(*)&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">group&nbsp;by&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;having&nbsp;count(*)&nbsp;&gt;&nbsp;1)</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　上面的语句非常简单，就是将查询到的数据删除掉。不过这种删除执行的效率非常低，对于大数据量来说，可能会将数据库吊死。所以我建议</span><span style="font-size: 10.5pt; color: rgb(0,0,255); font-family: 'Times New Roman'; mso-spacerun: 'yes'">先将查询到的重复的数据插入到一个临时表中，然后对进行删除，这样，执行删除的时候就不用再进行一次查询了</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">。如下：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">CREATE&nbsp;TABLE&nbsp;</font><font face="SimSun">临时表&nbsp;</font><font face="Times New Roman">AS</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">(select&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2,count(*)&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">group&nbsp;by&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;having&nbsp;count(*)&nbsp;&gt;&nbsp;1)</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　上面这句话就是建立了临时表，并将查询到的数据插入其中。</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　下面就可以进行这样的删除操作了：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">delete&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">a&nbsp;where&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1,</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;in&nbsp;(select&nbsp;</font><font face="SimSun">字段</font><font face="Times New Roman">1</font><font face="SimSun">，字段</font><font face="Times New Roman">2&nbsp;from&nbsp;</font><font face="SimSun">临时表</font><font face="Times New Roman">);</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　这种先建临时表再进行删除的操作要比直接用一条语句进行删除要高效得多。</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　这个时候，大家可能会跳出来说，什么<font face="Times New Roman">?</font><font face="SimSun">你叫我们执行这种语句，那不是把所有重复的全都删除吗</font><font face="Times New Roman">?</font><font face="SimSun">而我们想保留重复数据中最新的一条记录啊</font><font face="Times New Roman">!</font><font face="SimSun">大家不要急，下面我就讲一下如何进行这种操作。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　在<font face="Times New Roman">oracle</font><font face="SimSun">中，有个隐藏了自动</font><font face="Times New Roman">rowid</font><font face="SimSun">，里面给每条记录一个唯一的</font><font face="Times New Roman">rowid</font><font face="SimSun">，我们如果想保留最新的一条记录，</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　我们就可以利用这个字段，保留重复数据中<font face="Times New Roman">rowid</font><font face="SimSun">最大的一条记录就可以了。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　下面是查询重复数据的一个例子：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">select&nbsp;a.rowid,a.*&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">a&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">where&nbsp;a.rowid&nbsp;!=&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">(&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">select&nbsp;max(b.rowid)&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">b&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">where&nbsp;a.</font><font face="SimSun">字段</font><font face="Times New Roman">1&nbsp;=&nbsp;b.</font><font face="SimSun">字段</font><font face="Times New Roman">1&nbsp;and&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">a.</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;=&nbsp;b.</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">)</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　下面我就来讲解一下，上面括号中的语句是查询出重复数据中<font face="Times New Roman">rowid</font><font face="SimSun">最大的一条记录。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　而外面就是查询出除了<font face="Times New Roman">rowid</font><font face="SimSun">最大之外的其他重复的数据了。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　由此，我们要删除重复数据，只保留最新的一条数据，就可以这样写了：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">delete&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">a&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">where&nbsp;a.rowid&nbsp;!=&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">(&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">select&nbsp;max(b.rowid)&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">b&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">where&nbsp;a.</font><font face="SimSun">字段</font><font face="Times New Roman">1&nbsp;=&nbsp;b.</font><font face="SimSun">字段</font><font face="Times New Roman">1&nbsp;and&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">a.</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;=&nbsp;b.</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">)</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　随便说一下，上面语句的执行效率是很低的，可以考虑建立临时表，讲需要判断重复的字段、<font face="Times New Roman">rowid</font><font face="SimSun">插入临时表中，然后删除的时候在进行比较。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">create&nbsp;table&nbsp;</font><font face="SimSun">临时表&nbsp;</font><font face="Times New Roman">as&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">select&nbsp;a.</font><font face="SimSun">字段</font><font face="Times New Roman">1,a.</font><font face="SimSun">字段</font><font face="Times New Roman">2,MAX(a.ROWID)&nbsp;dataid&nbsp;from&nbsp;</font><font face="SimSun">正式表&nbsp;</font><font face="Times New Roman">a&nbsp;GROUP&nbsp;BY&nbsp;a.</font><font face="SimSun">字段</font><font face="Times New Roman">1,a.</font><font face="SimSun">字段</font><font face="Times New Roman">2;&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">delete&nbsp;from&nbsp;</font><font face="SimSun">表名&nbsp;</font><font face="Times New Roman">a&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">where&nbsp;a.rowid&nbsp;!=&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">(&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">select&nbsp;b.dataid&nbsp;from&nbsp;</font><font face="SimSun">临时表&nbsp;</font><font face="Times New Roman">b&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">where&nbsp;a.</font><font face="SimSun">字段</font><font face="Times New Roman">1&nbsp;=&nbsp;b.</font><font face="SimSun">字段</font><font face="Times New Roman">1&nbsp;and&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">a.</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;=&nbsp;b.</font><font face="SimSun">字段</font><font face="Times New Roman">2&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">);&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">commit;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　二、完全删除重复记录</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　对于表中两行记录完全一样的情况，可以用下面语句获取到去掉重复数据后的记录：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">select&nbsp;distinct&nbsp;*&nbsp;from&nbsp;</font><font face="SimSun">表名</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　可以将查询的记录放到临时表中，然后再将原来的表记录删除，最后将临时表的数据导回原来的表中。如下：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">CREATE&nbsp;TABLE&nbsp;</font><font face="SimSun">临时表&nbsp;</font><font face="Times New Roman">AS&nbsp;(select&nbsp;distinct&nbsp;*&nbsp;from&nbsp;</font><font face="SimSun">表名</font><font face="Times New Roman">);</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">truncate&nbsp;table&nbsp;</font><font face="SimSun">正式表</font><font face="Times New Roman">;&nbsp;--</font><font face="SimSun">注：原先由于笔误写成了</font><font face="Times New Roman">drop&nbsp;table&nbsp;</font><font face="SimSun">正式表</font><font face="Times New Roman">;</font><font face="SimSun">，现在已经改正过来</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">insert&nbsp;into&nbsp;</font><font face="SimSun">正式表&nbsp;</font><font face="Times New Roman">(select&nbsp;*&nbsp;from&nbsp;</font><font face="SimSun">临时表</font><font face="Times New Roman">);</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">drop&nbsp;table&nbsp;</font><font face="SimSun">临时表</font><font face="Times New Roman">;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　</span><span style="font-size: 10.5pt; color: rgb(0,0,255); font-family: 'Times New Roman'; mso-spacerun: 'yes'">如果想删除一个表的重复数据，可以先建一个临时表，将去掉重复数据后的数据导入到临时表，然后在从临时表将数据导入正式表中</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">，如下：</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">INSERT&nbsp;INTO&nbsp;t_table_bak&nbsp;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　<font face="Times New Roman">select&nbsp;distinct&nbsp;*&nbsp;from&nbsp;t_table;</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　三、怎样快速删除<font face="Times New Roman">oracle</font><font face="SimSun">数据库</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　最快的方法就进入注册表&nbsp;在运行<font face="Times New Roman">..</font><font face="SimSun">里输入</font><font face="Times New Roman">regedit.</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　依次展开<font face="Times New Roman">HKEY_LOCAL_MACHINE&nbsp;SOFTWARE</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　找到<font face="Times New Roman">ORACLE</font><font face="SimSun">节点。删除。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　然后删除<font face="Times New Roman">ORACLE</font><font face="SimSun">数据文件，安装的时候选的路径。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">　　最后删除<font face="Times New Roman">oracle</font><font face="SimSun">引导文件，在系统盘符的</font><font face="Times New Roman">Program&nbsp;Files&nbsp;</font><font face="SimSun">里面删除</font><font face="Times New Roman">oracle</font><font face="SimSun">文件夹。</font></span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<br />
（转自http://www.searchdatabase.com.cn/showcontent_23769.htm）</div>
<!--endfragment-->
<img src ="http://www.blogjava.net/lihao336/aggbug/295285.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-16 12:48 <a href="http://www.blogjava.net/lihao336/archive/2009/09/16/295285.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle查看DDL详细选项</title><link>http://www.blogjava.net/lihao336/archive/2009/09/12/294832.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sat, 12 Sep 2009 05:41:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/12/294832.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/294832.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/12/294832.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/294832.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/294832.html</trackback:ping><description><![CDATA[<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">例如，</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;&nbsp;create&nbsp;table&nbsp;t1</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">2&nbsp;(&nbsp;x&nbsp;int&nbsp;primary&nbsp;key,</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">3&nbsp;y&nbsp;varchar2(25),</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">4&nbsp;z&nbsp;date</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">5&nbsp;)</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">6&nbsp;organization&nbsp;index;</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">Table&nbsp;created.</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">使用一下方法查看详细定义语句：</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Courier New'; mso-spacerun: 'yes'">&nbsp;select&nbsp;dbms_metadata.get_ddl(&nbsp;'TABLE',&nbsp;'T1'&nbsp;)&nbsp;from&nbsp;dual;</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">S_METADATA.GET_DDL('TABLE','T1')</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">-----------------------------------------------------------------------------</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">CREATE&nbsp;TABLE&nbsp;"OPS$TKYTE"."T1"</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">(<br />
"X"&nbsp;NUMBER(*,0),</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">"Y"&nbsp;VARCHAR2(25),</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">"Z"&nbsp;DATE,</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">PRIMARY&nbsp;KEY&nbsp;("X")&nbsp;ENABLE</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><br />
)<br />
ORGANIZATION&nbsp;INDEX</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">NOCOMPRESS</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">PCTFREE&nbsp;10&nbsp;INITRANS&nbsp;2&nbsp;MAXTRANS&nbsp;255&nbsp;LOGGING</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">STORAGE(INITIAL&nbsp;65536&nbsp;NEXT&nbsp;1048576&nbsp;MINEXTENTS&nbsp;1&nbsp;MAXEXTENTS&nbsp;2147483645</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;PCTINCREASE&nbsp;0&nbsp;FREELISTS&nbsp;1&nbsp;FREELIST&nbsp;GROUPS&nbsp;1&nbsp;BUFFER_POOL&nbsp;DEFAULT)</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">TABLESPACE&nbsp;"USERS"</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">PCTTHRESHOLD&nbsp;50</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">在此基础上可以进行修改。</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">注意：<font face="Courier New">select&nbsp;dbms_metadata.get_ddl(&nbsp;'TABLE',&nbsp;'T1'&nbsp;)&nbsp;from&nbsp;dual;</font><font face="SimSun">中</font><font face="Courier New">&#8220;&nbsp;'TABLE',&nbsp;'T1'&#8221;</font><font face="SimSun">均要大写！</font></span></p>
<p><!--endfragment--></p>
<img src ="http://www.blogjava.net/lihao336/aggbug/294832.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-12 13:41 <a href="http://www.blogjava.net/lihao336/archive/2009/09/12/294832.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>索引组织表（Index Organizied Table）</title><link>http://www.blogjava.net/lihao336/archive/2009/09/12/294828.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sat, 12 Sep 2009 04:21:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/12/294828.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/294828.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/12/294828.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/294828.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/294828.html</trackback:ping><description><![CDATA[<div class="Section0" style="layout-grid:  15.6pt none">
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;索引组织表(index&nbsp;organized&nbsp;table,&nbsp;IOT)就是存储在一个索引结构中的表。存储在堆中的表是无组织的(也就是说，只要有可用的空间，数据可以放在任何地方)，IOT中的数据则按主键存储和排序。对你的应用来说，IOT表和一个&#8220;常规&#8221;表并无二致。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">索引组织表的数据按主键排序手段被存储在B-树索引中，</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">除了存储主键列值外还存储非键列的值。普通索引只存储索引列，而索引组织表则存储表的所有列的值</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">索引组织表一般适应于静态表，且查询多以主键列。当表的大部分列当作主键列时，且表相对静态，比较适合创建索引组织表！（8i以上）</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">既然它属于表，那么它当然也有建立索引的需求。由于它的索引的结构，比如说由于索引叶节点的分裂，行所在块可能会发生改变，因而建立在IOT上的索引和一般的索引的最大区别是</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">它存的是IOT的行的逻辑地址</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">，也就是UROWID，oracle用这个逻辑rowid来猜这个行所在的块，如果猜到了，那么这个urowid是正确的，否则它从这个地址向下遍历来找这条记录。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">IOT表的rowid是逻辑上的，因为IOT表中的行的位置是在不断变化的(例如插入新的行，有可能带来其它行的位置移动)</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;IOT有什么意义呢？使用堆组织表时，我们必须为表和表主键上的索引分别留出空间。而</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">IOT不存在主键的空间开销</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">，因为索引就是数据，数据就是索引，二者已经合二为一。但是，IOT带来的好处并不止于节约了磁盘空间的占用，更重要的是大幅度降低了I/O,减少了访问缓冲区缓存(尽管从缓冲区缓存获取数据比从硬盘读要快得多，但缓冲区缓存并不免费，而且也绝对不是廉价的。每个缓冲区缓存获取都需要缓冲区缓存的多个闩，而闩是串行化设备，会限制应用的扩展能力)</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IOT适用的场合有：</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;1、完全由主键组成的表。这样的表如果采用堆组织表，则</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">表本身完全是多余的开销</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">，因为所有的数据全部同样也保存在索引里，此时，堆表是没用的。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;2、代码查找表。如果你只会通过一个主键来访问一个表，这个表就非常适合实现为IOT.</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;3、如果你想保证数据存储在某个位置上，或者希望数据以某种特定的顺序物理存储，IOT就是一种合适的结构。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;IOT提供如下的好处：</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&#183;提高缓冲区缓存效率，因为给定查询在缓存中需要的块更少。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&#183;减少缓冲区缓存访问，这会改善可扩缩性。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&#183;获取数据的工作总量更少，因为获取数据更快。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&#183;每个查询完成的物理I/O更少，<span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">因为对于任何给定的查询，需要的块更少，而且对地址记录的一个物理&nbsp;I/O&nbsp;很可能可以获取所有地址（而不只是其中一个地址，但堆表实现就只是获取一个地址）</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span class="10" style="font-size: 10pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;如果经常在一个主键或惟一键上使用<font face="Times New Roman">BETWEEN&nbsp;</font><font face="SimSun">查询</font></span><span class="10" style="font-size: 10pt; font-family: 'SimSun'; mso-spacerun: 'yes'">也是如此，因为相近的记录存在一起，查询时引入的逻辑<font face="Times New Roman">IO</font><font face="SimSun">和物理</font><font face="Times New Roman">IO</font><font face="SimSun">都会更少。<br />
<br />
<br />
</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><strong style="font-size: 14pt">索引组织表的详细参数</strong></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Courier New'; mso-spacerun: 'yes'">&nbsp;select&nbsp;dbms_metadata.get_ddl(&nbsp;'TABLE',&nbsp;'T1'&nbsp;)&nbsp;from&nbsp;dual;</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">S_METADATA.GET_DDL('TABLE','T1')</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">-----------------------------------------------------------------------------</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">CREATE&nbsp;TABLE&nbsp;"OPS$TKYTE"."T1"</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">"X"&nbsp;NUMBER(*,0),</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">"Y"&nbsp;VARCHAR2(25),</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">"Z"&nbsp;DATE,</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">PRIMARY&nbsp;KEY&nbsp;("X")&nbsp;ENABLE</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">ANIZATION&nbsp;INDEX</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">OMPRESS</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">PCTFREE&nbsp;10&nbsp;INITRANS&nbsp;2&nbsp;MAXTRANS&nbsp;255&nbsp;LOGGING</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">STORAGE(INITIAL&nbsp;65536&nbsp;NEXT&nbsp;1048576&nbsp;MINEXTENTS&nbsp;1&nbsp;MAXEXTENTS&nbsp;2147483645</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">PCTINCREASE&nbsp;0&nbsp;FREELISTS&nbsp;1&nbsp;FREELIST&nbsp;GROUPS&nbsp;1&nbsp;BUFFER_POOL&nbsp;DEFAULT)</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">TABLESPACE&nbsp;"USERS"</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'">PCTTHRESHOLD&nbsp;50</span><span style="font-size: 10.5pt; font-family: 'Courier New'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><font face="Times New Roman"><strong>NOCOMPRESS</strong>&nbsp;<span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><strong>选项</strong></span></font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">这个选项对索引一般都可用。它告诉&nbsp;<font face="Times New Roman">Oracle&nbsp;</font><font face="SimSun">把每个值分别存储在各个索引条目中（也就是不压缩）。如果对象的主键在&nbsp;</font><font face="Times New Roman">A</font><font face="SimSun">、</font><font face="Times New Roman">B&nbsp;</font><font face="SimSun">和&nbsp;</font><font face="Times New Roman">C&nbsp;</font><font face="SimSun">列上，&nbsp;</font><font face="Times New Roman">A</font><font face="SimSun">、</font><font face="Times New Roman">B&nbsp;</font><font face="SimSun">和&nbsp;</font><font face="Times New Roman">C&nbsp;</font><font face="SimSun">的每一次出现都会物理地存储。&nbsp;</font><font face="Times New Roman">NOCOMPRESS&nbsp;</font><font face="SimSun">反过来就是&nbsp;</font><font face="Times New Roman">COMPRESS&nbsp;N&nbsp;</font><font face="SimSun">，<span style="color: red"><font face="SimSun">在此&nbsp;</font><font face="Times New Roman">N&nbsp;</font><font face="SimSun">是一个整数，表示要压缩的列数。这样可以避免重复值，并在块级提取&nbsp;&#8220;公因子&#8221;（&nbsp;</font><font face="Times New Roman">factor&nbsp;out&nbsp;</font><font face="SimSun">）。这样在&nbsp;</font><font face="Times New Roman">A&nbsp;</font><font face="SimSun">的值（以及&nbsp;</font><font face="Times New Roman">B&nbsp;</font><font face="SimSun">的值）重复出现时，将不再物理地存储它们</font></span></font><font face="SimSun">。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">下面做一个快速的测试，对前面&nbsp;<font face="Times New Roman">CREATE&nbsp;TABLE&nbsp;</font><font face="SimSun">的&nbsp;</font><font face="Times New Roman">SELECT&nbsp;</font><font face="SimSun">分别采用&nbsp;</font><font face="Times New Roman">NOCOMPRESS&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">COMPRESS&nbsp;1&nbsp;</font><font face="SimSun">和</font><font face="Times New Roman">COMPRESS&nbsp;2&nbsp;</font><font face="SimSun">选项，来展示能节省多少空间。先来创建&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">，但不进行压缩：</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;&nbsp;create&nbsp;table&nbsp;iot</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">2&nbsp;(&nbsp;owner,&nbsp;object_type,&nbsp;object_name,</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">3&nbsp;constraint&nbsp;iot_pk&nbsp;primary&nbsp;key(owner,object_type,object_name)</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">4&nbsp;)</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">5&nbsp;organization&nbsp;index</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">6&nbsp;<span style="color: red">NOCOMPRESS</span></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">7&nbsp;as</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">8&nbsp;select&nbsp;distinct&nbsp;owner,&nbsp;object_type,&nbsp;object_name</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">9&nbsp;from&nbsp;all_objects</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">10&nbsp;/</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">tablle&nbsp;created.</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">现在可以测量所用的空间。为此我们将使用&nbsp;</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: 'SimSun'; mso-spacerun: 'yes'">ANALYZE&nbsp;INDEX&nbsp;VALIDATE&nbsp;STRUCTURE</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;命令。<span style="color: red">这个命令会填写一个名为&nbsp;<font face="Times New Roman">INDEX_STATS&nbsp;</font><font face="SimSun">的动态性能视图，其中最多只包含一行，即这个&nbsp;</font><font face="Times New Roman">ANALYZE&nbsp;</font><font face="SimSun">命令最后一次执行的信息：</font></span></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;&nbsp;analyze&nbsp;index&nbsp;iot_pk&nbsp;validate&nbsp;structure;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">index&nbsp;analyzed.</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;&nbsp;select&nbsp;lf_blks,&nbsp;br_blks,&nbsp;used_space,</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">2&nbsp;opt_cmpr_count,&nbsp;opt_cmpr_pctsave</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">3&nbsp;from&nbsp;index_stats;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">LF_BLKS&nbsp;&nbsp;BR_BLKS&nbsp;&nbsp;USED_SPACE&nbsp;&nbsp;OPT_CMPR_COUNT&nbsp;&nbsp;OPT_CMPR_PCTSAVE</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">284&nbsp; 3&nbsp; 2037248 2 33</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">由此显示出，我们的索引目前使用了&nbsp;<font face="Times New Roman">284&nbsp;</font><font face="SimSun">个叶子块（即数据所在的块），并使用了&nbsp;</font><font face="Times New Roman">3&nbsp;</font><font face="SimSun">个分支块（&nbsp;</font><font face="Times New Roman">Oracle</font><font face="SimSun">在索引结构中导航所用的块）来找到这些叶子块。使用的空间大约是&nbsp;</font><font face="Times New Roman">2MB&nbsp;</font><font face="SimSun">（</font><font face="Times New Roman">2,038,248&nbsp;</font><font face="SimSun">字节）。另外两列名字有些奇怪，这两列是要告诉我们一些信息。&nbsp;</font><font face="Times New Roman">OPT_CMPR_COUNT&nbsp;</font><font face="SimSun">（最优压缩数）列要说的是：&#8220;&nbsp;如果你把这个索引置为&nbsp;</font><font face="Times New Roman">COMPRESS&nbsp;2&nbsp;</font><font face="SimSun">，就会得到最佳的压缩&nbsp;&#8221;&nbsp;。&nbsp;</font><font face="Times New Roman">OPT_CMPR_PCTSAVE&nbsp;</font><font face="SimSun">（最优的节省压缩百分比）则是说&nbsp;，</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">如果执行&nbsp;<font face="Times New Roman">COMPRESS&nbsp;2&nbsp;</font><font face="SimSun">，就能节省大约&nbsp;</font><font face="Times New Roman">1/3&nbsp;</font><font face="SimSun">的存储空间，索引只会使用现在&nbsp;</font><font face="Times New Roman">2&nbsp;/3&nbsp;</font><font face="SimSun">的磁盘空间。<br />
</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">下面用<font face="Times New Roman">COMPRESS&nbsp;2</font><font face="SimSun">进行压缩：</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;&nbsp;<span style="color: red"><strong><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">alter&nbsp;table&nbsp;iot&nbsp;move&nbsp;compress&nbsp;2;<br />
</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></strong></span></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">Table&nbsp;altered.</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;&nbsp;analyze&nbsp;index&nbsp;iot_pk&nbsp;validate&nbsp;structure;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">Index&nbsp;analyzed.</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">ops$tkyte@ORA10GR1&gt;&nbsp;select&nbsp;lf_blks,&nbsp;br_blks,&nbsp;used_space,</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">2&nbsp;opt_cmpr_count,&nbsp;opt_cmpr_pctsave</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">3&nbsp;from&nbsp;index_stats;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">LF_BLKS&nbsp;&nbsp;BR_BLKS&nbsp;&nbsp;USED_SPACE&nbsp;&nbsp;OPT_CMPR_COUNT&nbsp;&nbsp;OPT_CMPR_PCTSAVE</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">190&nbsp;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"> </span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">1&nbsp;</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"> </span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">1359357</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"> </span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">2</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"> </span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">0</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">现在大小有了显著减少，不论是叶子块数还是总的使用空间都大幅下降。<br />
<strong>（关于这个参数的详细说明参见第十一章 索引 11.2.1借 索引键压缩 ）<br />
</strong></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><!--endfragment--></font></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><strong>OVERFLOW&amp;PCTTHRESHOLD&amp;INCLUDING<font face="SimSun">选项</font></strong></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">OVERFLOW&nbsp;<font face="SimSun">子句允许你建立另一个段（这就使得&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">成为一个多段对象，就像有一个&nbsp;</font><font face="Times New Roman">CLOB&nbsp;</font><font face="SimSun">列一样），如果&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">的行数据变得太大，就可以溢出到这个段中。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">注意：构成主键的列不能溢出，它们必须直接放在叶子块上。</span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">PCTTHRESHOLD&nbsp;<font face="SimSun">：行中的数据量超过块的这个百分比时，行中余下的列将存储在溢出段中。所以，如果&nbsp;</font><font face="Times New Roman">PCTTHRESHOLD&nbsp;</font><font face="SimSun">是&nbsp;</font><font face="Times New Roman">10%&nbsp;</font><font face="SimSun">，而块大小是&nbsp;</font><font face="Times New Roman">8KB&nbsp;</font><font face="SimSun">，长度大于&nbsp;</font><font face="Times New Roman">800&nbsp;</font><font face="SimSun">字节的行就会把其中一部分存储在别处，而不能在索引块上存储。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">INCLUDING&nbsp;<font face="SimSun">：行中从第一列直到&nbsp;</font><font face="Times New Roman">INCLUDING&nbsp;</font><font face="SimSun">子句所指定列（也包括这一列）的所有列都存储在索引块上，余下的列存储在溢出段中。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">对于&nbsp;<font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">最后要考虑的是建立索引。&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">本身可以有一个索引，就像在索引之上再加索引，这称为二次索引（&nbsp;</font><font face="Times New Roman">secondary&nbsp;index&nbsp;</font><font face="SimSun">）。&nbsp;正常情况下，索引包含了所指向的行的物理地址，即&nbsp;</font><font face="Times New Roman">rowid&nbsp;</font><font face="SimSun">。而&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">二次索引无法做到这一点；它必须使用另外某种方法来指示行的地址。这是因为&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">中&nbsp;的行可以大量移动，&nbsp;而且它不像堆组织表中的行那样&nbsp;&#8220;&nbsp;迁移&nbsp;&#8221;&nbsp;。&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">中的行肯定在索引结构中的每个位置上，这取决于它的主键值；只有当索引本身的大小和形状&nbsp;发生改变时行才会移动（下一章将更详细地讨论索引结构如何维护）。</font></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;为了适应这种情况，&nbsp;<font face="Times New Roman">O&nbsp;racle&nbsp;</font><font face="SimSun">引入了一个逻辑&nbsp;</font><font face="Times New Roman">rowid&nbsp;</font><font face="SimSun">（&nbsp;</font><font face="Times New Roman">logical&nbsp;rowid&nbsp;</font><font face="SimSun">）。&nbsp;这些逻辑&nbsp;</font><font face="Times New Roman">rowid&nbsp;</font><font face="SimSun">根据&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">主键建立。对于行的当前位置还可以包含一个&nbsp;&#8220;&nbsp;猜测&nbsp;&#8221;&nbsp;，不过这个猜测几乎是错的，因为稍过一段时间后，&nbsp;</font><font face="Times New Roman">IOT</font><font face="SimSun">中的数据可能就会&nbsp;移动。这个猜测是行第一次置于二次索引结构中时在&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">中的物理地址。如果&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">中&nbsp;的行必须移动到另外一个块上，二次索引中的猜测就会变得&nbsp;&#8220;&nbsp;过时&nbsp;&#8221;&nbsp;。因&nbsp;此，与常规表相比，&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">上的索&nbsp;引效率稍低。在一个常规表上，索引访问通常需要完成一个&nbsp;</font><font face="Times New Roman">I/O&nbsp;</font><font face="SimSun">来扫描索引结构，然后需要一个读来读取表数据。对于&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">，&nbsp;通常要&nbsp;完成两个扫描；一次扫描二次结构，另一次扫描&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">本身。除此之外，&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">上的索引可以使用非主键列提供&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">数据的快速、高效访问。<br />
</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><strong>索引组织表小结</strong></span><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 10.5pt; font-family: 'SimSun'; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;在&nbsp;建立&nbsp;<font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">时，最关键的是适当地分配数据，即哪些数据存储在索引块上，哪些数据存储在溢出段上。对溢出条件不同的各种场景进行基准测试，查看对&nbsp;</font><font face="Times New Roman">INSERT&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">UPDATE&nbsp;</font><font face="SimSun">、&nbsp;</font><font face="Times New Roman">DELETE&nbsp;</font><font face="SimSun">和&nbsp;</font><font face="Times New Roman">SELECT&nbsp;</font><font face="SimSun">分别有怎样的影响。如果结构只建立一次，而且要频繁读取，就应该尽可能地把数据放在索引块上（最合适获取），要么频繁地组织索引中的数据（不适于修改）。堆表的&nbsp;</font><font face="Times New Roman">freelist&nbsp;</font><font face="SimSun">相关考虑对&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">也同样适用。&nbsp;</font><font face="Times New Roman"><span style="color: red"><font face="Times New Roman">PCTFREE&nbsp;</font><font face="SimSun">和</font><font face="Times New Roman">PCTUSED&nbsp;</font><font face="SimSun">在&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">中&nbsp;是两个重要的角色</font></span></font><font face="SimSun">。不过，&nbsp;</font><font face="Times New Roman">PCTFREE&nbsp;</font><font face="SimSun">对于&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">不像对于堆表那么重要，另外&nbsp;</font><font face="Times New Roman">PC&nbsp;TUSED&nbsp;</font><font face="SimSun">一般不起作用。不过，考虑&nbsp;</font><font face="Times New Roman">OVERFLOW&nbsp;</font><font face="SimSun">段时，&nbsp;</font><font face="Times New Roman">PCTFREE&nbsp;</font><font face="SimSun">和&nbsp;</font><font face="Times New Roman">PCTUSED&nbsp;</font><font face="SimSun">对于&nbsp;</font><font face="Times New Roman">IOT&nbsp;</font><font face="SimSun">的意义将与对于堆表一样重大；要采用与堆表相同的逻辑为溢出段设置这两个参数。</font></span></font></span><!--endfragment--><!--endfragment--></font></span></span></span></p>
</div>
<p><!--endfragment--></p>
<font face="Simsun"></font>
<img src ="http://www.blogjava.net/lihao336/aggbug/294828.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-12 12:21 <a href="http://www.blogjava.net/lihao336/archive/2009/09/12/294828.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>truncate，delete和drop的异同</title><link>http://www.blogjava.net/lihao336/archive/2009/09/10/294646.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Thu, 10 Sep 2009 12:43:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/10/294646.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/294646.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/10/294646.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/294646.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/294646.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注意:这里说的delete是指不带where子句的delete语句 <br />
相同点 <br />
truncate和不带where子句的delete, 以及drop都会删除表内的数据 </p>
<p>不同点: <br />
1. truncate和 delete只删除数据不删除表的结构(定义) <br />
&nbsp;&nbsp;&nbsp; drop语句将删除表的结构被依赖的约束(constrain),触发器(trigger),索引(index); 依赖于该表的存储过程/函数将保留,但是变为invalid状态. <br />
2.delete语句是dml,这个操作会放到rollback segement中,事务提交之后才生效;如果有相应的trigger,执行的时候将被触发. <br />
&nbsp;&nbsp; truncate,drop是ddl, 操作立即生效,原数据不放到rollback segment中,不能回滚. 操作不触发trigger. <br />
3.delete语句不影响表所占用的extent, 高水线(high watermark)保持原位置不动 <br />
&nbsp; 显然drop语句将表所占用的空间全部释放 <br />
&nbsp; truncate 语句缺省情况下见空间释放到 minextents个 extent,除非使用reuse storage;&nbsp;&nbsp; truncate会将高水线复位(回到最开始). <br />
4.速度,一般来说: drop&gt;; truncate &gt;; delete <br />
5.安全性:小心使用drop 和truncate,尤其没有备份的时候.否则哭都来不及&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用上,想删除部分数据行用delete,注意带上where子句. 回滚段要足够大.&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;想删除表,当然用drop&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;想保留表而将所有数据删除. 如果和事务无关,用truncate即可. 如果和事务有关,或者想触发trigger,还是用delete.&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果是整理表内部的碎片,可以用truncate跟上reuse stroage,再重新导入/插入数据 </p>
<p>TRUNCATE&nbsp;&nbsp; TABLE&nbsp;&nbsp; 在功能上与不带&nbsp;&nbsp; WHERE&nbsp;&nbsp; 子句的&nbsp;&nbsp; DELETE&nbsp;&nbsp; 语句相同：二者均删除表中的全部行。但&nbsp;&nbsp; TRUNCATE&nbsp;&nbsp; TABLE&nbsp;&nbsp; 比&nbsp;&nbsp; DELETE&nbsp;&nbsp; 速度快，且使用的系统和事务日志资源少。&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp; DELETE&nbsp;&nbsp; 语句每次删除一行，并在事务日志中为所删除的每行记录一项。TRUNCATE&nbsp;&nbsp; TABLE&nbsp;&nbsp; 通过释放存储表数据所用的数据页来删除数据，并且只在事务日志中记录页的释放。&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp; TRUNCATE&nbsp;&nbsp; TABLE&nbsp;&nbsp; 删除表中的所有行，但表结构及其列、约束、索引等保持不变。新行标识所用的计数值重置为该列的种子。如果想保留标识计数值，请改用&nbsp;&nbsp; DELETE。如果要删除表定义及其数据，请使用&nbsp;&nbsp; DROP&nbsp;&nbsp; TABLE&nbsp;&nbsp; 语句。&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp; 对于由&nbsp;&nbsp; FOREIGN&nbsp;&nbsp; KEY&nbsp;&nbsp; 约束引用的表，不能使用&nbsp;&nbsp; TRUNCATE&nbsp;&nbsp; TABLE，而应使用不带&nbsp;&nbsp; WHERE&nbsp;&nbsp; 子句的&nbsp;&nbsp; DELETE&nbsp;&nbsp; 语句。由于&nbsp;&nbsp; TRUNCATE&nbsp;&nbsp; TABLE&nbsp;&nbsp; 不记录在日志中，所以它不能激活触发器。&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp; TRUNCATE&nbsp;&nbsp; TABLE&nbsp;&nbsp; 不能用于参与了索引视图的表。</p>
<img src ="http://www.blogjava.net/lihao336/aggbug/294646.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-10 20:43 <a href="http://www.blogjava.net/lihao336/archive/2009/09/10/294646.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle乐观锁定</title><link>http://www.blogjava.net/lihao336/archive/2009/09/04/293934.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Fri, 04 Sep 2009 12:23:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/04/293934.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/293934.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/04/293934.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/293934.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/293934.html</trackback:ping><description><![CDATA[<p>&nbsp;Oracle中乐观锁定的四种实现方式：</p>
<ul>
    <li>更新前在应用中存储所要操作行的&#8220;前映像&#8221;，更新时使用存储的旧记录来判断当前值是否已经改变；
    <li>使用一个特殊的列，这个列由一个数据库触发器或应用程序代码维护，可以告诉我们记录的 &#8220;版本&#8221;；
    <li>使用一个校验和或散列值，这是使用原来的数据计算得出的；
    <li>使用新增的 Oracle 10g 特性 ORA_ROWSCN 。<br />
    </li>
</ul>
<p><strong>1.使用版本列</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;附加一个LAST_MODIFIED列，类型可以为 timestamp with time zone default systemstamp（ora 9i以上）,这个类型在Oracle中精度最高，精确到百万分之一秒。<br />
<span style="color: red">不建议使用触发器，因为开销太大，而由DML来负责。</span><br />
<br />
<strong>2.使用校验和的乐观锁定</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;使用一个虚拟的版本列来判断数据是否改变。<br />
&nbsp;&nbsp;&nbsp;&nbsp;与使用版本列的做法一样，我们可以采用同样的方法使用这些散列值或校验和，只需把从数据库读出数据时得到的散列或校验和值与修改数据前得到的散列或校验和值进行比较。在我们读出数据之后， 但是在修改数据之前，如果有人在这段时间内修改了这一行的值，散列值或校验和值往往会大不相同。<br />
&nbsp;&nbsp;&nbsp;&nbsp;以下为Oracle提供的三种计算散列值得数据包：<br />
OWA_OPT_LOCK.CHECKSUM ：这个方法在 Oracle8i 8.1.5 及以上版本中提供。给定一个串，其中一个函数会返回一个 16 位的校验和。给定 ROWID 时，另一个函数会计算该行的 16 位校验和，而且同时将这一行锁定。出现冲突的可能性是 65 536 分之一（ 65 536 个串中有一个冲突，这是假警报的最大几率）。<br />
&nbsp;DBMS_OBFUSCATION_TOOLKIT.MD5 ：这个方法在 Oracle8i 8.1.7 及以上版本中提供。它会计算一个 128 位的消息摘要。冲突的可能性是 3.4028E+38 分之一（非常小）。<br />
DBMS_CRYPTO.HASH ：这个方法在 Oracle 10g Release 1 及以上版本中提供。它能计算一个SHA-1 （安全散列算法 1 ， Secure Hash Algorithm 1 ）或 MD4/MD5 消息摘要。建议你使用 SHA- 1算法。<br />
&nbsp;&nbsp;&nbsp;&nbsp;注意 很多编程语言中都提供了一些散列和校验和函数，所以还可以使用数据库之外的散列和校验和函数。<br />
&nbsp;&nbsp;&nbsp;&nbsp;要记住，计算散列或校验和是一个 <span style="color: red">CPU 密集型操作</span>（相当占用 CPU ），其计算代价很昂贵。如果系统上 CPU 是稀有资源，在这种系统上就必须充分考虑到这一点。不过，如果从 &#8220; 网络友好性 &#8221; 角度看，这种方法会比较好，因为只需在网络上传输相当小的散列值，而不是行的完整的前映像和后映像（以便逐列地进行比较），所以消耗的资源会少得多。下面会使用一个新的 Oracle 10g 函数 ORA_ROWSCN ，它不仅很小（类似于散列），而且计算时不是 CPU 密集的（不会过多占用 CP U ）。<br />
<br />
<strong>3.使用ORA_ROWSCN</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;ORA_ROWSCN 建立在内部 Oracle 系统时钟（ SCN ）基础上。在 Oracle 中，每次提交时， SCN 都会推进（其他情况也可能导致 SCN 推进，要注意， SCN 只会推进，绝对不会后退）。这个概念与前面在获取数据 时得到 ORA_ROWSCN 的方法是一样的，更新数据时要验证 SCN 未修改过。之所以我会强调这一点（而不是草草带过），原因是除非你创建表时支持在行级维ORA_ROWSCN ，否则 Oracle 会在块级维护。<span style="color: red">也就是说，默认情况下，一个块上的多行会共享相同的 ORA_ROWSCN 值。</span>如果更新一个块上的某一行，而且 这个块上还有另外 50 行，那么这些行的 ORA_ROWSCN 也会推进。这往往会导致许多假警报，你认为某一行已经修改，但实际上它并没有改动。因此，需要注意这一点，并了解如何改变这种行为。<br />
&nbsp;&nbsp;&nbsp;&nbsp;要修改这个特性，只能重新建立表，并启用 <span style="color: red">ROWDEPENDENCIES </span>。<br />
<br />
<em><strong>使用乐观锁定还是悲观锁定？</strong></em><br />
</p>
<p style="text-indent: 18pt"><span style="font-family: SimSun">那么哪种方法最好呢？根据我的经验，悲观锁定在</span> Oracle <span style="font-family: SimSun">中工作得非常好（但是在其他数据库中可能不是这样），而且与乐观锁定相比，悲观锁定有很多优点。不过，它需要与数据库有一条有状态的连接，如客户</span> / <span style="font-family: SimSun">服务器连接，因为无法跨连接持有锁。正是因为这一点，在当前的许多情况下，悲观锁定不太现实</span><span style="font-family: SimSun">。过去，客户</span> / <span style="font-family: SimSun">服务器应用可能只有数十个或数百个用户，对于这些应用，悲观锁定是我的不二选择。不过，如今对大多数应用来说，我都建议采用乐观并发控制。要在整个事务期间保持连接，这个代价太大了，一般无法承受。</span></p>
<p style="text-indent: 18pt"><span style="font-family: SimSun">在这些可用的方法中，我使用哪一种呢？我喜欢使用版本列方法，<span style="color: red">并增加一个时间戳列</span>（而不只是</span><span style="font-family: SimSun">一个</span> NUMBER <span style="font-family: SimSun">）。从长远看，这样能为我提供一个额外的信息：</span> &#8220; <span style="font-family: SimSun">这一行最后一次更新发生在什么时间？</span> &#8221; <span style="font-family: SimSun">所以意义更大。而且与散列或校验和方法相比，计算的代价不那么昂贵，在处理</span> LONG <span style="font-family: SimSun">、</span> LONG RAW <span style="font-family: SimSun">、</span> CLOB <span style="font-family: SimSun">、</span> BLO B<span style="font-family: SimSun">和其他非常大的列时，散列或校验和方法可能会遇到一些问题，而版本列方法则没有这些问题。</span></p>
<p style="text-indent: 18pt"><span style="font-family: SimSun">如果必须向一个表增加乐观并发控制，而此时还在利用悲观锁定机制使用这个表（例如，客户</span> / <span style="font-family: SimSun">服务器应用都在访问这个表，而且还在通过</span> Web <span style="font-family: SimSun">访问），我则倾向于选择</span> ORA_ROWSCN <span style="font-family: SimSun">方法。这是因为，在现有的遗留应用中，可能不希望出现一个新列，或者即使我们另外增加一步把这个额外的列隐藏起来（使用散列等等方式），为了维护这个列，可能需要一个必要的触发器，而这个触发器的开销非常大，这是我们无法承受的。</span> ORA_ROWSCN<span style="font-family: SimSun">技术没有干扰性，而且在这个方面是轻量级的（当然，这是指我们执行表的重建之后）。</span></p>
<p style="text-indent: 18pt"><span style="font-family: SimSun">散列</span> / <span style="font-family: SimSun">校验和方法在数据库独立性方面很不错，特别是如果我们在数据库之外计算散列或校验和，则更是如此。不过，如果在中间层而不是在数据库中执行计算，从</span> CPU <span style="font-family: SimSun">使用和网络传输方面来看，就会带来更大的资源使用开销。</span></p>
<img src ="http://www.blogjava.net/lihao336/aggbug/293934.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-04 20:23 <a href="http://www.blogjava.net/lihao336/archive/2009/09/04/293934.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>for update 与 for update nowait</title><link>http://www.blogjava.net/lihao336/archive/2009/09/04/293932.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Fri, 04 Sep 2009 11:56:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/09/04/293932.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/293932.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/09/04/293932.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/293932.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/293932.html</trackback:ping><description><![CDATA[共同点：对当前行加锁，阻塞其它对这一行的写操作。<br />
<br />
for update:当当前行已经被锁定，当前语句会被阻塞，直到当前行被释放；<br />
for update nowait:当当前行已经被锁定时，当前语句会立即被数据库系统拒绝，迅速返回ORA-00054错误，提示资源正忙。
<img src ="http://www.blogjava.net/lihao336/aggbug/293932.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-09-04 19:56 <a href="http://www.blogjava.net/lihao336/archive/2009/09/04/293932.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle Memo</title><link>http://www.blogjava.net/lihao336/archive/2009/08/30/293177.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 30 Aug 2009 05:24:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/08/30/293177.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/293177.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/08/30/293177.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/293177.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/293177.html</trackback:ping><description><![CDATA[<ol>
    <li>在 Oracle 中使用一个连接。不论你想执行 5 个查询还是 500 个查询，都希望最多只打开一个连接。
    <li><span style="color: #ff0000">确保尽可能的使用绑定变量。</span>
    <li>Oracle锁定策略： </li>
</ol>
<ul>
    <li><span lang="EN-US" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">Oracle </span><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">只在修改时才对数据加行级锁。正常情况下不会升级到块级锁或表级锁（不过两段提交期间的一段很短的时间内除外，这是一个不常见的操作）。 </span>
    <li><span lang="EN-US" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN"><o:p>
    <p><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">如果只是读数据，</span><span lang="EN-US" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN"> Oracle </span><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">绝不会对数据锁定。不会因为简单的读操作在数据行上锁定。</span></p>
    </o:p></span>
    <li><span lang="EN-US" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN"><o:p>
    <p><span style="font-family: SimSun; mso-bidi-font-family: Tahoma">写入器（<span lang="EN-US"> writer </span>）不会阻塞读取器（<span lang="EN-US"> reader </span>）。换种说法：读（<span lang="EN-US"> read </span>）不会被写（<span lang="EN-US"> write </span>） 阻塞。</span><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">这一点几乎与其他所有数据库都不一样。在其他数据库中，读往往会被写阻塞。尽管听上去这个特性似乎很不错（一般情况下确实如此），但是，如果你没有充分理解这个思想，而且想通过应用逻辑对应用施加完整性约束，就极有可能做得不对。</span></o:p></span> </p>
    <li><span lang="EN-US" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN"><o:p><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">
    <p><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">写入器想写某行数据，但另一个写入器已经锁定了这行数据，此时该写入器才会被阻塞。 读取器绝对不会阻塞写入器。 </span></p>
    </span></o:p></span></li>
</ul>
<span lang="EN-US" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN"><o:p><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">
<p><span lang="ZH-CN" style="font-family: SimSun; mso-bidi-font-family: Tahoma; mso-fareast-language: ZH-CN">即：读既不会阻塞读，也不会阻塞写；写不会阻塞读，但会阻塞写。<br />
Oracle 的无阻塞方法有一个副作用，如果确实想保证一次最多只有一个用户访问一行数据，开发人员就得自己做些工作。要加入我们自己的串行化机制来确保业务逻辑的正确性，如for update语句会使读操作也对相应的行加锁，确保了串行访问。<br />
<br />
</span></span></o:p></span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;4.&nbsp;&nbsp; Oracle多版本<br />
&nbsp;&nbsp;&nbsp;&nbsp;①、Oracle多版本特性是Oracle并发控制机制的基础， Oracle 采用了一种多版本、读一致（ read-consistent ）的并发模型。实质上讲， Oracle 利用这种机制提供了以下特性：<br />
&nbsp;读一致查询：对于一个时间点（ point in time ），查询会产生一致的结果。<br />
&nbsp;非阻塞查询：查询不会被写入器阻塞，但在其他数据库中可能不是这样。<br />
&nbsp;&nbsp;&nbsp;&nbsp;②、由于有多版本机制，Oracle中没有&#8220;共享读&#8221;锁的概念。<br />
&nbsp;&nbsp;&nbsp;&nbsp;只要你修改数据， Oracle 就会创建撤销（ undo ）条目。这些 undo 条目写至 undo 段（撤销段， undo segment ）。如果事务失败，需要撤销， Oracle 就会从这个回滚段读取 &#8220; 之前 &#8221; 的映像，并恢复数据。除了使用回滚段数据撤销事务外， Oracle 还会用它撤销读取块时对块所做的修改，使之恢复到查询开始前的时间点 。这样就能摆脱锁来得到一致、正确的答案，而无需你自己对任何数据锁定。<br />
&nbsp;&nbsp;&nbsp;&nbsp;Oracle非阻塞读是这样实现的： Oracle 只看数据是否改变，它并不关心数据当前是否锁定（锁定意味着数据已经改变）。 Oracle 只是从回滚段中取回原来的值，并继续处理下一个数据块。<br />
&nbsp;&nbsp;&nbsp;&nbsp;在数据库中，可以得到同一个信息处于不同时间点的多个版本。Oracle 能充分使用不同时间点的数据快照来提供读一致查询和非阻塞查询。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;5.在SQL Server和Sybase中，NULL就等于NULL，但是，在Oracle中，NULL与NULL既不相等，也不完全不相等。<br />
&nbsp;&nbsp;&nbsp;&nbsp;6.Oracle没有&#8220;共享读&#8221;锁。<br />
</p>
<img src ="http://www.blogjava.net/lihao336/aggbug/293177.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-08-30 13:24 <a href="http://www.blogjava.net/lihao336/archive/2009/08/30/293177.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle 资源</title><link>http://www.blogjava.net/lihao336/archive/2009/08/30/293175.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 30 Aug 2009 04:45:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/08/30/293175.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/293175.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/08/30/293175.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/293175.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/293175.html</trackback:ping><description><![CDATA[<p><a href="http://otn.oracle.com" target="_blank"><br />
http://otn.oracle.com</a><br />
<br />
Oracle面试题目总结<br />
<a href="http://topic.csdn.net/u/20080731/21/4b8eb01e-0523-4898-be3f-9cddc3b3a5b3.html">http://topic.csdn.net/u/20080731/21/4b8eb01e-0523-4898-be3f-9cddc3b3a5b3.html</a><br />
</p>
<img src ="http://www.blogjava.net/lihao336/aggbug/293175.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-08-30 12:45 <a href="http://www.blogjava.net/lihao336/archive/2009/08/30/293175.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>设置sqlplus的autotrace</title><link>http://www.blogjava.net/lihao336/archive/2009/08/30/293164.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 30 Aug 2009 02:59:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/08/30/293164.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/293164.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/08/30/293164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/293164.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/293164.html</trackback:ping><description><![CDATA[&nbsp;
<p><span style="font-family: SimSun">（</span> 1 <span style="font-family: SimSun">）</span>cd [ORACLE_HOME]/rdbms/admin <span style="font-family: SimSun">；</span></p>
<p><span style="font-family: SimSun">（</span> 2 <span style="font-family: SimSun">）作为</span> SYSTEM <span style="font-family: SimSun">登录</span> SQL*Plus <span style="font-family: SimSun">；</span></p>
<p><span style="font-family: SimSun">（</span> 3 <span style="font-family: SimSun">）运行</span> @utlxplan <span style="font-family: SimSun">；</span></p>
<p><span style="font-family: SimSun">（</span> 4 <span style="font-family: SimSun">）运行</span> CREATE PUBLIC SYNONYM PLAN_TABLE FOR PLAN_TABLE <span style="font-family: SimSun">；</span></p>
<p><span style="font-family: SimSun">（</span> 5 <span style="font-family: SimSun">）运行</span> GRANT ALL ON PLAN_TABLE TO PUBLIC <span style="font-family: SimSun">。</span></p>
<p style="text-indent: 17.95pt"><span style="font-family: SimSun">可以把</span> GRANT TO PUBLIC <span style="font-family: SimSun">中的</span> PUBLIC <span style="font-family: SimSun">替换为某个用户。通过将</span> PLAN_TABLE <span style="font-family: SimSun">置为</span> public <span style="font-family: SimSun">，任何人都可以使用</span> SQL*Plus <span style="font-family: SimSun">进行跟踪。这么一来，就不需要每个用户都安装自己的计划表。还有一种做法是，在想要使用</span> AUTOTRACE <span style="font-family: SimSun">的每个模式中分别运行</span> @utlxplan <span style="font-family: SimSun">。</span></p>
<p style="text-indent: 17.95pt"><span style="font-family: SimSun">下一步是创建并授予</span> PLUSTRACE <span style="font-family: SimSun">角色：</span></p>
<p><span style="font-family: SimSun">（</span> 1 <span style="font-family: SimSun">）</span> cd [ORACLE_HOME]/sqlplus/admin <span style="font-family: SimSun">；</span></p>
<p><span style="font-family: SimSun">（</span> 2 <span style="font-family: SimSun">）作为</span> SYS <span style="font-family: SimSun">或</span> SYSDBA <span style="font-family: SimSun">登录</span> SQL*Plus <span style="font-family: SimSun">；</span></p>
<p><span style="font-family: SimSun">（</span> 3 <span style="font-family: SimSun">）运行</span> @plustrce <span style="font-family: SimSun">；</span></p>
<p><span style="font-family: SimSun">（</span> 4 <span style="font-family: SimSun">）运行</span> GRANT PLUSTRACE TO PUBLIC <span style="font-family: SimSun">。</span></p>
<p style="text-indent: 17.95pt"><span style="font-family: SimSun">通过设置</span> AUTOTRACE <span style="font-family: SimSun">系统变量可以控制这个报告：</span></p>
<p> SET AUTOTRACE OFF <span style="font-family: SimSun">：不生成</span> AUTOTRACE <span style="font-family: SimSun">报告，这是默认设置。</span></p>
<p> SET AUTOTRACE ON EXPLAIN <span style="font-family: SimSun">：</span> AUTOTRACE <span style="font-family: SimSun">报告只显示优化器执行路径。</span></p>
<p> SET AUTOTRACE ON STATISTICS <span style="font-family: SimSun">：</span> AUTOTRACE <span style="font-family: SimSun">报告只显示</span> SQL <span style="font-family: SimSun">语句的执行统计信息。</span></p>
<p> SET AUTOTRACE ON <span style="font-family: SimSun">：</span> AUTOTRACE <span style="font-family: SimSun">报告既包括优化器执行路径，又包括</span> SQL <span style="font-family: SimSun">语句的执行统计信息。</span></p>
<p> SET AUTOTRACE TRACEONLY <span style="font-family: SimSun">：这与</span> SET AUTOTRACE ON <span style="font-family: SimSun">类似，但是不显示用户的查询输出（如果有的话）。</span></p>
<img src ="http://www.blogjava.net/lihao336/aggbug/293164.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-08-30 10:59 <a href="http://www.blogjava.net/lihao336/archive/2009/08/30/293164.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sqlplus 初始化 glogin.sql</title><link>http://www.blogjava.net/lihao336/archive/2009/08/30/293163.html</link><dc:creator>calvin</dc:creator><author>calvin</author><pubDate>Sun, 30 Aug 2009 02:50:00 GMT</pubDate><guid>http://www.blogjava.net/lihao336/archive/2009/08/30/293163.html</guid><wfw:comment>http://www.blogjava.net/lihao336/comments/293163.html</wfw:comment><comments>http://www.blogjava.net/lihao336/archive/2009/08/30/293163.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lihao336/comments/commentRss/293163.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lihao336/services/trackbacks/293163.html</trackback:ping><description><![CDATA[文件位置：D:\oracle\ora92\sqlplus\admin\glogin.sql<br />
<br />
define _editor=notepad<br />
set serveroutput on size 1000000<br />
set trimspool on<br />
set long 5000<br />
set linesize 100<br />
set pagesize 9999<br />
column plan_plus_exp format a80<br />
column global_name new_value gname<br />
set termout off<br />
define gname=idle<br />
column global_name new_value gname<br />
select lower(user) || '@' || substr( global_name, 1, decode( dot, 0,<br />
length(global_name), dot-1) ) global_name<br />
&nbsp; from (select global_name, instr(global_name,'.') dot from global_name );<br />
set sqlprompt '&amp;gname&gt; '<br />
set termout on 
<img src ="http://www.blogjava.net/lihao336/aggbug/293163.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lihao336/" target="_blank">calvin</a> 2009-08-30 10:50 <a href="http://www.blogjava.net/lihao336/archive/2009/08/30/293163.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>