SlideShare a Scribd company logo
1 of 29
Indexes: Structure, Splits and Free 
Space Management Internals 
OakTable World, 29 September 2014 
Christian Antognini 
BASEL BERN BRUGG LAUSANNE ZUERICH DUESSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MUNICH STUTTGART VIENNA 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
1
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
2 
@ChrisAntognini 
 Senior principal consultant, trainer and partner 
at Trivadis in Zurich (CH) 
 christian.antognini@trivadis.com 
 http://antognini.ch 
 Focus: get the most out of Oracle Database 
 Logical and physical database design 
 Query optimizer 
 Application performance management 
 Author of Troubleshooting Oracle Performance 
Apress, 2008/2014 
 OakTable Network, Oracle ACE Director
AGENDA 
1. Concepts 
2. Index Keys 
3. Splits 
4. Free Space 
5. Reorganizations 
6. Bitmap 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
3
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
Concepts 
4
Structure of a B-Tree 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
5 
24 51 
12 29 42 86 
2 ROWID 
8 ROWID 
10 ROWID 
11 ROWID 
12 ROWID 
18 ROWID 
20 ROWID 
24 ROWID 
26 ROWID 
29 ROWID 
34 ROWID 
38 ROWID 
42 ROWID 51 ROWID 
55 ROWID 
73 ROWID 
branch 
blocks 
86 ROWID 
99 ROWID 
left<24 
right≥24 
leaf blocks 
root block
2014 © Trivadis 
Nulls 
 NULL values are stored in the index only when at least one of the 
indexed columns is not NULL 
 Exception: bitmap indexes always store indexed data 
 For unique indexes the uniqueness is guaranteed only if at least one of 
the indexed columns is not NULL 
 NULL values are stored after not NULL values in the index 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
6
2014 © Trivadis 
Myths 
 Oracle B-tree indexes can become “unbalanced” over time and need to 
be rebuilt 
 Deleted space in an index is “deadwood” and over time requires the 
index to be rebuilt 
 If an index reaches “x” number of levels, it becomes inefficient and 
requires the index to be rebuilt 
 If an index has a poor clustering factor, the index needs to be rebuilt 
 To improve performance, indexes need to be regularly rebuilt 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
7 
Source: Oracle B-Tree Index Internals: Rebuilding The Truth, Richard Foote
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
Index Keys 
8
Internal Key 
 Internally a unique key is needed to sort the indexed columns 
 For unique indexes the internal key is the same as the index key 
 For non-unique indexes the ROWID of the indexed row is added to the 
index key to make it unique 
 For global indexes an extended ROWID is used, otherwise a restricted 
ROWID is enough 
2014 © Trivadis 
 Therefore 
 The index entries are sorted in a consistent way 
 Even for non-unique indexed the order of the index entries changes only 
when the indexed table is reorganized (i.e. not if the index is rebuilt!) 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
9
Branch Block Key 
 In branch blocks the internal key is truncated after the first byte that 
differs from the last key of the left leaf block 
 All keys are preceded by a length field 
 1 byte for data up to 127 bytes 
 Otherwise 2 bytes 
- The high bit of the first byte is set (0x80) 
- The remaining bits of the first byte and the second byte contain the length 
 Partially stored keys are terminated by 0xFE 
 Nulls have a column length of 0xFF, trailing nulls are stored 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
10 
RDBA 
Len 
Key 1 
Data 
Key 1 
Len 
Key X 
Data 
Key X
Leaf Block Key 
 All keys are preceded by a length field 
 1 byte for data up to 127 bytes 
 Otherwise 2 bytes 
- The high bit of the first byte is set (0x80) 
- The remaining bits of the first byte and the second byte contain the length 
 Nulls have a column length of 0xFF, trailing nulls are stored 
 For global indexes an extended ROWID is used, otherwise a restricted 
ROWID is enough 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
11 
Flag Lock 
Len 
Key 1 
Data 
Key 1 
Len 
ROWID 
ROWID 
(optional)
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
Splits 
12
2014 © Trivadis 
Splits 
 Two split methods are implemented 
 50:50 split 
 The keys are evenly distributed over two blocks 
 Based on size, not number of keys 
 99:1 split (a.k.a. 90:10) 
 The new key is the right-most of the index 
 A new leaf block containing only the new key is added 
 Useful for increasing values like sequences and timestamps 
 A change in the structure of an index (like a split) is not rollbacked if the 
transaction that caused it is rollbacked 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
13
2014 © Trivadis 
Splits 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
14 
#1
2014 © Trivadis 
Splits 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
15 
#1 
#2 #3
2014 © Trivadis 
Splits 
#2 #4 #3 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
16 
#1 
#2 #3
2014 © Trivadis 
Splits 
#1 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
17 
#1 
#2 #4 #3 #5 
#2 #4 #3
2014 © Trivadis 
Splits 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
18
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
Free Space 
19
Reminder 
 PCTFREE is only used when the index is created (or rebuilt) 
 An update is implemented as a delete followed by an insert 
 The free space in leaf blocks is strongly dependent on the type of split (50:50 
2014 © Trivadis 
or 99:1) 
 PCTUSED cannot be used for indexes 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
20
Free Space 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
21 
#1 
#2 #3 #4
Free Space 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
22 
#1 
#2 #4 #3
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
Reorganizations 
23
Reorganizations 
 If the free space is not automatically reused, it should be manually 
reclaimed 
 This is unusual, therefore such an operation should only be performed if it is 
really necessary 
 To manually reclaim free space two possibilities exists 
 Rebuild: the index is recreated 
 Coalesce: free space in contiguous blocks is merged and, therefore, some 
blocks are unchained 
 Unnecessary rebuild/coalesce may lead to sub-optimal data density in 
leaf blocks 
 Too much free space, i.e. too low density 
 Too much block splits, i.e. too high density 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
24
Rebuild vs. Coalesce 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
25 
Pro Cons 
Rebuild 
 Doesn’t lock table 
(online rebuilds only) 
 Reclaim all the free 
space 
 Locks table during rebuild 
(offline rebuilds only) 
 Doubles space usage 
temporarily 
 The index is completely 
recreated (to do so large 
sorts may be performed) 
Coalesce 
 Doesn’t lock table 
 Current index structure is 
reused 
 Doesn’t reclaim all the free 
space 
 Can generate lot of redo
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
Bitmap 
26
2014 © Trivadis 
Bitmap 
 A bitmap index is a regular B-tree, only the internal key differs from the 
non-bitmap index! 
 The key is composed by 
 Indexed column(s) 
 Start/End ROWID 
 Bitmap representing the rows that have the key 
- To save space it is “compressed” 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
27
Summary 
2014 © Trivadis 
 B-tree indexes cannot become 
“unbalanced” 
 Deleted space in an index can 
be reused 
 Indexes do not need to be 
regularly rebuilt 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
28
Questions and answers ... 
Christian Antognini 
Senior Principal Consultant 
christian.antognini@trivadis.com 
BASEL BERN BRUGG LAUSANNE ZUERICH DUESSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MUNICH STUTTGART VIENNA 
2014 © Trivadis 
Indexes: Structure, Splits and Free Space Management Internals 
29 September 2014 
29

More Related Content

What's hot

Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaa
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaaPerfect trio : temporal tables, transparent archiving in db2 for z_os and idaa
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaa
Cuneyt Goksu
 
Adaptive Query Optimization in 12c
Adaptive Query Optimization in 12cAdaptive Query Optimization in 12c
Adaptive Query Optimization in 12c
Anju Garg
 
The Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12cThe Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12c
David Yahalom
 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
mCloud
 

What's hot (20)

Properly Use Parallel DML for ETL
Properly Use Parallel DML for ETLProperly Use Parallel DML for ETL
Properly Use Parallel DML for ETL
 
How should I monitor my idaa
How should I monitor my idaaHow should I monitor my idaa
How should I monitor my idaa
 
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaa
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaaPerfect trio : temporal tables, transparent archiving in db2 for z_os and idaa
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaa
 
Adaptive Query Optimization in 12c
Adaptive Query Optimization in 12cAdaptive Query Optimization in 12c
Adaptive Query Optimization in 12c
 
The Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12cThe Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12c
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query Optimization
 
DB2 LUW Access Plan Stability
DB2 LUW Access Plan StabilityDB2 LUW Access Plan Stability
DB2 LUW Access Plan Stability
 
Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizer
 
Db2 analytics accelerator technical update
Db2 analytics accelerator  technical updateDb2 analytics accelerator  technical update
Db2 analytics accelerator technical update
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New Features
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 
Db2 for z os trends
Db2 for z os trendsDb2 for z os trends
Db2 for z os trends
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
 
Indexing in Exadata
Indexing in ExadataIndexing in Exadata
Indexing in Exadata
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability Improvements
 
Part2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer StatisticsPart2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer Statistics
 
Best Practices for Oracle Exadata and the Oracle Optimizer
Best Practices for Oracle Exadata and the Oracle OptimizerBest Practices for Oracle Exadata and the Oracle Optimizer
Best Practices for Oracle Exadata and the Oracle Optimizer
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
 
Part1 of SQL Tuning Workshop - Understanding the Optimizer
Part1 of SQL Tuning Workshop - Understanding the OptimizerPart1 of SQL Tuning Workshop - Understanding the Optimizer
Part1 of SQL Tuning Workshop - Understanding the Optimizer
 

Viewers also liked

Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
Kyle Hailey
 
Free space managment46
Free space managment46Free space managment46
Free space managment46
myrajendra
 
Oracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmastersOracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmasters
Kyle Hailey
 

Viewers also liked (20)

Profiling the logwriter and database writer
Profiling the logwriter and database writerProfiling the logwriter and database writer
Profiling the logwriter and database writer
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
 
DevOps and its impact
DevOps and its impactDevOps and its impact
DevOps and its impact
 
Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?
 
Dan Norris: Exadata security
Dan Norris: Exadata securityDan Norris: Exadata security
Dan Norris: Exadata security
 
Mark Farnam : Minimizing the Concurrency Footprint of Transactions
Mark Farnam  : Minimizing the Concurrency Footprint of TransactionsMark Farnam  : Minimizing the Concurrency Footprint of Transactions
Mark Farnam : Minimizing the Concurrency Footprint of Transactions
 
OakTable World Sep14 clonedb
OakTable World Sep14 clonedb OakTable World Sep14 clonedb
OakTable World Sep14 clonedb
 
Free space managment46
Free space managment46Free space managment46
Free space managment46
 
Oaktable World 2014 Kevin Closson: SLOB – For More Than I/O!
Oaktable World 2014 Kevin Closson:  SLOB – For More Than I/O!Oaktable World 2014 Kevin Closson:  SLOB – For More Than I/O!
Oaktable World 2014 Kevin Closson: SLOB – For More Than I/O!
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
 
ARC202 Architecting for High Availability - AWS re: Invent 2012
ARC202 Architecting for High Availability - AWS re: Invent 2012ARC202 Architecting for High Availability - AWS re: Invent 2012
ARC202 Architecting for High Availability - AWS re: Invent 2012
 
Intro to ASH
Intro to ASHIntro to ASH
Intro to ASH
 
Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle
 
How to find and fix your Oracle application performance problem
How to find and fix your Oracle application performance problemHow to find and fix your Oracle application performance problem
How to find and fix your Oracle application performance problem
 
Oracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmastersOracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmasters
 
AWR Ambiguity: Performance reasoning when the numbers don't add up
AWR Ambiguity: Performance reasoning when the numbers don't add upAWR Ambiguity: Performance reasoning when the numbers don't add up
AWR Ambiguity: Performance reasoning when the numbers don't add up
 
Data control
Data controlData control
Data control
 
Oracle Database on ACFS: a perfect marriage?
Oracle Database on ACFS: a perfect marriage?Oracle Database on ACFS: a perfect marriage?
Oracle Database on ACFS: a perfect marriage?
 
Oaktable World 2014 Toon Koppelaars: database constraints polite excuse
Oaktable World 2014 Toon Koppelaars: database constraints polite excuseOaktable World 2014 Toon Koppelaars: database constraints polite excuse
Oaktable World 2014 Toon Koppelaars: database constraints polite excuse
 
Oracle Database Security: Top 10 Things You Could & Should Be Doing Differently
Oracle Database Security: Top 10 Things You Could & Should Be Doing DifferentlyOracle Database Security: Top 10 Things You Could & Should Be Doing Differently
Oracle Database Security: Top 10 Things You Could & Should Be Doing Differently
 

Similar to Indexes: Structure, Splits and Free Space Management Internals

Similar to Indexes: Structure, Splits and Free Space Management Internals (20)

Partitioning your Oracle Data Warehouse - Just a simple task?
Partitioning your Oracle Data Warehouse - Just a simple task?Partitioning your Oracle Data Warehouse - Just a simple task?
Partitioning your Oracle Data Warehouse - Just a simple task?
 
Data Warehousing and Bitmap Indexes - More than just some bits
Data Warehousing and Bitmap Indexes  - More than just some bitsData Warehousing and Bitmap Indexes  - More than just some bits
Data Warehousing and Bitmap Indexes - More than just some bits
 
Indexes overview
Indexes overviewIndexes overview
Indexes overview
 
Steam Learn: Introduction to RDBMS indexes
Steam Learn: Introduction to RDBMS indexesSteam Learn: Introduction to RDBMS indexes
Steam Learn: Introduction to RDBMS indexes
 
Vertex BD. Development of 2014 version.
Vertex BD. Development of 2014 version.Vertex BD. Development of 2014 version.
Vertex BD. Development of 2014 version.
 
Software System Engineering - Chapter 15
Software System Engineering - Chapter 15Software System Engineering - Chapter 15
Software System Engineering - Chapter 15
 
Management productivity tools1
Management productivity tools1Management productivity tools1
Management productivity tools1
 
Management productivity tools1
Management productivity tools1Management productivity tools1
Management productivity tools1
 
Module08
Module08Module08
Module08
 
Module08
Module08Module08
Module08
 
Software Engineering Lec 8-design-
Software Engineering Lec 8-design-Software Engineering Lec 8-design-
Software Engineering Lec 8-design-
 
Top 10 Interview Questions for Solidworks
Top 10 Interview Questions for SolidworksTop 10 Interview Questions for Solidworks
Top 10 Interview Questions for Solidworks
 
Five Tips to Get the Most Out of Your Indexing
Five Tips to Get the Most Out of Your IndexingFive Tips to Get the Most Out of Your Indexing
Five Tips to Get the Most Out of Your Indexing
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Top 35-interview-questions-on-sap-abap
Top 35-interview-questions-on-sap-abapTop 35-interview-questions-on-sap-abap
Top 35-interview-questions-on-sap-abap
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
 
CREO / PROE QUESTIONS
CREO / PROE QUESTIONSCREO / PROE QUESTIONS
CREO / PROE QUESTIONS
 
Tableau interview questions www.bigclasses.com
Tableau interview questions www.bigclasses.comTableau interview questions www.bigclasses.com
Tableau interview questions www.bigclasses.com
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptx
 
BUS-Chapter 07.ppt
BUS-Chapter 07.pptBUS-Chapter 07.ppt
BUS-Chapter 07.ppt
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Indexes: Structure, Splits and Free Space Management Internals

  • 1. Indexes: Structure, Splits and Free Space Management Internals OakTable World, 29 September 2014 Christian Antognini BASEL BERN BRUGG LAUSANNE ZUERICH DUESSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MUNICH STUTTGART VIENNA 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 1
  • 2. 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 2 @ChrisAntognini  Senior principal consultant, trainer and partner at Trivadis in Zurich (CH)  christian.antognini@trivadis.com  http://antognini.ch  Focus: get the most out of Oracle Database  Logical and physical database design  Query optimizer  Application performance management  Author of Troubleshooting Oracle Performance Apress, 2008/2014  OakTable Network, Oracle ACE Director
  • 3. AGENDA 1. Concepts 2. Index Keys 3. Splits 4. Free Space 5. Reorganizations 6. Bitmap 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 3
  • 4. 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 Concepts 4
  • 5. Structure of a B-Tree 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 5 24 51 12 29 42 86 2 ROWID 8 ROWID 10 ROWID 11 ROWID 12 ROWID 18 ROWID 20 ROWID 24 ROWID 26 ROWID 29 ROWID 34 ROWID 38 ROWID 42 ROWID 51 ROWID 55 ROWID 73 ROWID branch blocks 86 ROWID 99 ROWID left<24 right≥24 leaf blocks root block
  • 6. 2014 © Trivadis Nulls  NULL values are stored in the index only when at least one of the indexed columns is not NULL  Exception: bitmap indexes always store indexed data  For unique indexes the uniqueness is guaranteed only if at least one of the indexed columns is not NULL  NULL values are stored after not NULL values in the index Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 6
  • 7. 2014 © Trivadis Myths  Oracle B-tree indexes can become “unbalanced” over time and need to be rebuilt  Deleted space in an index is “deadwood” and over time requires the index to be rebuilt  If an index reaches “x” number of levels, it becomes inefficient and requires the index to be rebuilt  If an index has a poor clustering factor, the index needs to be rebuilt  To improve performance, indexes need to be regularly rebuilt Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 7 Source: Oracle B-Tree Index Internals: Rebuilding The Truth, Richard Foote
  • 8. 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 Index Keys 8
  • 9. Internal Key  Internally a unique key is needed to sort the indexed columns  For unique indexes the internal key is the same as the index key  For non-unique indexes the ROWID of the indexed row is added to the index key to make it unique  For global indexes an extended ROWID is used, otherwise a restricted ROWID is enough 2014 © Trivadis  Therefore  The index entries are sorted in a consistent way  Even for non-unique indexed the order of the index entries changes only when the indexed table is reorganized (i.e. not if the index is rebuilt!) Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 9
  • 10. Branch Block Key  In branch blocks the internal key is truncated after the first byte that differs from the last key of the left leaf block  All keys are preceded by a length field  1 byte for data up to 127 bytes  Otherwise 2 bytes - The high bit of the first byte is set (0x80) - The remaining bits of the first byte and the second byte contain the length  Partially stored keys are terminated by 0xFE  Nulls have a column length of 0xFF, trailing nulls are stored 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 10 RDBA Len Key 1 Data Key 1 Len Key X Data Key X
  • 11. Leaf Block Key  All keys are preceded by a length field  1 byte for data up to 127 bytes  Otherwise 2 bytes - The high bit of the first byte is set (0x80) - The remaining bits of the first byte and the second byte contain the length  Nulls have a column length of 0xFF, trailing nulls are stored  For global indexes an extended ROWID is used, otherwise a restricted ROWID is enough 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 11 Flag Lock Len Key 1 Data Key 1 Len ROWID ROWID (optional)
  • 12. 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 Splits 12
  • 13. 2014 © Trivadis Splits  Two split methods are implemented  50:50 split  The keys are evenly distributed over two blocks  Based on size, not number of keys  99:1 split (a.k.a. 90:10)  The new key is the right-most of the index  A new leaf block containing only the new key is added  Useful for increasing values like sequences and timestamps  A change in the structure of an index (like a split) is not rollbacked if the transaction that caused it is rollbacked Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 13
  • 14. 2014 © Trivadis Splits Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 14 #1
  • 15. 2014 © Trivadis Splits Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 15 #1 #2 #3
  • 16. 2014 © Trivadis Splits #2 #4 #3 Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 16 #1 #2 #3
  • 17. 2014 © Trivadis Splits #1 Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 17 #1 #2 #4 #3 #5 #2 #4 #3
  • 18. 2014 © Trivadis Splits Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 18
  • 19. 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 Free Space 19
  • 20. Reminder  PCTFREE is only used when the index is created (or rebuilt)  An update is implemented as a delete followed by an insert  The free space in leaf blocks is strongly dependent on the type of split (50:50 2014 © Trivadis or 99:1)  PCTUSED cannot be used for indexes Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 20
  • 21. Free Space 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 21 #1 #2 #3 #4
  • 22. Free Space 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 22 #1 #2 #4 #3
  • 23. 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 Reorganizations 23
  • 24. Reorganizations  If the free space is not automatically reused, it should be manually reclaimed  This is unusual, therefore such an operation should only be performed if it is really necessary  To manually reclaim free space two possibilities exists  Rebuild: the index is recreated  Coalesce: free space in contiguous blocks is merged and, therefore, some blocks are unchained  Unnecessary rebuild/coalesce may lead to sub-optimal data density in leaf blocks  Too much free space, i.e. too low density  Too much block splits, i.e. too high density 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 24
  • 25. Rebuild vs. Coalesce 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 25 Pro Cons Rebuild  Doesn’t lock table (online rebuilds only)  Reclaim all the free space  Locks table during rebuild (offline rebuilds only)  Doubles space usage temporarily  The index is completely recreated (to do so large sorts may be performed) Coalesce  Doesn’t lock table  Current index structure is reused  Doesn’t reclaim all the free space  Can generate lot of redo
  • 26. 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 Bitmap 26
  • 27. 2014 © Trivadis Bitmap  A bitmap index is a regular B-tree, only the internal key differs from the non-bitmap index!  The key is composed by  Indexed column(s)  Start/End ROWID  Bitmap representing the rows that have the key - To save space it is “compressed” Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 27
  • 28. Summary 2014 © Trivadis  B-tree indexes cannot become “unbalanced”  Deleted space in an index can be reused  Indexes do not need to be regularly rebuilt Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 28
  • 29. Questions and answers ... Christian Antognini Senior Principal Consultant christian.antognini@trivadis.com BASEL BERN BRUGG LAUSANNE ZUERICH DUESSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MUNICH STUTTGART VIENNA 2014 © Trivadis Indexes: Structure, Splits and Free Space Management Internals 29 September 2014 29