You are on page 1of 29

CENG 352

Database Management Systems


Instructor: Nihan Kesim Çiçekli
email: nihan@ceng.metu.edu.tr
URL: http://www.ceng.metu.edu.tr/~nihan
CENG 352
• Instructor: Nihan Kesim Çiçekli
• Office: A308
• Email: nihan@ceng.metu.edu.tr
• Lecture Hours: Mon. 14:40,15:40 (BMB4);
Thu. 13:40 (BMB2)
• Office Hours: Fri. 10:40-11:30
• Course Web page:
http://www.ceng.metu.edu.tr/~semra/nli/ceng352
• Teaching Assistant:
Semra Doğandağ (semra@ceng.metu.edu.tr)
SPRING 2004S CENG 352 2
Text Books and References
1. Raghu Ramakrishnan, Database Management
Systems, McGraw Hill, 3rd edition, 2003 (text
book).
2. R. Elmasri, S.B. Navathe, Fundamentals of
Database Systems, 4th edition, Addison-Wesley,
2004.
3. A. Silberschatz, H.F. Korth, S. Sudarshan,
Database System Concepts, McGraw Hill, 4th
edition, 2002.
4. H. Garcia-Molina, J. D. Ullman, J. Widom,
Database Systems The Complete Book, Prentice
Hall, 2002.
SPRING 2004S CENG 352 3
Grading
Written assignments 15%
Project 20%
Midterm Exam 30%
Final 35%

Exam Date:
Midterm Exam: 2nd week of April.

SPRING 2004S CENG 352 4


Grading Policies
• Policy on missed midterm:
– no make-up exam
• Lateness policy:
– Late assignments are penalized up to 10% per
day.
• All assignments are to be your own work.
Projects in groups of two.

SPRING 2004S CENG 352 5


Course Outline
• The Relational Data Model, Relational Algebra
and Calculus, SQL
• Query Evaluation and Optimization
• Relational Database Design and Tuning
• Transaction Management, Concurrency Control
and Crash Recovery
• Database Security and Authorization
• Parallel and Distributed Databases
• Object-Database Systems
• Information Retrieval and XML Data
SPRING 2004S CENG 352 6
What is a Database Management System?
• A Database Management System (DBMS) is a
software package designed to store and manage
databases:
1. Manages very large amounts of data.
2. Supports efficient access to very large amounts of data.
3. Supports concurrent access to very large amounts of data.
• Example: bank and its ATM machines.
4. Supports secure, atomic access to very large amounts of
data.
• Contrast two people editing the same UNIX file – last to write
“wins” – with the problem if two people deduct money from the
same account via ATM machines at the same time – new balance
is wrong whichever writes last.
SPRING 2004S CENG 352 7
Example: Online Bookseller
• Data = information on books (including categories,
bestsellers, etc.), customers, pending orders, order
histories, trends and preferences, etc.
– Massive: many gigabytes at a minimum for medium-size
bookseller, more if keep all order histories over all time,
even more if keep images of book covers and sample
pages
=> Far too big for memory
– Persistent: data outlives programs that operate on it
– Multi-user: many people/programs accessing same
database, or even same data, simultaneously
=> Need careful controls
SPRING 2004S CENG 352 8
Files vs. DBMS
• Application must stage large datasets between
main memory and secondary storage (e.g.,
buffering, page-oriented access, 32-bit addressing,
etc.)
• Special code for different queries
• Must protect data from inconsistency due to
multiple concurrent users
• Crash recovery
• Security and access control

SPRING 2004S CENG 352 9


What is a Relational Database?
• Based on the relational model (tables):

acct # name balance


12345 Sally 1000.21
34567 Sue 285.48
… … …
• Today used in most DBMS's.

SPRING 2004S CENG 352 10


The DBMS Marketplace
• Relational DBMS companies – Oracle, Sybase – are among the largest
software companies in the world.
• IBM offers its relational DB2 system. With IMS, a nonrelational
system, IBM is by some accounts the largest DBMS vendor in the
world.
• Microsoft offers SQL-Server, plus Microsoft Access for the cheap
DBMS on the desktop, answered by “lite” systems from other
competitors.
• Relational companies also challenged by “object-oriented DB”
companies.
• But countered with “object-relational” systems, which retain the
relational core while allowing type extension as in OO systems.

SPRING 2004S CENG 352 11


Three Aspects to Studying DBMS's
1. Modeling and design of databases.
– Allows exploration of issues before committing to an
implementation.
2. Programming: queries and DB operations like
update.
– SQL = “intergalactic dataspeak.”
3. DBMS implementation.

SPRING 2004S CENG 352 12


Query
Employee Languages
Department

Name Dept Dept Manager

SQL
SELECT Manager
FROM Employee, Department
WHERE Employee.name = "Clark Kent”
AND Employee.Dept = Department.Dept
Query Language
Data definition language (DDL) ~ like type defs in C or Pascal
Data Manipulation Language (DML)
Query (SELECT)
UPDATE < relation name >
SET <attribute> = < new-value>
WHERE <condition>
SPRING 2004S CENG 352 13
Host Languages
C, C++, Java, Lisp, COBOL

Application prog.
Calls to
DB DBMS

Local Vars
(Memory)

(Storage)

• Host language is completely general (Turing complete)


• Query language—less general "non procedural" and
optimizable

SPRING 2004S CENG 352 14


Relational Model
Relational model is good for:
• Large amounts of data —> simple operations
• Navigate among small number of relations

Difficult Applications for relational model:


• VLSI Design (CAD in general)
• CASE
• Graphical Data
SPRING 2004S CENG 352 15
Other Models
Where number of "relations" is large, relationships are complex
•Object Data Model
•Logic Data Model

OBJECT DATA MODEL


1. Complex Objects – Nested Structure (pointers or
references)
2. Encapsulation, set of Methods/Access functions
3. Object Identity
4. Inheritance – Defining new classes like old classes
Object model: usually find objects via explicit navigation
Also query language in some systems

SPRING 2004S CENG 352 16


Other Models
LOGIC (Horn Clause) DATA MODEL
• Prolog, Datalog:
if A1 and A2 then B
B:- A1 and A2
• Functions s(5) = 6 (successor)
• Predicates with Arguments: sum(X,Y,Z)  X + Y = Z
sum(X,0,X) means X + 0 = X (always true for all X)
sum(X,s(Y),s(Z)):-sum(X,Y,Z) means X+(Y+1) = (Z+1) if X
+Y=Z
• More powerful than relational
Can Compute Transitive Closure
edge(X,Y).
path(X,Y) :- edge(X,Y).
path(X,Z) :- path(X,Y) & edge(Y,Z).
SPRING 2004S CENG 352 17
Data Models
60’s
Hierarchical Network
70's

80's
Relational Choice for most new
applications
90’s

Object Bases Knowledge Bases

now

SPRING 2004S CENG 352 18


Why Use a DBMS?
• Data independence and efficient access.
• Reduced application development time.
• Data integrity and security.
• Uniform data administration.
• Concurrent access, recovery from crashes.

SPRING 2004S CENG 352 19


Data Independence *
• Applications insulated from how data is
structured and stored.
• Logical data independence: Protection
from changes in logical structure of data.
• Physical data independence: Protection
from changes in physical structure of data.

 One of the most important benefits of using a DBMS!

SPRING 2004S CENG 352 20


Levels of Abstraction
• Many views, single View 1 View 2 View 3
conceptual (logical) schema
and physical schema. Conceptual Schema
– Views describe how users see
the data. Physical Schema

– Conceptual schema defines


logical structure
– Physical schema describes the
files and indexes used.
 Schemas are defined using DDL; data is modified/queried using DML.

SPRING 2004S CENG 352 21


Concurrency Control
• Concurrent execution of user programs is essential
for good DBMS performance.
– Because disk accesses are frequent, and relatively slow, it
is important to keep the cpu humming by working on
several user programs concurrently.
• Interleaving actions of different user programs can
lead to inconsistency: e.g., check is cleared while
account balance is being computed.
• DBMS ensures such problems don’t arise: users can
pretend they are using a single-user system.

SPRING 2004S CENG 352 22


Transaction: An Execution of a DB Program
• Key concept is transaction, which is an atomic
sequence of database actions (reads/writes).
• Each transaction, executed completely, must leave the
DB in a consistent state if DB is consistent when the
transaction begins.
– Users can specify some simple integrity constraints on the
data, and the DBMS will enforce these constraints.
– Beyond this, the DBMS does not really understand the
semantics of the data. (e.g., it does not understand how the
interest on a bank account is computed).
– Thus, ensuring that a transaction (run alone) preserves
consistency is ultimately the user’s responsibility!

SPRING 2004S CENG 352 23


Scheduling Concurrent Transactions
• DBMS ensures that execution of {T1, ... , Tn} is
equivalent to some serial execution T1’ ... Tn’.
– Before reading/writing an object, a transaction requests a lock
on the object, and waits till the DBMS gives it the lock. All
locks are released at the end of the transaction. (Strict 2PL
locking protocol.)
– Idea: If an action of Ti (say, writing X) affects Tj (which
perhaps reads X), one of them, say Ti, will obtain the lock on
X first and Tj is forced to wait until Ti completes; this
effectively orders the transactions.
– What if Tj already has a lock on Y and Ti later requests a lock
on Y? (Deadlock!) Ti or Tj is aborted and restarted!
SPRING 2004S CENG 352 24
Ensuring Atomicity
• DBMS ensures atomicity (all-or-nothing property) even
if system crashes in the middle of a Xact.
• Idea: Keep a log (history) of all actions carried out by
the DBMS while executing a set of Xacts:
– Before a change is made to the database, the corresponding
log entry is forced to a safe location. (WAL protocol; OS
support for this is often inadequate.)
– After a crash, the effects of partially executed transactions are
undone using the log. (Thanks to WAL, if log entry wasn’t
saved before the crash, corresponding change was not applied
to database!)

SPRING 2004S CENG 352 25


The Log
• The following actions are recorded in the log:
– Ti writes an object: The old value and the new value.
• Log record must go to disk before the changed page!
– Ti commits/aborts: A log record indicating this action.
• Log records chained together by Xact id, so it’s
easy to undo a specific Xact (e.g., to resolve a
deadlock).
• Log is often duplexed and archived on “stable”
storage.
• All log related activities (and in fact, all CC related
activities such as lock/unlock, dealing with
deadlocks etc.) are handled transparently by the
DBMS.
SPRING 2004S CENG 352 26
Databases make these folks happy
• End users and DBMS vendors
• DB application programmers
– e.g., smart webmasters
• Database administrator (DBA)
– Designs logical /physical schemas
– Handles security and authorization
– Data availability, crash recovery
– Database tuning as needs evolve
Must understand how a DBMS works!
SPRING 2004S CENG 352 27
Structure of a DBMS These layers
must consider
concurrency
control and
• A typical DBMS has a recovery

layered architecture. Query Optimization


and Execution
• The figure does not
show the concurrency Relational Operators
control and recovery Files and Access Methods
components.
Buffer Management
• This is one of several
possible architectures; Disk Space Management
each system has its
own variations.
DB

SPRING 2004S CENG 352 28


Summary
• DBMS used to maintain, query large datasets.
• Benefits include recovery from system crashes,
concurrent access, quick application development,
data integrity and security.
• Levels of abstraction give data independence.
• A DBMS typically has a layered architecture.
• DBAs hold responsible jobs and
are well-paid! 
• DBMS R&D is one of the broadest,
most exciting areas in CS.

SPRING 2004S CENG 352 29

You might also like