創建一個有組織的organized和一個無組織的disorganized表 估計每一個塊有100行 (1024*8)/80多
create table organized ( x int,y varchar2(80));
alter table organized add constraint organized_pk primary key(x);-------插入數據
begin
for i in 1..100000 loop
insert into organized values(i,rpad(dbms_random.random,75,'*'));
end loop;
commit;
end;create table disorganized ( x int,y varchar2(80));
alter table disorganized add constraint disorganized_pk primary key(x);
insert into disorganized select * from organized order by y;
commit;
SQL> alter system flush buffer_cache;
系統已更改。
SQL> select * from organized where x between 10000 and 20000;
已選擇10001行。
統計信息
----------------------------------------------------------
0 recursive calls
0 db block gets
1474 consistent gets
167 physical reads
0 redo size
907109 bytes sent via SQL*Net to client
7742 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10001 rows processed
tkprof信息 select * from organized where x between 10000 and 20000 和select * from disorganized where x between 10000 and 20000;都執行兩次
SQL ID : 67xw772s5tffx
select * from organized where x between 10000 and 20000
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.08 2 2 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 1336 0.10 0.25 192 2948 0 20002
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1340 0.10 0.33 194 2950 0 20002
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 128
Rows Row Source Operation
------- ---------------------------------------------------
10001 TABLE ACCESS BY INDEX ROWID ORGANIZED (cr=1474 pr=25 pw=25 time=373 us cost=124 size=826320 card=15024)
10001 INDEX RANGE SCAN ORGANIZED_PK (cr=687 pr=16 pw=16 time=104 us cost=30 size=0 card=15024)(object id 132693)
SQL> alter system flush buffer_cache;
系統已更改。
SQL> select * from disorganized where x between 10000 and 20000;
已選擇10001行。
統計信息
----------------------------------------------------------
0 recursive calls
0 db block gets
10688 consistent gets
1337 physical reads
0 redo size
907109 bytes sent via SQL*Net to client
7742 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10001 rows processed
tkprof信息
SQL ID : fkjyf68kwr6xy
select * from disorganized where x between 10000 and 20000
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 1336 0.34 9.12 2674 21376 0 20002
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1340 0.34 9.12 2674 21376 0 20002
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 128
Rows Row Source Operation
------- ---------------------------------------------------
10001 TABLE ACCESS BY INDEX ROWID DISORGANIZED (cr=10688 pr=1337 pw=1337 time=32704 us cost=118 size=521345 card=9479)
10001 INDEX RANGE SCAN DISORGANIZED_PK (cr=692 pr=145 pw=145 time=138 us cost=38 size=0 card=9479)(object id 132695)
物理讀和一致性讀明顯增多,通過執行多次最後求一個平均值,