{"id":753,"date":"2013-03-24T23:25:10","date_gmt":"2013-03-24T15:25:10","guid":{"rendered":"http:\/\/www.yallonking.com\/?p=753"},"modified":"2013-03-27T09:53:32","modified_gmt":"2013-03-27T01:53:32","slug":"b%e6%a0%91%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"http:\/\/www.yallonking.com\/?p=753","title":{"rendered":"\u6709\u5173\u7d22\u5f15-B\u6811\u7d22\u5f15"},"content":{"rendered":"<p>B\u6811\u7d22\u5f15<br \/>\nB\u6811\u7d22\u5f15\u57fa\u7840\u77e5\u8bc6\uff1a<br \/>\n\t\u8868\u4e2d\u7684\u884c\u6807\u793a\u7b26\uff08rowid\uff09\u548c\u76f8\u5173\u7684\u5217\u503c\u5b58\u50a8\u5728\u4e00\u4e2a\u5e73\u8861\u7684\u6811\u72b6\u7ed3\u6784\u4e2d\u3002<\/p>\n<p>\u4f7f\u7528B\u6811\u7d22\u5f15\u7684\u539f\u56e0\uff1a<br \/>\n\t1\uff09\u63d0\u4f9bsql\u8bed\u53e5\u7684\u6027\u80fd<br \/>\n\t2\uff09\u5f3a\u5236\u6267\u884c\u4e3b\u952e\u548c\u552f\u4e00\u952e\u7ea6\u675f\u7684\u552f\u4e00\u6027<br \/>\n\t3\uff09\u51cf\u5c11\u901a\u8fc7\u4e3b\u952e\u548c\u5916\u952e\u7ea6\u675f\u5173\u8054\u7684\u7236\u8868\u548c\u5b50\u8868\u95f4\u6f5c\u5728\u7684\u9501\u8868\u95ee\u9898\uff0c\u5373\u5c31\u662f\u5916\u952e\u5217\u4e0a\u7f3a\u5c11B\u6811\u7d22\u5f15\u53ef\u80fd\u5bfc\u81f4\u8868\u9501\u5b9a\u95ee\u9898\u53d1\u751f<\/p>\n<p>\u6ce8\u610f\u4e8b\u9879\uff1a<br \/>\n\t1\uff09\u5efa\u8bae\u4e3a\u7d22\u5f15\u521b\u5efa\u5355\u72ec\u7684\u7d22\u5f15\u8868\u7a7a\u95f4\u4fbf\u4e8e\u7ba1\u7406\uff0c\u521b\u5efa\u65f6\u5efa\u8bae\u4f7f\u7528\u7edf\u4e00\u5927\u5c0f\u7684\u533a\u51cf\u5c11\u5bf9\u8c61\u521b\u5efa\u548c\u5220\u9664\u65f6\u7684\u788e\u7247\uff1b\u5982\u679c\u8be5\u7d22\u5f15\u8868\u7a7a\u95f4\u7684\u7d22\u5f15\u503e\u5411\u4e8e\u626b\u63cf\u7c7b\u7684\u7d22\u5f15\uff0c\u5efa\u8bae\u9009\u7528\u5927\u7684\u6570\u636e\u5757\uff0c\u4ee5\u51cf\u5c11I\/O\u3002<br \/>\n\t2\uff09\u4eceoracle11gr2\u5f00\u59cb\uff0c\u5728\u521b\u5efa\u8868\u7684\u65f6\u5019\u8fd8\u6ca1\u6709\u5411\u8868\u4e2d\u63d2\u5165\u6570\u636e\u65f6\uff0c\u76f8\u5173\u7684\u6bb5\u548c\u533a\u4f1a\u88ab\u63a8\u8fdf\u521b\u5efa\u3002<br \/>\n\t3\uff09\u4f7f\u4e00\u4e2a\u7d22\u5f15\u4e0d\u53ef\u89c1\uff08invisible\uff09\u5728oracle11g\u5f00\u59cb\u652f\u6301\u3002\u800c\u4e14\u4e0d\u53ef\u89c1\u7d22\u5f15\u4ecd\u7136\u7531oracle\u7ef4\u62a4\uff0c\u4f46\u662f\u67e5\u8be2\u4f18\u5316\u5668\u5728\u786e\u5b9a\u6267\u884c\u8ba1\u5212\u7684\u65f6\u5019\u4e0d\u8003\u8651\u5979\u3002<br \/>\n\t4\uff09\u5982\u679c\u9700\u8981\u5916\u952e\u7ea6\u675f\uff0c\u5219\u5fc5\u987b\u4f7f\u7528\u4e3b\u952e\u6216\u552f\u4e00\u952e\u7ea6\u675f\u3002<br \/>\n\t5\uff09\u5220\u9664\u4e3b\u952e\u7d22\u5f15\uff0c\u5fc5\u987b\u5148\u5220\u9664\u6216\u7981\u7528\u4e3b\u673a\u7ea6\u675f\u3002\u5728\u5220\u9664\u6216\u7981\u7528\u4e3b\u952e\u7ea6\u675f\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0d\u5220\u9664\u76f8\u5173\u7d22\u5f15\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<br \/>\n\t\talter table test drop constraint test_pk keep index;<br \/>\n\t6\uff09\u4f7f\u4e00\u4e2a\u7d22\u5f15\u4e0d\u53ef\u7528\uff08unusable\uff09\uff0coracle\u5c06\u4e0d\u4f1a\u518d\u7ef4\u62a4\u8fd9\u4e2a\u7d22\u5f15\uff0c\u5e76\u4e14\u4f18\u5316\u5668\u4e5f\u4e0d\u4f1a\u8003\u8651\u8be5\u7d22\u5f15\u3002\u5982\u679c\u9700\u8981\u518d\u6b21\u5c06\u4e00\u4e2a\u4e0d\u53ef\u7528\u7684\u7d22\u5f15\u518d\u6b21\u53ef\u7528\uff0c\u90a3\u4e48\u5fc5\u987b\u5c06\u5176\u91cd\u5efa\u3002<br \/>\n\t7\uff09\u5916\u952e\u5fc5\u987b\u521b\u5efaB\u6811\u7d22\u5f15\uff0c\u4e0d\u7136\u5f53\u5bf9\u5b50\u8868\u64cd\u4f5c\u65f6\uff0c\u7236\u8868\u4f1a\u88ab\u5168\u9501\u5b9a\u3002\u5982\u4f55\u67e5\u770b\u6570\u636e\u5e93\u54ea\u4e9b\u5916\u952e\u7f3a\u5931\u7d22\u5f15\uff0c\u53ef\u89c1\u811a\u672c\uff1ascripts:\u67e5\u770b\u5916\u952e\u7d22\u5f15\u662f\u5426\u5b58\u5728\uff08http:\/\/www.yallonking.com\/tools-scripts\/2013\/02\/737.html\uff09\u4ee5\u53ca\u300a\u5916\u952e\u7f3a\u5931\u7d22\u5f15\u5bfc\u81f4\u9501\u8868\u7684\u95ee\u9898\u300b\uff08http:\/\/www.yallonking.com\/database\/troubleshooting\/2013\/02\/739.html\uff09<\/p>\n<p>oracle\u5982\u4f55\u4f7f\u7528B\u6811\u7d22\u5f15\uff1a<br \/>\n\t1\uff09\u6240\u6709\u6570\u636e\u90fd\u5728\u7d22\u5f15\u5757\u4e2d<br \/>\n\t2\uff09\u7d22\u5f15\u4e2d\u4e0d\u5305\u542b\u6240\u6709\u4fe1\u606f<br \/>\n\t3\uff09\u53ea\u6709\u8868\u88ab\u8bbf\u95ee<\/p>\n<p>\u521b\u5efa\u7d22\u5f15\u524d\uff0c\u4f30\u7b97B\u6811\u7d22\u5f15\u7684\u5927\u5c0f\uff1a<\/p>\n<pre class=\"wp-code-highlight prettyprint\">\r\nSQL&gt; sho user\r\nUSER is &quot;SYS&quot;\r\nSQL&gt; conn test\/test \r\nConnected.\r\nSQL&gt; sho user\r\nUSER is &quot;TEST&quot;\r\nSQL&gt; select * from test;\r\n\r\nno rows selected\r\n\r\nSQL&gt; drop table test;\r\n\r\nTable dropped.\r\n\r\nSQL&gt; create table test as select rownum id,&#039;yallonking&#039; name from dual connect by level &lt;= 1000;\r\n\r\nTable created.\r\n\r\nSQL&gt; select * from test where rownum&lt;10;\r\n\r\n\t\tID NAME\r\n---------- ----------\r\n\t\t1 yallonking\r\n\t\t2 yallonking\r\n\t\t3 yallonking\r\n\t\t4 yallonking\r\n\t\t5 yallonking\r\n\t\t6 yallonking\r\n\t\t7 yallonking\r\n\t\t8 yallonking\r\n\t\t9 yallonking\r\n\r\n9 rows selected.\r\n\r\nSQL&gt; conn \/as sysdba\r\nConnected.\r\nSQL&gt; set serverout on\r\nSQL&gt; exec dbms_stats.gather_table_stats(&#039;TEST&#039;,&#039;TEST&#039;);\r\n\r\nPL\/SQL procedure successfully completed.\r\n\r\nSQL&gt; select to_char(LAST_ANALYZED,&#039;yyyy\/mm\/dd hh24:mi:ss&#039;) from dba_tables where TABLE_NAME =&#039;TEST&#039;;\r\n\r\nTO_CHAR(LAST_ANALYZ\r\n-------------------\r\n2013\/03\/24 07:51:44\r\nSQL&gt; variable used_bytes number\r\nSQL&gt; variable alloc_bytes number\r\nSQL&gt; exec dbms_space.create_index_cost(&#039;create index test_id on test(id)&#039;,:used_bytes,:alloc_bytes);\r\nBEGIN dbms_space.create_index_cost(&#039;create index test_id on test(id)&#039;,:used_bytes,:alloc_bytes); END;\r\n\r\n*\r\nERROR at line 1:\r\nORA-00942: table or view does not exist\r\nORA-06512: at &quot;SYS.DBMS_SPACE&quot;, line 1731\r\nORA-06512: at &quot;SYS.DBMS_SPACE&quot;, line 1752\r\nORA-06512: at line 1\r\n<\/pre>\n<p>\u6ce8\uff1a\u6b64\u5904\u7248\u672c\u4e0d\u652f\u6301<\/p>\n<pre class=\"wp-code-highlight prettyprint\">\r\nSQL&gt; select * from gv$version;\r\n\r\nINST_ID BANNER\r\n---------- ----------------------------------------------------------------\r\n\t\t1 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod\r\n\t\t1 PL\/SQL Release 10.2.0.1.0 - Production\r\n\t\t1 CORE 10.2.0.1.0      Production\r\n\t\t1 TNS for Linux: Version 10.2.0.1.0 - Production\r\n\t\t1 NLSRTL Version 10.2.0.1.0 - Production\r\n<\/pre>\n<p>\u91cd\u65b0\u572811g\u7248\u672c\u4e2d\u91cd\u590d\u4ee5\u4e0a\u6b65\u9aa4<\/p>\n<pre class=\"wp-code-highlight prettyprint\">\r\nSQL&gt; select * from gv$version;\r\n\r\nINST_ID BANNER\r\n---------- --------------------------------------------------------------------------------\r\n\t\t1 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production\r\n\t\t1 PL\/SQL Release 11.2.0.3.0 - Production\r\n\t\t1 CORE 11.2.0.3.0      Production\r\n\t\t1 TNS for Linux: Version 11.2.0.3.0 - Production\r\n\t\t1 NLSRTL Version 11.2.0.3.0 - Production\r\n\r\nSQL&gt; create table test as select rownum id,&#039;yallonking&#039; name from dual connect by level &lt;= 1000;\r\n\r\nTable created.\r\n\r\nSQL&gt; select * from test where rownum&lt;10;\r\n\r\n\t\tID NAME\r\n---------- ----------\r\n\t\t1 yallonking\r\n\t\t2 yallonking\r\n\t\t3 yallonking\r\n\t\t4 yallonking\r\n\t\t5 yallonking\r\n\t\t6 yallonking\r\n\t\t7 yallonking\r\n\t\t8 yallonking\r\n\t\t9 yallonking\r\n\r\n9 rows selected.\r\n\r\nSQL&gt; set serverout on\r\nSQL&gt; exec dbms_stats.gather_table_stats(&#039;SYS&#039;,&#039;TEST&#039;);\r\n\r\nPL\/SQL procedure successfully completed.\r\n\r\nSQL&gt; select to_char(LAST_ANALYZED,&#039;yyyy\/mm\/dd hh24:mi:ss&#039;) from dba_tables where TABLE_NAME =&#039;TEST&#039;;\r\n\r\nTO_CHAR(LAST_ANALYZ\r\n-------------------\r\n2013\/03\/24 22:58:48\r\n\r\nSQL&gt; variable used_bytes number\r\nSQL&gt; variable alloc_bytes number\r\nSQL&gt; exec dbms_space.create_index_cost(&#039;create index test_id on test(id)&#039;,:used_bytes,:alloc_bytes);\r\n\r\nPL\/SQL procedure successfully completed.\r\n\r\nSQL&gt; print :used_bytes\r\n\r\nUSED_BYTES\r\n----------\r\n\t4000\r\n\r\nSQL&gt; print :alloc_bytes\r\n\r\nALLOC_BYTES\r\n-----------\r\n\t65536\r\n\r\nSQL&gt; declare\r\n2  l_index_ddl varchar(1000);\r\n3  l_used_bytes number;\r\n4  l_allocated_bytes number;\r\n5  begin\r\n6  dbms_space.create_index_cost(\r\n7  ddl =&gt;&#039;create index test_id on test(id)&#039;,\r\n8  used_bytes=&gt;l_used_bytes,\r\n9  alloc_bytes =&gt;l_allocated_bytes);\r\n10  dbms_output.put_line(&#039;used =&#039;||l_used_bytes||&#039;bytes&#039;\r\n11  ||&#039;  allocated= &#039;|| l_allocated_bytes || &#039;bytes&#039;);\r\n12  end;\r\n13  \/\r\nused =4000bytes  allocated= 65536bytes\r\n\r\nPL\/SQL procedure successfully completed.\r\n<\/pre>\n<p>\u4ee5\u4e0b\u5728\u7d22\u5f15\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u572810g\u548c11g\u4e2d\u5747\u53ef\u67e5\u770boracle\u7ed9\u8be5\u7d22\u5f15\u5206\u914d\u7684\u7a7a\u95f4\u5927\u5c0f\uff1a<\/p>\n<pre class=\"wp-code-highlight prettyprint\">\r\nSQL&gt; create index test_id on test(id);\r\n\r\nIndex created.\r\n\r\nSQL&gt; COL SEGMENT_NAME FOR A20\r\nSQL&gt; select a.segment_name,a.tablespace_name,b.table_name,a.bytes\/1024\/1024 mbytes,a.blocks\r\n2  from dba_segments a, dba_indexes b\r\n3  where a.segment_name = b.index_name\r\n4  and a.segment_type = &#039;INDEX&#039;\r\n5  and b.index_name=&#039;TEST_ID&#039;\r\n6  group by a.tablespace_name,b.table_name,a.segment_name,a.blocks,a.bytes\/1024\/1024\r\n7  order by a.bytes\/1024\/1024 desc,a.tablespace_name,table_name;\r\n\r\nSEGMENT_NAME         TABLESPACE_NAME                TABLE_NAME                         MBYTES     BLOCKS\r\n-------------------- ------------------------------ ------------------------------ ---------- ----------\r\nTEST_ID              SYSTEM                         TEST                                .0625          8\r\n\r\nSQL&gt; SELECT 0.0625*1024*1024 FROM DUAL;\r\n\r\n0.0625*1024*1024\r\n----------------\r\n\t\t65536\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>B\u6811\u7d22\u5f15 B\u6811\u7d22\u5f15\u57fa\u7840\u77e5\u8bc6\uff1a \u8868\u4e2d\u7684\u884c\u6807\u793a\u7b26\uff08rowid\uff09\u548c\u76f8\u5173\u7684\u5217\u503c\u5b58\u50a8\u5728\u4e00\u4e2a\u5e73\u8861\u7684\u6811\u72b6\u7ed3\u6784\u4e2d\u3002 \u4f7f\u7528B\u6811\u7d22 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[87],"tags":[141,144,143,142],"_links":{"self":[{"href":"http:\/\/www.yallonking.com\/index.php?rest_route=\/wp\/v2\/posts\/753"}],"collection":[{"href":"http:\/\/www.yallonking.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yallonking.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yallonking.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yallonking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=753"}],"version-history":[{"count":7,"href":"http:\/\/www.yallonking.com\/index.php?rest_route=\/wp\/v2\/posts\/753\/revisions"}],"predecessor-version":[{"id":769,"href":"http:\/\/www.yallonking.com\/index.php?rest_route=\/wp\/v2\/posts\/753\/revisions\/769"}],"wp:attachment":[{"href":"http:\/\/www.yallonking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yallonking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yallonking.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}