The Worlds of Database Systems

数据库管理系统全方位解析

目录

Why DBMS?

What can DBMS do for applications?

Alternative to Using a DBMS

Data Models

Relational Model

Levels of Abstractions in DBMS

Example: University Database

Data Independence

Queries in DBMS

Transaction Management

Concurrency Control

Crash Recovery

Overview of DBMS

Layered Architecture

ApplicationArchitectures


Why DBMS?

  • Suppose that you want to build an university database. It must store the following information:
  1. Entities: Students, Professors, Classes, Classrooms
  2. Relationships: Who teaches what? Who teaches where? Who teaches whom

What can DBMS do for applications?

  • Store huge amount of data (e.g., TB+) over a long period of time
  • Allow apps to query and update data
  1. Query: what is Mary’s grade in the “Operating System” course?
  2. Update: enroll Mary in the “Database” course
  • Protect from unauthorized access
  1. Students cannot change their course grades.        
  • Protect from system crashes
  1. When some system components fail (hard drive, network, etc.), database can be restored to a good state
  • Protect from incorrect inputs

Mary has registered for 100 courses

  • Support concurrent access from multiple users

1000 students using the registration system at the same time

  • Allow administrators to easily change data schema

At a later time, add TA info to courses.

  • Efficient database operations

Search for students with 5 highest GPAs

Alternative to Using a DBMS

  • Store data as files in operating systems.
  • Applications have to deal with the following issues:
  1. 32-bit addressing (4GB) is insufficient to address 100GB+ data file
  2. Write special code to support different queries
  3. Write special code to protect data from concurrent access
  4. Write special code to protect against system crashes
  5. Optimize applications for efficient access and query
  6. May often rewrite applications
  • Easier to buy a DBMS to handle these issues

这样说明,数据库管理系统是能够给我们提供大量方便的。 

Data Models

  • A data model is a collection of concepts for describing data
  1. Entity-relation (ER) model
  2. Relational model (main focus of this course)
  • A schema is a description of data
  1. The relational model is the most widely used data model.
  • A relation is basically a table with rows and columns of records.

Every relation has a schema, which describes the columns, or fields(字段)

Relational Model

The entire table shows an instance of the Students relation.

• The Students schema is the column heads

Students(Sid: String, Name: String, Login: String, age: Integer,… )

Levels of Abstractions in DBMS

Many views, one conceptual(概念模式)schema and one physical 、schema.

  • Conceptual schema defines logical structure(概念模式定义的是逻辑结构)
  • Physical schema describes the file and indexing used(物理模式定义的是文件和索引方式)
  • Views describe how applications (users) see the data(储存的是一种数据之间的关系,并不 真实存在)

Example: University Database

  • Conceptual schema:
  1. Students (sid: string, name: string, login: string, age: integer, gpa:real)
  2. Courses (cid: string, cname:string, credits:integer)
  3. Enrolled (sid:string, cid:string, grade:string) --选课表
  • Physical schema:

Relations stored as unordered files. Index on first column of Students. 

  • View (External Schema):

Course_info(cid:string, enrollment:integer)

Data Independence

Three levels of abstraction provides data independence.

  • Changes in one layer only affect one upper layer.
  • E.g., applications are not affected by changes in conceptual & physical schema.

Queries in DBMS

  • Sample queries on university database:

What is the name of the student with student ID 123456?

  • The key benefits of using a relational database are Easy to specify queries using a query language: Structured Query Language (SQL)

SELECT S.name FROM Students S WHERE S.sid = 123456

  • Efficient query processor to get answer

Transaction Management

• A transaction is an execution of a user program in a DBMS.

• Transaction management deals with two things:

  1. Concurrent execution of transactions(并发事务处理)
  2. Incomplete transactions and system crashes(事务回滚机制)

Concurrency Control

  • Example

two travel agents (A, B) are trying to book one remaining airline seat (two transactions), only one transaction can succeed in booking.

  • How to solve this?

Solution: use locking protocol(锁机制)

Transaction A: get exclusive lock on num_seats

Transaction B: wait until A releases lock on num_seats

Transaction A: if num_seats > 0, book & num_seat--;

// book the seat, num_seat is set to 0

Transaction A: release exclusive lock on num_seats

Transaction B: num_seats = 0, no booking;

// does not book the seat

Crash Recovery

  • Example:

a bank transaction transfers $100 from account A to account B

A = A - $100

<system crashes> // good for the bank!

B = B + $100

  • How to solve this?

Solution:use logging, meaning that all write operations are recorded in a log on a stable storage

A = A - $100 // recorded A value (checkpoint) in a log

<system crashes>

// start recovery: read the log from disk

//analyze, undo, & redo 

Overview of DBMS

Layered Architecture

  • 应用层
  • 查询优化和执行层
  • 关系操作符层
  • 文件和访问方法层
  • 缓冲管理层
  • 磁盘空间管理层

要注意的是,这些分层架构都应该考虑到并发管理的问题

ApplicationArchitectures

  •  两层架构:客户端和数据库系统(客户端程序使用数据库互接或者Java连接与数据库进行通信)
  • 三层架构:客户端、应用服务器和数据库系统(给予Web的程序、使用中间件构建的应用程序)

 

The Worlds I See》是李飞飞的一本日记笔记,收录了作者在旅行中所见所闻的各种世界的描写和观察。这本书以自然景观、人文风情为主线,展示了作者独特的旅行体验和感悟。 通过阅读《The Worlds I See》,读者可以感受到作者对大自然的热爱和对人类文明的思考。作为一个充满好奇心的旅行者,李飞飞以敏锐的观察力和细腻的书写技巧将所见所闻生动地展现在读者面前。他试图用文字描绘出自己眼中的世界,让读者通过他的叙述感受到那些美丽和壮丽。 《The Worlds I See》不仅仅是一个旅行笔记,更是一本启发思考的书籍。作者在书中不断反思自己的旅行经历,思考旅行给自己的意义和对内心的影响。他通过与当地人的交流和身临其境的观察,展现了人与自然和谐共存的力量,也揭示了人类文明带来的负面影响。 这本书所收录的旅行经历涵盖了世界各地的风景名胜和人文背景。无论是沙漠里的星空、山峦间的喧嚣、海滩上的阳光,还是城市中的繁华,作者用文笔将这些独特的景色和人文风情描绘得栩栩如生。在阅读过程中,读者好像置身于作者所描述的那些美丽景色之中,感受到了旅行的魅力。 《The Worlds I See》是一本值得阅读的书籍,它不仅给予读者欣赏世界之美的机会,也引发了对生活的思考和对未来的追求。通过李飞飞的笔触,我们可以更加热爱自然,更加关注环境问题,也更加珍惜生活中的每一个瞬间。这本书带给读者的不仅仅是美的享受,更是一次心灵的洗礼。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值