http://tech.it168.com/o/2006-04-09/200604091434742.shtml
作者:ahlu
SQL > create table test as select * from dba_objects; Table created. SQL > desc test Name Null ? Type -- --------------------------------------- -------- ---------------------------- OWNER VARCHAR2 ( 30 ) OBJECT_NAME VARCHAR2 ( 128 ) SUBOBJECT_NAME VARCHAR2 ( 30 ) OBJECT_ID NUMBER DATA_OBJECT_ID NUMBER OBJECT_TYPE VARCHAR2 ( 18 ) CREATED DATE LAST_DDL_TIME DATE TIMESTAMP VARCHAR2 ( 19 ) STATUS VARCHAR2 ( 7 ) TEMPORARY VARCHAR2 ( 1 ) GENERATED VARCHAR2 ( 1 ) SECONDARY VARCHAR2 ( 1 ) SQL > update test set owner = ' RAINY ' ; 6251 rows updated. SQL > commit ; Commit complete. SQL > create index test_ind on test(owner, object_id ); Index created. SQL > set autotrace traceonly SQL > select * from test where owner = ' RAINY ' and object_id = 2000 ; Execution Plan -- -------------------------------------------------------- 0 SELECT STATEMENT Optimizer = CHOOSE 1 0 TABLE ACCESS ( BY INDEX ROWID) OF ' TEST ' 2 1 INDEX (RANGE SCAN) OF ' TEST_IND ' (NON - UNIQUE ) Statistics -- -------------------------------------------------------- 0 recursive calls 0 db block gets 4 consistent gets 1 physical reads 0 redo size 1155 bytes sent via SQL * Net to client 499 bytes received via SQL * Net from client 2 SQL * Net roundtrips to / from client 0 sorts (memory) 0 sorts ( disk ) 1 rows processed SQL > drop index test_ind; Index dropped. SQL > update test set owner = rownum; 6251 rows updated. Execution Plan -- -------------------------------------------------------- 0 UPDATE STATEMENT Optimizer = CHOOSE 1 0 UPDATE OF ' TEST ' 2 1 COUNT 3 2 TABLE ACCESS ( FULL ) OF ' TEST ' Statistics -- -------------------------------------------------------- 164 recursive calls 6403 db block gets 97 consistent gets 0 physical reads 1557952 redo size 620 bytes sent via SQL * Net to client 528 bytes received via SQL * Net from client 3 SQL * Net roundtrips to / from client 6 sorts (memory) 0 sorts ( disk ) 6251 rows processed SQL > commit ; Commit complete. SQL > create index test_ind on test(owner, object_id ); Index created. SQL > select * from test where owner = ' 1234 ' and object_id = 2000 ; no rows selected Execution Plan -- -------------------------------------------------------- 0 SELECT STATEMENT Optimizer = CHOOSE 1 0 TABLE ACCESS ( BY INDEX ROWID) OF ' TEST ' 2 1 INDEX (RANGE SCAN) OF ' TEST_IND ' (NON - UNIQUE ) Statistics -- -------------------------------------------------------- 0 recursive calls 0 db block gets 2 consistent gets 1 physical reads 0 redo size 918 bytes sent via SQL * Net to client 368 bytes received via SQL * Net from client 1 SQL * Net roundtrips to / from client 0 sorts (memory) 0 sorts ( disk ) 0 rows processed
Re:
SQL > desc t Name Null ? Type -- --------------------------------------- -------- ---------------------------- OWNER VARCHAR2 ( 30 ) OBJECT_NAME VARCHAR2 ( 128 ) SUBOBJECT_NAME VARCHAR2 ( 30 ) OBJECT_ID NUMBER DATA_OBJECT_ID NUMBER OBJECT_TYPE VARCHAR2 ( 18 ) CREATED DATE LAST_DDL_TIME DATE TIMESTAMP VARCHAR2 ( 19 ) STATUS VARCHAR2 ( 7 ) TEMPORARY VARCHAR2 ( 1 ) GENERATED VARCHAR2 ( 1 ) SECONDARY VARCHAR2 ( 1 ) SQL > update t set owner = ' sys ' ; 481216 rows updated. SQL > commit ; Commit complete. SQL > update t set OBJECT_ID = rownum; 481216 rows updated. SQL > commit ; Commit complete. SQL > create index t_ind12 on t(owner, object_id ); Index created. SQL > set autotrace traceonly SQL > select * from t where owner = ' sys ' and object_id = 12345 ; Execution Plan -- -------------------------------------------------------- 0 SELECT STATEMENT Optimizer = CHOOSE 1 0 TABLE ACCESS ( BY INDEX ROWID) OF ' T ' 2 1 INDEX (RANGE SCAN) OF ' T_IND12 ' (NON - UNIQUE ) Statistics -- -------------------------------------------------------- 0 recursive calls 0 db block gets 5 consistent gets 2 physical reads 0 redo size 1156 bytes sent via SQL * Net to client 499 bytes received via SQL * Net from client 2 SQL * Net roundtrips to / from client 0 sorts (memory) 0 sorts ( disk ) 1 rows processed SQL > create index t_ind21 on t( object_id ,owner); Index created. SQL > select * from t where owner = ' sys ' and object_id = 12345 ; Execution Plan -- -------------------------------------------------------- 0 SELECT STATEMENT Optimizer = CHOOSE 1 0 TABLE ACCESS ( BY INDEX ROWID) OF ' T ' 2 1 INDEX (RANGE SCAN) OF ' T_IND21 ' (NON - UNIQUE ) Statistics -- -------------------------------------------------------- 0 recursive calls 0 db block gets 5 consistent gets 2 physical reads 0 redo size 1156 bytes sent via SQL * Net to client 499 bytes received via SQL * Net from client 2 SQL * Net roundtrips to / from client 0 sorts (memory) 0 sorts ( disk ) 1 rows processed SQL >
quote: 最初由 ahlu 发布
就想你看书一样,当你要看大多数页时,还不如直接去翻书,看目录反而慢。
在问个问题,每次取索引快时,使取出满足条件的一个块后直接去访问表,还是等取出所有满足条件的索引块后再去访问表?有什么办法使表中数据能顺序排列,这样当取出一个索引块后也能对应一个表块,如果无序状态下,可能一个索引块中的rowid会对应多个表块,并且其他索引块也会访问相同的表块,这可能造成极大的浪费,可能也是大量逻辑读产生的原因!
quote: 最初由 ahlu 发布
就想你看书一样,当你要看大多数页时,还不如直接去翻书,看目录反而慢。
在问个问题,每次取索引快时,使取出满足条件的一个块后直接去访问表,还是等取出所有满足条件的索引块后再去访问表?有什么办法使表中数据能顺序排列,这样当取出一个索引块后也能对应一个表块,如果无序状态下,可能一个索引块中的rowid会对应多个表块,并且其他索引块也会访问相同的表块,这可能造成极大的浪费,可能也是大量逻辑读产生的原因!
quote: 最初由 ahlu 发布
而无所谓是不是前导列,但我又在想在rule下,oracle没有统计资料,他怎么会知道哪个列范围大?