CENG 352 Database Management Systems

Download Report

Transcript CENG 352 Database Management Systems

CENG 352
Database Management Systems
Nihan Kesim Çiçekli
email: [email protected]
URL: http://www.ceng.metu.edu.tr/~nihan
CENG 352
•
•
•
•
Instructor: Nihan Kesim Çiçekli
Office: A308
Email: [email protected]
Lecture Hours: Tue. 13:40,14:40 (BMB3);
Thu. 9:40 (BMB3)
• Course Web page: http://cow.ceng.metu.edu.tr
• Teaching Assistant:
Ali Anıl Sınacı
CENG 352 Database Management Systems
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.
CENG 352 Database Management Systems
3
Grading
•
•
•
•
Midterm
Assignments and Quizzes
Project
Final Exam
25 %
25 %
20 %
30 %
CENG 352 Database Management Systems
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.
CENG 352 Database Management Systems
5
Course Outline
•
•
•
•
•
•
•
•
•
The Relational Data Model
Query Languages: Relational Calculus and SQL
Relational Database Design and Tuning
Query Evaluation and Optimization
Transaction Management
Concurrency Control
Crash Recovery
XML, XQuery, XPath
Internet Applications
CENG 352 Database Management Systems
6
Basic Definitions
•
•
•
•
•
Data
Database
Mini-world
Database Management System (DBMS)
Database System
CENG 352 Database Management Systems
7
Basic Definitions
• Data: Known facts that can be recorded and have an implicit
meaning.
• Database: A collection of related data.
• Mini-world: Some part of the real world about which data is
stored in a database. For example, student grades and
transcripts at a university.
• Database Management System (DBMS): A software
package/ system to facilitate the creation and maintenance of a
computerized database.
• Database System: The DBMS software together with the data
itself. Sometimes, the applications are also included.
CENG 352 Database Management Systems
8
Files vs. DBMS
• Application must stage large datasets between
main memory and secondary storage (e.g.,
buffering, page-oriented access, etc.)
• Special code for different queries
• Must protect data from inconsistency due to
multiple concurrent users
• Crash recovery
• Security and access control
CENG 352 Database Management Systems
9
Typical DBMS Functionality
• Define a database : in terms of data types,
structures and constraints
• Construct or load the database on a secondary
storage medium
• Manipulating the database : querying, generating
reports, insertions, deletions and modifications to
its content
• Concurrent Processing and Sharing by a set of
users and programs – yet, keeping all data valid and
consistent
CENG 352 Database Management Systems
10
What is a Relational Database?
• Based on the relational model (tables):
acct #
12345
34567
…
name
Sally
Sue
…
balance
1000.21
285.48
…
• Today used in most DBMS's.
CENG 352 Database Management Systems
11
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
CENG 352 Database Management Systems
12
Data Models
60’s
Hierarchical
Network
70's
80's
Relational
Choice for most new
applications
90’s
Object Bases
Knowledge Bases
now
CENG 352 Database Management Systems
13
The DBMS Marketplace
• Relational DBMS companies – Oracle, Sybase – are among the
largest software companies in the world.
• IBM offers its relational DB2 system.
• 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.
CENG 352 Database Management Systems
14
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
3. DBMS implementation.
CENG 352 Database Management Systems
15
Database Schema vs. Database State
• Database State (Instance): Refers to the content of a
database at a moment in time.
• Initial Database State: Refers to the database when it
is loaded
• Valid State: A state that satisfies the structure and
constraints of the database.
• Distinction
• The database schema changes very infrequently. The
database state changes every time the database is updated.
• Schema is also called intension, whereas state is called
extension.
CENG 352 Database Management Systems
16
Three-Schema Architecture
• Proposed to support DBMS characteristics
of:
• Program-data independence.
• Support of multiple views of the data.
CENG 352 Database Management Systems
17
Three-Schema Architecture
• Many views (External schemas), View 1 View 2 View 3
single conceptual (logical)
schema and physical
Conceptual Schema
schema(internal schema).
–
–
–
Views describe how users see the
data.
Conceptual schema defines logical
structure
Physical schema describes the files
and indexes used.
Physical Schema
* Schemas are defined using DDL; data is modified/queried using DML.
CENG 352 Database Management Systems
18
Three-Schema Architecture
Mappings among schema levels are needed
to transform requests and data. Programs
refer to an external schema, and are mapped
by the DBMS to the internal schema for
execution.
CENG 352 Database Management Systems
19
Data Independence
• Logical Data Independence: The capacity
to change the conceptual schema without
having to change the external schemas and
their application programs.
• Physical Data Independence: The capacity
to change the internal schema without
having to change the conceptual schema.
CENG 352 Database Management Systems
20
Data Independence
• When a schema at a lower level is changed,
only the mappings between this schema
and higher-level schemas need to be
changed in a DBMS that fully supports data
independence.
• The higher-level schemas themselves are
unchanged. Hence, the application
programs need not be changed since they
refer to the external schemas.
CENG 352 Database Management Systems
21
Query Languages
Employee
Name
Department
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 definitions
Data Manipulation Language (DML)
Query (SELECT)
UPDATE < relation name >
SET <attribute> = < new-value>
WHERE <condition>
CENG 352 Database Management Systems
22
Host Languages
C, C++, Java
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
CENG 352 Database Management Systems
23
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.
CENG 352 Database Management Systems
24
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!
CENG 352 Database Management Systems
25
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!
CENG 352 Database Management Systems
26
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!)
CENG 352 Database Management Systems
27
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.
CENG 352 Database Management Systems
28
Structure of a DBMS
• A typical DBMS has a
layered architecture.
• The figure does not
show the concurrency
control and recovery
components.
• This is one of several
possible architectures;
each system has its
own variations.
These layers
must consider
concurrency
control and
recovery
Query Optimization
and Execution
Relational Operators
Files and Access Methods
Buffer Management
Disk Space Management
DB
CENG 352 Database Management Systems
29
Centralized Architectures
• Centralized DBMS: combines everything
into single system including- DBMS
software, hardware, application programs
and user interface processing software.
CENG 352 Database Management Systems
30
Single-User System
centralized system
presentation application
services
services
DBMS
user module
• Presentation Services - displays forms, handles flow of
information to/from screen
• Application Services - implements user request,
interacts with DBMS
CENG 352 Database Management Systems
31
Centralized Multi-User System
• Dumb terminals connected to mainframe
– Application and presentation services on mainframe
• Transactions can be executed concurrently
– Isolation: DBMS sees an interleaved schedule
– Atomicity and durability: system supports a major
enterprise
• Transaction abstraction is necessary; supplied by
DBMS’s transaction support module.
CENG 352 Database Management Systems
32
Centralized Multi-User System
communication
central machine
•••
presentation application
services
services
DBMS
(Xaction
support)
presentation application
services
services
user module
CENG 352 Database Management Systems
33
Transaction Processing in a
Distributed System
• Decreased cost of hardware and
communication makes it possible to
distribute components of transaction
processing system
– Dumb terminals replaced by computers
• Client/server organization generally used
CENG 352 Database Management Systems
34
Basic Client-Server Architecture
• The idea is to define specialized servers with
specific functions.
•
•
•
•
File Servers
Printer Servers
Web Servers
E-mail Servers …
• The client machines provide the user with the
appropriate interfaces to utilize these servers, as
well as with local processing power to run local
applications.
• All equipment is connected via a network.
CENG 352 Database Management Systems
35
DBMS Server
• DBMS server provides database query and
transaction services to the clients
• Sometimes called query and transaction servers
• It is common that client and server software run
on separate machines.
• Two main types of basic DBMS architectures
were created under this client/server framework:
• Two-tier
• Three-tier
CENG 352 Database Management Systems
36
Two Tier Client-Server Architecture
• User Interface Programs and Application
Programs run on the client side
• An interface (e.g. JDBC (Java Database
Connectivity)) provides an Application
program interface (API) allow client side
programs to call the DBMS.
CENG 352 Database Management Systems
37
Two-Tiered Model of TPS
client machines
database server
machine
•••
presentation application
services
services
DBMS
presentation application
services
services
communication
CENG 352 Database Management Systems
38
Three Tier Client-Server Architecture
• Common for Web applications
• Intermediate Layer called Application Server or Web
Server:
• stores the web connectivity software and the rules and
business logic (constraints) part of the application used to
access the right amount of data from the database server
• acts like a conduit for sending partially processed data
between the database server and the client.
• Additional Features- Security:
• encrypt the data at the server before transmission
• decrypt data at the client
CENG 352 Database Management Systems
39
Three-Tiered Model of TPS
application server
machine
client machines
database server
machine
•••
presentation
server
application
server
DBMS
presentation
server
communication
CENG 352 Database Management Systems
40
Classification of DBMSs
• Based on the data model used:
• Traditional: Relational, Network, Hierarchical.
• Emerging: Object-oriented, Object-relational.
• Other classifications:
• Single-user (typically used with microcomputers) vs. multi-user (most DBMSs).
• Centralized (uses a single computer with one
database) vs. distributed (uses multiple
computers, multiple databases)
CENG 352 Database Management Systems
41
Variations of Distributed
Environments
• Homogeneous DDBMS
• Heterogeneous DDBMS
• Federated or Multidatabase Systems
CENG 352 Database Management Systems
42
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.
CENG 352 Database Management Systems
43