背景:
在前一篇文章中,我已经提到过index表空间写入次数是table表空间写入次数的10倍的原因之一是索引重建。那么是否有原因之二,原因之三呢?
分析:
我认为是有的,下面请先看看示例代码及AWR数据展示:
--create tablespace qqt and qqtinx , qqt store table data ,qqtinx store index data. create tablespace qqt datafile '+datadg' size 12g; create tablespace qqtinx datafile '+datadg' size 8g; --create table for T_orders create table hqq.T_orders tablespace qqt as select * from orders where rownum<1; --create index for hqq.T_ORDERS create index hqq.idx_TO_01 on hqq.so_master(no,period) tablespace qqtinx; create index hqq.idx_TO_02 on hqq.so_master (store_no) tablespace qqtinx; --create snapshot truncate table hqq.T_ORDERS; call sys.dbms_workload_repository.create_snapshot(); --initial data insert /*+ append */ into hqq.T_Orders select * from orders; commit; --create snapshot call sys.dbms_workload_repository.create_snapshot(); awr数据: Tablespace ------------------------------ Av Av Av Av Buffer Av Buf Reads Reads/s Rd(ms) Blks/Rd Writes Writes/s Waits Wt(ms) -------------- ------- ------- ------- ------------ -------- ---------- ------- QQTINX 8 0 2.5 1.0 70,407 65 0 0.0 QQT 1,305 1 1.3 1.0 39,939 37 0 0.0 从以上来的数据可以看出,当我将orders表全表插入T_ORDERS时,AWR中记录qqtinx的写入次数是QQT的1.8倍,由此我推断,当进行全表插入(大数量或bulk copy)时,ORACLE优化器会将多个table data block打包成一个IO请求发送到disk device上,以节省IO资源,提高IO利用率,但是为什么index block不会呢?可能与index的存储组织方式有关,不能打包发送,毕竟索引是b-tree嘛。 另外,这里又引发了一个问题,writes是否就等于io request呢? 我觉得当IO能力充足时,writes是等于io request的,反之writes会比io request大,这就说明出现io瓶颈,出现IO等待。争取在下一篇文章中完成这个问题的论证。