课件知识点整理(英文上课) |
---|
introduction to the database
Basic concepts about databases
-
Database management system (DBMS) (数据库管理系统)
- provide a convenient and efficient way to store and retrieve database information
-
Database systems
- highly valuable
- relatively large
- accessed by multiple (often concurrent) users and applications
Purpose of Database Systems
-
In early days, database applications built directly on top of file systems, leading to many problems
早期数据库建立在文件夹基础上,也就是存储在不同的文件夹中会导致冗余,难获取等等问题
-
data redundancy (冗余) and inconsistency (不一致)
-
difficulty in accessing data
-
data isolation (数据隔离)
-
integrity problems (完整性问题)
-
Atomicity (原子性) problems
原子性:这个侧重点是事务执行的完整,一套事务下来,如果有一个失败,那整体失败。也就是要么大家一起成功,要么全都回滚。
-
Concurrent (并发) access anomalies (异常)
一致性:这个侧重点是业务逻辑和规则,一致性的核心一部分是靠原子性实现的,而另一部分是逻辑实现。
简单点说:原子性不存在,那一致性基本不能保障,至少强一致性不行,也许可以通过业务逻辑的修改达到最终一致性。
另外来个常见的例子:转账:张三给李四转账100元。那数据库假设需要张三扣100,李四加100,记录一条流水。
如果流水没记录成功,那整体回滚,张三也没转账成功,李四也没多钱。这就是原子性的体现。
而张三必须扣100,李四必须加100,这个就是一致性了,如果因为某些逻辑原因,导致张三扣了100,流水记录100转账,而李四只加了60。然后这3条操作都成功了,那原子性就符合了,但是一致性就不符合了。
其实在实际应用中肯定不是这么简单的例子的。往往是类似,买东西扣库存这类的逻辑,主表里有库存,库存表里有库存,然后就因为设计缺陷,就算加了事务还是出现了主表库存对不上库存表库存的问题,这个就是一致性不满足的了。 -
Security problems
-
View of Data
-
Data models(数据模型的分类)
collection of conceptual (概念性的) tools for describing data, data relationships, data semantics (语义), and consistency constraints
中文解释:描述数据、数据联系、数据语义及一致性约束的概念工具的集合,提供一种描述物理层、逻辑层及视图层数据库设计的方式。-
relational model
collection of tables to represent both data and relationships among those data.
中文解释:
一种基于记录的模型,用表的集合来表示数据和数据间的联系,每个表有多个列,每列有唯一的列名。 -
entity-relational model
collection of basic objects (entities) and relationships among these objects.
中文解释:
基于对现实世界的一种认识——现实世界由一组基本对象(实体)及这些对象间的联系构成。实体是现实世界中可区别于其他对象的一件事情或一个物体.
E-R提供一种方便的图形化方式来观察数据、联系和约束。
数据库中实体通过属性(attribute)集合来描述;
联系(relationship)是几个实体之间的关联;
同一类型的所有实体的集合称为实体集(entity set),同一类型的所有联系的集合称作联系集(relationship set) -
semi-structured data model
permit individual data items of same type with different set of attributes
中文解释:
允许相同类型的数据项含有不同的属性集的数据定义 -
object-based data model
support entities and situations represented as objects in object-oriented programming.
中文解释:
可看作E-R模型增加了封装、方法和对象标志等概念后的扩展。对象-关系数据模型结合了面向对象的数据模型和关系数据模型的特征.
-
-
Data abstraction(数据的抽象结构)
数据库的标准体结构 : 三级ANSI / SPARC体系结构
- physical level
lowest level of abstraction
describe how data actually stored
中文解释:属于系统实现视图,描述数据如何存储在数据库中(如物理存储结构)
中文解释:用户或应用程序视图,描述应用程序中使用的数据库的重构部分
- logical level
describe what data stored in database, and what relationships exist among those data
describe entire database in terms of small number of relatively simple structures
=> physical data independence: user of logical level does not need to aware of complex physical-level structures
中文解释:
属于用户社区视图,描述数据库中存储什么数据及这些数据间存在的关系.
- view level
simplify user interaction with system based on access needs.
中文解释:
只描述数据库的某个部分,系统可以为同一数据库提供多个视图,使用户与系统交互更简单.
- 结构图:
Instances and Schemas(实例和模式)
-
database instance
collection of information stored in database at a particular moment
analogous to value of a variable
解释:特定时刻存储在数据库中的信息的集合称作数据的一个实例. -
database schema
overall design of database
analogous(相似的) to variable declarations (along with associated type definitions) in a program
解释:
数据库的总体设计,即使发生变化,也不频繁.
数据库系统可分为几种不同的模式:
e.g.物理模式、逻辑模式、子模式(subschema,描述数据库的不同视图) -
logical schema
overall logical structure of database
example: database consists of information about a set of customers and accounts in bank and relationship between them -
physical schema
overall physical structure of database
Database Languages
-
Data-definition language (DDL) (数据定义语言)
specify database schema
解释:
一系列特殊的DDL语句,用于说明数据库系统所使用的存储结构和访问方式,定义了数据库模式的实现细节。
存储在数据库中的数据值必须满足某些一致性约束(consistency constraint),DDL语言提供指定这种约束的工具,每当数据库更新时数据库系统都会检查这些约束。
约束(拓展内容,了解就行):
域约束(domain constraint):每个属性都对应于一个所有可能的取值构成的域。参照完整性(referential integrity):一个关系中给定属性集上的取值也在另一关系的某一属性集的取值中出现。
断言(assertion):数据库需要时刻满足某一条件。断言创建后系统会监测其有效性,如果断言有效,则以后只有不破坏断言的数据库更新才被允许。
授权(authorization):对于不同用户在数据库中的不同数据值上允许不同的访问类型,这些区别以授权来表达。如:a. 读权限(read authorization)允许读取数据但不能修改数据;b. 插入权限(insert authorization)允许插入新数据但不允许修改已有数据;更新权限(update authorization)允许修改但不能删除数据;删除权限(delete authorization)允许删除数据。
-
Data-manipulation language (DML) (数据操作语言)/query language(查询语言)
支持增删改查,因为是查询语言
-
procedural DML
require user to specify what data needed and how to get those data
解释:
要求用户指定需要什么数据以及如何获得这些数据. -
declarative DML
require user to specify what data needed without specifying how to get those data
解释:
声明式DML(declarative DML):也称非过程化DML,还要求用户指定需要什么数据,而不指明如何获得这些数据。
-
Database engine
-
storage manager (存储管理器)
-
权限及完整性管理器(authorization and integrity manager)
test for satisfaction of integrity constraints and check authorization
中文解释:
检测是否满足完整性约束,检查视图访问数据的用户的权限。 -
事务管理器(transaction manager)
ensure database in consistent state
中文解释:
保证即使发生故障,数据库也保持在一致(正确)的状态,并保证并发事务的执行不发生冲突。 -
文件管理器(file manager)
manage allocation of disk space and data structures
中文解释:
管理磁盘存储空间的分配,管理用于表示磁盘上所存储信息的数据结构 -
缓冲管理器(buffer manager)
responsible for fetching data from disk storage into main memory and deciding what data to cache in main memory
中文解释:
负责将数据从磁盘取到内存中来,并决定哪些数据应被缓冲存储在内存中。
-
-
query processor (查询处理器)
-
DDL解释器(DDL interpreter)
interpret DDL statements and record definitions in data dictionary
中文解释:
解释DDL语句并将这些定义记录在数据字典中 -
DML编译器(DML compiler)
translate DML statements in query language into evaluation plan consisting of low-level instructions that query evaluation engine understands
perform query optimization: pick lowest cost evaluation plan from among various alternatives
中文解释:
将查询语言中的DML语句翻译为执行方案,包括一系列查询执行引擎能理解的低级指令。
DML编译器还进行查询优化(query optimization),从几种等价的具有相同结果的执行方案中选出代价最小的一种。 -
查询执行引擎(query evaluation engine)
execute low-level instructions generated by DML compiler
中文解释:
执行由DML编译器产生的低级指令 -
过程图:
-
-
transaction management (交易管理)
ensure that database remains in consistent (correct) state despite system failures (e.g., power failures and operating system crashes) and transaction failures
- Concurrency-control manager
control interaction among concurrent transactions ensure database consistency 中文解释: 控制并发事物间的相互影响,保证一致性
-
Recovery manager
perform failure recovery
中文解释:
控制并发事物间的相互影响,保证一致性 -
what is transaction?
collection of operations that performs a single logical function in database application
中文解释:
数据库应用中完成单一逻辑功能的操作集合。每一个事务是一个既具有原子性又具有一致性的单元
事务的定义应使之不违反数据库的一致性约束。一个事务可以被定义为由多个单独程序组成,程序依次执行可以保持一致性,但单个程序自身都不是把数据库从一个一致状态转入一个新的抑制状态,因此这些程序不是事务。
-
Database Architecture
-
Centralized databases
one to a few cores, shared memory
-
Parallel databases
many core shared memory
shared disk
shared nothing -
Distributed databases
geographical distribution
Schema/data heterogeneity
-
-
Database applications
-
two-tier architecture(两层体系结构)
application resides at client machine, where it invokes database system functionality at server machine
中文解释:
应用程序驻留在客户机上(前端),通过查询语言表达式来调用服务器上的数据库系统功能(后端)。(应用程序接口标准e.g.ODBC/JDBC用于进行客户端和服务器的交互) -
three-tier architecture(三层体系结构)
client machine as a front end and not contain any direct database calls
client end: communicate with application server, usually through a forms interface
application server: in turn communicate with database system to access data
中文解释:
后端分为应用服务器和数据库服务器;客户机只作为前端,不包含任何直接的数据库调用,通过一个表单界面与应用服务器(application server)通信;应用服务器与数据库系统通信以访问数据,应用程序的业务逻辑(business logic)被嵌入到应用服务器中而不是分布在多个客户机上。 -
示例图:
-