Database Internals: How Indexes Work

Slides:



Advertisements
Similar presentations
DB-03: A Tour of the OpenEdge™ RDBMS Storage Architecture Richard Banville Technical Fellow.
Advertisements

©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part C Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
Advanced Databases: Lecture 2 Query Optimization (I) 1 Query Optimization (introduction to query processing) Advanced Databases By Dr. Akhtar Ali.
Spring 2003 ECE569 Lecture ECE 569 Database System Engineering Spring 2003 Yanyong Zhang
Spring 2004 ECE569 Lecture ECE 569 Database System Engineering Spring 2004 Yanyong Zhang
1 Indexing Structures for Files. 2 Basic Concepts  Indexing mechanisms used to speed up access to desired data without having to scan entire.
1 External Sorting for Query Processing Yanlei Diao UMass Amherst Feb 27, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Lecture 8 Index Organized Tables Clusters Index compression
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
A first look at table partitioning PUG Challenge Americas Richard Banville & Havard Danielsen OpenEdge Development June 9, 2014.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Chapter 11 Indexing & Hashing. 2 n Sophisticated database access methods n Basic concerns: access/insertion/deletion time, space overhead n Indexing 
Module 5 Planning for SQL Server® 2008 R2 Indexing.
Database Management Systems, R. Ramakrishnan and J. Gehrke 1 External Sorting Chapter 13.
DB-08: A Day in the Life of a Type II Record Richard Banville Progress Fellow.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Relational Operator Evaluation. Overview Application Programmer (e.g., business analyst, Data architect) Sophisticated Application Programmer (e.g.,
Chapter 5 Index and Clustering
Alon Levy 1 Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation. – Projection ( ) Deletes.
Query Optimization Cases. D. ChristozovINF 280 DB Systems Query Optimization: Cases 2 Executable Block 1 Algorithm using Indices (if available) Temporary.
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
N5 Databases Notes Information Systems Design & Development: Structures and links.
Databases and DBMSs Todd S. Bacastow January
INLS 623– Database Systems II– File Structures, Indexing, and Hashing
Indexing Structures for Files and Physical Database Design
CS522 Advanced database Systems
Record Storage, File Organization, and Indexes
Practical Office 2007 Chapter 10
Behind The Scenes: Updating A Record
CS 728 Advanced Database Systems Chapter 18
Physical Changes That Don’t Change the Logical Design
Database Management System
Indices.
Multidimensional Access Structures
We Have Found Nirvana with Online Dump and Load (224)
External Sorting Chapter 13
Extra: B+ Trees CS1: Java Programming Colorado State University
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
COMP 430 Intro. to Database Systems
Database Management Systems (CS 564)
B+ Tree.
Database Performance Tuning and Query Optimization
Evaluation of Relational Operations
Database Applications (15-415) DBMS Internals- Part VI Lecture 18, Mar 25, 2018 Mohammad Hammoud.
Relational Operations
Lecture 12 Lecture 12: Indexing.
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
Introduction to Database Systems File Organization and Indexing
Database Applications (15-415) DBMS Internals- Part VII Lecture 19, March 27, 2018 Mohammad Hammoud.
Database Applications (15-415) DBMS Internals- Part VI Lecture 15, Oct 23, 2016 Mohammad Hammoud.
Physical Database Design
Sidharth Mishra Dr. T.Y. Lin CS 257 Section 1 MH 222 SJSU - Fall 2016
Introduction to Database Systems
External Sorting Chapter 13
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
CS202 - Fundamental Structures of Computer Science II
File Storage and Indexing
Database Design and Programming
Chapter 12 Query Processing (1)
Implementation of Relational Operations
Lecture 13: Query Execution
Chapter 11 Database Performance Tuning and Query Optimization
ICOM 5016 – Introduction to Database Systems
Database Systems (資料庫系統)
Indexing, Access and Database System Architecture
External Sorting Chapter 13
Advanced Topics: Indexes & Transactions
Unit 12 Index in Database 大量資料存取方法之研究 Approaches to Access/Store Large Data 楊維邦 博士 國立東華大學 資訊管理系教授.
Index Structures Chapter 13 of GUW September 16, 2019
Presentation transcript:

Database Internals: How Indexes Work Mike Furgal PUG Challenge US October 25, 2018

Abstract Have you ever wondered how the 4GL uses indexes? This talk describes the internal workings of the index manager of the OpenEdge RBDMS. Include algorithms for key compression and lookups. Also covers multi- component keys, equality and range brackets, bracket scans, user of multiple indexes, on disk storage, locking. Several 4GL query examples will be studied and the 4GL compiler rules for index selection will be explained.

Abstract This is a 2-part session. Session 1 (this one) covers the internals of the index structure, compresssion, etc. Part 2 is Called “How the 4GL Uses Indexes” 4pm Friday in the Hollis room. Gus Bjorklund is delivering this session

Subjects Basics: What Are Indexes Index Structure Index Types Index Compression Basic Index Usage

What are Indexes Indexes are used for Quick access to a row or set of rows To retrieve rows in a specific order To enforce uniqueness of columns To locate rows that contain a word or phrase

Records Have A Rowid 000000000000000000000000000000000001 000000000 Unique 64-bit identifies for a record in a table Partitionid, Block number in an area, row in a block Unique within an area or partition Encodes the “physiological” storage addresss Used to locate a record “fast’ Same as a RECID for OpenEdge databases Constant for the “life” of the record Until you delete it or change it’s partition Rowid established by the storage allocation

Index – an Ordered List of Rowids City BOLONIA BOLTON BOLTON BOLTON BONN BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON CARDIFF Rowid 3331 5554 9001 9022 8001 1111 1118 7001 9002 9003 9006 9007 9008 9009 9999 3333

What if the ordered list of records is too LONG?

1. Subdivide the list into multiple lists 2 1.Subdivide the list into multiple lists 2. Make an ordered list of lists

Subdivided List City BOLONIA BOLTON BOLTON BOLTON BONN BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON CARDIFF Rowid 3331 5554 9001 9022 8001 1111 1118 7001 9002 9003 9006 9007 9008 9009 9999 3333 4 lists

A List of Lists BOLONIA BONN BOSTON BOSTON City BOLONIA BOLTON BOLTON BOLTON BONN BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON CARDIFF Rowid 3331 5554 9001 9022 8001 1111 1118 7001 9002 9003 9006 9007 9008 9009 9999 3333 BOLONIA BONN BOSTON BOSTON

What if the ordered list of lists is too LONG?

1. Subdivide the list of lists into multiple lists of lists 2 1.Subdivide the list of lists into multiple lists of lists 2. Make a list of lists of lists

Index Block

Index Leaf Block Index Entries with Rowids

B-Trees All Indexes are structured as compressed B-Trees Hugh Concurrency Multi-threaded access Locking minimum blocks, instead of the entire B-Tree The index is compressed Four different ways

Index B-Tree (2 levels)

Index B-Tree (3 levels)

Index Entry KS Key Value IS Info Two parts: Key Value and Info Key Value: byte array, up to ~3000 bytes Info: byte array, up to 255 bytes Entries ordered by Numeric Value (integer, int64, decimal) or Date or Datetime or Collating order of characters Compared left to right, byte by byte

Multiple Indexes on A Table Each index contains All the rows of the table Same number of entries Same number of rows at the leaf level Each index Is a different B-Tree Gives different ordering Is a different size Requires a different number of accesses to traverse

Index Types Unique or Non-Unique Single or Multi Component Index Word Index

Unique vs. Non-Unique Not much difference Unique only allows one entry per key value FIND is a bit more efficient Deleted entries must be reserved until deleting transaction ends

Multi-Component Index State City Department AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Sales, AZ, Phoenix, Marketing, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Shipping, AZ, Tucson, Marketing, AZ, Tucson, Shipping, AZ, Tucson, Shipping, AZ, Tucson, Shipping, CA, San Diego, Admin, CA, San Diego, Marketing, Rowid 3341 9800 9806 9876 7776 7777 0076 0888 3876 0006 0345 0347 8877 8888 0066 1198

Multi-Compnent Keys Key value composed from more than 1 field State, City, Department Last Name, First Name Country, State, City, Zipcode Field values are “logically concatenated” All component values needed to find an entry Ordered by concatenated value

Word Indexes Word index Word index is structured as a regular index A text field with many words has many index entries, one entry for each word One word per key value rather than the entire field Word index is structured as a regular index B-Tree like other indexes Same structure of index entries and keys A word index with a field with one word in it looks exactly like a regular index on that field

Word Indexes: Queries … field CONTAINS “eye exam* | (visual test)” This is a multi-bracket query 1) all entries where key = “eye” AND 2) all entries where key BEGINS “exam” OR 3) all entries where key = “visual” AND 4) all entries where key = “test”. Result is all records that satisfy (1 AND 2) OR (3 AND 4)

Index Compression

Compression Improves Performance Storage Efficiency Reduces the number of key comparisons Reduces the number of B-Tree levels Reduces the number of index blocks Reduces the number of DB Accesses Storage Efficiency More entries per block Fewer blocks

4 Types of Compression Delete common prefix in all levels of the B-Tree Delete non contributing trailing bytes in the lowest non- leaf level Delete first key in all non-leaf blocks Use tag lists or bit maps for non-unique keys

Prefix Compression City BOLONIA BOLTON BOLTON BOLTON BONN BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON CARDIFF Rowid 3331 5554 9001 9022 8001 1111 1118 7001 9002 9003 9006 9007 9008 9009 9999 3333

Index – an Ordered List of Rowids City BOLONIA BOLTON BOLTON BOLTON BONN BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON CARDIFF Rowid 3331 5554 9001 9022 8001 1111 1118 7001 9002 9003 9006 9007 9008 9009 9999 3333 CS 0 3 6 8 2 2 9 6 6 9 9 9 9 9 7 0 Number of duplicate bytes (discarded)

Basic Index Usage

Simple Index Usage: FIND, Update

Find a Record FIND customer WHERE cust-num = 20. Index “cust-num” is used for the find Compiler determines it is index #113 Index 113 searched for key value = 20 Starting at the “_StorageObject” entry for index 113 Find the area (or partition) and root block of the index 113 Search the B-Tree of index 113 for key value 20 Extract the records ROWID Use the ROWID to fetch the record for cust-num = 20

B-Tree Search Root Level 1 Level 2 Level 3 Records Records Records

If Index is Unique replace Rowid with an “Index Lock” Update a key field City BOLONIA BOLTON BOLTON BOLTON BONN BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON BOSTON MONTREAL Rowid 3331 5554 9001 9022 8001 1111 1118 7001 9002 9003 9006 9007 9008 9009 9999 1118 Original Key entry is deleted New Key entry is created in correct location If Index is Unique replace Rowid with an “Index Lock”

FIND must return 0 or 1 records If index is Unique At most one row with matching can exist If found, then return matching record If index is not Unique Check the next index entry for more than on match If yes, then error If no, then return matching record

Database Block Size The size of the index block is the significant Larger blocks lead to fewer B-Tree levels Saves Database I/O Compresses tighter Larger blocks add search time per block CPU time is used to search Search costs less than Database I/O

B-Tree Search 1,000,000 Records 50 names per block 20,000 Leaf Blocks 1,000,000 Records needs 4 levels 3 levels: 50 x 50 x 50 = 125,000 records 4 levels: 50 x 50 x 50 x 50 = 6,250,000 records

B-Tree Search 1,000,000 Records 100 names per block Records Records 1,000,000 Records needs 3 levels 3 levels: 100 x 100 x 100 = 1,000,000 records 4 levels: 100 x 100 x 100 x 100 = 100,000,000 records

3 Level index about the same size with fewer blocks Index Utilization Index Analysis 3 Level index about the same size with fewer blocks 4 Level Index Average % full

Index Compaction Index Analysis Index Compaction can be run online and will likely reduce the number of levels from 4 to 3

Database Block Size Matters!! Index Utilization Matters!! Benchmarks show that a FIND on a 4 level index is 20% slower than a FIND on a 3 level index Database Block Size Matters!! Index Utilization Matters!!

More complex Index Usage Index Brackets

Index Brackets A set of consecutive entries in an index Defined by a range of key values Cust-num = 20 Age >= 21 Age >= 21 AND age <= 50 Name BEGINS “John” Determined by Index number Low key High Key

2 Bracket Types Equality Bracket Range Bracket All key values are equal (including all the components) Index entries are consecutive Range Bracket All key values within a specific range Between low key and high key

Equality Brackets Entire key same Entire key same State City Department AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Sales, AZ, Phoenix, Marketing, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Shipping, AZ, Tucson, Marketing, AZ, Tucson, Shipping, AZ, Tucson, Shipping, AZ, Tucson, Shipping, CA, San Diego, Admin, CA, San Diego, Marketing, Rowid 3341 9800 9806 9876 7776 7777 0076 0888 3876 0006 0345 0347 8877 8888 0066 1198 Entire key same Entire key same

Equality Brackets State = “AZ” State City Department AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Sales, AZ, Phoenix, Marketing, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Shipping, AZ, Tucson, Marketing, AZ, Tucson, Shipping, AZ, Tucson, Shipping, AZ, Tucson, Shipping, CA, San Diego, Admin, CA, San Diego, Marketing, Rowid 3341 9800 9806 9876 7776 7777 0076 0888 3876 0006 0345 0347 8877 8888 0066 1198 State = “AZ”

Equality Brackets State = “AZ” (State = “AZ”) AND (City = “Phoenix”) State City Department AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Sales, AZ, Phoenix, Marketing, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Shipping, AZ, Tucson, Marketing, AZ, Tucson, Shipping, AZ, Tucson, Shipping, AZ, Tucson, Shipping, CA, San Diego, Admin, CA, San Diego, Marketing, Rowid 3341 9800 9806 9876 7776 7777 0076 0888 3876 0006 0345 0347 8877 8888 0066 1198 State = “AZ” (State = “AZ”) AND (City = “Phoenix”)

RangeBrackets State = “AZ” (State = “AZ”) AND (City >= “Phoenix”) State City Department AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Sales, AZ, Phoenix, Marketing, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Shipping, AZ, Tucson, Marketing, AZ, Tucson, Shipping, AZ, Tucson, Shipping, AZ, Tucson, Shipping, CA, San Diego, Admin, CA, San Diego, Marketing, Rowid 3341 9800 9806 9876 7776 7777 0076 0888 3876 0006 0345 0347 8877 8888 0066 1198 State = “AZ” (State = “AZ”) AND (City >= “Phoenix”)

Is there a bracket for (State = “AZ”) AND (Department = “Marketing” Bracket Quiz State City Department AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Sales, AZ, Phoenix, Marketing, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Shipping, AZ, Tucson, Marketing, AZ, Tucson, Shipping, AZ, Tucson, Shipping, AZ, Tucson, Shipping, CA, San Diego, Admin, CA, San Diego, Marketing, Rowid 3341 9800 9806 9876 7776 7777 0076 0888 3876 0006 0345 0347 8877 8888 0066 1198 Is there a bracket for (State = “AZ”) AND (Department = “Marketing” ?

Entries are not consecutive Bracket Quiz State City Department AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Marketing, AZ, Flagstaff, Sales, AZ, Phoenix, Marketing, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Sales, AZ, Phoenix, Shipping, AZ, Tucson, Marketing, AZ, Tucson, Shipping, AZ, Tucson, Shipping, AZ, Tucson, Shipping, CA, San Diego, Admin, CA, San Diego, Marketing, Rowid 3341 9800 9806 9876 7776 7777 0076 0888 3876 0006 0345 0347 8877 8888 0066 1198 Is there a bracket for (State = “AZ”) AND (Department = “Marketing” NO!! Entries are not consecutive

Index Cursors

Index Cursors An internal data structure Allocated as needed on behalf of the connection Used for a sequential scan of a bracket Used to maintain location in an index bracket One or more are used in a query resolution

Index Cursors Has index number, area, etc 1 entry per level in the index Block Number Block Version Position in the block

This ends Part 1 Part 2 - How the 4GL Uses Indexes” 4pm Friday in the Hollis room.