Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 IOT Internals Julian Dyke Independent Consultant Web Version juliandyke.com © 2005 Julian Dyke.

Similar presentations


Presentation on theme: "1 IOT Internals Julian Dyke Independent Consultant Web Version juliandyke.com © 2005 Julian Dyke."— Presentation transcript:

1 1 IOT Internals Julian Dyke Independent Consultant Web Version juliandyke.com © 2005 Julian Dyke

2 juliandyke.com © 2005 Julian Dyke 2 Agenda Heap Organized Tables Index Organized Tables IOT Overflow IOT Secondary Indexes IOT Mapping Tables

3 juliandyke.com © 2005 Julian Dyke 3 Heap Organized Tables Introduction 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 4 Heap Organized Tables Indexes 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 5 Heap Organized Tables Execution Plans CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3), CONSTRAINT team_pk PRIMARY KEY (team_key) ) ORGANIZATION HEAP; INSERT INTO team VALUES (FER, Ferrari, ITA); SELECT team_name FROM team WHERE team_key = FER; SELECT STATEMENT TABLE ACCESS (BY INDEX ROWID) OF TEAM INDEX (UNIQUE SCAN) OF TEAM_PK

6 juliandyke.com © 2005 Julian Dyke 6 Heap Organized Tables Example Index Block INSERT INTO team VALUES (FER,Ferrari,ITA); Row#0[8024] flag: -----, lock: 2, data col 0; len 3; (3): Flag LockLength F E R Index Row Header Index Col 0 Table ROWID

7 juliandyke.com © 2005 Julian Dyke 7 Heap Organized Tables Example Table Block 2C INSERT INTO team VALUES (FER,Ferrari,ITA); Tab 0, row tl: 19 fb: --H-FL– lb: 0x1 cc: 3 col 0: [ 3] FER col 1: [ 7] Ferrari col 2: [ 3] ITA Table Row Header Table Col 0 Table Col 2 I T AF e r r a r i F E R Flag LockLength #Cols

8 juliandyke.com © 2005 Julian Dyke 8 Heap Organized Tables Summary 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 9 Index Organised Tables Introduction 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.com © 2005 Julian Dyke 10 Index Organised Tables Introduction 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 11 Index Organised Tables Restrictions Maximum number of primary key columns is 33 Maximum number of columns is 1000 Maximum primary key lengths in Oracle 9.2 Block SizeMaximum Key Length Non-key column lengths are not restricted

12 juliandyke.com © 2005 Julian Dyke 12 Index Organized Tables Inline versus Out-of-Line Constraints Primary key constraint can be inline or out-of-line CREATE TABLE team ( team_keyVARCHAR2(3) PRIMARY KEY, team_nameVARCHAR2(50), country_keyVARCHAR2(3) ) ORGANIZATION INDEX; CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3), CONSTRAINT team_pk PRIMARY KEY (team_key) ) ORGANIZATION INDEX; Out-of-line Inline

13 juliandyke.com © 2005 Julian Dyke 13 Index Organized Tables Implementation The statement CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3), CONSTRAINT team_pk PRIMARY KEY (team_key) ) ORGANIZATION INDEX; CREATE UNIQUE INDEX TEAM_PK ON TEAM (TEAM_KEY) INDEX ONLY TOPLEVEL TABLESPACE TS01 NOPARALLEL; generates the following recursive statement (10046)

14 juliandyke.com © 2005 Julian Dyke 14 Index Organised Tables Heap tables versus IOTs CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION HEAP; CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION INDEX; Heap-organised tableIndex-organised table SELECT team_name FROM team WHERE 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.com © 2005 Julian Dyke 15 Index Organised Tables Heap tables versus IOTs Root Branch Leaf Table CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION HEAP; CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION INDEX; Heap-organised tableIndex-organised table

16 juliandyke.com © 2005 Julian Dyke 16 Index Organized Tables Segments 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_ where objectid is object ID of IOT / IOT partition e.g. SYS_IOT_TOP_6650

17 juliandyke.com © 2005 Julian Dyke 17 Index Organized Tables Example Index Block C INSERT INTO team VALUES (FER,Ferrari,ITA); Row#0[8015] flag: K----, lock: 2 col 0; len 3; (3): tl: 15 fb: --H-FL– lb: 0x0 cc: 2 col 0: [ 7] Dump of memory from 0x05C92FB5 to 0x05C92FBC 5C92FB [.Ferrari] col 1: [ 3] Dump of memory from 0x05C92FBD to 0x05C92FC0 5C92FB [.ITA] Index Row Header Index Col 0 Table Row Header Table Col 0 Table Col 1 Flag LockLength Flag Lock #Cols Length I T AF e r r a r iF E R

18 juliandyke.com © 2005 Julian Dyke 18 Index Organized Tables Heap organised tables versus IOTs C Index Row Header Index Col 0 Table Row Header Table Col 0 Table Col E C Table Row Header Table Col 0 Table Col 1 Table Col 2 Index Row Header Index Col 0 Table ROWID Heap-organised table Index-organised table Index Row Table Row F E R I T A F e r r a r i I T A

19 juliandyke.com © 2005 Julian Dyke 19 Index Organized Tables Physical ROWIDs CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION INDEX; CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3) CONSTRAINT team_pk PRIMARY KEY (team_key); ) ORGANIZATION HEAP; SELECT ROWID FROM team; ROWID AAABvFAAEAAAADgAAA AAABvFAAEAAAADgAAB AAABvFAAEAAAADgAAC AAABvFAAEAAAADgAAD ROWID *BAEAAOoDQUdT/g *BAEAAOoDQUxG/g *BAEAAOoDQU1P/g *BAEAAOoDQU5E/g Heap-organised tableIndex-organised table

20 juliandyke.com © 2005 Julian Dyke 20 Index Organized Tables Column Ordering If primary key columns are not first in table declaration, Oracle will reorder columns within the segment CREATE TABLE team ( team_nameVARCHAR2(50), country_keyVARCHAR2(3), team_keyVARCHAR2(3) PRIMARY KEY ) ORGANIZATION INDEX Column NameColumn Type team_nameVARCHAR2(50) country_keyVARCHAR2(3) team_keyVARCHAR2(3) DESCRIBE team NAMECOL#INTCOL#SEGCOL# team_name112 country_key223 team_key331 SYS.COL$

21 juliandyke.com © 2005 Julian Dyke 21 Index Organized Tables Column Ordering C INSERT INTO team VALUES (Ferrari,ITA, FER); Row#0[8015] flag: K----, lock: 2 col 0; len 3; (3): tl: 15 fb: --H-FL– lb: 0x0 cc: 2 col 0: [ 7] Dump of memory from 0x05C92FB5 to 0x05C92FBC 5C92FB [.Ferrari] col 1: [ 3] Dump of memory from 0x05C92FBD to 0x05C92FC0 5C92FB [.ITA] Index Row Header Index Col 0 Table Row Header Table Col 0 Table Col 1 Flag LockLength Flag Lock #Cols Length I T AF e r r a r iF E R

22 juliandyke.com © 2005 Julian Dyke 22 Index Organised Tables Summary 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.com © 2005 Julian Dyke 23 IOT Overflow Introduction 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.com © 2005 Julian Dyke 24 IOT Overflow PCTTHRESHOLD 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 Default value is 50 CREATE TABLE team ( team_keyVARCHAR2(3) PRIMARY KEY, team_nameVARCHAR2(50), historyVARCHAR2(4000) ) ORGANIZATION INDEX OVERFLOW PCTTHRESHOLD 5;

25 juliandyke.com © 2005 Julian Dyke 25 IOT Overflow INCLUDING 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_keyVARCHAR2(3) PRIMARY KEY, team_nameVARCHAR2(50), historyVARCHAR2(4000) ) ORGANIZATION INDEX OVERFLOW INCLUDING team_name; Column NameColumn TypeBlock Type team_keyPrimary KeyIndex Block team_nameNon-KeyIndex Block historyNon-KeyOverflow Block

26 juliandyke.com © 2005 Julian Dyke 26 IOT Overflow Tables Segments 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_ SYS_IOT_OVER_6650 e.g.

27 juliandyke.com © 2005 Julian Dyke 27 IOT Overflow Execution Plans CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), historyVARCHAR2(4000), CONSTRAINT team_pk PRIMARY KEY (team_key) ) ORGANIZATION INDEX OVERFLOW INCLUDING team_name; SELECT team_name, history FROM team WHERE team_key = FER; 0SELECT STATEMENT 10INDEX (UNIQUE SCAN) OF TEAM_PK INSERT INTO team VALUES (FER,Ferrari,History);

28 juliandyke.com © 2005 Julian Dyke 28 IOT Overflow Example Index Block INSERT INTO team VALUES (FER,Ferrari,ITA); Row#0[8013] flag: K----, lock: 2 col 0; len 3; (3): tl: 17 fb: --H-F-– lb: 0x0 cc: 1 nrid: 0x010000ea.0 col 0: [ 7] Dump of memory from 0x04B92FB9 to 0x04B92FC0 4B92FB [.Ferrari] EA Index Row Header Index Col 0 Table Row Header Pointer to Overflow Table Col 0 Flag Lock Length Lock #Cols Length ROWID Flag F E RF e r r a r i

29 juliandyke.com © 2005 Julian Dyke 29 IOT Overflow Example Overflow Block INSERT INTO team VALUES (FER,Ferrari,ITA); tab 0, row tl: 7 fb: -----L– lb: 0x1 cc: 1 col 0: [ 3] Table Row Header Table Col 0 Lock #Cols Length Flag I T A

30 juliandyke.com © 2005 Julian Dyke 30 IOT Overflow Summary 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.com © 2005 Julian Dyke 31 IOT Secondary Indexes Introduction Introduced in Oracle 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.com © 2005 Julian Dyke 32 IOT Secondary Indexes Execution Plans CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3), CONSTRAINT team_pk PRIMARY KEY (team_key) ) ORGANIZATION INDEX; SELECT team_key,team_name FROM team WHERE country_key = ITA; CREATE INDEX team_country ON team (country_key); 0SELECT STATEMENT 10INDEX (UNIQUE SCAN) OF TEAM_PK 21INDEX (RANGE_SCAN) OF TEAM_COUNTRY;

33 juliandyke.com © 2005 Julian Dyke 33 IOT Secondary Indexes Row 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.com © 2005 Julian Dyke 34 IOT Secondary Indexes Example Leaf Row row#0[8018] flag: K----, lock: 2 col 0; len 3; (3): col 1; len 3; (3): tl: 8 fb: --H-FL– lb: 0x0 cc: 1 col 0: [ 4] Dump of memory from 0x05B12FBC to 0x05B12FC0 5B12FB0 EA C EA Index Row Header Index Col 0 Table Row Header Pointer to IOT Block Index Col 1 Flag Lock Length Lock #Cols Length Flag Length INSERT INTO team VALUES (FER,Ferrari,ITA); I T AF E R

35 juliandyke.com © 2005 Julian Dyke 35 IOT Mapping Tables Introduction Introduced in Oracle 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.com © 2005 Julian Dyke 36 IOT Mapping Tables Segments 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_ Column NameColumn Type SYS_NC_01UROWID (Type 208) SYS_IOT_MAP_6650 e.g.

37 juliandyke.com © 2005 Julian Dyke 37 IOT Mapping Tables Execution Plan CREATE TABLE team ( team_keyVARCHAR2(3), team_nameVARCHAR2(50), country_keyVARCHAR2(3), CONSTRAINT team_pk PRIMARY KEY (team_key) ) ORGANIZATION INDEX MAPPING TABLE; CREATE BITMAP INDEX team_country ON team (country_key); SELECT team_key,team_name FROM team WHERE country_key = ITA; 0SELECT STATEMENT 10INDEX (UNIQUE SCAN) OF SYS_IOT_TOP_ BITMAP CONVERSION (TO ROWIDS) 32BITMAP INDEX (SINGLE VALUE) OF TEAM_COUNTRY;

38 juliandyke.com © 2005 Julian Dyke 38 IOT Mapping Tables Example Bitmap Index Leaf Block Row#0[8013] flag: -----, lock 0 Col 0: len 3; (3): Col 1: len 6; (6): a Col 2: len 6; (6): a Col 3: len 1; (2): 00 INSERT INTO team VALUES (FER,Ferrari,ITA); A A Length Flag Lock Length Index Row Header Start ROWID End ROWID Index Key Column Bitmap Start ROWID and end ROWID refer to blocks in mapping table I T A

39 juliandyke.com © 2005 Julian Dyke 39 IOT Mapping Tables Example Mapping Table Block tab 0, row tl: 15 fb: --HFL- lb: 0x1 cc:1 col 0: [11] FE 0B FE Index Col 0 Block Pointer ? Terminator Length #Cols Length INSERT INTO team VALUES (FER,Ferrari,ITA); 2C B FE Flag Lock #Cols Table Row Header UROWID F E R

40 juliandyke.com © 2005 Julian Dyke 40 IOT Mapping Indexes Example IOT Block INSERT INTO team VALUES (FER,Ferrari,ITA); A C Row#0[8009] flag: K----, lock: 2, data:(6) a col 0; len 3; (3): tl: 15 fb: --H-FL– lb: 0x0 cc: 2 col 0: [ 7] Dump of memory from 0x05C92FB5 to 0x05C92FBC 5C92FB [.Ferrari] col 1: [ 3] Dump of memory from 0x05C92FBD to 0x05C92FC0 5C92FB [.ITA] Flag Lock Length Flag Lock #Cols Length Index Row Header Mapping Table ROWID Table Row Header Table Col 0 Table Col 1 Index Col 0 F E RI T A F e r r a r i

41 juliandyke.com © 2005 Julian Dyke 41 IOT Mapping Tables Summary 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.com © 2005 Julian Dyke 42 Thank you for your interest For more information and to provide feedback please contact me My address is: My website address is:


Download ppt "1 IOT Internals Julian Dyke Independent Consultant Web Version juliandyke.com © 2005 Julian Dyke."

Similar presentations


Ads by Google