* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download CENG 352 Database Management Systems - COW :: Ceng
Survey
Document related concepts
Commitment ordering wikipedia , lookup
Microsoft Access wikipedia , lookup
Oracle Database wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Serializability wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Ingres (database) wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Functional Database Model wikipedia , lookup
Open Database Connectivity wikipedia , lookup
ContactPoint wikipedia , lookup
Concurrency control wikipedia , lookup
Clusterpoint wikipedia , lookup
Versant Object Database wikipedia , lookup
Transcript
CENG 553 Database Management Systems Nihan Kesim Çiçekli email: [email protected] URL: http://www.ceng.metu.edu.tr/~nihan CENG 553 • • • • Instructor: Nihan Kesim Çiçekli Office: A308 Email: [email protected] Lecture Hours: Mon. 18:00-21:00 (BMB5) • Course Web page: http://cow.ceng.metu.edu.tr • Teaching Assistant: To be announced 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. 3 Grading • • • • Midterm Assignments and Quizzes Project Final Exam 30 % 15 % 20 % 35 % 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. 5 Course Outline • The Relational Data Model • Relational Query Languages (Relational Algebra, Relational Calculus, SQL) • Relational Database Design and Tuning • Transaction Management and Concurrency Control • Crash Recovery • Query Processing and Optimization • Object-Relational Databases • Distributed Databases • XML, XQuery, XPath 6 Basic Definitions • • • • • Data Database Mini-world Database Management System (DBMS) Database System 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. 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 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 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. 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 12 Data Models 60’s Hierarchical Network 70's 80's Relational Choice for most new applications 90’s Object Bases Knowledge Bases now 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. 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. 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. 16 Three-Schema Architecture • Proposed to support DBMS characteristics of: • Program-data independence. • Support of multiple views of the data. 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. 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. 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. 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. 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> 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 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. 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! 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! 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!) 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. 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 29 Centralized Architectures • Centralized DBMS: combines everything into single system including- DBMS software, hardware, application programs and user interface processing software. 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 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. 32 Centralized Multi-User System communication central machine ••• presentation application services services DBMS (Xaction support) presentation application services services user module 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 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. 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 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. 37 Two-Tiered Model of TPS client machines database server machine ••• presentation application services services DBMS presentation application services services communication 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 39 Three-Tiered Model of TPS client machines application server machine database server machine ••• presentation server application server DBMS presentation server communication 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) 41 Variations of Distributed Environments • Homogeneous DDBMS • Heterogeneous DDBMS • Federated or Multidatabase Systems 42 Application Designer’s View of a Distributed Database • Designer might see the individual schemas of each local database -- called a multidatabase -- in which case distribution is visible – Can be homogeneous (all databases from one vendor) or heterogeneous (databases from different vendors) • Designer might see a single global schema that integrates all local schemas (is a view) in which case distribution is hidden • Designer might see a restricted global schema, which is the union of all the local schemas – Supported by some vendors of homogeneous systems 43 Views of Distributed Data (a) Multidatabase with local schemas (b) Integrated distributed database with global schema 44 Multidatabases • Application must explicitly connect to each site • Application accesses data at a site using SQL statements based on that site’s schema • Application may have to do reformatting in order to integrate data from different sites • Application must manage replication – Know where replicas are stored and decide which replica to access 45 Global and Restricted Global Schemas • Middleware provides integration of local schemas into a global schema – Application need not connect to each site – Application accesses data using global schema • Need not know where data is stored – location transparency – Global joins are supported – Middleware performs necessary data reformatting – Middleware manages replication – replication transparency 46 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. 47