zoukankan      html  css  js  c++  java
  • Oracle 11G INDEX FULL SCAN 和 INDEX FAST FULL SCAN 对比分析

    SQL> drop table test;

    表已删除。

    SQL> create table test as select * from dba_objects where 1!=1;

    表已创建。

    SQL> create index idx_test_id on test(object_id);

    索引已创建。

    SQL> insert into test select * from dba_objects where object_id is not null and object_id >1000 order by object_id desc;

    已创建71863行。

    SQL> analyze table test compute statistics for table for all columns for all indexes;

    表已分析。

    SQL> select object_id from test where rownum<11;

    OBJECT_ID
    ----------
    75981
    75980
    75964
    75963
    75962
    75960
    75959
    75958
    75956
    75955

    已选择10行。


    执行计划
    ----------------------------------------------------------
    Plan hash value: 3931117773

    ---------------------------------------------------------------------------
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    ---------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | | 10 | 40 | 2 (0)| 00:00:01 |
    |* 1 | COUNT STOPKEY | | | | | |
    | 2 | TABLE ACCESS FULL| TEST | 10 | 40 | 2 (0)| 00:00:01 |
    ---------------------------------------------------------------------------

    Predicate Information (identified by operation id):
    ---------------------------------------------------

    1 - filter(ROWNUM<11)


    统计信息
    ----------------------------------------------------------
    1 recursive calls
    0 db block gets
    5 consistent gets
    0 physical reads
    0 redo size
    553 bytes sent via SQL*Net to client
    419 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    10 rows processed

    因为object_id 没有not null 约束,索引走了全部扫描.

    SQL> alter table test modify object_id not null;

    表已更改。

    SQL> select object_id from test where rownum<11;

    OBJECT_ID
    ----------
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010

    已选择10行。


    执行计划
    ----------------------------------------------------------
    Plan hash value: 1062221432

    -------------------------------------------------------------------------------------
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    -------------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | | 10 | 40 | 2 (0)| 00:00:01 |
    |* 1 | COUNT STOPKEY | | | | | |
    | 2 | INDEX FAST FULL SCAN| IDX_TEST_ID | 10 | 40 | 2 (0)| 00:00:01 |
    -------------------------------------------------------------------------------------

    Predicate Information (identified by operation id):
    ---------------------------------------------------

    1 - filter(ROWNUM<11)


    统计信息
    ----------------------------------------------------------
    141 recursive calls
    0 db block gets
    26 consistent gets
    0 physical reads
    0 redo size
    543 bytes sent via SQL*Net to client
    419 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    5 sorts (memory)
    0 sorts (disk)
    10 rows processed

    SQL> select /*+ index(test idx_test_id) */object_id from test where rownum<11;

    OBJECT_ID
    ----------
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010

    已选择10行。


    执行计划
    ----------------------------------------------------------
    Plan hash value: 2708872424

    --------------------------------------------------------------------------------
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    --------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | | 10 | 40 | 2 (0)| 00:00:01 |
    |* 1 | COUNT STOPKEY | | | | | |
    | 2 | INDEX FULL SCAN| IDX_TEST_ID | 10 | 40 | 2 (0)| 00:00:01 |
    --------------------------------------------------------------------------------

    Predicate Information (identified by operation id):
    ---------------------------------------------------

    1 - filter(ROWNUM<11)


    统计信息
    ----------------------------------------------------------
    1 recursive calls
    0 db block gets
    3 consistent gets
    0 physical reads
    0 redo size
    543 bytes sent via SQL*Net to client
    419 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    10 rows processed


    这里走INDEX FULL SCAN 和 INDEX FAST FULL SCAN 找到的数据相同只是一个巧合. 这说明索引做最左边的leaf block也同时是索引存储的最前的一个block.

    下面DUMP 出索引 来具体看看.


    SQL> select object_id from test where object_name='IDX_TEST_ID';

    OBJECT_ID
    ----------
    75981

    SQL> alter session set events 'immediate trace name treedump level 75981';

    会话已更改。

    下面是dump的全部信息.

    ----- begin tree dump
    branch: 0x45cd09 4574473 (0: nrow: 289, level: 1)
    leaf: 0x45cd0a 4574474 (-1: nrow: 416 rrow: 416)
    leaf: 0x45d222 4575778 (0: nrow: 262 rrow: 262)
    leaf: 0x45d221 4575777 (1: nrow: 262 rrow: 262)
    leaf: 0x45d220 4575776 (2: nrow: 262 rrow: 262)
    leaf: 0x45d21f 4575775 (3: nrow: 262 rrow: 262)
    leaf: 0x45d21e 4575774 (4: nrow: 262 rrow: 262)
    leaf: 0x45d21d 4575773 (5: nrow: 262 rrow: 262)
    leaf: 0x45d21c 4575772 (6: nrow: 262 rrow: 262)
    leaf: 0x45d21b 4575771 (7: nrow: 262 rrow: 262)
    leaf: 0x45d21a 4575770 (8: nrow: 262 rrow: 262)
    leaf: 0x45d219 4575769 (9: nrow: 262 rrow: 262)
    leaf: 0x45d218 4575768 (10: nrow: 262 rrow: 262)
    leaf: 0x45d217 4575767 (11: nrow: 262 rrow: 262)
    leaf: 0x45d216 4575766 (12: nrow: 262 rrow: 262)
    leaf: 0x45d215 4575765 (13: nrow: 262 rrow: 262)
    leaf: 0x45d214 4575764 (14: nrow: 269 rrow: 269)
    leaf: 0x45d213 4575763 (15: nrow: 262 rrow: 262)
    leaf: 0x45d212 4575762 (16: nrow: 262 rrow: 262)
    leaf: 0x45d211 4575761 (17: nrow: 262 rrow: 262)
    leaf: 0x45d210 4575760 (18: nrow: 267 rrow: 267)
    leaf: 0x45d20f 4575759 (19: nrow: 262 rrow: 262)
    leaf: 0x45d20e 4575758 (20: nrow: 262 rrow: 262)
    leaf: 0x45d20d 4575757 (21: nrow: 262 rrow: 262)
    leaf: 0x45d20c 4575756 (22: nrow: 262 rrow: 262)
    leaf: 0x45d20b 4575755 (23: nrow: 262 rrow: 262)
    leaf: 0x45d20a 4575754 (24: nrow: 262 rrow: 262)
    leaf: 0x45d209 4575753 (25: nrow: 262 rrow: 262)
    leaf: 0x45d208 4575752 (26: nrow: 262 rrow: 262)
    leaf: 0x45d207 4575751 (27: nrow: 262 rrow: 262)
    leaf: 0x45d206 4575750 (28: nrow: 262 rrow: 262)
    leaf: 0x45d205 4575749 (29: nrow: 262 rrow: 262)
    leaf: 0x45d204 4575748 (30: nrow: 262 rrow: 262)
    leaf: 0x45d203 4575747 (31: nrow: 259 rrow: 259)
    leaf: 0x45d202 4575746 (32: nrow: 246 rrow: 246)
    leaf: 0x45d201 4575745 (33: nrow: 246 rrow: 246)
    leaf: 0x45d200 4575744 (34: nrow: 246 rrow: 246)
    leaf: 0x45cfff 4575231 (35: nrow: 246 rrow: 246)
    leaf: 0x45cffe 4575230 (36: nrow: 246 rrow: 246)
    leaf: 0x45cffd 4575229 (37: nrow: 246 rrow: 246)
    leaf: 0x45cffc 4575228 (38: nrow: 246 rrow: 246)
    leaf: 0x45cffb 4575227 (39: nrow: 246 rrow: 246)
    leaf: 0x45cffa 4575226 (40: nrow: 246 rrow: 246)
    leaf: 0x45cff9 4575225 (41: nrow: 246 rrow: 246)
    leaf: 0x45cff8 4575224 (42: nrow: 246 rrow: 246)
    leaf: 0x45cff7 4575223 (43: nrow: 250 rrow: 250)
    leaf: 0x45cff6 4575222 (44: nrow: 246 rrow: 246)
    leaf: 0x45cff5 4575221 (45: nrow: 246 rrow: 246)
    leaf: 0x45cff4 4575220 (46: nrow: 246 rrow: 246)
    leaf: 0x45cff3 4575219 (47: nrow: 246 rrow: 246)
    leaf: 0x45cff2 4575218 (48: nrow: 246 rrow: 246)
    leaf: 0x45cff1 4575217 (49: nrow: 246 rrow: 246)
    leaf: 0x45cff0 4575216 (50: nrow: 246 rrow: 246)
    leaf: 0x45cfef 4575215 (51: nrow: 246 rrow: 246)
    leaf: 0x45cfee 4575214 (52: nrow: 246 rrow: 246)
    leaf: 0x45cfed 4575213 (53: nrow: 246 rrow: 246)
    leaf: 0x45cfec 4575212 (54: nrow: 246 rrow: 246)
    leaf: 0x45cfeb 4575211 (55: nrow: 248 rrow: 248)
    leaf: 0x45cfea 4575210 (56: nrow: 246 rrow: 246)
    leaf: 0x45cfe9 4575209 (57: nrow: 246 rrow: 246)
    leaf: 0x45cfe8 4575208 (58: nrow: 246 rrow: 246)
    leaf: 0x45cfe7 4575207 (59: nrow: 246 rrow: 246)
    leaf: 0x45cfe6 4575206 (60: nrow: 246 rrow: 246)
    leaf: 0x45cfe5 4575205 (61: nrow: 246 rrow: 246)
    leaf: 0x45cfe4 4575204 (62: nrow: 246 rrow: 246)
    leaf: 0x45cfe3 4575203 (63: nrow: 246 rrow: 246)
    leaf: 0x45cfe2 4575202 (64: nrow: 246 rrow: 246)
    leaf: 0x45cfe1 4575201 (65: nrow: 246 rrow: 246)
    leaf: 0x45cfe0 4575200 (66: nrow: 246 rrow: 246)
    leaf: 0x45cfdf 4575199 (67: nrow: 246 rrow: 246)
    leaf: 0x45cfde 4575198 (68: nrow: 248 rrow: 248)
    leaf: 0x45cfdd 4575197 (69: nrow: 246 rrow: 246)
    leaf: 0x45cfdc 4575196 (70: nrow: 246 rrow: 246)
    leaf: 0x45cfdb 4575195 (71: nrow: 246 rrow: 246)
    leaf: 0x45cfda 4575194 (72: nrow: 246 rrow: 246)
    leaf: 0x45cfd9 4575193 (73: nrow: 246 rrow: 246)
    leaf: 0x45cfd8 4575192 (74: nrow: 246 rrow: 246)
    leaf: 0x45cfd7 4575191 (75: nrow: 246 rrow: 246)
    leaf: 0x45cfd6 4575190 (76: nrow: 246 rrow: 246)
    leaf: 0x45cfd5 4575189 (77: nrow: 246 rrow: 246)
    leaf: 0x45cfd4 4575188 (78: nrow: 246 rrow: 246)
    leaf: 0x45cfd3 4575187 (79: nrow: 246 rrow: 246)
    leaf: 0x45cfd2 4575186 (80: nrow: 246 rrow: 246)
    leaf: 0x45cfd1 4575185 (81: nrow: 248 rrow: 248)
    leaf: 0x45cfd0 4575184 (82: nrow: 246 rrow: 246)
    leaf: 0x45cfcf 4575183 (83: nrow: 246 rrow: 246)
    leaf: 0x45cfce 4575182 (84: nrow: 246 rrow: 246)
    leaf: 0x45cfcd 4575181 (85: nrow: 246 rrow: 246)
    leaf: 0x45cfcc 4575180 (86: nrow: 246 rrow: 246)
    leaf: 0x45cfcb 4575179 (87: nrow: 246 rrow: 246)
    leaf: 0x45cfca 4575178 (88: nrow: 246 rrow: 246)
    leaf: 0x45cfc9 4575177 (89: nrow: 246 rrow: 246)
    leaf: 0x45cfc8 4575176 (90: nrow: 246 rrow: 246)
    leaf: 0x45cfc7 4575175 (91: nrow: 246 rrow: 246)
    leaf: 0x45cfc6 4575174 (92: nrow: 246 rrow: 246)
    leaf: 0x45cfc5 4575173 (93: nrow: 246 rrow: 246)
    leaf: 0x45cfc4 4575172 (94: nrow: 248 rrow: 248)
    leaf: 0x45cfc3 4575171 (95: nrow: 246 rrow: 246)
    leaf: 0x45cfc2 4575170 (96: nrow: 246 rrow: 246)
    leaf: 0x45cfc1 4575169 (97: nrow: 246 rrow: 246)
    leaf: 0x45cfc0 4575168 (98: nrow: 246 rrow: 246)
    leaf: 0x45cfbf 4575167 (99: nrow: 246 rrow: 246)
    leaf: 0x45cfbe 4575166 (100: nrow: 246 rrow: 246)
    leaf: 0x45cfbd 4575165 (101: nrow: 246 rrow: 246)
    leaf: 0x45cfbc 4575164 (102: nrow: 246 rrow: 246)
    leaf: 0x45cfbb 4575163 (103: nrow: 246 rrow: 246)
    leaf: 0x45cfba 4575162 (104: nrow: 246 rrow: 246)
    leaf: 0x45cfb9 4575161 (105: nrow: 246 rrow: 246)
    leaf: 0x45cfb8 4575160 (106: nrow: 246 rrow: 246)
    leaf: 0x45cfb7 4575159 (107: nrow: 248 rrow: 248)
    leaf: 0x45cfb6 4575158 (108: nrow: 246 rrow: 246)
    leaf: 0x45cfb5 4575157 (109: nrow: 246 rrow: 246)
    leaf: 0x45cfb4 4575156 (110: nrow: 246 rrow: 246)
    leaf: 0x45cfb3 4575155 (111: nrow: 246 rrow: 246)
    leaf: 0x45cfb2 4575154 (112: nrow: 246 rrow: 246)
    leaf: 0x45cfb1 4575153 (113: nrow: 246 rrow: 246)
    leaf: 0x45cfb0 4575152 (114: nrow: 246 rrow: 246)
    leaf: 0x45cfaf 4575151 (115: nrow: 246 rrow: 246)
    leaf: 0x45cfae 4575150 (116: nrow: 246 rrow: 246)
    leaf: 0x45cfad 4575149 (117: nrow: 246 rrow: 246)
    leaf: 0x45cfac 4575148 (118: nrow: 246 rrow: 246)
    leaf: 0x45cfab 4575147 (119: nrow: 246 rrow: 246)
    leaf: 0x45cfaa 4575146 (120: nrow: 248 rrow: 248)
    leaf: 0x45cfa9 4575145 (121: nrow: 246 rrow: 246)
    leaf: 0x45cfa8 4575144 (122: nrow: 246 rrow: 246)
    leaf: 0x45cfa7 4575143 (123: nrow: 246 rrow: 246)
    leaf: 0x45cfa6 4575142 (124: nrow: 246 rrow: 246)
    leaf: 0x45cfa5 4575141 (125: nrow: 246 rrow: 246)
    leaf: 0x45cfa4 4575140 (126: nrow: 246 rrow: 246)
    leaf: 0x45cfa3 4575139 (127: nrow: 246 rrow: 246)
    leaf: 0x45cfa2 4575138 (128: nrow: 246 rrow: 246)
    leaf: 0x45cfa1 4575137 (129: nrow: 246 rrow: 246)
    leaf: 0x45cfa0 4575136 (130: nrow: 246 rrow: 246)
    leaf: 0x45cf9f 4575135 (131: nrow: 246 rrow: 246)
    leaf: 0x45cf9e 4575134 (132: nrow: 246 rrow: 246)
    leaf: 0x45cf9d 4575133 (133: nrow: 248 rrow: 248)
    leaf: 0x45cf9c 4575132 (134: nrow: 246 rrow: 246)
    leaf: 0x45cf9b 4575131 (135: nrow: 246 rrow: 246)
    leaf: 0x45cf9a 4575130 (136: nrow: 246 rrow: 246)
    leaf: 0x45cf99 4575129 (137: nrow: 246 rrow: 246)
    leaf: 0x45cf98 4575128 (138: nrow: 246 rrow: 246)
    leaf: 0x45cf97 4575127 (139: nrow: 246 rrow: 246)
    leaf: 0x45cf96 4575126 (140: nrow: 246 rrow: 246)
    leaf: 0x45cf95 4575125 (141: nrow: 246 rrow: 246)
    leaf: 0x45cf94 4575124 (142: nrow: 246 rrow: 246)
    leaf: 0x45cf93 4575123 (143: nrow: 246 rrow: 246)
    leaf: 0x45cf92 4575122 (144: nrow: 246 rrow: 246)
    leaf: 0x45cf91 4575121 (145: nrow: 246 rrow: 246)
    leaf: 0x45cf90 4575120 (146: nrow: 248 rrow: 248)
    leaf: 0x45cf8f 4575119 (147: nrow: 246 rrow: 246)
    leaf: 0x45cf8e 4575118 (148: nrow: 246 rrow: 246)
    leaf: 0x45cf8d 4575117 (149: nrow: 246 rrow: 246)
    leaf: 0x45cf8c 4575116 (150: nrow: 246 rrow: 246)
    leaf: 0x45cf8b 4575115 (151: nrow: 246 rrow: 246)
    leaf: 0x45cf8a 4575114 (152: nrow: 246 rrow: 246)
    leaf: 0x45cf89 4575113 (153: nrow: 246 rrow: 246)
    leaf: 0x45cf88 4575112 (154: nrow: 246 rrow: 246)
    leaf: 0x45cf87 4575111 (155: nrow: 246 rrow: 246)
    leaf: 0x45cf86 4575110 (156: nrow: 246 rrow: 246)
    leaf: 0x45cf85 4575109 (157: nrow: 246 rrow: 246)
    leaf: 0x45cf84 4575108 (158: nrow: 246 rrow: 246)
    leaf: 0x45cf83 4575107 (159: nrow: 248 rrow: 248)
    leaf: 0x45cf82 4575106 (160: nrow: 246 rrow: 246)
    leaf: 0x45cf81 4575105 (161: nrow: 246 rrow: 246)
    leaf: 0x45cf80 4575104 (162: nrow: 246 rrow: 246)
    leaf: 0x45cdff 4574719 (163: nrow: 246 rrow: 246)
    leaf: 0x45cdfe 4574718 (164: nrow: 246 rrow: 246)
    leaf: 0x45cdfd 4574717 (165: nrow: 246 rrow: 246)
    leaf: 0x45cdfc 4574716 (166: nrow: 246 rrow: 246)
    leaf: 0x45cdfb 4574715 (167: nrow: 246 rrow: 246)
    leaf: 0x45cdfa 4574714 (168: nrow: 246 rrow: 246)
    leaf: 0x45cdf9 4574713 (169: nrow: 246 rrow: 246)
    leaf: 0x45cdf8 4574712 (170: nrow: 246 rrow: 246)
    leaf: 0x45cdf7 4574711 (171: nrow: 246 rrow: 246)
    leaf: 0x45cdf6 4574710 (172: nrow: 248 rrow: 248)
    leaf: 0x45cdf5 4574709 (173: nrow: 246 rrow: 246)
    leaf: 0x45cdf4 4574708 (174: nrow: 246 rrow: 246)
    leaf: 0x45cdf3 4574707 (175: nrow: 246 rrow: 246)
    leaf: 0x45cdf2 4574706 (176: nrow: 246 rrow: 246)
    leaf: 0x45cdf1 4574705 (177: nrow: 246 rrow: 246)
    leaf: 0x45cdf0 4574704 (178: nrow: 246 rrow: 246)
    leaf: 0x45cdef 4574703 (179: nrow: 246 rrow: 246)
    leaf: 0x45cdee 4574702 (180: nrow: 246 rrow: 246)
    leaf: 0x45cded 4574701 (181: nrow: 246 rrow: 246)
    leaf: 0x45cdec 4574700 (182: nrow: 246 rrow: 246)
    leaf: 0x45cdeb 4574699 (183: nrow: 246 rrow: 246)
    leaf: 0x45cdea 4574698 (184: nrow: 246 rrow: 246)
    leaf: 0x45cde9 4574697 (185: nrow: 248 rrow: 248)
    leaf: 0x45cde8 4574696 (186: nrow: 246 rrow: 246)
    leaf: 0x45cde7 4574695 (187: nrow: 246 rrow: 246)
    leaf: 0x45cde6 4574694 (188: nrow: 246 rrow: 246)
    leaf: 0x45cde5 4574693 (189: nrow: 246 rrow: 246)
    leaf: 0x45cde4 4574692 (190: nrow: 246 rrow: 246)
    leaf: 0x45cde3 4574691 (191: nrow: 246 rrow: 246)
    leaf: 0x45cde2 4574690 (192: nrow: 246 rrow: 246)
    leaf: 0x45cde1 4574689 (193: nrow: 246 rrow: 246)
    leaf: 0x45cde0 4574688 (194: nrow: 246 rrow: 246)
    leaf: 0x45cddf 4574687 (195: nrow: 246 rrow: 246)
    leaf: 0x45cdde 4574686 (196: nrow: 246 rrow: 246)
    leaf: 0x45cddd 4574685 (197: nrow: 246 rrow: 246)
    leaf: 0x45cddc 4574684 (198: nrow: 253 rrow: 253)
    leaf: 0x45cddb 4574683 (199: nrow: 246 rrow: 246)
    leaf: 0x45cdda 4574682 (200: nrow: 246 rrow: 246)
    leaf: 0x45cdd9 4574681 (201: nrow: 246 rrow: 246)
    leaf: 0x45cdd8 4574680 (202: nrow: 246 rrow: 246)
    leaf: 0x45cdd7 4574679 (203: nrow: 246 rrow: 246)
    leaf: 0x45cdd6 4574678 (204: nrow: 246 rrow: 246)
    leaf: 0x45cdd5 4574677 (205: nrow: 246 rrow: 246)
    leaf: 0x45cdd4 4574676 (206: nrow: 246 rrow: 246)
    leaf: 0x45cdd3 4574675 (207: nrow: 246 rrow: 246)
    leaf: 0x45cdd2 4574674 (208: nrow: 246 rrow: 246)
    leaf: 0x45cdd1 4574673 (209: nrow: 246 rrow: 246)
    leaf: 0x45cdd0 4574672 (210: nrow: 246 rrow: 246)
    leaf: 0x45cdcf 4574671 (211: nrow: 246 rrow: 246)
    leaf: 0x45cdce 4574670 (212: nrow: 246 rrow: 246)
    leaf: 0x45cdcd 4574669 (213: nrow: 252 rrow: 252)
    leaf: 0x45cdcc 4574668 (214: nrow: 246 rrow: 246)
    leaf: 0x45cdcb 4574667 (215: nrow: 250 rrow: 250)
    leaf: 0x45cdca 4574666 (216: nrow: 246 rrow: 246)
    leaf: 0x45cdc9 4574665 (217: nrow: 246 rrow: 246)
    leaf: 0x45cdc8 4574664 (218: nrow: 246 rrow: 246)
    leaf: 0x45cdc7 4574663 (219: nrow: 246 rrow: 246)
    leaf: 0x45cdc6 4574662 (220: nrow: 246 rrow: 246)
    leaf: 0x45cdc5 4574661 (221: nrow: 246 rrow: 246)
    leaf: 0x45cdc4 4574660 (222: nrow: 246 rrow: 246)
    leaf: 0x45cdc3 4574659 (223: nrow: 246 rrow: 246)
    leaf: 0x45cdc2 4574658 (224: nrow: 247 rrow: 247)
    leaf: 0x45cdc1 4574657 (225: nrow: 246 rrow: 246)
    leaf: 0x45cdc0 4574656 (226: nrow: 248 rrow: 248)
    leaf: 0x45cdbf 4574655 (227: nrow: 246 rrow: 246)
    leaf: 0x45cdbe 4574654 (228: nrow: 246 rrow: 246)
    leaf: 0x45cdbd 4574653 (229: nrow: 246 rrow: 246)
    leaf: 0x45cdbc 4574652 (230: nrow: 246 rrow: 246)
    leaf: 0x45cdbb 4574651 (231: nrow: 246 rrow: 246)
    leaf: 0x45cdba 4574650 (232: nrow: 246 rrow: 246)
    leaf: 0x45cdb9 4574649 (233: nrow: 246 rrow: 246)
    leaf: 0x45cdb8 4574648 (234: nrow: 246 rrow: 246)
    leaf: 0x45cdb7 4574647 (235: nrow: 246 rrow: 246)
    leaf: 0x45cdb6 4574646 (236: nrow: 246 rrow: 246)
    leaf: 0x45cdb5 4574645 (237: nrow: 246 rrow: 246)
    leaf: 0x45cdb4 4574644 (238: nrow: 246 rrow: 246)
    leaf: 0x45cdb3 4574643 (239: nrow: 253 rrow: 253)
    leaf: 0x45cdb2 4574642 (240: nrow: 246 rrow: 246)
    leaf: 0x45cdb1 4574641 (241: nrow: 246 rrow: 246)
    leaf: 0x45cdb0 4574640 (242: nrow: 246 rrow: 246)
    leaf: 0x45cdaf 4574639 (243: nrow: 246 rrow: 246)
    leaf: 0x45cdae 4574638 (244: nrow: 253 rrow: 253)
    leaf: 0x45cdad 4574637 (245: nrow: 246 rrow: 246)
    leaf: 0x45cdac 4574636 (246: nrow: 246 rrow: 246)
    leaf: 0x45cdab 4574635 (247: nrow: 246 rrow: 246)
    leaf: 0x45cdaa 4574634 (248: nrow: 248 rrow: 248)
    leaf: 0x45cda9 4574633 (249: nrow: 246 rrow: 246)
    leaf: 0x45cda8 4574632 (250: nrow: 246 rrow: 246)
    leaf: 0x45cd97 4574615 (251: nrow: 246 rrow: 246)
    leaf: 0x45cd96 4574614 (252: nrow: 252 rrow: 252)
    leaf: 0x45cd95 4574613 (253: nrow: 246 rrow: 246)
    leaf: 0x45cd94 4574612 (254: nrow: 246 rrow: 246)
    leaf: 0x45cd93 4574611 (255: nrow: 246 rrow: 246)
    leaf: 0x45cd92 4574610 (256: nrow: 246 rrow: 246)
    leaf: 0x45cd91 4574609 (257: nrow: 251 rrow: 251)
    leaf: 0x45cd90 4574608 (258: nrow: 248 rrow: 248)
    leaf: 0x45cd77 4574583 (259: nrow: 246 rrow: 246)
    leaf: 0x45cd76 4574582 (260: nrow: 246 rrow: 246)
    leaf: 0x45cd75 4574581 (261: nrow: 246 rrow: 246)
    leaf: 0x45cd74 4574580 (262: nrow: 249 rrow: 249)
    leaf: 0x45cd73 4574579 (263: nrow: 246 rrow: 246)
    leaf: 0x45cd72 4574578 (264: nrow: 246 rrow: 246)
    leaf: 0x45cd71 4574577 (265: nrow: 246 rrow: 246)
    leaf: 0x45cd70 4574576 (266: nrow: 246 rrow: 246)
    leaf: 0x45cd57 4574551 (267: nrow: 246 rrow: 246)
    leaf: 0x45cd56 4574550 (268: nrow: 246 rrow: 246)
    leaf: 0x45cd55 4574549 (269: nrow: 246 rrow: 246)
    leaf: 0x45cd54 4574548 (270: nrow: 246 rrow: 246)
    leaf: 0x45cd53 4574547 (271: nrow: 246 rrow: 246)
    leaf: 0x45cd52 4574546 (272: nrow: 246 rrow: 246)
    leaf: 0x45cd51 4574545 (273: nrow: 246 rrow: 246)
    leaf: 0x45cd50 4574544 (274: nrow: 246 rrow: 246)
    leaf: 0x45cd2f 4574511 (275: nrow: 246 rrow: 246)
    leaf: 0x45cd2e 4574510 (276: nrow: 246 rrow: 246)
    leaf: 0x45cd2d 4574509 (277: nrow: 246 rrow: 246)
    leaf: 0x45cd2c 4574508 (278: nrow: 246 rrow: 246)
    leaf: 0x45cd2b 4574507 (279: nrow: 246 rrow: 246)
    leaf: 0x45cd2a 4574506 (280: nrow: 246 rrow: 246)
    leaf: 0x45cd29 4574505 (281: nrow: 246 rrow: 246)
    leaf: 0x45cd28 4574504 (282: nrow: 246 rrow: 246)
    leaf: 0x45cd0f 4574479 (283: nrow: 246 rrow: 246)
    leaf: 0x45cd0e 4574478 (284: nrow: 246 rrow: 246)
    leaf: 0x45cd0d 4574477 (285: nrow: 246 rrow: 246)
    leaf: 0x45cd0c 4574476 (286: nrow: 246 rrow: 246)
    leaf: 0x45cd0b 4574475 (287: nrow: 246 rrow: 246)
    ----- end tree dump

    对于B*Tree Index的dump文件,稍微解释一下:

    branch/leaf代表该行是分支节点还是页节点(第一行的branch其实是root节点)。
    随后是该节点的rdba,前面是16进制的,后面是10进制的。
    括号里的第一个数字是同一个level的节点位置计数,root节点从0开始,其他的level从-1开始。
    nrow:节点中曾经有过的index entry数,
    rrow:节点中当前的index entry数,从这两个值可以分析出index的空间使用效率。
    对于branch节点,后面还有个level,叶节点隐含level为0,向上计数直到root。


    分析发现 下面的leaf 是最左边的leaf,同时也是最小的RDBA.
    leaf: 0x45cd0a 4574474 (-1: nrow: 416 rrow: 416) --RDBA 地址 4574474 是所有leaf中最小的,也就是物理存储在最前面的.

    这个叶子含有416条记录,那么也就是说让我们只选前416条记录的时候,INDEX FULL SCAN 和 INDEX FAST FULL SCAN 的结果相同.
    因为两者都只是读了同一个block.
    如果读两个block,那么

    INDEX FULL SCAN 这按照dump出来leaf从上到下的顺利读取前面两个leaf
    leaf: 0x45cd0a 4574474 (-1: nrow: 416 rrow: 416)
    leaf: 0x45d222 4575778 (0: nrow: 262 rrow: 262)

    INDEX FAST FULL SCAN 则按照 RDBA的顺读取下面两个block
    leaf: 0x45cd0a 4574474 (-1: nrow: 416 rrow: 416)
    leaf: 0x45cd0b 4574475 (287: nrow: 246 rrow: 246)

    我们参试查询前419条记录,它会读两个block,因为第一个block 4574474只含有 416条记录.

    SQL>select /*+ index(test idx_test_id) */object_id from test where rownum<420;

    OBJECT_ID
    ----------
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    .... //中间的记录省略
    1425
    1426
    1427
    1428
    1429
    1430

    已选择419行。
    执行计划
    ----------------------------------------------------------
    Plan hash value: 2708872424

    --------------------------------------------------------------------------------
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    --------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | | 419 | 1676 | 3 (0)| 00:00:01 |
    |* 1 | COUNT STOPKEY | | | | | |
    | 2 | INDEX FULL SCAN| IDX_TEST_ID | 419 | 1676 | 3 (0)| 00:00:01 |
    --------------------------------------------------------------------------------

    Predicate Information (identified by operation id):
    ---------------------------------------------------

    1 - filter(ROWNUM<420)


    统计信息
    ----------------------------------------------------------
    1 recursive calls
    0 db block gets
    31 consistent gets
    0 physical reads
    0 redo size
    6118 bytes sent via SQL*Net to client
    716 bytes received via SQL*Net from client
    29 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    419 rows processed

    SQL> select object_id from test where rownum<420;

    OBJECT_ID
    ----------
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    .... //中间的记录省略
    1425
    1426
    1427
    74733
    74734
    74735

    已选择419行。
    执行计划
    ----------------------------------------------------------
    Plan hash value: 1062221432

    -------------------------------------------------------------------------------------
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    -------------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | | 419 | 1676 | 2 (0)| 00:00:01 |
    |* 1 | COUNT STOPKEY | | | | | |
    | 2 | INDEX FAST FULL SCAN| IDX_TEST_ID | 419 | 1676 | 2 (0)| 00:00:01 |
    -------------------------------------------------------------------------------------

    Predicate Information (identified by operation id):
    ---------------------------------------------------

    1 - filter(ROWNUM<420)


    统计信息
    ----------------------------------------------------------
    1 recursive calls
    0 db block gets
    37 consistent gets
    0 physical reads
    0 redo size
    6121 bytes sent via SQL*Net to client
    716 bytes received via SQL*Net from client
    29 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    419 rows processed

    果然,此时结果出现了不同,下面的记录object_id 非常大,显然是最后一个块4574475的记录.
    74733
    74734
    74735

    查看RDBA =4574474 的leaf 的 file# 和 block#

    SQL>select dbms_utility.data_block_address_file('4574474') FILE_ID,dbms_utility.data_block_address_block('4574474') BLOCK_ID from dual;

    FILE_ID BLOCK_ID
    ---------- ----------
    1 380170
    生成DUMP
    SQL> alter system dump datafile 1 block 380170


    Block dump from cache:
    Dump of buffer cache at level 4 for tsn=0, rdba=4574474
    BH (0x2BFE8C40) file#: 1 rdba: 0x0045cd0a (1/380170) class: 1 ba: 0x2BCF4000
    .....//省略部分内容
    col 0; len 3; (3): c2 0b 02 //object_id = 1001
    col 1; len 6; (6): 00 45 d1 fc 00 00 //非扩展的rowid 又 file#+blcok#+row# 组成,前八位包括file#和block#
    row#1[2645] flag: ------, lock: 0, len=13
    col 0; len 3; (3): c2 0b 03
    col 1; len 6; (6): 00 45 d1 fb 00 4d
    row#2[2658] flag: ------, lock: 0, len=13
    col 0; len 3; (3): c2 0b 04
    col 1; len 6; (6): 00 45 d1 fb 00 4c
    row#3[2671] flag: ------, lock: 0, len=13
    col 0; len 3; (3): c2 0b 05
    col 1; len 6; (6): 00 45 d1 fb 00 4b
    row#4[2684] flag: ------, lock: 0, len=13
    col 0; len 3; (3): c2 0b 06
    col 1; len 6; (6): 00 45 d1 fb 00 4a
    row#5[2697] flag: ------, lock: 0, len=13
    col 0; len 3; (3): c2 0b 07
    col 1; len 6; (6): 00 45 d1 fb 00 49

    下面的数据证明 第一个索引行就是 object_id=1001 对应的索引记录
    SQL> select dump(1001,16) from dual;

    DUMP(1001,16)
    --------------------------------------
    Typ=2 Len=3: c2,b,2


    下面查看 object_id=1001 对应的rowid 的file# 和block#
    SQL> select
    dbms_rowid.rowid_relative_fno(rowid) file_id,
    dbms_rowid.rowid_block_number(rowid) block_id,
    dbms_rowid.rowid_row_number(rowid) row#
    from test
    where object_id=1001;


    FILE_ID BLOCK_ID ROW#
    ---------- ---------- ----------
    1 381436 0


    下面将object_id=1001对应的索引记录中存储的非扩展的16进制rowid "00 45 d1 fc 00 00" 转换得到file# blcok#

    先把16进制的前8位转换成 10进制数
    SQL> select to_number('0045d1fc','xxxxxxxx') RDBA from dual;

    RDBA
    ----------
    4575740

    将10进制的RDBA中提取中 file# 和blcok#
    SQL>select dbms_utility.data_block_address_file('4575740') FILE_ID,dbms_utility.data_block_address_block('4575740') BLOCK_ID from dual;

    FILE_ID BLOCK_ID
    ---------- ----------
    1 381436

    结果显示和前面直接用table记录里的扩展类型的rowid 得到的信息一致.


    SQL> select dbms_utility.data_block_address_file('4574475') FILE_ID,dbms_utility.data_block_address_block('4574475') BLOCK_ID from dual;

    FILE_ID BLOCK_ID
    ---------- ----------
    1 380171

    SQL> alter system dump datafile 1 block 380171;

    系统已更改。

    Block dump from cache:
    Dump of buffer cache at level 4 for tsn=0, rdba=4574475
    BH (0x2BFE8B6C) file#: 1 rdba: 0x0045cd0b (1/380171) class: 1 ba: 0x2BCF2000
    set: 5 pool 3 bsz: 8192 bsi: 0 sflg: 2 pwc: 351,28
    dbwrid: 0 obj: 75981 objn: 75981 tsn: 0 afn: 1 hint: f
    hash: [0x2C7F2FE0,0x48227468] lru: [0x2BFE8CEC,0x2BFE8B44]
    ckptq: [NULL] fileq: [NULL] objq: [0x2BFE8D04,0x2BFE88E0]
    st: XCURRENT md: NULL tch: 6
    flags: block_written_once redo_since_read
    LRBA: [0x0.0.0] LSCN: [0x0.0] HSCN: [0xffff.ffffffff] HSUB: [1]
    cr pin refcnt: 0 sh pin refcnt: 0
    .....//省略部分内容
    row#0[4596] flag: ------, lock: 0, len=14
    col 0; len 4; (4): c3 08 30 22 //object_id = 74733
    col 1; len 6; (6): 00 45 cd 04 00 25
    row#1[4610] flag: ------, lock: 0, len=14
    col 0; len 4; (4): c3 08 30 23
    col 1; len 6; (6): 00 45 cd 04 00 24
    row#2[4624] flag: ------, lock: 0, len=14
    col 0; len 4; (4): c3 08 30 24
    col 1; len 6; (6): 00 45 cd 04 00 23
    row#3[4638] flag: ------, lock: 0, len=14
    col 0; len 4; (4): c3 08 30 25
    col 1; len 6; (6): 00 45 cd 04 00 22
    row#4[4652] flag: ------, lock: 0, len=14

    下面的数据证明 第一个索引行就是 object_id=74733 对应的索引记录

    SQL> select dump(74733,16) from dual;

    DUMP(74733,16)
    ----------------------------------------------
    Typ=2 Len=4: c3,8,30,22

    我们也可以用下面的 PL/SQL 直接将dump出来的 16进制数据还原

    SQL> declare n number;
    2 begin
    3 dbms_stats.convert_raw_value('c3083022',n);
    4 dbms_output.put_line(n);
    5 end;
    6 /
    74733

    PL/SQL 过程已成功完成。

    下面的SQL也能做到.

    SQL> select utl_raw.cast_to_number('c3083022') from dual;

    UTL_RAW.CAST_TO_NUMBER('C3083022')
    ----------------------------------
    74733

    结论:当进行index full scan的时候 oracle定位到索引的root block,然后到branch block(如果有的话),再定位到第一个leaf block, 然后根据leaf block的双向链表顺序读取。它所读取的块都是有顺序的,也是经过排序的。

    而index fast full scan则不同,它是从段头开始,读取包含位图块,root block,所有的branch block, leaf block,读取的顺序完全有物理存储位置决定,并采取多块读,没次读取db_file_multiblock_read_count个块。

  • 相关阅读:
    关于公司电脑修改host文件无法生效的问题
    Cannot access nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public) in offline mode and the artifact org.springframework
    DCL-单例模式的线程安全
    关于volatile
    关于CAS中的ABA问题存在的隐患
    无法获取 dpkg 前端锁 (/var/lib/dpkg/lock-frontend),是否有其他进程正占用它
    vue整合笔记
    vue9-axios、细节和杂项
    vue8-vuex、路径配置别名、promise
    vue07-路由 vue-router、keep-alive、tab-bar
  • 原文地址:https://www.cnblogs.com/princessd8251/p/3612789.html
Copyright © 2011-2022 走看看