Documente Academic
Documente Profesional
Documente Cultură
juliandyke.com
Agenda
Heap
Organized Tables Index Organized Tables IOT Overflow IOT Secondary Indexes IOT Mapping Tables
juliandyke.com
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
juliandyke.com
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
juliandyke.com
juliandyke.com
Table ROWID
Index Col 0
00 02
Flag Lock
01 00 00 72 00 00
Length
F E R 03 46 45 52
Length
juliandyke.com
Table Col 0
Table Col 0
Table Col 2
2C 01 03
Flag Lock
F E R 03 46 45 52
#Cols Length
F e r r a r i 07 46 65 72 72 61 72 69
Length
I T A 03 49 54 41
Length
juliandyke.com
Tables include Three byte row header Table columns (including key columns) Indexes include Two byte row header Redundant key columns Six byte ROWID
juliandyke.com
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
juliandyke.com
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
10
juliandyke.com
Maximum number of primary key columns is 33 Maximum number of columns is 1000 Maximum primary key lengths in Oracle 9.2
Block Size 2048 4096 8192 16384 Maximum Key Length 755 1575 3215 3800
11
juliandyke.com
Out-of-line
CREATE TABLE team ( team_key VARCHAR2(3), team_name VARCHAR2(50), country_key VARCHAR2(3), CONSTRAINT team_pk PRIMARY KEY (team_key) ) ORGANIZATION INDEX;
12
juliandyke.com
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;
13
juliandyke.com
Index-organised table
CREATE TABLE team ( team_key VARCHAR2(3), team_name VARCHAR2(50), country_key VARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION INDEX; SELECT team_name FROM team WHERE team_key = FER;
SELECT STATEMENT INDEX (UNIQUE SCAN) OF TEAM_PK
14
juliandyke.com
Index-organised table
CREATE TABLE team ( team_key VARCHAR2(3), team_name VARCHAR2(50), country_key VARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION INDEX;
Table
15
juliandyke.com
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>
e.g.
SYS_IOT_TOP_6650
16
juliandyke.com
F E R F e r r a r i I T A 04 02 03 46 45 52 2C 00 02 07 46 65 72 72 61 72 69 03 49 54 41
Flag
17
Lock
Length
Flag
Lock
#Cols
Length
Length
juliandyke.com
00 02
Table Row Header
F E R 01 00 01 E2 00 00 03 46 45 52
Table Col 0 Table Col 1 Table Col 2
Table Row
F E R 2C 01 03 03 46 45 52
F e r r a r 07 46 65 72 72 61 72 69i
I T A 03 49 54 41
Index-organised table
Index Row Header Index Row
18
Index Col 0
Table Col 0
Table Col 1
04 02 03 46 45 52 2C 00 02 07 46 65 72 72 61 72 69 03 49 54 41 F E R I T A F e r r a r i
juliandyke.com
Index-organised table
CREATE TABLE team ( team_key VARCHAR2(3), team_name VARCHAR2(50), country_key VARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION INDEX; SELECT ROWID FROM team; ROWID *BAEAAOoDQUdT/g *BAEAAOoDQUxG/g *BAEAAOoDQU1P/g *BAEAAOoDQU5E/g
19
juliandyke.com
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
DESCRIBE team
Column Name team_name country_key team_key Column Type VARCHAR2(50) VARCHAR2(3) VARCHAR2(3) NAME team_name country_key team_key
SYS.COL$
COL# INTCOL# SEGCOL# 1 2 3 1 2 3 2 3 1
20
juliandyke.com
F E R F e r r a r i I T A 04 02 03 46 45 52 2C 00 02 07 46 65 72 72 61 72 69 03 49 54 41
Flag
21
Lock
Length
Flag
Lock
#Cols
Length
Length
juliandyke.com
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
22
juliandyke.com
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
23
juliandyke.com
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
24
juliandyke.com
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 INDEX OVERFLOW INCLUDING team_name; Column Name team_key team_name history Column Type Primary Key Non-Key Non-Key Block Type Index Block Index Block Overflow Block
25
juliandyke.com
IOT Overflow Table segments are created automatically when OVERFLOW clause is used Overflow segment name is
SYS_IOT_OVER_<object_id>
e.g.
SYS_IOT_OVER_6650
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
26
juliandyke.com
27
juliandyke.com
Index Col 0
Pointer to Overflow
Table Col 0
F E R 04 02 03 46 45 52
Flag Lock Length
28 00 01
Lock
F e r r a r i 01 00 00 EA 00 00 07 46 65 72 72 61 72 69
#Cols ROWID Length
Flag
28
juliandyke.com
Table Col 0
04 01 01 03 49 54 41 I T A
Flag Lock #Cols Length
29
juliandyke.com
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
30
juliandyke.com
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
31
juliandyke.com
32
juliandyke.com
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
33
juliandyke.com
Index Col 0
Index Col 1
I T A 04 02 03 49 54 41
Flag Lock Length
F E R 03 46 45 52 2C 00 01
Length Flag Lock
04 01 00 01 EA
#Cols Length
34
juliandyke.com
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
35
juliandyke.com
IOT Mapping Table segments are created automatically when MAPPING TABLE clause is used Segment name is
SYS_IOT_MAP_<object_id>
e.g.
SYS_IOT_MAP_6650
Where object_id is the object id of the IOT / IOT partition Mapping table contains one column
Column Name SYS_NC_01 Column Type UROWID (Type 208)
36
juliandyke.com
37
juliandyke.com
End ROWID
Bitmap
00 00 03 49 54 41 I T A
Flag Lock Length
06 01 00 0A 62 00 00
Length
06 01 00 0A 62 00 07
Length
01 00
Length
38
juliandyke.com
2C 01 01 0B 02
Flag Lock #Cols
F E R 04 00 00 00 00 03 46 45 52
Block Pointer ? Index Col 0
FE
0B 02
Length
39
F E R 04 00 00 00 00 03 46 45 52 FE
Length Length Terminator
#Cols
juliandyke.com
F E R I 54 41 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 T A F e r r a r i
Flag
40
Lock
Length
Flag
Lock
#Cols
Length
Length
juliandyke.com
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
41
juliandyke.com
42
juliandyke.com