View
213
Download
0
Embed Size (px)
Citation preview
7/29/2019 A Close Look at Index Internals
1/32
1
A Close Look at Oracle8/8iIndex Internals
by
Dan HotkaDirector of Database Field
Operations
7/29/2019 A Close Look at Index Internals
2/32
2
Dan Hotka
!
Renowned author, speaker, and Oracle expert Oracle Unleashed Oracle 8 Server Unleashed
Oracle Development Unleashed Special Edition Using Oracle 8/8i
!
New book: Oracle 8i from Scratch ISBN 0-7897-2369-7
7/29/2019 A Close Look at Index Internals
3/32
3
Todays Presentation! Introduction
! B*Tree indexes What is
Structure
Tips & techniques
! Unique indexes
!
Non-unique indexes! Reverse-key indexes
! Bitmapped indexes
7/29/2019 A Close Look at Index Internals
4/32
4
B*Tree History
! Balanced-tree index
! Originally conceived by Bayer and McCreight in
1972
! Performs well with a consistent number of reads tolocate a row/series of rows
7/29/2019 A Close Look at Index Internals
5/32
5
B*Tree Index Structure
77 --> 110
79 --> 120
756 --> 130
778 --> 410
787 --> 410
793 --> 500
7369 --> ROWID
7499 --> ROWID
7521 --> ROWID7566 --> ROWID
7654 --> ROWID
7698 --> ROWID
7782 --> ROWID7788 --> ROWID
7839 --> ROWID
7844 --> ROWID
7876 --> ROWID
7900 --> ROWID
7902 --> ROWID
7934 --> ROWID
Branch DBA=100
Branch DBA=110 Branch DBA=120
Leaf Leaf Leaf Leaf DBA=130 DBA=410 DBA=440 DBA=500
7/29/2019 A Close Look at Index Internals
6/32
6
B*Tree Index Split77 --> 110
79 --> 120
756 --> 130
769 --> 410778 --> 600
787 --> 410
793 --> 500
7654 --> ROWID7698 --> ROWID
7839 --> ROWID7844 --> ROWID
7876 --> ROWID
7900 --> ROWID7902 --> ROWID
7934 --> ROWID
Branch DBA=100
Branch DBA=110 Branch DBA=120
Leaf Leaf Leaf DBA=130 DBA=410 DBA=440
7700 --> ROWID
7782 --> ROWID
7788 --> ROWID
Leaf DBA=600
7/29/2019 A Close Look at Index Internals
7/32
7
Index Block LayoutType Format Filler DBA
SCN
Base
SCN
WrapSeq Flag Chk Val Filler
Tail
Obj ID SCN of LastCleanout
No of ITLSlots
Free ListFlag
BlockType
ITL Freelist SlotDBA of next block
on Freelist
Block
Header
CacheLayer
Trans
LayerITL Index Number Trans ID Undo Address ...
No of
Rows
Affected
Committed SCN/Free
Space Credits
Index Common Header
Index Row Info
...
Index Branch or
Leaf Block Info
7/29/2019 A Close Look at Index Internals
8/32
8
Dump Commands
!
Unix dd bs=2k if=/ora8/data/users01.dbf skip=200 count =
5 | od -x > pg
! VMS
DUMP /BLOCKS = (START:, END:,os
block #>) /OUT = blockdmp.out users01.dbf
7/29/2019 A Close Look at Index Internals
9/32
9
Dump Commands
!
NT HEDIT
! SVRMGR
alter system dump datafile 7 block 201
7/29/2019 A Close Look at Index Internals
10/32
10
Index Common Header
Oracle Block Header
Index Branch or Leaf
Block Info
Index Branch or Leaf
Row Info
Field
Prefix=KDXCO
Index Common Header
Block
Level
...LEV
Free
Space
...AVS
# Key
Column
...NCO
End
Freespace
...OFEO
Begin
Freespace
...OFBO
Row
Count
...NRO
Split
Cntr
...SDC
Lock
Code
...OPC
ITL
...LOK
7/29/2019 A Close Look at Index Internals
11/32
11
Branch Block Header
Index Common
Header
Field
Prefix=KDXBR
Index Branch Block
Left mostChild Block
...LMC
Block Size
...BKSZ
Last ServiceTrans
...SNO
Oracle Block Header
Branch Block
Header
Branch BlockRows
Row # Partial KeyCol LenColDBA
Row # Partial KeyCol LenColDBA
Row # Partial KeyCol LenColDBA
...{
7/29/2019 A Close Look at Index Internals
12/32
12
Index Leaf Block Header
Oracle Block Header
Index CommonHeader
Index Leaf Row Info
Field
Prefix=KDXLE
Split
Holes
...SPL
IOT non-key
columns
...COL
Key
Size
...DSZ
Next Leaf
Block DBA
...NXT
Deleted
Rows
...NDE
Prev Leaf
Block DBA
...PRV
7/29/2019 A Close Look at Index Internals
13/32
13
Index Rows: Non-Unique
Oracle Block Header
Index Common
Header
Index Leaf Block Info
Row # Key DataColumnFlag Length ROWIDColumn Length
Row # Key or NULLColumnFlag Length ROWIDColumn Length
Row # Key or NULLColumnFlag Length ROWIDColumn Length
...
7/29/2019 A Close Look at Index Internals
14/32
14
Index Rows: Unique
Oracle Block Header
Index Common
Header
Index Leaf Block Info
Row # Key DataROWIDFlag Column Length
...
Row # Key DataROWIDFlag Column Length
Row # Key DataROWIDFlag Column Length
7/29/2019 A Close Look at Index Internals
15/32
15
B*Tree Tips & Techniques
!
B*Tree not best suited for sequential key inserts Deletes leave gaps to the left of the index Leaves are maintained for future possible inserts
Possible index height change (additional I/Os) REVERSE KEY Indexes solves this problem
!
Unique Indexes Better individual row performance - stores justROWID
7/29/2019 A Close Look at Index Internals
16/32
16
B*Tree Tips & Techniques
!
Non-unique Indexes Better range-scan performance - stores ROWID
pairs
! Reverse key indexes
Setup like non-unique
Oracle reads index blocks from left to right Oracle will NOT use a reverse-key Index on a range
scan!
7/29/2019 A Close Look at Index Internals
17/32
17
B*Tree Space Management
!
Empty blocks not removed from index Makes for longer index searches
May increase the height of the index
! High PCTFREE
Assists Oracle by doing most of the block splitting
during the initial data load
7/29/2019 A Close Look at Index Internals
18/32
18
B*Tree Space Management
!
Low PCTFREE Helps Oracle minimize block splits due to
inserts/updates by leaving some room in each index
block behind
7/29/2019 A Close Look at Index Internals
19/32
19
B*Tree Space Management! PCTFREE = 0
Where index key is sequentially always increasing NOT for reverse-key indexes
! Oracle 8.1.6
Recognizes types of rows being added:
If random in nature - loads blocks 70% full
If sequential in nature - loads blocks 95% full
! Index Height Change
Candidate for reorg/rebuild
7/29/2019 A Close Look at Index Internals
20/32
20
Index-Organized Tables
SQL> CREATE TABLE emp_iot2 (emp_id number,
3 ename varchar2(20),
4 sal number(9,2),
5 deptno number,6 CONSTRAINT pk_emp_iot_index PRIMARY KEY (emp_id))
7 ORGANIZATION index
8 TABLESPACE spc_demo_ts_01
9 PCTHRESHOLD 20 INCLUDING
7/29/2019 A Close Look at Index Internals
21/32
21
IOT Dictionary Info
SQL> select table_name, tablespace_name, iot_name, iot_type
2 from user_tables;
TABLE_NAME TABLESPACE_NAME IOT_NAME IOT_TYPE
------------------ --------------- ---------- ------------
EMP_IOT IOT
SYS_IOT_OVER_6011 SPC_DEMO_TS_02 EMP_IOT IOT_OVERFLOW
SQL> select index_name, index_type, table_name
2 from user_indexes;
INDEX_NAME INDEX_TYPE TABLE_NAME
------------------ ------------ ------------------
PK_EMP NORMAL EMPPK_EMP_IOT_ INDEX IOT - TOP EMP_IOT
7/29/2019 A Close Look at Index Internals
22/32
22
IOT Dictionary Info
SQL> select segment_name, segment_type, tablespace_name
2 from user_segments;
SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME
------------------ ------------ ---------------
EMP TABLE USER_DATA
SYS_IOT_OVER_6011 TABLE USER_OVERFLOW
PK_EMP INDEX USER_DATAPK_EMP_IOT_INDEX INDEX SPC_DEMO_TS_01
select object_name, status, generated
from dba_objects;
OBJECT_NAME STATUS GENERATED--------------------------- ------- -
EMP_IOT VALID N
PK_EMP_IOT_INDEX VALID N
SYS_IOT_OVER_6011 VALID Y
7/29/2019 A Close Look at Index Internals
23/32
23
IOT Tips & Techniques
!
Keep as many rows as possible in each IOTblock
! Keep seldom accessed data in the overflow area
! Eliminates duplication of data between an index
and a table
7/29/2019 A Close Look at Index Internals
24/32
24
Bitmap Indexes
000110000110000
100110001101000
000000010000010
001001100100110
101010001000100
100100100100100
01101101101101101000010000100001
0001000001000010
ROWIDrowidROWIDrowid
ROWIDrowidROWIDrowid
ROWIDrowidROWIDrowid...
RED
BLU
GRE
BLAAQA
VIO
ROWIDrowidROWIDrowid
ROWIDrowidROWIDrowid
ROWIDrowidROWIDrowid...
YEL
ORA
GRA
Database Block
7/29/2019 A Close Look at Index Internals
25/32
25
Bitmap Indexes Tips &Techniques
! Resembles non-unique Index structure
! DML will add leaves if bitmap at its limit ORoutside the range of the keys
! Can be slow on DML May have to reshuffle bitmap to accommodate a
change
! Searches are efficient
! Boolean operations are efficient
7/29/2019 A Close Look at Index Internals
26/32
26
Bitmap Indexes Tips &Techniques
!
The fewer the unique values, the faster this willperform
! No row-level locking!
DML locks entire bitmap which in turn, locks entire
underlying table
! Rule-based optimizer ignores bitmap indexes
Wh t h l d?
7/29/2019 A Close Look at Index Internals
27/32
27
What have we learned?
! B*Tree Index
Structure
Layout Unique
Non-unique
Reverse key
Tips & techniques
!
Index-organized tables Tips & techniques
! Bitmap indexes
Tips & techniques
7/29/2019 A Close Look at Index Internals
28/32
28
About Quest Software
A li ti
7/29/2019 A Close Look at Index Internals
29/32
29
Application
Availability & PerformanceSQL Developers
DBAs
Application Managers
System Administrators
Webmasters
Windows Administrators
Enabling
IT professionalsto meet and exceed
end-user &
managementexpectations on
application
performance &
information
availability
7/29/2019 A Close Look at Index Internals
30/32
30
Cover All Relevant Users
and Platforms
Relevant IT Users
Developers
DBAs
System Admins
Windows Admins
Webmasters
Relevant Platforms
Oracle
DB2
Unix
Windows
Web
Quests Free eSeminars
7/29/2019 A Close Look at Index Internals
31/32
31
Quests Free eSeminars
Register Today!www.quest.com/events/eseminar_index.asp
! PL/SQL Best Practices with Steven Feuerstein Package Design, 5/8
Unit Testing PL/SQL Code, 6/8! A Close Look Series with Dan Hotka
Meet Your HA and Performance SLAs, 6/4! Performance Monitoring for Oracle, 5/9
!
!
7/29/2019 A Close Look at Index Internals
32/32
32