2010-06-18 20 views
8

我在Oracle環境中有一些表,我發現可以從新索引中受益。然而,它們是大表,從1M寄存器到300M寄存器,所以我會首先嚐試估計索引創建需要多少時間,所以我知道至少需要它的數量級(幾小時,幾天,幾周)?在oracle中估計索引創建時間

有一些啓發式/ oracle功能/經驗法則可以幫助我解決這個問題嗎?

回答

7

需要考慮的因素太多,如機器速度,內存等可能會影響創建時間。此外,數據本身的性質可能會對創作時間產生重大影響。

我會做的是從大表中選擇一個,在其上創建索引並查看需要多長時間。然後,花費時間併除以表格中的行數,這應該給你一個粗略的指標以預期結果。再次請注意,這不會很準確,但這只是您可以使用的經驗法則。它會變化很多,因爲一些表格有更多的列,更少的列值等,但這是一個起點。

Ex. It takes 3600 seconds to create a index on table X, which has 3 million rows. 
So the metric is 3600/3,000,000 = 0.0012 seconds per row. 

So if table Y has 8 million rows, you could expect 
.0012 * 8,000,000 = 9600 seconds (or 160 minutes) to create the index. 
+0

好的一點是要啓動一個基本原理。 – kurast 2010-06-18 19:44:24

5

Oracle可以估計與EXPLAIN PLAN命令索引創建時間和指數大小:

示例模式

--Create a table with 1 million rows. 
drop table table1; 
create table table1(a number); 
insert into table1 select level from dual connect by level <= 1000000; 
--Gather statistics. 
begin 
    dbms_stats.gather_table_stats(user, 'table1'); 
end; 
/
--Estimate index creation and size. 
explain plan for create index table1_idx on table1(a); 
select * from table(dbms_xplan.display); 

結果

Plan hash value: 290895522 

------------------------------------------------------------------------------------- 
| Id | Operation    | Name  | Rows | Bytes | Cost (%CPU)| Time  | 
------------------------------------------------------------------------------------- 
| 0 | CREATE INDEX STATEMENT |   | 1000K| 4882K| 683 (2)| 00:00:10 | 
| 1 | INDEX BUILD NON UNIQUE| TABLE1_IDX |  |  |   |   | 
| 2 | SORT CREATE INDEX |   | 1000K| 4882K|   |   | 
| 3 | TABLE ACCESS FULL | TABLE1  | 1000K| 4882K| 254 (5)| 00:00:04 | 
------------------------------------------------------------------------------------- 

Note 
----- 
    - automatic DOP: skipped because of IO calibrate statistics are missing 
    - estimated index size: 24M bytes 

筆記

我的系統上的實際創建時間爲2.5秒,而估計值爲10秒。但是,如果你只是在尋找一個數量級的估計,那還是很好的。準確度取決於具有精確的表格統計以及良好的system statistics。 (但在收集系統統計信息之前要小心,它可能會影響很多執行計劃!)您可以通過手動修改sys.aux_stats$來進一步調整設置。這是少數可以修改的SYS表格之一,儘管您仍然需要小心。