﻿<?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-xinyoulinglei-文章分类-oracle</title><link>http://www.blogjava.net/xinyoulinglei/category/53700.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 06 Jul 2013 23:40:21 GMT</lastBuildDate><pubDate>Sat, 06 Jul 2013 23:40:21 GMT</pubDate><ttl>60</ttl><item><title>oracle重建index</title><link>http://www.blogjava.net/xinyoulinglei/articles/401118.html</link><dc:creator>Lenovo123</dc:creator><author>Lenovo123</author><pubDate>Mon, 01 Jul 2013 11:29:00 GMT</pubDate><guid>http://www.blogjava.net/xinyoulinglei/articles/401118.html</guid><wfw:comment>http://www.blogjava.net/xinyoulinglei/comments/401118.html</wfw:comment><comments>http://www.blogjava.net/xinyoulinglei/articles/401118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xinyoulinglei/comments/commentRss/401118.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xinyoulinglei/services/trackbacks/401118.html</trackback:ping><description><![CDATA[<p><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">一：考虑重建索引的场合</span><br style="line-height: 25px" />1：表上频繁发生update,delete操作<br style="line-height: 25px" />2：表上发生了alter table ..move操作（move操作导致了rowid变化）</p>
<p><br style="line-height: 25px" /><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">二：判断重建索引的标准</span><br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">索引重建是否有必要，一般看索引是否倾斜的严重，是否浪费了空间；<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">那应该如何才可以判断索引是否倾斜的严重，是否浪费了空间，如下：<br style="line-height: 25px" />1，&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;对索引进行结构分析<br style="line-height: 25px" />Analyze index indexname validate structure;<br style="line-height: 25px" />2, 在执行步骤1的session中查询index_stats表，不要到别的session去查询<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">select height,DEL_LF_ROWS/LF_ROWS from index_stats;<br style="line-height: 25px" />3, 在步骤2查询出来的height&gt;=4或者DEL_LF_ROWS/LF_ROWS&gt;0.2的场合，该索引考虑重建；<br style="line-height: 25px" />Example:<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">SQL&gt; select count(*) from test_index;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">COUNT(*)<br style="line-height: 25px" />----------<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;2072327<br style="line-height: 25px" />SQL&gt; analyze index pk_t_test validate structure;<br style="line-height: 25px" />Index analyzed<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;SQL&gt; select height,DEL_LF_ROWS/LF_ROWS from index_stats;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">HEIGHT &nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;DEL_LF_ROWS/LF_ROWS<br style="line-height: 25px" />---------- -------------------<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">3&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;0<br style="line-height: 25px" />SQL&gt; delete from test_index where rownum&lt;250000;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;249999 rows deleted<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;SQL&gt; select height,DEL_LF_ROWS/LF_ROWS from index_stats;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">HEIGHT &nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;DEL_LF_ROWS/LF_ROWS<br style="line-height: 25px" />---------- -------------------<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">3&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;0<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;SQL&gt; analyze index pk_t_test validate structure;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;Index analyzed<br style="line-height: 25px" />SQL&gt; select height,DEL_LF_ROWS/LF_ROWS from index_stats;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">HEIGHT &nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">DEL_LF_ROWS/LF_ROWS<br style="line-height: 25px" />---------- -------------------<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;3&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">0.0777430939338362</p>
<p><br style="line-height: 25px" /><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">三：重建索引的方式</span><br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;1：drop 原来的索引，然后再创建索引;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;2：alter index indexname rebuild (online);<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;方式一：耗时间，无法在24*7环境中实现<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;方式二：比较快，可以在24*7环境中实现<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;建议使用方式二</p>
<p><br style="line-height: 25px" /><strong style="line-height: 25px; font-weight: bold">四：alter index rebuid内部过程和注意点</strong><br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;1：alter index rebuild 和alter index rebuild online的区别<br style="line-height: 25px" />(1)&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;扫描方式不同<br style="line-height: 25px" />Rebuild以index fast full scan（or table full scan）方式读取原索引中的数据来构建一个新的索引，有排序的操作; rebuild online 执行表扫描获取数据，有排序的操作;<br style="line-height: 25px" />Rebuild&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">方式 (index fast full scan&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">or&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">table full scan&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">取决于统计信息的cost)<br style="line-height: 25px" />Eg1:<br style="line-height: 25px" />SQL&gt; explain plan for alter index idx_policy_id2 rebuild;<br style="line-height: 25px" />Explained<br style="line-height: 25px" />SQL&gt; select * from table(dbms_xplan.display);<br style="line-height: 25px" />PLAN_TABLE_OUTPUT<br style="line-height: 25px" />---------------------------------------------------------------------<br style="line-height: 25px" />| Id&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Operation&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">Name&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Rows&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Bytes | Cost&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|<br style="line-height: 25px" />---------------------------------------------------------------------<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">0 | ALTER INDEX STATEMENT&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">999K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">4882K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">3219 |<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">1 |&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">INDEX BUILD NON UNIQUE| IDX_POLICY_ID2&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">2 |&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">SORT CREATE INDEX&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">999K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">4882K|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">3 |&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;INDEX FAST FULL SCAN | IDX_POLICY_ID2&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">999K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">4882K|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|<br style="line-height: 25px" />---------------------------------------------------------------------<br style="line-height: 25px" />Eg2:<br style="line-height: 25px" />SQL&gt;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">explain plan for alter index idx_policy_id rebuild;<br style="line-height: 25px" />Explained<br style="line-height: 25px" />SQL&gt; select * from table(dbms_xplan.display);<br style="line-height: 25px" />PLAN_TABLE_OUTPUT<br style="line-height: 25px" />---------------------------------------------------------------------<br style="line-height: 25px" />| Id&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Operation&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">Name&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;| Rows&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Bytes | Cost&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|<br style="line-height: 25px" />---------------------------------------------------------------------<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">0 | ALTER INDEX STATEMENT&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">2072K|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">9M|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">461 |<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">1 |&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">INDEX BUILD NON UNIQUE| IDX_POLICY_ID&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">2 |&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">SORT CREATE INDEX&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">2072K|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">9M|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">3 |&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;TABLE ACCESS FULL&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">| TEST_INDEX&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">2072K|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">9M|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">461 |<br style="line-height: 25px" /><br style="line-height: 25px" /><br style="line-height: 25px" />Eg3： (注意和Eg1比较)<br style="line-height: 25px" />Rebuil online 方式：<br style="line-height: 25px" />SQL&gt; explain plan for alter index idx_policy_id2 rebuild online;<br style="line-height: 25px" />Explained<br style="line-height: 25px" />SQL&gt; select * from table(dbms_xplan.display);<br style="line-height: 25px" />PLAN_TABLE_OUTPUT<br style="line-height: 25px" />---------------------------------------------------------------------<br style="line-height: 25px" />| Id&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Operation&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">Name&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Rows&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">| Bytes | Cost&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|<br style="line-height: 25px" />---------------------------------------------------------------------|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">0 | ALTER INDEX STATEMENT&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">999K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">4882K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">3219 |<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">1 |&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">INDEX BUILD NON UNIQUE| IDX_POLICY_ID2&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">2 |&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">SORT CREATE INDEX&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">999K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">4882K|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;|<br style="line-height: 25px" />|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">3 |&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;TABLE ACCESS FULL&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">| TEST_INDEX2&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">|&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">999K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">4882K|&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">3219 |<br style="line-height: 25px" />(2)&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;rebuild 会阻塞dml操作，rebuil online 不会阻塞dml操作；<br style="line-height: 25px" />(3)&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;rebuild online时系统会产生一个SYS_JOURNAL_xxx的IOT类型的系统临时日志表，所有rebuild online时索引的变化都记录在这个表中，当新的索引创建完成后，把这个表的记录维护到新的索引中去，然后drop掉旧的索引，rebuild online就完成了。<br style="line-height: 25px" /><br style="line-height: 25px" />注意点：<br style="line-height: 25px" />1，&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;执行rebuild操作时，需要检查表空间是否足够；<br style="line-height: 25px" />2，&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;虽然说rebuild online操作允许dml操作，但是还是建议在业务不繁忙时间段进行；<br style="line-height: 25px" />3，&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;Rebuild操作会产生大量redo log ；<br style="line-height: 25px" /><br style="line-height: 25px" /><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">五：重建分区表上的分区索引</span><br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">1：重建分区索引方法：<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">Alter index indexname rebuild partition paritionname tablespace tablespacename;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">Alter index indexname rebuild subpartition partitioname tablespace&nbsp;<wbr style="line-height: 25px">tablespacename;<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">Partition name 可以从user_ind_partitions查找<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">Tablepace 参数允许alter index操作更改索引的存储空间；</p>
<p>&nbsp;<wbr style="line-height: 25px"></p>
<p><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">六：索引状态描述</span></p>
<p><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">在数据字典中查看索引状态，发现有三种：&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px"><br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">VALID&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px"><br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">N/A&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px"><br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">UNUSABLE&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px"><br style="line-height: 25px" /></span></p>
<p><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">valid:当前索引有效<br style="line-height: 25px" />N/A :分区索引有效<br style="line-height: 25px" />unusable:索引失效</span></p>
<p>&nbsp;<wbr style="line-height: 25px"></p>
<p><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold"><span style="line-height: 21px; word-wrap: normal; word-break: normal">七：术语</span></span></p>
<p><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold"><span style="line-height: 21px; word-wrap: normal; word-break: normal">&nbsp;<wbr style="line-height: 25px">&nbsp;高基数：简单理解就是表中列的不同值多<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;低基数：建单理解就是表中的列的不同值少<br style="line-height: 25px" /></span>&nbsp;<wbr style="line-height: 25px">&nbsp;以删除的叶节点数量：指得是数据行的delete操作从逻辑上删除的索引节点的数量，要记住<a style="line-height: 25px; color: rgb(127,88,105)" href="http://hi.baidu.com/hanbingxiaoshi/blog/item/%20:;" rel="nofollow" target="_self"><u style="line-height: 25px">oracle</u></a>在删除数据行后，将&#8220;死&#8220;节点保留在索引中，这样做可以加快<a style="line-height: 25px; color: rgb(127,88,105)" href="http://hi.baidu.com/hanbingxiaoshi/blog/item/%20:;" rel="nofollow" target="_self"><u style="line-height: 25px">sql</u></a>删除操作的速度，因此oracle删除数据行后可以不必重新平衡索引。<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">索引高度：索引高度是指由于数据行的插入操作而产生的索引层数，当表中添加大量数据时，oracle将生成索引的新层次以适应加入的数据行，因此，oracle索引可能有4层，但是这只会出现在索引数中产生大量插入操作的区域。Oracle索引的三层结构可以支持数百万的项目，而具备4层或是更多层的需要重建。<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;每次索引访问的读取数：是指利用索引读取一数据行时所需要的逻辑I/O操作数，逻辑读取不必是物理读取，因为索引的许多内容已经保存在数据缓冲区，然而，任何数据大于10的索引都需要重建。</span></p>
<p><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;那么什么时候重建呢？我们可以利用analyze index &#8230;&#8230;.. compute statistics 对表进行分析。然后察看dba_indexes中的blevel。这列是说明索引从根块到叶快的级别，或是深度。如果级别大于等于4。则需要重建，如下：<br style="line-height: 25px" />Select index_name,blevel from dba_indexes where blevel&gt;=4.<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">另一个从重建中受益的指标显然是当该索引中的被删除项占总的项数的百分比。如果在20%以上时，也应当重建，如下<br style="line-height: 25px" />SQL&gt;anlyze index ------ validate structure<br style="line-height: 25px" />SQL&gt;select (del_lf_rows_len/lf_rows_len)*100 from index_stats where name=&#8217;------&#8216;<br style="line-height: 25px" />就能看到是否这个索引被删除的百分比。<br style="line-height: 25px" />上面只是判断，那么，怎样重建会更好呢？<br style="line-height: 25px" />建索引的办法：<br style="line-height: 25px" />a.&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;删除并从头开始建立索引。<br style="line-height: 25px" />b.&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;使用alter index -------- rebuild 命令重建索引<br style="line-height: 25px" />c.&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;使用alter index -------- coalesce命令重建索引。<br style="line-height: 25px" />下面讨论一下这三种方法的优缺点：<br style="line-height: 25px" />1).删除并从头开始建索引：方法是最慢的，最耗时的。一般不建议。<br style="line-height: 25px" />2).Alter index ---- rebuild 快速重建索引的一种有效的办法，因为使用现有索引项来重建新索引，如果客户操作时有其他用户在对这个表操作，尽量使用带online参数来最大限度的减少索引重建时将会出现的任何加锁问题，alter index ------- rebuild online.但是,由于新旧索引在建立时同时存在，因此，使用这种技巧则需要有额外的磁盘空间可临时使用，当索引建完后把老索引删除，如果没有成功，也不会影响原来的索引。利用这种办法可以用来将一个索引以到新的表空间。<br style="line-height: 25px" />Alter index ------ rebuild&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">tablespace -----。<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">这个命令的执行步骤如下：<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">首先，逐一读取现有索引，以获取索引的关键字。<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">其次，按新的结构填写临时数据段。<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">最后，一旦操作成功，删除原有索引树，降临时数据段重命名为新的索引。<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">需要注意的是alter index ---rebuild 命令中必须使用tablespace字句，以保证重建工作是在现有索引相同的表空间进行。<br style="line-height: 25px" />3).alter index ----- coalesce 使用带有coalesce参数时重建期间不需要额外空间，它只是在重建索引时将处于同一个索引分支内的叶块拼合起来，这最大限度的减少了与查询过程中相关的潜在的加锁问题，但是，coalesce选项不能用来讲一个索引转移到其他表空间。<br style="line-height: 25px" /></span><br style="line-height: 25px" /><span style="line-height: 21px; word-wrap: normal; word-break: normal; font-weight: bold">八：其他</span><br style="line-height: 25px" /><strong style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">1：truncate 分区操作和truncate 普通表的区别<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">Truncate 分区操作会导致全局索引失效; truncate 普通表对索引没有影响；<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">Truncate 分区操作不会释放全局索引中的空间，而truncate 普通表会释放索引所占空间；<br style="line-height: 25px" />&nbsp;<wbr style="line-height: 25px">&nbsp;&nbsp;<wbr style="line-height: 25px">2：rename 表名操作对索引没有影响，因为rename操作只是更改了数据字典，表中数据行的rowid并没有发生变化</strong></p><img src ="http://www.blogjava.net/xinyoulinglei/aggbug/401118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xinyoulinglei/" target="_blank">Lenovo123</a> 2013-07-01 19:29 <a href="http://www.blogjava.net/xinyoulinglei/articles/401118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle hint</title><link>http://www.blogjava.net/xinyoulinglei/articles/401117.html</link><dc:creator>Lenovo123</dc:creator><author>Lenovo123</author><pubDate>Mon, 01 Jul 2013 10:52:00 GMT</pubDate><guid>http://www.blogjava.net/xinyoulinglei/articles/401117.html</guid><wfw:comment>http://www.blogjava.net/xinyoulinglei/comments/401117.html</wfw:comment><comments>http://www.blogjava.net/xinyoulinglei/articles/401117.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xinyoulinglei/comments/commentRss/401117.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xinyoulinglei/services/trackbacks/401117.html</trackback:ping><description><![CDATA[<span style="background-color: #ccffff">1. /*+ALL_ROWS*/</span><br /><span style="background-color: #ccffff">表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO=&#8217;SCOTT&#8217;;</span><br /><span style="background-color: #ccffff">2. /*+FIRST_ROWS*/</span><br /><span style="background-color: #ccffff">表明对语句块选择基于开销的优化方法,并获得最佳响应时间,使资源消耗最小化.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+FIRST_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO=&#8217;SCOTT&#8217;;</span><br /><br /><span style="background-color: #ccffff">3. /*+CHOOSE*/</span><br /><span style="background-color: #ccffff">表明如果数据字典中有访问表的统计信息,将基于开销的优化方法,并获得最佳的吞吐量;</span><br /><span style="background-color: #ccffff">表明如果数据字典中没有访问表的统计信息,将基于规则开销的优化方法;</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+CHOOSE*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO=&#8217;SCOTT&#8217;;</span><br /><br /><span style="background-color: #ccffff">4. /*+RULE*/</span><br /><span style="background-color: #ccffff">表明对语句块选择基于规则的优化方法.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+ RULE */ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO=&#8217;SCOTT&#8217;;</span><br /><br /><span style="background-color: #ccffff">5. /*+FULL(TABLE)*/</span><br /><span style="background-color: #ccffff">表明对表选择全局扫描的方法.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM FROM BSEMPMS A WHERE EMP_NO=&#8217;SCOTT&#8217;;</span><br /><br /><span style="background-color: #ccffff">6. /*+ROWID(TABLE)*/</span><br /><span style="background-color: #ccffff">提示明确表明对指定表根据ROWID进行访问.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+ROWID(BSEMPMS)*/ * FROM BSEMPMS WHERE ROWID&gt;=&#8217;AAAAAAAAAAAAAA&#8217;</span><br /><span style="background-color: #ccffff">AND EMP_NO=&#8217;SCOTT&#8217;;</span><br /><br /><span style="background-color: #ccffff">7. /*+CLUSTER(TABLE)*/</span><br /><span style="background-color: #ccffff">提示明确表明对指定表选择簇扫描的访问方法,它只对簇对象有效.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+CLUSTER */ BSEMPMS.EMP_NO,DPT_NO FROM BSEMPMS,BSDPTMS</span><br /><span style="background-color: #ccffff">WHERE DPT_NO=&#8217;TEC304&#8242; AND BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br /><br /><span style="background-color: #ccffff">8. /*+INDEX(TABLE INDEX_NAME)*/</span><br /><span style="background-color: #ccffff">表明对表选择索引的扫描方法.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+INDEX(BSEMPMS SEX_INDEX) USE SEX_INDEX BECAUSE THERE ARE FEWMALE BSEMPMS */ FROM BSEMPMS WHERE SEX=&#8217;M';</span><br /><br /><span style="background-color: #ccffff">9. /*+INDEX_ASC(TABLE INDEX_NAME)*/</span><br /><span style="background-color: #ccffff">表明对表选择索引升序的扫描方法.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+INDEX_ASC(BSEMPMS PK_BSEMPMS) */ FROM BSEMPMS WHERE DPT_NO=&#8217;SCOTT&#8217;;</span><br /><br /><span style="background-color: #ccffff">10. /*+INDEX_COMBINE*/</span><br /><span style="background-color: #ccffff">为指定表选择位图访问路经,如果INDEX_COMBINE中没有提供作为参数的索引,将选择出位图索引的布尔组合方式.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+INDEX_COMBINE(BSEMPMS SAL_BMI HIREDATE_BMI)*/ * FROM BSEMPMS</span><br /><span style="background-color: #ccffff">WHERE SAL&lt;5000000 AND HIREDATE</span><br /><br /><span style="background-color: #ccffff">11. /*+INDEX_JOIN(TABLE INDEX_NAME)*/</span><br /><span style="background-color: #ccffff">提示明确命令优化器使用索引作为访问路径.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+INDEX_JOIN(BSEMPMS SAL_HMI HIREDATE_BMI)*/ SAL,HIREDATE</span><br /><span style="background-color: #ccffff">FROM BSEMPMS WHERE SAL&lt;60000;</span><br /><br /><span style="background-color: #ccffff">12. /*+INDEX_DESC(TABLE INDEX_NAME)*/</span><br /><span style="background-color: #ccffff">表明对表选择索引降序的扫描方法.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+INDEX_DESC(BSEMPMS PK_BSEMPMS) */ FROM BSEMPMS WHERE DPT_NO='SCOTT';</span><br /><br /><span style="background-color: #ccffff">13. /*+INDEX_FFS(TABLE INDEX_NAME)*/</span><br /><span style="background-color: #ccffff">对指定的表执行快速全索引扫描,而不是全表扫描的办法.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+INDEX_FFS(BSEMPMS IN_EMPNAM)*/ * FROM BSEMPMS WHERE DPT_NO='TEC305';</span><br /><br /><span style="background-color: #ccffff">14. /*+ADD_EQUAL TABLE INDEX_NAM1,INDEX_NAM2,...*/</span><br /><span style="background-color: #ccffff">提示明确进行执行规划的选择,将几个单列索引的扫描合起来.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+INDEX_FFS(BSEMPMS IN_DPTNO,IN_EMPNO,IN_SEX)*/ * FROM BSEMPMS WHERE EMP_NO='SCOTT' AND DPT_NO='TDC306';</span><br /><br /><span style="background-color: #ccffff">15. /*+USE_CONCAT*/</span><br /><span style="background-color: #ccffff">对查询中的WHERE后面的OR条件进行转换为UNION ALL的组合查询.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+USE_CONCAT*/ * FROM BSEMPMS WHERE DPT_NO='TDC506' AND SEX='M';</span><br /><br /><span style="background-color: #ccffff">16. /*+NO_EXPAND*/</span><br /><span style="background-color: #ccffff">对于WHERE后面的OR 或者IN-LIST的查询语句,NO_EXPAND将阻止其基于优化器对其进行扩展.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+NO_EXPAND*/ * FROM BSEMPMS WHERE DPT_NO='TDC506' AND SEX='M';</span><br /><br /><span style="background-color: #ccffff">17. /*+NOWRITE*/</span><br /><span style="background-color: #ccffff">禁止对查询块的查询重写操作.</span><br /><br /><span style="background-color: #ccffff">18. /*+REWRITE*/</span><br /><span style="background-color: #ccffff">可以将视图作为参数.</span><br /><br /><span style="background-color: #ccffff">19. /*+MERGE(TABLE)*/</span><br /><span style="background-color: #ccffff">能够对视图的各个查询进行相应的合并.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+MERGE(V) */ A.EMP_NO,A.EMP_NAM,B.DPT_NO FROM BSEMPMS A (SELET DPT_NO</span><br /><span style="background-color: #ccffff">,AVG(SAL) AS AVG_SAL FROM BSEMPMS B GROUP BY DPT_NO) V WHERE A.DPT_NO=V.DPT_NO</span><br /><span style="background-color: #ccffff">AND A.SAL&gt;V.AVG_SAL;</span><br /><br /><span style="background-color: #ccffff">20. /*+NO_MERGE(TABLE)*/</span><br /><span style="background-color: #ccffff">对于有可合并的视图不再合并.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+NO_MERGE(V) */ A.EMP_NO,A.EMP_NAM,B.DPT_NO FROM BSEMPMS A (SELECT DPT_NO,AVG(SAL) AS AVG_SAL FROM BSEMPMS B GROUP BY DPT_NO) V WHERE A.DPT_NO=V.DPT_NO AND A.SAL&gt;V.AVG_SAL;</span><br /><br /><span style="background-color: #ccffff">21. /*+ORDERED*/</span><br /><span style="background-color: #ccffff">根据表出现在FROM中的顺序,ORDERED使ORACLE依此顺序对其连接.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+ORDERED*/ A.COL1,B.COL2,C.COL3 FROM TABLE1 A,TABLE2 B,TABLE3 C WHERE A.COL1=B.COL1 AND B.COL1=C.COL1;</span><br /><br /><span style="background-color: #ccffff">22. /*+USE_NL(TABLE)*/</span><br /><span style="background-color: #ccffff">将指定表与嵌套的连接的行源进行连接,并把指定表作为内部表.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+ORDERED USE_NL(BSEMPMS)*/ BSDPTMS.DPT_NO,BSEMPMS.EMP_NO,BSEMPMS.EMP_NAM FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br /><br /><span style="background-color: #ccffff">23. /*+USE_MERGE(TABLE)*/</span><br /><span style="background-color: #ccffff">将指定的表与其他行源通过合并排序连接方式连接起来.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+USE_MERGE(BSEMPMS,BSDPTMS)*/ * FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br /><br /><span style="background-color: #ccffff">24. /*+USE_HASH(TABLE)*/</span><br /><span style="background-color: #ccffff">将指定的表与其他行源通过哈希连接方式连接起来.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+USE_HASH(BSEMPMS,BSDPTMS)*/ * FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br /><br /><span style="background-color: #ccffff">25. /*+DRIVING_SITE(TABLE)*/</span><br /><span style="background-color: #ccffff">强制与ORACLE所选择的位置不同的表进行查询执行.</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+DRIVING_SITE(DEPT)*/ * FROM BSEMPMS,DEPT@BSDPTMS WHERE BSEMPMS.DPT_NO=DEPT.DPT_NO;</span><br /><br /><span style="background-color: #ccffff">26. /*+LEADING(TABLE)*/</span><br /><span style="background-color: #ccffff">将指定的表作为连接次序中的首表.</span><br /><br /><span style="background-color: #ccffff">27. /*+CACHE(TABLE)*/</span><br /><span style="background-color: #ccffff">当进行全表扫描时,CACHE提示能够将表的检索块放置在缓冲区缓存中最近最少列表LRU的最近使用端</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+FULL(BSEMPMS) CAHE(BSEMPMS) */ EMP_NAM FROM BSEMPMS;</span><br /><br /><span style="background-color: #ccffff">28. /*+NOCACHE(TABLE)*/</span><br /><span style="background-color: #ccffff">当进行全表扫描时,CACHE提示能够将表的检索块放置在缓冲区缓存中最近最少列表LRU的最近使用端</span><br /><span style="background-color: #ccffff">例如:</span><br /><span style="background-color: #ccffff">SELECT /*+FULL(BSEMPMS) NOCAHE(BSEMPMS) */ EMP_NAM FROM BSEMPMS;</span><br /><br /><span style="background-color: #ccffff">29. /*+APPEND*/</span><br /><span style="background-color: #ccffff">直接插入到表的最后,可以提高速度.</span><br /><span style="background-color: #ccffff">insert /*+append*/ into test1 select * from test4 ;</span><br /><br /><span style="background-color: #ccffff">30. /*+NOAPPEND*/</span><br /><span style="background-color: #ccffff">通过在插入语句生存期内停止并行模式来启动常规插入.</span><br /><span style="background-color: #ccffff">insert /*+noappend*/ into test1 select * from test4 ;</span><img src ="http://www.blogjava.net/xinyoulinglei/aggbug/401117.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xinyoulinglei/" target="_blank">Lenovo123</a> 2013-07-01 18:52 <a href="http://www.blogjava.net/xinyoulinglei/articles/401117.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>