Oracle表刪除大量數(shù)據(jù)(千萬)后查詢變慢問題

          1. delete 后 TRUNCATE TABLE ;然后重新分析一下 (analyze table tablename compute statistics)。
           
          2.
          Oracle 表刪除大量數(shù)據(jù)后,即使表中只有幾行記錄,但用select count(*) from table 來查詢發(fā)覺都不會(huì)馬上出來,
          原因是該表的空間大了,查詢起來很慢。解決的方法是把該表所占用的表空間縮小,或者說釋放表空間。
          alter table XXXX move; 這樣處理后就釋放了表空間了。
          但是釋放表空間后,表的行號(hào)rowid會(huì)發(fā)生變化,而基于rowid的索引則會(huì)變成無效。因此該操作后必須重建索引。
          否則會(huì) 提示“ORA-01502: 索引'SMP.ITEMLOG_MID_IDX'或這類索引的分區(qū)處于不可用狀態(tài)”
          而重建索引的方法當(dāng)然可以先drop掉再create ,但是這樣太麻煩了,
          用alter index XXX rebuild 這樣最快了,不會(huì)改變?cè)瓉淼乃饕Y(jié)構(gòu)。

          3@URL>
          http://www.2cto.com/database/201106/94162.html

          Oracle分析表簡(jiǎn)介
          Oracle分析表是Oracle數(shù)據(jù)庫管理的重要部分,下面就為您詳細(xì)介紹Oracle分析表方面的知識(shí),希望對(duì)您學(xué)習(xí)Oracle分析表方
              面能有所幫助。
              1、分析SQL:
              analyze table tablename compute statistics
              等同于 analyze table tablename compute statistics for table for all indexes for all columns
              for table的統(tǒng)計(jì)信息存在于視圖:user_tables 、all_tables、dba_tables
              for all indexes的統(tǒng)計(jì)信息存在于視圖: user_indexes 、all_indexes、dba_indexes
              for all columns的統(tǒng)計(jì)信息存在于試圖:user_tab_columns、all_tab_columns、dba_tab_columns
              刪除分析SQL:
              analyze table tablename delete statistics 會(huì)刪除所有的statistics
              2、Oracle分析表的作用:為了使基于CBO的執(zhí)行計(jì)劃更加準(zhǔn)確
              DBA_tables的數(shù)據(jù)有變化,可做對(duì)比。詳見官方文檔:
              Use the ANALYZE statement to collect non-optimizer statistics, for example, to:
              Collect or delete statistics about an index or index partition, table or table partition, index-organized
              table, cluster, or scalar object attribute.
              Validate the structure of an index or index partition, table or table partition, index-organized table,
              cluster, or object reference (REF)。
              Identify migrated and chained rows of a table or cluster.
              dbms_stats的作用主要是替代analyze的收集統(tǒng)計(jì)信息這一塊的功能,且在這一方面做了相當(dāng)大程度上的增強(qiáng)。
              以analyze table table_name compute statistics;這條為例,生成的統(tǒng)計(jì)信息會(huì)存在于user_tables這個(gè)視圖,查看一下
              select * from user_tables where table_name=table_name;
              觀察一下NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN幾列你就會(huì)明白,這就是變化。

          posted on 2012-09-07 13:02 Dragon4s 閱讀(5255) 評(píng)論(0)  編輯  收藏 所屬分類: Oracle

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計(jì)

          留言簿

          文章分類(6)

          文章檔案(6)

          最新隨筆

          搜索

          最新評(píng)論

          主站蜘蛛池模板: 古蔺县| 色达县| 辽宁省| 敦化市| 英德市| 稷山县| 莎车县| 施秉县| 荣昌县| 辽源市| 江川县| 安吉县| 达日县| 缙云县| 县级市| 沧州市| 德安县| 万年县| 肥城市| 济宁市| 肥东县| 铁岭市| 响水县| 上蔡县| 龙岩市| 兰溪市| 包头市| 永宁县| 赣榆县| 南投县| 独山县| 古丈县| 新建县| 霸州市| 桐梓县| 民权县| 贡山| 钟祥市| 晋州市| 封丘县| 册亨县|