Overview of storage and indexing l.jpg
This presentation is the property of its rightful owner.
Sponsored Links
1 / 23

Overview of Storage and Indexing PowerPoint PPT Presentation


  • 150 Views
  • Uploaded on
  • Presentation posted in: General

Overview of Storage and Indexing. Chapter 8 (part 1). Motivation. DBMS stores vast quantities of data Data is stored on external storage devices and fetched into main memory as needed for processing

Download Presentation

Overview of Storage and Indexing

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Overview of storage and indexing l.jpg

Overview of Storage and Indexing

Chapter 8

(part 1)


Motivation l.jpg

Motivation

  • DBMS stores vast quantities of data

  • Data is stored on external storage devices and fetched into main memory as needed for processing

  • Page is unit of information read from or written to disk. (in DBMS, a page may have size 8KB or more).

  • Data on external storage devices :

    • Disks: Can retrieve random page at fixed cost

      But reading several consecutive pages is much cheaper than reading them in random order

    • Tapes: Can only read pages in sequence

      Cheaper than disks; used for archival storage

  • Cost of page I/O dominates cost of typical database operations


Files versus indices l.jpg

Files versus Indices

  • File organization :

    • Method of arranging a file of records on external storage.

    • Record id (rid) is sufficient to physically locate record

  • Indexes :

    • Indexes are data structures that allow to find record ids of records with given values in index search key fields


File organizations l.jpg

File Organizations

  • Heap (random order) files:Suitable when typical access is a file scan retrieving all records.

  • Sorted Files:Best if records must be retrieved in some order, or only a `range’ of records is needed.

  • Indexes: Data structures to organize records to optimize certain kinds of retrieval operations.

    • Speed up searches for a subset of records, based on values in certain (“search key”) fields

    • Updates are much faster than in sorted files.


Alternatives for data entry k in index l.jpg

Alternatives for Data Entry k*in Index

  • Data Entry :Records stored in index file

    • Given search key value k, provide for efficient retrieval of all data entries k*with value k.

  • In a data entry k* , alternatives include that we can store:

    • alternative 1: Full data record with key value k, or

    • alternative 2: <k, rid of data record with search key value k>, or

    • alternative 3: <k, list of rids of data records with search key k>

  • Choice of above 3 alternative data entries is orthogonal to indexing technique used to locate data entries.

    • Example indexing techniques: B+ trees, hash-based structures, etc.


Alternatives for data entries l.jpg

Alternatives for Data Entries

  • Alternative 1: Full data record with key value k

    • Index structure is file organization for data records (instead of a Heap file or sorted file).

    • At mostone index on a given collection of data records can use Alternative 1. Otherwise, data records are duplicated, leading to redundant storage and potential inconsistency.

    • If data records are very large, this implies size of auxiliary information in index is also large.


Alternatives for data entries7 l.jpg

Alternatives for Data Entries

  • Alternatives 2 (<k, rid>)and 3 (<k, list-of-rids>):

    • Data entries typically much smaller than data records.

  • Comparison:

    • Both better than Alternative 1 with large data records, especially if search keys are small.

    • Alternative 3 more compact than Alternative 2, but leads to variable sized data entries even if search keys are of fixed length.


Index classification l.jpg

Index Classification

  • Primary vs. secondary index:

    • If search key contains primary key, then called primary index.

  • Clustered vs. unclustered index :

    • If order of data records is the same as, or `close to’, order of data entries, then called clustered index.


Index clustered vs unclustered l.jpg

Index Clustered vs Unclustered

  • Observation 1:

    • Alternative 1 implies clustered. True ?

  • Observation 2:

    • In practice, clustered also implies Alternative 1 (since sorted files are rare).

  • Observation 3:

    • A file can be clustered on at most one search key.

  • Observation 4:

    • Cost of retrieving data records through index varies greatly based on whether index is clustered or not !!


Index clustered vs unclustered10 l.jpg

Index Clustered vs Unclustered

  • Observation 1:

    • Alternative 1 implies clustered. True ?

  • Observation 2:

    • In practice, clustered also implies Alternative 1 (since sorted files are rare).

  • Observation 3:

    • A file can be clustered on at most one search key.

  • Observation 4:

    • Cost of retrieving data records through index varies greatly based on whether index is clustered or not !!


Clustered vs unclustered index l.jpg

Clustered vs. Unclustered Index

Index entries

UNCLUSTERED

CLUSTERED

direct search for

data entries

Data entries

Data entries

(Index File)

(Data file)

Data Records

Data Records

Suppose Alternative (2) is used for data entries.


Clustered vs unclustered index12 l.jpg

Clustered vs. Unclustered Index

  • Use Alternative (2) for data entries

  • Data records are stored in Heap file.

    • To build clustered index, first sort the Heap file

    • Overflow pages may be needed for inserts.

    • Thus, order of data recs is close to (not identical to) sort order.

Index entries

UNCLUSTERED

CLUSTERED

direct search for

data entries

Data entries

Data entries

(Index File)

(Data file)

Data Records

Data Records


B tree indexes l.jpg

B+ Tree Indexes

Non-leaf

Pages

Leaf

Pages

(Sorted by search key)

  • Index leaf pages containdata entries, and are chained (prev & next)

  • Index non-leaf pages have index entries; only used to direct searches:

index entry

P

K

P

K

P

P

K

m

0

1

2

1

m

2


Example b tree l.jpg

Example B+ Tree

Note how data entries

in leaf level are sorted

Root

17

  • Find: 29*? 28*? All > 15* and < 30*

  • Insert/delete: Find data entry in leaf, then change it.

Entries < 17

Entries >= 17

27

5

13

30

39*

2*

3*

5*

7*

8*

22*

24*

27*

29*

38*

33*

34*

14*

16*


Hash based indexes l.jpg

Hash-Based Indexes

  • Index is a collection of buckets.

    • Bucket = primary page plus zero or moreoverflow pages.

    • Buckets contain data entries.

  • Hashing functionh:

    • h(r) = bucket in which data entry for record r belongs.

    • h looks at search key fields of r.

    • No need for “index entries” due to one-level index file

  • Good for equality selections.


Cost model for our analysis l.jpg

Cost Model for Our Analysis

  • Notes:

    • We ignore CPU costs, for simplicity.

    • Measuring number of page I/Os ignores gains of pre-fetching a sequence of pages

    • Thus even I/O cost is only approximated.

    • Average-case analysis; based on simplistic assumptions.

  • Good enough to show overall trends!


Cost model for our analysis17 l.jpg

Cost Model for Our Analysis

Variables :

  • B: The number of data pages

  • R: Number of records per page

  • D: (Average) time to read or write disk page


Comparing file organizations l.jpg

Comparing File Organizations

  • Heap files (random order; insert at eof)

  • Sorted files, sorted on <age, sal>

  • Clustered B+ tree file, Alternative (1), search key <age, sal>

  • Heap file with unclustered B + tree index on search key <age, sal> (Alt 2)

  • Heap file with unclustered hash index on search key <age, sal> (Alt 2)


Operations to compare l.jpg

Operations to Compare

  • Scan: Fetch all records from disk

  • Equality search

  • Range selection

  • Insert a record

  • Delete a record


Assumptions in our analysis l.jpg

Assumptions in Our Analysis

  • Heap Files:

    • Equality selection on key; exactly one match.

  • Sorted Files:

    • Files compacted after deletions.

  • Indexes:

    • Alt (2), (3): data entry size/pointers = 10% size of record

    • Hash: No overflow buckets.

      • 80% page occupancy => File size = 1.25 data size

    • Tree: 67% occupancy (this is typical).

      • Implies file size = 1.5 data size

  • Scans:

    • Leaf levels of a tree-index are chained.

    • Index data-entries plus actual file scanned for unclustered indexes.

  • Range searches:

    • We use tree indexes to restrict set of data records fetched, but ignore hash indexes.


Cost of operations l.jpg

Cost of Operations

  • Several assumptions underlie these (rough) estimates!


Summary l.jpg

Summary

  • Many alternative file organizations exist, each appropriate in some situation.

  • If selection queries are frequent, sorting the file or building anindex is important.

    • Hash-based indexes only good for equality search.

    • Sorted files and tree-based indexes best for range search; also good for equality search.

    • Files rarely kept sorted in practice; B+ tree index is better.

  • Index is a collection of data entries plus a way to quickly find entries with given key values.


Summary23 l.jpg

Summary

  • Data entries can be :

    • actual data records,

    • <key, rid> pairs, or

    • <key, rid-list> pairs.

  • Can have several indexes on a given file of data records, each with a different search key.

  • Indexes can be classified as clustered vs. unclustered,

  • Differences have important consequences for utility/performance of query processing


  • Login