1。如果你的表經(jīng)常由幾千萬(wàn)變成幾百萬(wàn),又變成幾千萬(wàn)那么需要制定分析計(jì)劃定期表分析,同時(shí)可以一并分析索引,計(jì)算索引中數(shù)據(jù)的分布情況,這樣CBO會(huì)選擇更加準(zhǔn)確的執(zhí)行計(jì)劃。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、重慶小程序開發(fā)公司、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了休寧縣免費(fèi)建站歡迎大家使用!
2。如果表結(jié)構(gòu)變化了也要做下,也就是經(jīng)常對(duì)表做dml就需要分析,現(xiàn)在推薦使用dbms_stats包。
全表還是全庫(kù)啊?
全表的話,可以針對(duì)某個(gè)用戶來(lái)分析:
SQL exec dbms_stats.gather_schema_stats(ownname='scott',options='gather auto',estimate_percent=dbms_stats.auto_sample_size,degree=6); 具體的參數(shù)可以根據(jù)實(shí)際情況修改,也可以加其他的參數(shù)進(jìn)來(lái)
全庫(kù)的話,10g會(huì)自動(dòng)分析的,但是也可以收到分析,統(tǒng)計(jì)分析要消耗大量資源,建議不要在業(yè)務(wù)繁忙時(shí)做:
SQL exec dbms_stats.gather_system_stats('start'); 開始
SQL exec dbms_stats.gather_system_stats('stop'); 結(jié)束
SQL exec dbms_stats.gather_system_stats('interval',interval=N); 一直工作N分鐘
analyze table 表名 compute statistics
analyze index 索引ID compute statistics
如果想分析所有的表名和index名可以從視圖user_tables,user_indexes取得相關(guān)的信息,自動(dòng)生成SQL命令
一.表分區(qū)策略
1.識(shí)別大表
采用ANALYZE TABLE語(yǔ)句進(jìn)行分析,然后查詢數(shù)據(jù)字典獲得相應(yīng)的數(shù)據(jù)量。
2.大表如何分區(qū)
可根據(jù)月份,季度以及年份等進(jìn)行分區(qū);
3.分區(qū)的表空間規(guī)劃
要對(duì)每個(gè)表空間的大小進(jìn)行估計(jì)
二.創(chuàng)建表分區(qū)
a.創(chuàng)建范圍分區(qū)的關(guān)鍵字是'RANGE'
1.范圍分區(qū)
create table ware_retail_part --創(chuàng)建一個(gè)描述商品零售的數(shù)據(jù)表
(
id integer primary key,--銷售編號(hào)
retail_date date,--銷售日期
ware_name varchar2(50)--商品名稱
)
partition by range(retail_date)
(
--2011年第一個(gè)季度為part_01分區(qū)
partition par_01 values less than(to_date('2011-04-01','yyyy-mm-dd')) tablespace TEMP01,
--2011年第二個(gè)季度為part_02分區(qū)
partition par_02 values less than(to_date('2011-07-01','yyyy-mm-dd')) tablespace TEMP01,
--2011年第三個(gè)季度為part_03分區(qū)
partition par_03 values less than(to_date('2011-10-01','yyyy-mm-dd')) tablespace TEMP01,
--2011年第四個(gè)季度為part_04分區(qū)
partition par_04 values less than(to_date('2012-01-01','yyyy-mm-dd')) tablespace TEMP01
);
2.創(chuàng)建散列分區(qū)
3.組合分區(qū):
4.interval 分區(qū)
三.創(chuàng)建索引分區(qū)
索引分區(qū)分為本地索引分區(qū)和全局索引分區(qū),全局索引不反應(yīng)基礎(chǔ)表的結(jié)構(gòu),要分區(qū)只能進(jìn)行范圍分區(qū)。
創(chuàng)建索引分區(qū)要參照表分區(qū)
四.分區(qū)技術(shù)簡(jiǎn)介
優(yōu)點(diǎn):
1.減少維護(hù)工作量
2.增強(qiáng)數(shù)據(jù)的可用性
3.均衡I/O,提升性能
4.提高查詢速度
5.分區(qū)對(duì)用戶保持透明,用戶感覺(jué)不到分區(qū)的存在。
五,管理表分區(qū)
1.添加表分區(qū)
ALTER TABLE...ALTER PARATITION
2.合并表分區(qū)
3.刪除分區(qū)
ALTER TABLE...DROP PARTITION
刪除分區(qū)時(shí),里面的數(shù)據(jù)也會(huì)被刪除。
-創(chuàng)建表和分區(qū)
create table sales--創(chuàng)建一個(gè)銷售記錄表
(
id number primary key,--記錄編號(hào)
goodsname varchar2(10),--商品名
saledate date--銷售日期
)
partition by range(saledate)--按照日期分區(qū)
(
--第一季度數(shù)據(jù)
partition part_sea1 values less than(to_date('2011-04-01','yyyy-mm-dd')) tablespace tbsp_1,
--第二季度數(shù)據(jù)
partition part_sea2 values less than(to_date('2011-07-01','yyyy-mm-dd')) tablespace tbsp_2,
--第三季度數(shù)據(jù)
partition part_sea3 values less than(to_date('2011-10-01','yyyy-mm-dd')) tablespace tbsp_1,
--第四季度數(shù)據(jù)
partition part_sea4 values less than(to_date('2012-01-01','yyyy-mm-dd')) tablespace tbsp_2
);
--創(chuàng)建局部索引
create index index_3_4 on sales(saledate)
local(
partition part_seal tablespace tbsp_1,
partition part_sea2 tablespace tbsp_2,
partition part_sea3 tablespace tbsp_1,
partition part_sea4 tablespace tbsp_2
);
--并入分區(qū)
alter table sales merge partitions part_sea3,part_sea4 into partition part_sea4;
--重建局部索引
alter table sales modify partition part_sea4 rebuild unusable local indexes;
六.管理索引分區(qū)
刪除索引:DROP PARTITION
重建分區(qū):REBUILT PARTITION
更名索引分區(qū):RENAME PARTITION
分割索引分區(qū):SPLIT PARTITION
參數(shù)說(shuō)明:
ownname:要分析表的擁有者
tabname:要分析的表名.
partname:分區(qū)的名字,只對(duì)分區(qū)表或分區(qū)索引有用.
estimate_percent:采樣行的百分比,取值范圍[0.000001,100],null為全部分析,不采樣. 常量:DBMS_STATS.AUTO_SAMPLE_SIZE是默認(rèn)值,由oracle決定最佳取采樣值.
block_sapmple:是否用塊采樣代替行采樣.
method_opt:決定histograms信息是怎樣被統(tǒng)計(jì)的.method_opt的取值如下:
for all columns:統(tǒng)計(jì)所有列的histograms.
for all indexed columns:統(tǒng)計(jì)所有indexed列的histograms.
for all hidden columns:統(tǒng)計(jì)你看不到列的histograms
for columns SIZE | REPEAT | AUTO | SKEWONLY:統(tǒng)計(jì)指定列的histograms.N的取值范圍[1,254]; REPEAT上次統(tǒng)計(jì)過(guò)的histograms;AUTO由oracle決定N的大小;SKEWONLY multiple end-points with the same value which is what we define by "there is skew in the data
degree:決定并行度.默認(rèn)值為null.
granularity:Granularity of statistics to collect ,only pertinent if the table is partitioned.
cascace:是收集索引的信息.默認(rèn)為falase.
stattab指定要存儲(chǔ)統(tǒng)計(jì)信息的表,statid假如多個(gè)表的統(tǒng)計(jì)信息存儲(chǔ)在同一個(gè)stattab中用于進(jìn)行區(qū)分.statown存儲(chǔ)統(tǒng)計(jì)信息表的擁有者.以上三個(gè)參數(shù)若不指定,統(tǒng)計(jì)信息會(huì)直接更新到數(shù)據(jù)字典.
no_invalidate: Does not invalidate the dependent cursors if set to TRUE. The procedure invalidates the dependent cursors immediately if set to FALSE.
force:即使表鎖住了也收集統(tǒng)計(jì)信息.
例子:
execute dbms_stats.gather_table_stats(ownname = 'owner',tabname = 'table_name' ,estimate_percent = null ,method_opt = 'for all indexed columns' ,cascade = true);
新聞名稱:oracle表分析怎么做 oracle總結(jié)
文章來(lái)源:http://aaarwkj.com/article46/hhhdhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、微信小程序、動(dòng)態(tài)網(wǎng)站、建站公司、標(biāo)簽優(yōu)化、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)