自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

超詳細(xì)的Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更規(guī)范

數(shù)據(jù)庫(kù) 其他數(shù)據(jù)庫(kù)
很多時(shí)候我們都需要對(duì)某些大表去建索引或者重建,如果不正當(dāng)操作就很有可能會(huì)影響到生產(chǎn)環(huán)境,針對(duì)這個(gè)方面我寫了一些關(guān)于數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更的規(guī)范,僅供參考。

很多時(shí)候我們都需要對(duì)某些大表去建索引或者重建,如果不正當(dāng)操作就很有可能會(huì)影響到生產(chǎn)環(huán)境,針對(duì)這個(gè)方面我寫了一些關(guān)于數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更的規(guī)范,僅供參考。

一、索引創(chuàng)建前檢查

1. 檢查表段大?。?/p>

  1. select segment_name, bytes/1024/1024 MB from user_segments where segment_name='<表名>'

超詳細(xì)的Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更規(guī)范

2. 檢查表列不同值分布情況:

  1. select a.table_name, 
  2.  a.column_name, 
  3.  a.num_distinct, 
  4.  round(a.num_distinct * 100 / b.num_rows) "distinct percent%" 
  5.  from user_tab_columns a, user_tables b 
  6.  where a.table_name = b.table_name 
  7.  and a.table_name = 'ORDER_RELEASE_STATUS'

超詳細(xì)的Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更規(guī)范

這里可以看到一般不同值分布占全表記錄數(shù),如果percent%達(dá)到15%以上就可以建立索引提高效率

超詳細(xì)的Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更規(guī)范

二、索引創(chuàng)建

因?yàn)橹皵?shù)據(jù)庫(kù)規(guī)范沒建立,居然有一張表建立了255個(gè)字段,且索引建了50多個(gè)...

超詳細(xì)的Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更規(guī)范

1. 創(chuàng)建單列索引:

  1. create index index_name on table(col1) tablespace tbs_name [nologging] [online] [parallel n]; 
  2. alter index index_name noparallel ; 

2. 創(chuàng)建復(fù)合索引:

  1. create index index_name on table(col1,col2,…) tablespace tbs_name [nologging] [online][parallel n]; 
  2. alter index index_name noparallel ; 

3. 創(chuàng)建索引:

  1. create unique index index_name on table(col1,col2,…) tablespace tbs_name [nologging][online][parallel n]; 
  2. alter index index_name noparallel ; 

4. 創(chuàng)建分區(qū)索引:

Local 索引:

  1. 小表: 
  2. create index index_name on table(col1) local; 
  3. 大表: 
  4. 1)create index index_name on table(col1) local unusable; 
  5. 2)alter index index_name rebuild partition p_name [parallel n]; 
  6. alter index index_name noparallel ; 
  7. 3)execute dbms_stats.gather_index_stats(ownname=> '',indname=> '',) 

Global 索引:

  1. create [global] index index_name on table(col); 

5. 刪掉創(chuàng)建的索引

  1. drop index index_name; 

三、索引重建

1. 重建普通索引:

  1. alter index index_name rebuild tablespace w_data [online][ parallel n][ nologging];  
  2. alter index index_name noparallel ; 

2. 重建分區(qū)索引:

  1. alter index index_name rebuild partition partition_name tablespace tbs_name[online][parallel n][nologging]; 
  2. alter index index_name noparallel ; 

四、數(shù)據(jù)庫(kù)索引檢查

1. 普通索引檢查

  1. select index_name,table_name,status,tablespace_name from user_indexes;  

status 為 valid 表示索引狀態(tài)正常。

超詳細(xì)的Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更規(guī)范

2. 分區(qū)索引檢查

  1. select index_name,partition_name,status,tablespace_name from user_ind_partitions;  

status 為 usable 表示索引狀態(tài)正常。

超詳細(xì)的Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建及索引重建變更規(guī)范

最后提一點(diǎn),大家在建索引后一定要注意觀察數(shù)據(jù)庫(kù) SQL 執(zhí)行計(jì)劃是否 OK,執(zhí)行效率是否提高,然后監(jiān)控下應(yīng)用是否正常,不能創(chuàng)建完就拍拍屁股走人,后面會(huì)分享更多devops和DBA方面的內(nèi)容,感興趣的朋友可以關(guān)注下。

責(zé)任編輯:趙寧寧 來源: 今日頭條
相關(guān)推薦

2011-07-27 13:22:35

檢查索引碎片Oracle數(shù)據(jù)庫(kù)重建索引

2011-03-16 08:54:45

Oracle數(shù)據(jù)庫(kù)索引

2011-05-26 10:11:24

Oracle數(shù)據(jù)庫(kù)索引

2010-11-16 09:18:39

oracle重建索引

2019-08-20 09:46:14

DBA收藏腳本語言

2023-12-20 12:49:05

索引數(shù)據(jù)檢索數(shù)據(jù)庫(kù)

2022-03-24 20:44:53

數(shù)據(jù)庫(kù)索引SQL

2009-06-11 13:12:59

Oracle索引創(chuàng)建索引

2011-07-04 10:19:41

索引ONLINE

2011-07-27 11:08:49

Oracle數(shù)據(jù)庫(kù)EM Console重

2020-10-26 10:20:20

數(shù)據(jù)庫(kù)索引MySQL

2023-11-16 17:12:33

數(shù)據(jù)庫(kù)oracle

2010-04-19 13:31:42

Oracle索引

2019-08-01 07:31:51

數(shù)據(jù)庫(kù)主機(jī)日志

2010-10-26 16:33:54

創(chuàng)建Oracle索引

2010-04-07 17:45:22

Oracle位圖索引

2010-05-10 18:54:12

Oracle數(shù)據(jù)庫(kù)索引

2011-04-11 16:50:13

Oracle數(shù)據(jù)庫(kù)索引

2010-04-26 14:24:58

Oracle數(shù)據(jù)庫(kù)索引

2011-03-23 17:39:34

Oracle數(shù)據(jù)庫(kù)索引創(chuàng)建
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)