Indexing December 12, 2008 Indexing Introduction New tuple is - - PowerPoint PPT Presentation

indexing
SMART_READER_LITE
LIVE PREVIEW

Indexing December 12, 2008 Indexing Introduction New tuple is - - PowerPoint PPT Presentation

Indexing December 12, 2008 Indexing Introduction New tuple is stored without any order next available space Indexing Introduction New tuple is stored without any order next available space Access will require inspection of every tuple


slide-1
SLIDE 1

Indexing

December 12, 2008

Indexing

slide-2
SLIDE 2

Introduction

New tuple is stored without any order

next available space

Indexing

slide-3
SLIDE 3

Introduction

New tuple is stored without any order

next available space

Access will require inspection of every tuple SELECT name, salary FROM department WHERE name LIKE ’A%’;

requires visiting each row for comparison since no alphabetical storage

Indexing

slide-4
SLIDE 4

Introduction

Indexing: speeds up access to desired data

e.g., a book index, catalog index in library

Indexing

slide-5
SLIDE 5

Introduction

Indexing: speeds up access to desired data

e.g., a book index, catalog index in library

DB Indexes: used by DB server to locate tuples in a table Indexes: special tables with ordered tuples

  • ne (or more) columns from main table

includes pointer to the full row in main file

Indexing

slide-6
SLIDE 6

Basic Index Operations in MySQL

Create on the column most often used in queries, update, delete In MySQL: ALTER TABLE employee ADD INDEX dept_indx (dept_id); Other DB: CREATE INDEX dept_indx ON employee (dept_id); View indexes on a table: SHOW INDEX from employee; Drop an index: ALTER TABLE employee drop INDEX dept_indx;

Indexing

slide-7
SLIDE 7

Multi-column Indexes

Create index on two columns: ALTER TABLE person ADD INDEX name_indx (lname, fname); Can use for queries with:

both lname and fname lname alone not for fname alone

Indexing

slide-8
SLIDE 8

Basic Concepts for Index Implementation

SearchKey - attribute to set of attributes used to look up records in a file. An index file consists of records (called index entries) of the form Index files are typically much smaller than the original file Two basic kinds of indices:

Ordered indices: search keys are stored in sorted order Hash indices: search keys are distributed using a “hash function”

Indexing

slide-9
SLIDE 9

Dense Index Files

Dense Index: search-key appears for every search-key value from main file

Figure: A dense index file

Indexing

slide-10
SLIDE 10

Sparse Index Files

Sparse Index: search-key appears for only a few values

Figure: A sparse index file

Indexing

slide-11
SLIDE 11

B-Tree Indexes

Balanced trees:

length from root to any leaf is same every non-leaf node has n to n/2 nodes; n is fixed

Most common, default index type

Figure: Example of a B-tree Index

Indexing

slide-12
SLIDE 12

B-tree Indexes

Sequential search (without B-tree index): O(n) B-tree search: O(log(n))

Indexing

slide-13
SLIDE 13

B-tree Indexes

Sequential search (without B-tree index): O(n) B-tree search: O(log(n)) Adds:

performance overhead (insertion, deletion) adds space overhead

Indexing