* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Lecture 1 : Introduction
Microsoft Access wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Serializability wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Oracle Database wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Functional Database Model wikipedia , lookup
Versant Object Database wikipedia , lookup
Concurrency control wikipedia , lookup
Relational model wikipedia , lookup
Clusterpoint wikipedia , lookup
CENG 352 Database Management Systems Nihan Kesim Çiçekli email: [email protected] URL: http://www.ceng.metu.edu.tr/courses/ceng352 CENG 352 • • • • Instructor: Nihan Kesim Çiçekli Office: A308 Email: [email protected] 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 [email protected] SPRING 2005 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. SPRING 2005 CENG 352 Database Management Systems 3 Grading • • • • Midterm Assignments and Quizzes Project Final Exam 25 % 20 % 20 % 35 % Exam Date: Midterm Exam: 2nd week of April. SPRING 2005 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. SPRING 2005 CENG 352 Database Management Systems 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 2005 CENG 352 Database Management Systems 6 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. SPRING 2005 CENG 352 Database Management Systems 7 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 SPRING 2005 CENG 352 Database Management Systems 8 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 SPRING 2005 CENG 352 Database Management Systems 9 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 ENTITYRELATIONSHIP data model. SPRING 2005 CENG 352 Database Management Systems 10 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 ENTITYRELATIONSHIP data model. SPRING 2005 CENG 352 Database Management Systems 11 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 mediumsize 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 2005 CENG 352 Database Management Systems 12 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 SPRING 2005 CENG 352 Database Management Systems 13 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. SPRING 2005 CENG 352 Database Management Systems 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 2005 CENG 352 Database Management Systems 15 Data Models 60’s Hierarchical Network 70's 80's Relational Choice for most new applications 90’s Object Bases Knowledge Bases now SPRING 2005 CENG 352 Database Management Systems 16 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. SPRING 2005 CENG 352 Database Management Systems 17 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 2005 CENG 352 Database Management Systems 18 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. SPRING 2005 CENG 352 Database Management Systems 19 Three-Schema Architecture • Proposed to support DBMS characteristics of: • Program-data independence. • Support of multiple views of the data. SPRING 2005 CENG 352 Database Management Systems 20 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. SPRING 2005 CENG 352 Database Management Systems 21 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. SPRING 2005 CENG 352 Database Management Systems 22 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. SPRING 2005 CENG 352 Database Management Systems 23 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. SPRING 2005 CENG 352 Database Management Systems 24 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> SPRING 2005 CENG 352 Database Management Systems 25 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 2005 CENG 352 Database Management Systems 26 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 2005 CENG 352 Database Management Systems 27 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 2005 CENG 352 Database Management Systems 28 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 2005 CENG 352 Database Management Systems 29 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 2005 CENG 352 Database Management Systems 30 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 2005 CENG 352 Database Management Systems 31 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 SPRING 2005 CENG 352 Database Management Systems 32 Centralized and Client-Server Architectures • Centralized DBMS: combines everything into single system including- DBMS software, hardware, application programs and user interface processing software. SPRING 2005 CENG 352 Database Management Systems 33 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. SPRING 2005 CENG 352 Database Management Systems 34 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 SPRING 2005 CENG 352 Database Management Systems 35 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. SPRING 2005 CENG 352 Database Management Systems 36 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) SPRING 2005 CENG 352 Database Management Systems 37 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 SPRING 2005 CENG 352 Database Management Systems 38 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) SPRING 2005 CENG 352 Database Management Systems 39 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. SPRING 2005 CENG 352 Database Management Systems 40 Variations of Distributed Environments: • Homogeneous DDBMS • Heterogeneous DDBMS • Federated or Multidatabase Systems SPRING 2005 CENG 352 Database Management Systems 41 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 2005 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. SPRING 2005 CENG 352 Database Management Systems 43