Upload
michelle-wilcox
View
225
Download
0
Tags:
Embed Size (px)
Citation preview
1
IOTInternals
Julian Dyke
Independent Consultant
Web Version
juliandyke.com
© 2005 Julian Dyke
2
juliandyke.com
© 2005 Julian Dyke
Agenda
Heap Organized Tables Index Organized Tables IOT Overflow IOT Secondary Indexes IOT Mapping Tables
3
juliandyke.com
© 2005 Julian Dyke
Heap Organized TablesIntroduction Tables can be
ORGANIZATION HEAP (default) ORGANIZATION INDEX (8.0 and above) ORGANIZATION EXTERNAL (9.0 and above)
By default all tables are heap organized
Heap organized tables are not sorted on any column
Rows can be located using a physical ROWID which comprises Relative tablespace number Block number Slot number
4
juliandyke.com
© 2005 Julian Dyke
Heap Organized TablesIndexes Indexes on heap organized tables can be
B*Tree indexes Bitmap indexes
B*Tree indexes contain Key (one or more table columns) Physical ROWID
Bitmap indexes contain Key (one or more table columns) Start ROWID End ROWID Bitmap
5
juliandyke.com
© 2005 Julian Dyke
Heap Organized TablesExecution Plans
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3),CONSTRAINT team_pk PRIMARY KEY (team_key)
)ORGANIZATION HEAP;
INSERT INTO team VALUES (‘FER’, ’Ferrari’, ’ITA’);
SELECT team_name FROM teamWHERE team_key = ‘FER’;
SELECT STATEMENT TABLE ACCESS (BY INDEX ROWID) OF ‘TEAM’
INDEX (UNIQUE SCAN) OF ‘TEAM_PK’
6
juliandyke.com
© 2005 Julian Dyke
Heap Organized TablesExample Index Block
00 02 01 00 00 72 00 00 03 46 45 52
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
Row#0[8024] flag: -----, lock: 2, data 01 00 00 72 00 00col 0; len 3; (3): 46 45 52
Flag Lock Length Length
F E R
Index Row Header
Index Col 0
Table ROWID
7
juliandyke.com
© 2005 Julian Dyke
Heap Organized TablesExample Table Block
2C 01 03 03 46 45 52 07 46 65 72 72 61 72 69 03 49 54 41
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
Tab 0, row 0,@0x1f8dtl: 19 fb: --H-FL– lb: 0x1 cc: 3col 0: [ 3] 46 45 52 -- FERcol 1: [ 7] 46 65 72 72 61 72 69 -- Ferraricol 2: [ 3] 49 54 41 -- ITA
Table Row Header
Table Col 0
Table Col 0
Table Col 2
I T AF e r r a r iF E R
Flag Lock LengthLength Length#Cols
8
juliandyke.com
© 2005 Julian Dyke
Heap Organized TablesSummary Tables include
Three byte row header Table columns (including key columns)
Indexes include Two byte row header Redundant key columns Six byte ROWID
9
juliandyke.com
© 2005 Julian Dyke
Index Organised TablesIntroduction Introduced in Oracle 8.0
Must be declared as ORGANIZATION INDEX
Must have primary key constraint held in index row
Can contain non-key columns held in table row may be stored in overflow segment
Do not have table segment Do not store physical ROWIDs
10 juliandyke.co
m
© 2005 Julian Dyke
Index Organised TablesIntroduction Can be compressed Can be range or hash partitioned (8.1.5 and above) Can have secondary B*tree indexes (8.1.5 and above) Can have secondary bitmap indexes (9.2 and above) Can include LOBs in non-key columns Can include ADTs in non-key columns Can include ROWID columns
Cannot be reversed Cannot be list or composite partitioned Cannot contain LONG columns
11
juliandyke.com
© 2005 Julian Dyke
Index Organised TablesRestrictions Maximum number of primary key columns is 33 Maximum number of columns is 1000 Maximum primary key lengths in Oracle 9.2
Block Size Maximum Key Length
2048 755
4096 1575
8192 3215
16384 3800
Non-key column lengths are not restricted
12 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesInline versus Out-of-Line Constraints Primary key constraint can be inline or out-of-line
CREATE TABLE team(
team_key VARCHAR2(3) PRIMARY KEY,team_name VARCHAR2(50),country_key VARCHAR2(3)
)ORGANIZATION INDEX;
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3),CONSTRAINT team_pk PRIMARY KEY (team_key)
)ORGANIZATION INDEX;
Out-of-line
Inline
13 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesImplementation The statement
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3),CONSTRAINT team_pk PRIMARY KEY (team_key)
)ORGANIZATION INDEX;
CREATE UNIQUE INDEX “TEAM_PK” ON “TEAM” (“TEAM_KEY”)INDEX ONLY TOPLEVELTABLESPACE “TS01”NOPARALLEL;
generates the following recursive statement (10046)
14 juliandyke.co
m
© 2005 Julian Dyke
Index Organised TablesHeap tables versus IOTs
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3)CONSTRAINT team_pkPRIMARY KEY (team_key);
)ORGANIZATION HEAP;
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3)CONSTRAINT team_pkPRIMARY KEY (team_key);
)ORGANIZATION INDEX;
Heap-organised table Index-organised table
SELECT team_name FROM teamWHERE team_key = ‘FER’;
SELECT team_name FROM teamWHERE team_key = ‘FER’;
SELECT STATEMENT INDEX (UNIQUE SCAN) OF ‘TEAM_PK’
SELECT STATEMENT TABLE ACCESS (BY INDEX ROWID) OF ‘TEAM’
INDEX (UNIQUE SCAN) OF ‘TEAM_PK’
15 juliandyke.co
m
© 2005 Julian Dyke
Index Organised TablesHeap tables versus IOTs
Root
Branch
Leaf
Table
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3)CONSTRAINT team_pkPRIMARY KEY (team_key);
)ORGANIZATION HEAP;
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3)CONSTRAINT team_pkPRIMARY KEY (team_key);
)ORGANIZATION INDEX;
Heap-organised table Index-organised table
16 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesSegments IOTs do not have table segments
Index segment name depends on primary key constraint
Out-of-line constraints Index segment name same as constraint name
Inline constraints Index segment name is
SYS_IOT_TOP_<objectid>
where objectid is object ID of IOT / IOT partition
e.g.
SYS_IOT_TOP_6650
17 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesExample Index Block
04 02 03 46 45 52 2C 00 02 07 46 65 72 72 61 72 69 03 49 54 41
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
Row#0[8015] flag: K----, lock: 2col 0; len 3; (3): 46 45 52tl: 15 fb: --H-FL– lb: 0x0 cc: 2col 0: [ 7]Dump of memory from 0x05C92FB5 to 0x05C92FBC5C92FB0 72654607 69726172 [.Ferrari]col 1: [ 3]Dump of memory from 0x05C92FBD to 0x05C92FC05C92FB0 41544903 [.ITA]
Index Row Header
Index Col 0
Table Row Header
Table Col 0
Table Col 1
Flag Lock Length Flag Lock #Cols LengthLength
I T AF e r r a r iF E R
18 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesHeap organised tables versus IOTs
04 02 03 46 45 52 2C 00 02 07 46 65 72 72 61 72 69 03 49 54 41
Index Row Header
Index Col 0
Table Row Header
Table Col 0
Table Col 1
00 02 01 00 01 E2 00 00 03 46 45 52
2C 01 03 03 46 45 52 07 46 65 72 72 61 72 69 03 49 54 41
Table Row Header
Table Col 0
Table Col 1
Table Col 2
Index Row Header
Index Col 0
TableROWID
Heap-organised table
Index-organised table
Index Row
Index Row
TableRow F E R
F E RF E R
F E R
I T AF e r r a r i
F e r r a r i I T A
19 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesPhysical ROWIDs
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3)CONSTRAINT team_pkPRIMARY KEY (team_key);
)ORGANIZATION INDEX;
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3)CONSTRAINT team_pkPRIMARY KEY (team_key);
)ORGANIZATION HEAP;
SELECT ROWID FROM team; SELECT ROWID FROM team;
ROWID
AAABvFAAEAAAADgAAAAAABvFAAEAAAADgAABAAABvFAAEAAAADgAACAAABvFAAEAAAADgAAD
ROWID
*BAEAAOoDQUdT/g*BAEAAOoDQUxG/g*BAEAAOoDQU1P/g*BAEAAOoDQU5E/g
Heap-organised table Index-organised table
20 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesColumn Ordering If primary key columns are not first in table declaration, Oracle
will reorder columns within the segment
CREATE TABLE team(
team_name VARCHAR2(50),country_key VARCHAR2(3),team_key VARCHAR2(3) PRIMARY KEY
)ORGANIZATION INDEX
Column Name Column Type
team_name VARCHAR2(50)
country_key VARCHAR2(3)
team_key VARCHAR2(3)
DESCRIBE team
NAME COL# INTCOL# SEGCOL#
team_name 1 1 2
country_key 2 2 3
team_key 3 3 1
SYS.COL$
21 juliandyke.co
m
© 2005 Julian Dyke
Index Organized TablesColumn Ordering
04 02 03 46 45 52 2C 00 02 07 46 65 72 72 61 72 69 03 49 54 41
INSERT INTO team VALUES (’Ferrari’ ,’ITA’, ’FER’);
Row#0[8015] flag: K----, lock: 2col 0; len 3; (3): 46 45 52tl: 15 fb: --H-FL– lb: 0x0 cc: 2col 0: [ 7]Dump of memory from 0x05C92FB5 to 0x05C92FBC5C92FB0 72654607 69726172 [.Ferrari]col 1: [ 3]Dump of memory from 0x05C92FBD to 0x05C92FC05C92FB0 41544903 [.ITA]
Index Row Header
Index Col 0
Table Row Header
Table Col 0
Table Col 1
Flag Lock Length Flag Lock #Cols LengthLength
I T AF e r r a r iF E R
22 juliandyke.co
m
© 2005 Julian Dyke
Index Organised TablesSummary For SELECT statements
useful for lookup tables avoid additional logical I/O for non-key data reduce latching
Do not store physical ROWID Six bytes less storage required
Optionally can store non-key data Requires three byte table row header
23 juliandyke.co
m
© 2005 Julian Dyke
IOT OverflowIntroduction Introduced in Oracle 8.0
Inefficient to store long rows in index segment Store rarely accessed columns in overflow segment
Primary key rows always stored in index segment Non-key rows can stored in index segment or overflow Overflow segment is additional table segment Index row includes six byte ROWID for overflow row
24 juliandyke.co
m
© 2005 Julian Dyke
IOT OverflowPCTTHRESHOLD Clause Specifies percentage of space reserved in index block for IOT
row Must be large enough to hold primary key All columns causing threshold to be exceeded are stored in
overflow segment Syntax is
PCTTHRESHOLD threshold
where threshold is integer in the range 1..50 Default value is 50
CREATE TABLE team(
team_key VARCHAR2(3) PRIMARY KEY,team_name VARCHAR2(50),history VARCHAR2(4000)
)ORGANIZATION INDEXOVERFLOWPCTTHRESHOLD 5;
25 juliandyke.co
m
© 2005 Julian Dyke
IOT OverflowINCLUDING Clause Can be used to specify which columns are held on index
block Syntax is
INCLUDING column_name
where column_name can be last column of primary key any non-key column
CREATE TABLE team(
team_key VARCHAR2(3) PRIMARY KEY,team_name VARCHAR2(50),history VARCHAR2(4000)
)ORGANIZATION INDEXOVERFLOWINCLUDING team_name;
Column Name Column Type Block Type
team_key Primary Key Index Block
team_name Non-Key Index Block
history Non-Key Overflow Block
26 juliandyke.co
m
© 2005 Julian Dyke
IOT Overflow TablesSegments IOT Overflow Table segments are created automatically when
OVERFLOW clause is used
Overflow segment name is
where object_id is the object id of the IOT / IOT partition
Overflow segment cannot be directly accessed by SELECT, INSERT, UPDATE or DELETE operations
For partitioned IOTs, overflow segment is locally partitioned
SYS_IOT_OVER_<object_id>
SYS_IOT_OVER_6650
e.g.
27 juliandyke.co
m
© 2005 Julian Dyke
IOT OverflowExecution Plans
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),history VARCHAR2(4000),CONSTRAINT team_pkPRIMARY KEY (team_key)
)ORGANIZATION INDEXOVERFLOWINCLUDING team_name;
SELECT team_name, historyFROM teamWHERE team_key = ‘FER’;
0 SELECT STATEMENT1 0 INDEX (UNIQUE SCAN) OF ‘TEAM_PK’
INSERT INTO team VALUES (‘FER’,’Ferrari’,’History’);
28 juliandyke.co
m
© 2005 Julian Dyke
IOT OverflowExample Index Block
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
Row#0[8013] flag: K----, lock: 2col 0; len 3; (3): 46 45 52tl: 17 fb: --H-F-– lb: 0x0 cc: 1nrid: 0x010000ea.0col 0: [ 7]Dump of memory from 0x04B92FB9 to 0x04B92FC04B92FB0 72654607 69726172 [.Ferrari]
04 02 03 46 45 52 28 00 01 01 00 00 EA 00 00 07 46 65 72 72 61 72 69
Index Row Header
Index Col 0
Table Row Header
Pointer to Overflow
Table Col 0
Flag Lock Length Lock #Cols LengthROWIDFlag
F E R F e r r a r i
29 juliandyke.co
m
© 2005 Julian Dyke
IOT OverflowExample Overflow Block
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
tab 0, row 0, @0x1fb1tl: 7 fb: -----L– lb: 0x1 cc: 1col 0: [ 3] 49 54 41
04 01 01 03 49 54 41
Table Row Header
Table Col 0
Lock #Cols LengthFlag
I T A
30 juliandyke.co
m
© 2005 Julian Dyke
IOT OverflowSummary Store frequently accessed columns in index segment Store rarely accessed columns in overflow segments
Overflow segments Useful for variable length columns e.g Useful for nullable columns May reduce index height May increase row density
Statements accessing overflow segments must access index segment first require additional logical I/Os
31 juliandyke.co
m
© 2005 Julian Dyke
IOT Secondary IndexesIntroduction Introduced in Oracle 8.1.5
Allow additional B*tree indexes to be created on IOTs Allow new access paths
Can be created on Primary key columns Non key columns Overflow columns
Can be compressed Can be partitioned Cannot be reversed
32 juliandyke.co
m
© 2005 Julian Dyke
IOT Secondary IndexesExecution Plans
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3),CONSTRAINT team_pkPRIMARY KEY (team_key)
)ORGANIZATION INDEX;
SELECT team_key,team_name FROM teamWHERE country_key = ‘ITA’;
CREATE INDEX team_countryON team (country_key);
0 SELECT STATEMENT1 0 INDEX (UNIQUE SCAN) OF ‘TEAM_PK’2 1 INDEX (RANGE_SCAN) OF ‘TEAM_COUNTRY’;
33 juliandyke.co
m
© 2005 Julian Dyke
IOT Secondary IndexesRow Structure Each secondary index row contains
key values physical ROWID guess primary key
Not the same as UROWIDs
As insertions occur IOT rows can move to different blocks Physical ROWID guesses are not updated in secondary index Guesses degrade over time
Percentage of rows with valid guesses is collected by ANALYZE and DBMS_STATS and recorded in
DBA_INDEXES.PCT_DIRECT_ACCESS
34 juliandyke.co
m
© 2005 Julian Dyke
IOT Secondary IndexesExample Leaf Row
row#0[8018] flag: K----, lock: 2col 0; len 3; (3): 49 54 41col 1; len 3; (3): 46 45 52tl: 8 fb: --H-FL– lb: 0x0 cc: 1col 0: [ 4]Dump of memory from 0x05B12FBC to 0x05B12FC05B12FB0 EA010001
04 02 03 49 54 41 03 46 45 52 2C 00 01 04 01 00 01 EA
Index Row Header
Index Col 0
Table Row Header
Pointer to IOT Block
Index Col 1
Flag Lock Length Lock #Cols LengthFlagLength
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
I T A F E R
35 juliandyke.co
m
© 2005 Julian Dyke
IOT Mapping TablesIntroduction Introduced in Oracle 9.2.0 Required to support IOT bitmap secondary indexes IOT rows subject to block splits
Can move from block to block Bitmap indexes rows reference contiguous set of slots
IOT must be created with MAPPING TABLE clause
Bitmap index stores mapping table blocks Read access via IOT bitmap secondary indexes as follows
Obtain mapping table block number from bitmap index Obtain primary key from mapping table block Use primary key to access IOT
36 juliandyke.co
m
© 2005 Julian Dyke
IOT Mapping TablesSegments IOT Mapping Table segments are created automatically when
MAPPING TABLE clause is used
Segment name is
Where object_id is the object id of the IOT / IOT partition
Mapping table contains one column
SYS_IOT_MAP_<object_id>
Column Name Column Type
SYS_NC_01 UROWID (Type 208)
SYS_IOT_MAP_6650
e.g.
37 juliandyke.co
m
© 2005 Julian Dyke
IOT Mapping TablesExecution Plan
CREATE TABLE team(
team_key VARCHAR2(3),team_name VARCHAR2(50),country_key VARCHAR2(3),CONSTRAINT team_pkPRIMARY KEY (team_key)
)ORGANIZATION INDEXMAPPING TABLE;
CREATE BITMAP INDEX team_countryON team (country_key);
SELECT team_key,team_name FROM teamWHERE country_key = ‘ITA’;
0 SELECT STATEMENT1 0 INDEX (UNIQUE SCAN) OF ‘SYS_IOT_TOP_6650’2 1 BITMAP CONVERSION (TO ROWIDS)3 2 BITMAP INDEX (SINGLE VALUE) OF ‘TEAM_COUNTRY’;
38 juliandyke.co
m
© 2005 Julian Dyke
IOT Mapping TablesExample Bitmap Index Leaf Block
Row#0[8013] flag: -----, lock 0Col 0: len 3; (3): 49 54 41Col 1: len 6; (6): 01 00 0a 62 00 00Col 2: len 6; (6): 01 00 0a 62 00 07Col 3: len 1; (2): 00
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
00 00 03 49 54 41 06 01 00 0A 62 00 00 06 01 00 0A 62 00 07 01 00
LengthFlag Lock Length Length Length
Index Row Header
Start ROWID
End ROWID
Index KeyColumn
Bitmap
Start ROWID and end ROWID refer to blocks in mapping table
I T A
39 juliandyke.co
m
© 2005 Julian Dyke
IOT Mapping TablesExample Mapping Table Block
tab 0, row 0, @0x1f91tl: 15 fb: --H—FL- lb: 0x1 cc:1col 0: [11] 02 04 00 00 00 00 03 46 45 52 FE
0B 02 04 00 00 00 00 03 46 45 52 FE
Index Col 0
Block Pointer ?
TerminatorLength Length#Cols Length
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
2C 01 01 0B 02 04 00 00 00 00 03 46 45 52 FE
Flag Lock #Cols
Table Row Header
UROWID
F E R
F E R
40 juliandyke.co
m
© 2005 Julian Dyke
IOT Mapping IndexesExample IOT Block
INSERT INTO team VALUES (‘FER’,’Ferrari’,’ITA’);
04 02 01 00 0A 62 00 00 03 46 45 52 2C 00 02 07 46 65 72 72 61 72 69 03 49 54 41
Row#0[8009] flag: K----, lock: 2, data:(6) 01 00 0a 62 00 00col 0; len 3; (3): 46 45 52tl: 15 fb: --H-FL– lb: 0x0 cc: 2col 0: [ 7]Dump of memory from 0x05C92FB5 to 0x05C92FBC5C92FB0 72654607 69726172 [.Ferrari]col 1: [ 3]Dump of memory from 0x05C92FBD to 0x05C92FC05C92FB0 41544903 [.ITA]
Flag Lock Length Flag Lock #Cols LengthLength
Index Row Header
MappingTable
ROWID
Table Row Header
Table Col 0
Table Col 1
Index Col 0
F E R I T AF e r r a r i
41 juliandyke.co
m
© 2005 Julian Dyke
IOT Mapping TablesSummary Bitmap indexes can be much more efficient than B*Tree
indexes requiring Less physical storage Fewer logical I/Os
Mapping tables require Additional physical disk usage Additional logical I/Os for SELECT and DML
Each IOT leaf row requires additional six bytes for mapping table ROWID
42 juliandyke.co
m
© 2005 Julian Dyke
Thank you for your interest
For more information and to provide feedback
please contact me
My e-mail address is:[email protected]
My website address is:
www.juliandyke.com