Docsity

Lecture Notes on Relational Database Systems | CS 587, Quizzes of Computer Science

Toggle sidebar
bg1
3/24/2009 1
PSU’s CS 587
CS 587/410, Spring 2009
Relational Database Systems /Database
Internals
Dave Archer, [email protected]
Course Website:
www.cs.pdx.edu/~darcher/CS587 –Spring 2009
This work, and all other files in this series, are licensed under the Creative
Commons Attribution License. To view a copy of this license, visit
http://creativecommons.org/licenses or send a letter to Creative Commons,
171 2nd Street, Suite 300, San Francisco, California, 94105, USA
These slides have benefited from the content of slides developed by Raghu
Ramakrishnan, Johannes Gehrke, and Len Shapiro, whom I thank
Slides will be online by noon each Monday
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30

Partial preview of the text

Download Lecture Notes on Relational Database Systems | CS 587 and more Quizzes Computer Science in PDF only on Docsity!

CS 587/410, Spring 2009

Relational Database Systems /Database

Internals

Dave Archer, [email protected]

Course Website:

www.cs.pdx.edu/~darcher/CS587 – Spring 2009

This work, and all other files in this series, are licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses or send a letter to Creative Commons, 171 2nd Street, Suite 300, San Francisco, California, 94105, USA

 These slides have benefited from the content of slides developed by Raghu Ramakrishnan, Johannes Gehrke, and Len Shapiro, whom I thank

 Slides will be online by noon each Monday

Plan for today

 Review Syllabus

 Pre-requisite quiz

 Personal Introductions  What is your background in Databases?  Any experience in DBMS aside from classes?

 Minibase Intro, Buffer Manager assignment

 Lecture on Chapter 8

 Lecture on part of Chapter 9 needed for homework

 Quit 10 minutes early to form teams  What is your background in Java?

Learning Objectives for Chapter 8

 Identify the input, output and function of each component in the architecture diagram

 Be able to describe the relationships between different classifications of indexes  Alternatives, clustering, uniqueness, denseness, primary

 For each cell in the table on the “cost of operations” slide , explain the underlying algorithm and justify the cost.

 Definitions: Index only plans, composite keys

 Given a workload, choose an optimal index configuration.

Table of Contents: Chapter 8 (*review)

 8.1 Data on external storage*  Database architecture

 8.2 File organizations and indexing*  Indexes  Alternatives for k* data entries  Index classification: clustered, dense, unique, primary

 8.3 Index search data structures*  Hash-based indexes  Tree indexes

 8.4 Comparing File Organizations

 8.5 Indexes and performance tuning*

Discussion

 What happens when an application reads a page from disk?

 What else happens if the application writes the page?

How the Records Fall

16 9

22 41

62 15

2 11

2 9

11 15

16 22

41 62

16

9 41 2 22 62

11 15

Heap Sorted Hashed Bucket 0

1

2

3

Typical index architecture

 Used by modern DBMSs

 What are typical search structures in CS?

(Data file)

Data entries

Data Records

(Index File)^ k^ k^ k*

Search structure: given a key, it finds thedata entry for that key

Alternatives for Data Entry _k_* in Index

 In a data entry k* we can store:

  1. Data record with key value k, or
    • In this case the previous page is not accurate
  2. < k , rid of data record with search key value k >, or
  3. < k , list of rids of data records with search key k >

 Choice of alternative for data entries is orthogonal to the indexing technique used to locate data entries with a given key value k.  Examples of indexing techniques: B+ trees, hash-based structures  Typically, index contains auxiliary information that directs searches to the desired data entries

8.Storage

Alternative 2: One pointer per

k*

10* 10* 21* 24* 30* 42*

10 Blue

42 Red

10 Green 30 Blue

21 Red 24 Blue INDEX

Alternative 3: 1 or more pointers per

k*

10* 18* 21* 24* 30*

10 Blue

18 Red

10 Green 30 Blue

21 Red 24 Blue INDEX

8.2.1 Clustered vs. Unclustered

 Suppose that Alternative (2) is used for data entries, and that Index the data records are stored in a Heap file.  To build clustered index, first sort the Heap file (with some free space on each page for future inserts).  Overflow pages may be needed for inserts. (Thus, order of data recs is `close to’, but not identical to, the sort order.)

Index entries

Data entries

direct search for

(Index File)

Data Records

CLUSTERED data entries

(Data file)

Data entries

Data Records

UNCLUSTERED

8.Storage

8.2.2 Index Classification

Primary vs. secondary : If search key contains primary key, then called primary index.  In practice, primary means alternative 1

Unique index: Search key contains a candidate key.

Clustered vs. unclustered : If order of data records is the same as, or `close to’, order of data entries, then called clustered index.  Alternative 1 implies clustered.  A file can be clustered on at most one single-attributesearch key.  Cost of retrieving data records through index varies greatly based on whether index is clustered or not!

8.Storage

Index Classification

Clustered, sparse indexes are smaller; they work well for range searches and sorting.

But…data blocks are difficult to keep sorted and some useful optimizations are based on dense indexes.

Note: one file can have at most one clustered index - all of the additional indices must be unclustered.

sparse dense

clustered YES YES

unclustered NO! YES

8.3.1 Hash-based Index

Examples

age h

Smith,44, Jones,40, Tracy,44,

Ashby,25, Basu,33, Bristow,29,

Cass,50, Daniels,22,

h(age)=

h(age)=

h(age)=

3000 3000 5004 5004

4003 2007 6003 6003

h sal

h(sal)=

h(sal)=

Employees file hashed on age Index on salary