430 likes | 617 Views
CENG 352 Database Management Systems. Nihan Kesim Çiçekli email: nihan@ceng.metu.edu.tr URL: http://www.ceng.metu.edu.tr/courses/ceng352. CENG 352. Instructor: Nihan Kesim Çiçekli Office: A308 Email : nihan@ceng.metu.edu.tr
E N D
CENG 352 Database Management Systems Nihan Kesim Çiçekli email: nihan@ceng.metu.edu.tr URL: http://www.ceng.metu.edu.tr/courses/ceng352
CENG 352 • Instructor: Nihan Kesim Çiçekli • Office: A308 • Email: nihan@ceng.metu.edu.tr • Lecture Hours: Tue. 10:40,11:40 (BMB1); Thu. 9:40 (BMB3) • Course Web page:http://www.ceng.metu.edu.tr/courses/ceng352 • Teaching Assistant: Ömer Önder Tola onder@ceng.metu.edu.tr CENG 352 Database Management Systems
Text Books and References • Raghu Ramakrishnan, Database Management Systems, McGraw Hill, 3rd edition, 2003 (text book). • R. Elmasri, S.B. Navathe, Fundamentals of Database Systems, 4th edition, Addison-Wesley, 2004. • A. Silberschatz, H.F. Korth, S. Sudarshan, Database System Concepts, McGraw Hill, 4th edition, 2002. • H. Garcia-Molina, J. D. Ullman, J. Widom, Database Systems The Complete Book, Prentice Hall, 2002. CENG 352 Database Management Systems
Grading • Midterm 25 % • Assignments and Quizzes 20 % • Project 20 % • Final Exam 35 % Exam Date: Midterm Exam: 2nd week of April. CENG 352 Database Management Systems
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
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 CENG 352 Database Management Systems
Basic Definitions • Database: A collection of related data. • Data: Known facts that can be recorded and have an implicit meaning. • 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
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
Typical DBMS Functionality Other features: • Protection or Security measures to prevent unauthorized access • “Active” processing to take internal actions on data • Presentation and Visualization of data CENG 352 Database Management Systems
Example of a Database(with a Conceptual Data Model) • Mini-world for the example: Part of a UNIVERSITY environment. • Some mini-world entities: • STUDENTs • COURSEs • SECTIONs (of COURSEs) • (academic) DEPARTMENTs • INSTRUCTORs Note: The above could be expressed in the ENTITY-RELATIONSHIP data model. CENG 352 Database Management Systems
Example of a Database(with a Conceptual Data Model) • Some mini-world relationships: • SECTIONs are of specific COURSEs • STUDENTs take SECTIONs • COURSEs have prerequisite COURSEs • INSTRUCTORs teach SECTIONs • COURSEs are offered by DEPARTMENTs • STUDENTs major in DEPARTMENTs Note: The above could be expressed in the ENTITY-RELATIONSHIP data model. CENG 352 Database Management Systems
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 CENG 352 Database Management Systems
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
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. CENG 352 Database Management Systems
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
Data Models 60’s 70's 80's 90’s now Hierarchical Network Relational Choice for most new applications Object Bases Knowledge Bases CENG 352 Database Management Systems
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
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. CENG 352 Database Management Systems
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
Three-Schema Architecture • Proposed to support DBMS characteristics of: • Program-data independence. • Support of multiple views of the data. CENG 352 Database Management Systems
Three-Schema Architecture • Many views (External schemas), single conceptual (logical) schemaand physical schema(internal schema). • Views describe how users see the data. • Conceptual schema defines logical structure • Physical schema describes the files and indexes used. View 1 View 2 View 3 Conceptual Schema Physical Schema • Schemas are defined using DDL; data is modified/queried using DML. CENG 352 Database Management Systems
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
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
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
Query Languages Employee Department SELECT ManagerFROM Employee, DepartmentWHERE Employee.name = "Clark Kent”AND Employee.Dept = Department.Dept Query LanguageData definition language (DDL) ~ like type definitions Data Manipulation Language (DML) Query (SELECT) UPDATE < relation name > SET <attribute> = < new-value> WHERE <condition> Name Dept Dept Manager SQL CENG 352 Database Management Systems
Host Languages C, C++, Java, Lisp, COBOL Application prog. • Host language is completely general (Turing complete) • Query language—less general "non procedural" and optimizable DBMS Calls to DB Local Vars (Memory) (Storage) CENG 352 Database Management Systems
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
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 stateif DB is consistent when the transaction begins. • Users can specify some simple integrity constraintson 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
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
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
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
Query Optimization and Execution Relational Operators Files and Access Methods Buffer Management Disk Space Management DB Structure of a DBMS These layers must consider concurrency control and recovery • 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. CENG 352 Database Management Systems
Centralized and Client-Server Architectures • Centralized DBMS: combines everything into single system including- DBMS software, hardware, application programs and user interface processing software. CENG 352 Database Management Systems
Basic Client-Server Architectures • 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
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
Two Tier Client-Server Architecture • User Interface Programs and Application Programs run on the client side • Interface called ODBC (Open Database Connectivity) provides an Application program interface (API) allow client side programs to call the DBMS. Most DBMS vendors provide ODBC drivers. CENG 352 Database Management Systems
Two Tier Client-Server Architecture • A client program may connect to several DBMSs. • Other variations of clients are possible: • e.g., in some DBMSs, more functionality is transferred to clients including data dictionary functions, optimization and recovery across multiple servers, etc. • In such situations the server may be called the Data Server (because it provides data in disk pages) CENG 352 Database Management Systems
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
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 micro- computers) 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
Classification of DBMSs Distributed Database Systems have now come to be known as client server based database systems because they do not support a totally distributed environment, but rather a set of database servers supporting a set of clients. CENG 352 Database Management Systems
Variations of Distributed Environments: • Homogeneous DDBMS • Heterogeneous DDBMS • Federated or Multidatabase Systems CENG 352 Database Management Systems
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! CENG 352 Database Management Systems
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