Professional Documents
Culture Documents
Tamilselvan G
Be
In ac
Co f o t o n
rp ech
or
at
io
n
-5
ss
a
Cl
2007-11-25
Major
Major Types
Types of
of Indexes
Indexes
1.
1.
2.
2.
B*Tree
B*Tree Index
Index itithas
hassubtype
subtype also.
also.
Index
IndexOrganized
Organized Table
Table
3.
3.
4.
4.
Index
IndexCluster
Cluster
Function
FunctionBased
Based Index
Index
5.
5.
6.
6.
Reverse
Reverse Key
KeyIndex
Index
Descending
DescendingIndex
Index
7.
7.
8.
8.
Bit
Bit Map
MapIndex
Index
Application
Application Domain
DomainIndex
Index
9.
9. Intermedia
IntermediaText
Text Index
Index
10.
10.R*Tree
R*TreeIndex
Index
Beacon infotech Corporation
www.oracleact.com
2007-11-25
1. B-Tree Index
Index
IndexBlock
BlockStructure
Structure
Root
Root Block
Block
Branch
BranchBlock
Block
Leaf
Leaf Block
Block
One
One column
columnIndex
Index
Three
Three columns
columnsIndex
Index
Low
LowLevel
LevelProcessing
Processing
Myths
Mythsabout
aboutIndex
Index
2007-11-25
Branch Level 2
Branch Level 1
Branch Level 2
Branch Level 1
Branch Level 1
Branch Level 1
Leaf Level 0
Leaf Level 0
Leaf Level 0
Leaf Level 0
Leaf Level 0
Leaf Level 0
Leaf Level 0
Leaf Level 0
2007-11-25
B-Tree Index
Columns Indexed:
COUNT(*)
---------14,336,064
Index analyzed.
SQL> select name, height, blocks, lf_blks, br_blks, DEL_LF_ROWS from index_stats ;
NAME
------------
HEIGHT BLOCKS
---------- ----------
SALES_IDX_2
Beacon infotech Corporation
www.oracleact.com
204800
1431
2007-11-25
B-Tree Index
Note:
PCTFREE is not used in
branch blocks, hence they
are well packed.
The index height is 4 as you
see the highest level 3.
104921610 is the root block
and has 16 entries.
Root and branch blocks do
not have rrow.
NROW is the number of
slots in the block directory
currently in use.
RROW is the number that
would be in use after all
current transactions have
committed and the block has
been cleaned.
2007-11-25
B-Tree Index
2007-11-25
B-Tree Index
2007-11-25
B-Tree Index
2007-11-25
B-Tree Index
10
2007-11-25
B-Tree Index
11
2007-11-25
B-Tree Index
Single
Column
Index
12
2007-11-25
B-Tree Index
The tree dump shows:
Note:
To get multiple leaf blocks, I used PCTFREE 99.
Since the number of entries are only 30, there is no
branch blocks.
13
2007-11-25
B-Tree Index
Itl
Xid
Uba
Flag Lck
Scn/Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.06762c34
--- continued --
Key Value is NOT stored for the first block in the branch.
Beacon infotech Corporation
www.oracleact.com
14
2007-11-25
B-Tree Index
15
ID DUMP(ID,16)
------ -----------------------------30001 Typ=2 Len=4: c3,4,1,2
30002 Typ=2 Len=4: c3,4,1,3
30003 Typ=2 Len=4: c3,4,1,4
30004 Typ=2 Len=4: c3,4,1,5
30005 Typ=2 Len=4: c3,4,1,6
30006 Typ=2 Len=4: c3,4,1,7
30007 Typ=2 Len=4: c3,4,1,8
30008 Typ=2 Len=4: c3,4,1,9
30009 Typ=2 Len=4: c3,4,1,a
30010 Typ=2 Len=4: c3,4,1,b
30011 Typ=2 Len=4: c3,4,1,c
30012 Typ=2 Len=4: c3,4,1,d
30013 Typ=2 Len=4: c3,4,1,e
30014 Typ=2 Len=4: c3,4,1,f
30015 Typ=2 Len=4: c3,4,1,10
-------------30029 Typ=2 Len=4: c3,4,1,1e
30030 Typ=2 Len=4: c3,4,1,1f
30 rows selected.
2007-11-25
B-Tree Index
Itl
Xid
Uba
Flag Lck
Scn/Fsc
0x01 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
0x02 0xffff.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.06762c34
16
2007-11-25
B-Tree Index
17
2007-11-25
B-Tree Index
ID DUMP(ID,16)
DUMP(ROWID,16)
------ ------------------------------ ---------------------------------------30005 Typ=2 Len=4: c3,4,1,6
Typ=69 Len=10: 0,1,b,94,4,83,b6,a,0,4
18
2007-11-25
B-Tree Index
Three
Column
Index
19
2007-11-25
B-Tree Index
commit;
20
2007-11-25
B-Tree Index
Itl
Xid
Uba
Flag Lck
Scn/Fsc
0 scn 0x0000.067620bd
21
2007-11-25
B-Tree Index
Note: Watch out TERM in the branch data. Available space was 7997.
Roughly, 480 bytes (3 * 160) is needed for 3 entries in the branch block.
My assumption is: Oracle either compress all the key values or use
some hash value to store it in the col 1.
22
2007-11-25
B-Tree Index
ID NAME
---------- ---------15001 TAMIL
15002 SCOTT
15003 TANDON
15004 KUMAR
15005 PALANI
15006 SIVA
15007 SUDA
15008 APPULLY
15009 MANOJ
15010 MIKE
DUMP(ID,16)
DUMP(NAME,16)
-----------------------------------------------------Typ=2 Len=4: c3,2,33,2 Typ=1 Len=5: 54,41,4d,49,4c
Typ=2 Len=4: c3,2,33,3 Typ=1 Len=5: 53,43,4f,54,54
Typ=2 Len=4: c3,2,33,4 Typ=1 Len=6: 54,41,4e,44,4f,4e
Typ=2 Len=4: c3,2,33,5 Typ=1 Len=5: 4b,55,4d,41,52
Typ=2 Len=4: c3,2,33,6 Typ=1 Len=6: 50,41,4c,41,4e,49
Typ=2 Len=4: c3,2,33,7 Typ=1 Len=4: 53,49,56,41
Typ=2 Len=4: c3,2,33,8 Typ=1 Len=4: 53,55,44,41
Typ=2 Len=4: c3,2,33,9 Typ=1 Len=7: 41,50,50,55,4c,4c,59
Typ=2 Len=4: c3,2,33,a Typ=1 Len=5: 4d,41,4e,4f,4a
Typ=2 Len=4: c3,2,33,b Typ=1 Len=4: 4d,49,4b,45
10 rows selected.
23
2007-11-25
B-Tree Index
Itl
Xid
Uba
Flag Lck
Scn/Fsc
0x01 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
0x02 0xffff.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.067620bd
24
2007-11-25
B-Tree Index
--- MIKE
--- 15010
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78
78 78 78 78 78 78 78 78
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78
25
2007-11-25
B-Tree Index
Low Level
Processing
26
2007-11-25
B-Tree Index
27
2007-11-25
B-Tree Index
Get a treedump
Now I am going to insert one row and let see what happens in the index leaf
blocks.
28
2007-11-25
B-Tree Index
SQL> alter system set events 'immediate trace name treedump level 68504';
*** SESSION ID:(34.45141) 2006-05-22 20:42:43.420
----- begin tree dump
branch: 0x483840a 75727882 (0: nrow: 3, level: 1)
leaf: 0x483840b 75727883 (-1: nrow: 3 rrow: 3)
leaf: 0x483840c 75727884 (0: nrow: 4 rrow: 4) --- From 3 it went to 4
leaf: 0x483840d 75727885 (1: nrow: 1 rrow: 1)
----- end tree dump
Since the new key value start with B_xxxx, it went to the block, 75727884.
All the leaf blocks have lot of free space because I used PCTFREE 90.
29
2007-11-25
B-Tree Index
Now I am going to insert one row with NAME starting with C_XXXX and lets
see what happens in the index leaf blocks.
SQL> insert into my_table values (15008, 'C_KANNAN', rpad('x',150,'x')) ;
SQL> commit;
SQL> alter system set events 'immediate trace name treedump level 68504';
*** 2006-05-22 20:47:46.475
*** SESSION ID:(34.45144) 2006-05-22 20:47:46.474
----- begin tree dump
branch: 0x483840a 75727882 (0: nrow: 3, level: 1)
leaf: 0x483840b 75727883 (-1: nrow: 3 rrow: 3)
leaf: 0x483840c 75727884 (0: nrow: 5 rrow: 5)
leaf: 0x483840d 75727885 (1: nrow: 1 rrow: 1)
----- end tree dump
Note: Before inserting a new entry in a leaf block, Oracle has to find out the
highest block just lower than the incoming value.
This is one of reasons why FREELIST parameter should not be set more than 1
for indexes.
Beacon infotech Corporation
www.oracleact.com
30
2007-11-25
B-Tree Index
select object_id,
object_name
from user_objects
where object_name in
('MY_TABLE',
'MY_TABLE_IDX');
OBJECT_ID OBJECT_NAME
-----------------------68510
MY_TABLE_IDX
68509
MY_TABLE
SQL> alter system set events 'immediate trace name treedump level 68510' ;
System altered.
31
2007-11-25
B-Tree Index
Now I insert a row that has a name starting with C_XXXX and
let us see what happens to the index leaf blocks.
SQL> insert into my_table values (50007, 'C_SUBBU', rpad('x',2500,'x'));
1 row created.
SQL> commit;
Commit complete.
Beacon infotech Corporation
www.oracleact.com
32
2007-11-25
B-Tree Index
Even though the block 75727885 has only one row (for Name D_MIKE),
Oracle will not use that block for the new entry (NAME C_SUBBU) because it
always try to find the highest block just lower than the incoming value. Hence,
finally Oracle added a new block 75727886 for C_SUBBU.
33
2007-11-25
B-Tree Index
Low Level
Split
Processing
34
2007-11-25
B-Tree Index
OBJECT_ID OBJECT_NAME
---------- ---------------68510 MY_TABLE_IDX
68509 MY_TABLE
8 rows selected.
SQL> commit;
Commit complete.
35
2007-11-25
B-Tree Index
TREEDUMP
36
2007-11-25
B-Tree Index
SQL> commit;
Commit complete.
TREEDUMP
*** 2006-05-22 22:34:41.973
*** SESSION ID:(34.45531) 2006-05-22 22:34:41.972
----- begin tree dump
branch: 0x483840a 75727882 (0: nrow: 6, level: 1)
leaf: 0x483840b 75727883 (-1: nrow: 2 rrow: 2) -- Original row
leaf: 0x4838410 75727888 (0: nrow: 2 rrow: 2) --- New Block added
leaf: 0x483840f 75727887 (1: nrow: 1 rrow: 1)
leaf: 0x483840c 75727884 (2: nrow: 3 rrow: 3)
leaf: 0x483840e 75727886 (3: nrow: 1 rrow: 1)
leaf: 0x483840d 75727885 (4: nrow: 1 rrow: 1)
----- end tree dump
Beacon infotech Corporation
www.oracleact.com
37
When lowest
value is
inserted,
Oracle splits
the entries in
the block into
50:50.
2007-11-25
B-Tree Index
ID NAME
---------- ---------50001 A_ANBU
50002 A_SCOTT
50003 A_TANDON
50004 B_KUMAR
50005 B_PALANI
50006 B_SIVA
50010 D_MIKE
OBJECT_ID OBJECT_NAME
---------- --------------68514 MY_TABLE_IDX
68513 MY_TABLE
7 rows selected.
38
2007-11-25
B-Tree Index
SQL> commit;
Commit complete.
Beacon infotech Corporation
www.oracleact.com
39
2007-11-25
B-Tree Index
90:10 or
99:1 Split
happened
when a
middle
value is
inserted.
40
2007-11-25
B-Tree Index
41
2007-11-25
B-Tree Index
kdxlenxt 75727884=0x483840c
Partial dump
kdxleprv 75727883=0x483840b
kdxledsz 0
kdxlebksz 8032
row#0[5507] flag: -----, lock: 0
col 0; len 8; (8): 41 5f 54 41 4e 44 4f 4e -- A_TANDON
col 1; len 4; (4): c3 06 01 04
col 2; len 2500; (2500):
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78
(a lot of rows are deleted for readability)
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78
col 3; len 6; (6): 07 c0 32 0b 00 00
----- end of leaf block dump ----End dump data blocks tsn: 10 file#: 18 minblk 230414 maxblk 230414
42
2007-11-25
B-Tree Index
declare
M number ;
N Number := 200001;
begin
For M in 100001 .. 200000 LOOP
N := N - 1;
insert into my_table (id1,name, id2)
values
(M, 'XXXXXX', N);
commit;
END LOOP;
end;
/
spool off
----------
----------
200000
100001
---------200000
43
2007-11-25
B-Tree Index
Note:
COUNT(*)
---------100000
SQL> analyze index my_table_idx_1 validate structure;
Index analyzed.
SQL> select name, blocks, lf_blks, br_blks, distinct_keys from index_stats;
NAME
-------------MY_TABLE_IDX_1
394 leaf
blocks for
the
ascending
sequence vs
406 leaf
blocks for
the
descending
seq. The
difference is
not much.
BLOCKS
---------12800
44
2007-11-25
B-Tree Index
declare
M number ;
N Number := 200001;
begin
For M in 100001 .. 300000 LOOP
N := N - 1;
insert into my_table (id1,name, id2)
values
(M, 'XXXXXX', N);
commit;
END LOOP;
end;
/
spool off
This is a myth.
create table my_table
(id1 number(6),
name varchar2(10),
id2 number(6) );
BLOCKS
------------------------------
----------
MY_TABLE_IDX_1
12800
LF_BLKS
BR_BLKS
DISTINCT_KEYS
----------
----------
-------------
400
45
200000
2007-11-25
B-Tree Index
values
46
2007-11-25
B-Tree Index
NAME
-------------MY_TABLE_IDX_1
BLOCKS
---------12800
LF_BLKS
---------404
PCT_USED
---------100
You see the number of leaf blocks did not increase by 50%. All the
available free leaf blocks are reused.
PCT_USED column in INDEX_STATS does not tell you the truth
because it assumes that the blocks which are in the FREELIST are
also used by leaf blocks. Hence, we got 100 % PCT_USED.
Beacon infotech Corporation
www.oracleact.com
47
2007-11-25
B-Tree Index
48
SQL> select
distinct id1
from my_table;
ID1
---------0
1
2
3
4
2007-11-25
B-Tree Index
49
2007-11-25
B-Tree Index
2.
3.
Table and Indexes are not analyzed properly or analyzed with low
estimate or statistics are out of date
4.
5.
6.
7.
50
2007-11-25
51
2007-11-25