B Tree Index
Structure of the index:
1. Create a test table
CREATE TABLE it
(x number, y varchar2 (100));
2. Inserting 10,000 rows of data
Begin
For I in 1..100000
Loop
INSERT into it values (I,rpad (i,100, ' * '));
End Loop;
End
/
3. Create an index on the x column
CREATE index Idx_it on it (x);
4. Collecting table information
sql> exec dbms_stats.gather_table_stats (user, ' IT ', cascade=>true);
PL/SQL procedure successfully completed
5. Writing a dirty block to a file
alter system flush Buffer_cache;
6. Find out the object_id of the table it
Sql> Select object_id from dba_objects where object_name= ' idx_it ';
object_id
----------
86433
7.dump out the entire index structure
Sql> alter session SET events ' immediate trace name treedump level 86433 ';
Session altered.
Sql> SELECT * from V$diag_info where name= ' Default Trace File ';
inst_id NAME
---------- ----------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
1 Default Trace File
/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_5816.trc
8.VI Partial dump File
-----Begin Tree Dump
branch:0x1016403 16868355 (0:nrow:222, level:1)
leaf:0x1016404 16868356 ( -1:nrow:485 rrow:485)
leaf:0x1016405 16868357 (0:nrow:479 rrow:479)
leaf:0x1016406 16868358 (1:nrow:479 rrow:479)
leaf:0x1016407 16868359 (2:nrow:479 rrow:479)
leaf:0x1016408 16868360 (3:nrow:479 rrow:479)
leaf:0x1016409 16868361 (4:nrow:478 rrow:478)
leaf:0x101640a 16868362 (5:nrow:479 rrow:479)
leaf:0x101640b 16868363 (6:nrow:479 rrow:479)
leaf:0x101640c 16868364 (7:nrow:479 rrow:479)
leaf:0x101640d 16868365 (8:nrow:478 rrow:478)
leaf:0x101640e 16868366 (9:nrow:479 rrow:479)
leaf:0x101640f 16868367 (10:nrow:479 rrow:479)
leaf:0x1016411 16868369 (11:nrow:479 rrow:479)
leaf:0x1016412 16868370 (12:nrow:479 rrow:479)
leaf:0x1016413 16868371 (13:nrow:478 rrow:478)
leaf:0x1016414 16868372 (14:nrow:479 rrow:479)
leaf:0x1016415 16868373 (15:nrow:479 rrow:479)
leaf:0x1016416 16868374 (16:nrow:479 rrow:479)
leaf:0x1016417 16868375 (17:nrow:479 rrow:479)
leaf:0x1016418 16868376 (18:nrow:478 rrow:478)
leaf:0x1016419 16868377 (19:nrow:475 rrow:475)
leaf:0x101641a 16868378 (20:nrow:449 rrow:449)
leaf:0x101641b 16868379 (21:nrow:449 rrow:449)
leaf:0x101641c 16868380 (22:nrow:449 rrow:449)
leaf:0x101641d 16868381 (23:nrow:449 rrow:449)
leaf:0x101641e 16868382 (24:nrow:449 rrow:449)
leaf:0x101641f 16868383 (25:nrow:449 rrow:449)
leaf:0x1016421 16868385 (26:nrow:449 rrow:449)
leaf:0x1016422 16868386 (27:nrow:449 rrow:449)
leaf:0x1016423 16868387 (28:nrow:449 rrow:449)
leaf:0x1016424 16868388 (29:nrow:449 rrow:449)
leaf:0x1016425 16868389 (30:nrow:449 rrow:449)
leaf:0x1016426 16868390 (31:nrow:449 rrow:449)
leaf:0x1016427 16868391 (32:nrow:449 rrow:449)
leaf:0x1016428 16868392 (33:nrow:449 rrow:449)
leaf:0x1016429 16868393 (34:nrow:449 rrow:449)
leaf:0x101642a 16868394 (35:nrow:449 rrow:449)
The first column of each row represents the node type: branch represents the branch node (including the root node), while the leaf represents the leaf node;
The second column represents the address of the node represented by hexadecimal; DBA
The third column represents the address of the node represented by the decimal DBA
The fourth column represents the position relative to the previous node, the root node is calculated from 0, and the other branch and leaf nodes are calculated starting from 1
The nrow of the fifth column represents the number of index entries contained in the current node. For example, we can see that the root node contains a nrow of 9, indicating that the root node contains 9 index entries, pointing to 9 branch nodes respectively;
The level of the root node and the sixth column of the branch node represents the hierarchy of the branch node, which is 0 for the leaf node;
The Rrow in the sixth column of the leaf node represents a valid index entry (because the index entry is not immediately purged from the index block if it is deleted).
So the number of Nrow minus Rrow indicates the number of indexed entries that have been deleted, for example, for the first Leaf, whose rrow is 359, which means that the leaf node holds 359 usable index entries, pointing to 359 records of the table Warecountd, respectively.
9.
Sql> Select Dbms_utility.data_block_address_file (16868355) "File", Dbms_utility.data_block_address_block ( 16868355) "block" from dual;
File Block
---------- ----------
4 91139
Note: data_block_address_file:this function Gets the file number part of a data block address
To validate using a query view:
Sql> Select Header_file,header_block from dba_segments where segment_name= ' idx_it ';
Header_file Header_block
----------- ------------
4 91138
Note: This segment header file, so requires +1, so is the root node of index
10.dump out file 4 block 91139
sql> alter system dump DATAFILE 4 block 91139;
System altered.
Vi/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_5816.trc
Branch Block Dump
=================
Header Address 47125592066636=0x2adc482cca4c
Kdxcolev 1--where the Kdxcolev represents the index level number, because we dump the root node, its level number is 1
Kdxcolev Flags =---
Kdxcolok 0--kdxcolok Indicates whether a transaction that modifies the block structure is occurring on the index
KDXCOOPC 0x80:opcode=0:iot flags=---is converted=y--kdxcoopc represents internal operation code
Kdxconco 2--kdxconco represents the number of columns in an index entry (column ROWID, index value)
KDXCOSDC 0--KDXCOSDC Indicates the number of changes in the index structure, and when you modify an index key value in the table, the value increases;
Kdxconro 221--kdxconro represents the number of index entries in the current index node, but note that KDXBRLMC pointers are not included
Kdxcofbo 470=0x1d6--KDXCOFBO represents the amount of displacement of the free space in the current index node relative to the current block
Kdxcofeo 5868=0x16ec--kdxcofeo represents the amount of displacement relative to the current block at the end of the available space in the current index node
Kdxcoavs 5398--kdxcoavs represents the total amount of free space in the current index block, equal to the KDXCOFEO-KDXCOFBO obtained.
KDXBRLMC 16868356=0x1016404--KDXBRLMC represents the address of a branch node that holds all the node information for which the index key value is less than the minimum value contained in the Row#0 (the second half of the dump document is displayed)
Kdxbrsno 0--kdxbrsno represents the last modified index entry number, which is shown here as 0, indicating that the index is a new index;
Kdxbrbksz 8056--kdxbrbksz Indicates the amount of space available for a block of data
KDXBR2URRC 0
ROW#0[8047] dba:16868357=0x1016405
Col 0; Len 3; (3): C2--col 0 indicates the minimum key value that the branch node is linked to
Col 1; Term-if there are no other branch nodes under the root node, Col 1 is a term
ROW#1[8038] dba:16868358=0x1016406
Col 0; Len 3; (3): C2 0a 42
Col 1; Term
ROW#2[8029] dba:16868359=0x1016407
Col 0; Len 3; (3): C2 0f 2d
Col 1; Term
ROW#3[8020] dba:16868360=0x1016408
Col 0; Len 3; (3): C2 14 18
Col 1; Term
ROW#4[8011] dba:16868361=0x1016409
Col 0; Len 3; (3): C2 19 03
Col 1; Term
In the process of obtaining the final physical block, we cannot read more than one block at a time because we do not know which block to access next if we do not get the current block. Therefore, when the data block is accessed on the index, it corresponds to the DB file sequential read wait event, which is rooted in the fact that we jump from one index block to another in order to find the final index block
Then for a full table scan, there is no case to access the previous block before accessing the next block. When the full table is scanned, Oracle knows to access all the data blocks, so the only problem is to access them as efficiently as possible. As a result, Oracle can be synchronized in several batches, while acquiring multiple blocks of data. These batches of data blocks may be physically dispersed in the table, so they correspond to the db file scattered read wait event
2.B Tree Index for insertion (insert) management
For the first case, it is relatively simple. When you create an index on a table that is full of data (the CREATE INDEX command), Oracle scans the table's data and sorts it first, and then generates the leaf node. After all the leaf nodes are generated, several levels of branching nodes are generated based on the number of leaf nodes, and finally the root node is generated. This process is very clear.
3 byte wardrobe + 1 byte column length + 150 byte column itself + 1 bytes column length + 6 bytes rowID
When the first leaf node is filled, the split takes two available index blocks as new leaf nodes, and then copies all the index entries in the current leaf node to the two newly acquired leaf nodes,
Finally, the original leaf node is changed to the root node.
Analyze index idx_it validate structure;
One thing to note, though, is that the command has the disadvantage of locking the entire table during operation, blocking other sessions from inserting, updating, and deleting the table.
This is because the primary purpose of the command is not to populate the Index_stats view, but to verify that each valid index entry in the index corresponds to a row in the table.
At the same time, each row of data in the table has a corresponding index entry in the index. To accomplish this, the entire table is locked during the run,
At the same time, it takes a lot of time to run the command for a large table
Index deletion: summary
1) When deleting a record in the table, its corresponding index entry in the index will not be physically deleted, just a delete tag.
2) When a new index entry enters an index leaf node, Oracle checks to see if there is an index entry marked for deletion in the leaf node, and if so, all index entries with the delete tag are physically removed from the leaf node.
3) When a new index entry enters the index, Oracle reclaims all currently emptied leaf nodes (all index entries in the leaf node are set to delete tags) and becomes the usable index block again.
The method is simple for how to tell if an index is fragmented: Run Analyze index ... directly. VALIDATE STRUCTURE
command, and then check the pct_used field of the Index_stats view, if the field is too low (less than 50%), it means that there is fragmentation
Updates to Indexes
The update of the index is the combination of Delete + insert.
This article references: http://blog.csdn.net/csd_xuming/article/details/7542584
Learn a lot, thank you!
B Tree Index Learning Summary