Oracle可以使用EXPLAIN PLAN命令估计索引创建时间和索引大小:
示例架构
代码语言:javascript运行复制--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);结果
代码语言:javascript运行复制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表之一,尽管您仍然需要小心。