估计oracle中的索引创建时间

kur*_*ast 9 oracle indexing creation

我在Oracle环境中有一些表,我发现它可以从新索引中受益.然而,它们是大表,从1M寄存器到300M寄存器,所以我首先会尝试估计创建索引所需的时间,因此我至少知道它需要的数量级(小时) ,天,周)?

是否有一些启发式/ oracle功能/经验法则可以帮助我解决这个问题?

dcp*_*dcp 8

有太多因素需要考虑,例如机器速度,内存等可能影响创建时间的因素.此外,数据本身的性质可能会对创建时间产生重大影响.

我要做的是选择一个较大的表,在其上创建一个索引并查看它需要多长时间.然后,花费时间并除以表中的行数,这应该给出一个粗略的度量标准.请再次注意,这不是精确的,但它只是您可以使用的经验法则.它会变化很大,因为有些表有更多的列,更少的稀疏列值等,但它是一个起点.

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.
Run Code Online (Sandbox Code Playgroud)


Jon*_*ler 7

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);
Run Code Online (Sandbox Code Playgroud)

结果

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
Run Code Online (Sandbox Code Playgroud)

笔记

我的系统上的实际创建时间为2.5秒,而估计值为10秒.但是如果你只是在寻找一个数量级的估计,这仍然足够好.准确性取决于具有准确的表统计信息以及良好的系统统计信息.(但在收集系统统计信息之前要小心,它可能会影响很多执行计划!)您可以通过手动修改来进一步调整设置sys.aux_stats$.这是可以修改的少数SYS表之一,尽管你仍然需要小心.