第五课|学习笔记

简介: 快速学习第五课

开发者学堂课程【高校精品课-西安交通大学-数据库理论与技术:第五课】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/12/detail/15861


第五课

 

内容介绍

一、Data Guides

二、Existence of Multiple DataGuides

三、Annotations

四、Strong Data Guides

五、Mapping Long Records to Pages

六、Allocation and Free-Space Management

七、文件组织

八、文件中的记录组织 

 

一、Data Guides

首先将前面剩下的内容讲完,有这样一个定义, OEM 源对象 s 的数据向导是 OEM 对象 d ,使得 s 的每个标签路径在 d 中恰好有一个数据路径实例,并且 d 的每个标签路径是 s 的标签路径。这也是Data Guide的一个模式模式图,如图所示:

图1:

 图片91.png

图2:

 图片90.png

图2显示了图1所示的源OEM数据库的数据指南。

图1中的1、2、3、4都是根结点,2、3结点共用8结点,中间结点是没有原始值的。模式图将所有相同的路径都取消了,即压缩了(图2所示)。在 Data Guide 里只有数据路径,没有标记路径,到达节点后,可以发现它没有原子值了。 Data Guide 就是用于结构汇总,将复杂的路径压缩简化。

使用 Data Guide ,我们可以通过考虑数据向导中最多 n 个对象来检查长度为 n 的给定标签路径是否存在于原始数据库中。假如写一个查询路径,这个路径在原本的数据库中占比较大,当我们查询 F 是否存在时,在原数据库中可能较为繁琐,而在 Data Guide 里检查,可以很快的看到结果,提高了查询速度。

例如,在图2中,我们只需要检查对象12和13的外出边缘,用来验证路径餐馆。数据库中存在所有者。 Data Guide 的结构信息可以更好的帮助查询处理。类似地,如果我们遍历数据指南中标签路径的单个实例,并到达一些对象 O ,则 O 的输出边上的标签表示可能跟随源数据库所有可能的标签。例如,在图2中,对象13的五个不同的带标签的外出边,它们表示源中所有可能的跟随餐馆的标签。 

需要注意的是,在 Data Guide 的叶结点上不包含原子值,这是它与普通数据图的区别,普通数据图的叶结点是有原子值的。由于 Data Guide 旨在反映数据库的结构,因此原子值是不必要的。由于 Data Guide 中的任何标签路径都只有一个数据路径实例,因此目标集合只包含一个对象,即该数据路径中的最后一个对象。 Data Guide 没有原子值,这样就可以在叶节点上存放一些特殊的信息,可以更好地帮助查询和产品优化。

这里要注意的是, Data Guide 中的每个目标集合都是单例集合,单例集合里只有一个元素。 

Data Guide 也是有理论基础的,可以在1997年的一篇论文中找到。那篇论文证明了创造一个源数据库上的 Data Guide ,等效于非确定性有限自动机( NFA )转化到确定性有限自动机( DFA )的有效时间,它存在于自动机理论里,是一个被充分研究的问题。

 

二、Existence of Multiple DataGuides

From automata theory, we know that a single NFA may have many equivalent DFAs 

Similarly, as shown in Figure 3,one OEM source database may have multiple DataGuides.Figures 3(b) and (c) are both DataGuides of the source in Figure 3(a).

 图片89.png

Each label path in the source appears exactly once in each DataGuide, and neither DataGuide introduces any label paths that do not exist in the source.

Figure 3(c) is in fact minimal: the smallest possible DataGuide.( Well-known state minimization algorithms can be used to convert any DataGuide into a minimal one [Hop71]. 

Given the existence of multiple DataGuides for a source, it is important to decide what kind of DataGuide should be built and maintained in a semistructured database system 

Intuitively, a minimal DataGuide might seem desirable, furthering our goal of having as concise a summary as possible; But, as we now explain,a minimal DataGuide is not always best.

 

三、Annotations

First, incremental maintenance of a minimal DataGuide can be very difficult.

For example,in Figure 3(a), suppose we add a new child object to 10,via the label E.

To correctly reflect this source insertion in Figure 3(b), we simply add a new object via label E to object 17.

 图片88.png 

But to reflect the same insertion in the minimal DataGuide in Figure 3(c), we must do more work in order to somehow generate the same DataGuide as our updated version of Figure 3(b) ,since it now is the minimal DataGuide for the source.

In general, maintaining a minimal DataGuide in response to a source update may require much of the original database to be reexamined. 

Beyond using a DataGuide to summarize the structure of a source, we may wish to keep additional information in a DataGuide.

For example, consider a source with a label path l.To aid query formulation, we might want to present to a user sample database values that are reachable via 1.(Such a feature is very useful in OEM , since there are no constraints on the type or format of atomic data.) 

As another example, we may wish to provide the user or the query processor with the statistical odds than an object reachable via l has any outgoing edges with a specific label. 

Finally, for query processing, direct access through the DataGuide to all objects reachable via l can be very useful,The following definition classifies all of these examples. 

Definition 6: In a source database sgiven a label path l, a property of the set of objects that comprise the target set of l in s is said to be an annotation of l. 

That is, an annotation of a label path is a statement about the set of obiects in the database reachable by that path. 

A DataGuide should quarantees that each source label path l reaches exactly one object o in the DataGuide.Object o seems like an ideal place to store annotations for l,since we can access all annotations of l simply by traversing the DataGuide's single data path instance of l. 

Unfortunately, nothing in our definition of a DataGuide prevents multiple label paths from reaching the same object in a DataGuide,even if the label paths have different target sets in the source. 

Referring to Figure 3(c), we see that label paths A.C and B.C both reach the same object.Thus,if we store an annotation on object 20, we cannot know if the annotation applies to label path A.C ,label path B.C, or both. 

In the DataGuide in Figure 3(b), however, we have two distinct objects for the two label paths, so we can correctly separate the annotations. 

Next, we formalize DataGuide characteristics that enable unambiguous annotation storage.

 

四、Strong Data Guides

We define a class of DataGuides that supports annotations as described in the previous subsection.

Intuitively , we are interested in DataGuides where each set of label paths that share the same ( singleton ) target set in the DataGuide is exactly the set of label paths that share the same target set in the source. 

Definition 7.:Consider OEM objects s and d where d is a DataGuide for a sources.Given a label path l of slet Ts(l) be the target set of l in s, and let Td(l) be the ( singleton ) target set of l in d. Let Ls(l) = { m | Ts(m) =Ts(l)}. That is, Ls(l) is the set of all label paths in s that share the same target set as l.Similarly,let Ld(l)={ m | Td(m)=Td(l) }. That is, Ld(l) is the set of all label paths in d that share the same target set as l. If, for all label paths l of s, Ls(l) = Ld(l), then d is a strong DataGuide for s. 

For example , Figure 3(c) is not a strong DataGuide for Figure 3(a). The source target set Ts(B.C)is {6,7},and the DataGuide target set Td(B.C) is {20}.

In the source, Ls(B.C) is {B.C}, since no other source label paths have the same target set. 

In the DataGuide(c),however,Ld(B.C)is{B.C,A.C}. SinceLs(B.C)# Ld(B.C), the DataGuide is not strong.The reader may verify that Figure 3(b)is in fact a strong DateGuide 

Next, we prove that a strong DataGuide is sufficient for storage of annotations.

Theorem 1:Suppose d is a strong DataGuide for a source s. lf an annotation p of some label path l is stored on the object o reachable via l in d,then p describes the target set in s of each label path that reaches o.

We also prove that a strong DataGuide induces a straightforward one-to-one correspondence between source target sets and DataGuide objects.This property is useful for incremental maintenance and query processing.

Theorem 2:Suppose d is a strong DataGuide for a source s.Given any target sett of s,t is by definition the target set of some label path l.Compute Td(l),the target set of l in d,which has a single element o.Let F describe this procedure, which takes a source target set as input and yields a DataGuide object as output. In a strong DataGuide,F induces a one-to-one correspondence between source target sets and DataGuide objects.

 

五、Mapping Long Records to Page

1.Long Pages

(1)Allows long pages (up to 64K bytes).

(2)Internally, long records are managed just as short ones.

(3)Simple solution, but inadequate for very large records.

(4)Used in DB2 and Oracle.

2.Separate Pages for Long Fields

(1)Instead of keeping entire long field in a record.

(2)maintains only a pointer to the long field stored in another page.

(3)The main record is then treated as a short tuple.

(4)Good results if long attributes are accessed infrequently.

(5)Unfortunately, performance suffers in situations when ong attributes are accessed frequently.

 图片87.png

 

六、Allocation and Free-Space Management

1.Free-Space Information Pages

Advantages:

(1)FSIPs need not always be updated during allocation and deallocation.

(2)Deallocations are relatively fast and simple

(3)Provides good storage utilization and reclamation(回收) of free and unused space.

Disadvantages:

Allocations may require several disk accesses.

部分习题如下:

 图片86.png

图片85.png

 

七、文件组织

文件组织是数据库保存为若干文件的集合。其中文件是记录的序列,记录是字段的序列。记录方法有定长记录、变长记录、指针法。

1.定长记录

简单方法:

(1)记录 i 从字节 n * ( i - 1 ) 开始存储,其中 n  是记录大小。

(2)记录存取简单,但记录可能跨块。唯一的变化是不允许记录跨越块边界。

 图片84.png

删除记录 i 可选则的方法:

(1)将记录 i+1 ,..., n 前移成 i ..., n-1 。

(2)将记录 n 前移成 i 。

(3)不移动记录,而是将所有自由记录链成一条自由链表。

2.自由链表

自由链表是指在文件头中存储第一条被删记录的地址,然后在第一条被删记录中,存储第二条被删记录的地址,等等。这些存储的地址可视为指针,因为它们“指向”记录的位置。它是更有效利用空间的表示法,可以重新利用自由记录的正常字段空间来存储指针(使用中的记录则不存储指针)。

 图片83.png

3.变长记录

数据库系统中在多种情况下需要变长记录。一个文件中需要存储多种记录类型,允许一个或多个变长字段的记录类型,允许重复字段的记录类型,以上几种情况都需要用到变长记录。

它的方法有预留空间法、字节串表示法、指针法、 Slotted Page  结构.

(1)预留空间法

它是利用具有已知最大长度的定长记录,较小记录中的未用空间用 null 或  end - of - record  符号填充。

图片82.png

(2)字节串表示法

它在每条记录末尾附加控制字符 end - of - record ( L ),缺点是难以删除或增长。 

 图片81.png

(3)指针法

变长记录可用若干通过指针念在一起的定长记录表示,即使是最大记录,长度未知时也可以使用。缺点是除了链中首记录,其他所有记录中都可能有空间浪费。解决方法是文件中采用两种块,锚块和溢出块,锚块包含链中的首记录,溢出块包含链中其他记录。 

图片80.png

解决方法是文件中采用两种块,锚块和溢出块,锚块包含链中的首记录,溢出块包含链中其他记录。

图片79.png

(4) Slotted Page  结构

Slotted page 页头包含记录登记项数目、块中自由空间末端、每条记录的位置和大小。记录可以在页内移动以便保持记录间的连续存储,但页头中的登记项必须更新。指针不能直接指向记录,而是指向该记录在页头中的登记项。

图片78.png


八、文件中的记录组织

文件中的记录组织有堆、顺序、散列、聚簇、动机。堆,记录可至于文件中的任何有空间的地方。顺序,记录按顺序存储,基于每条记录在搜索键上的值。散列,对记录的某些属性 k 计算散列函数 h( k ) ,计算结果决定该记录应该置于文件的哪个块中。每一个关系的记录可存储在单独的文件中,但在聚簇文件组织下,多个关系的记录可存储于同一文件中。动机,相关联的记录存储在同一块中可减少磁盘 I/O 。

1.顺序文件组织 

它适用于需要顺序处理整个文件的应用,文件中的记录按搜索键排序。

 图片77.png

删除时可利用指针链。插入时需要确定带插入记录的位置。若有自由空间,则在该处插入,若无自由空间,则插入到溢出块,两种情况都有,则需要更新指针链。需要不时重组文件,以恢复物理存储的顺序。

图片76.png

2.聚簇文件组织

简单的文件结构将每个关系存储在一个单独的文件中,利用聚簇文件组织可以将多个关系存储在一个文件中。

图片92.png

有利于涉及 depositor 和 customer 的查询,以及涉及单个客户和他的账户的查询,对只涉及 customer 的查询不好(可用指针链,见上图),容易导致变长记录。

相关文章
|
8月前
|
人工智能 Linux iOS开发
openclaw安装教程从0到1部署,三大系统全覆盖操作流程3.0版本
覆盖 Windows、macOS、Linux 三大系统,国内海外网络环境全适配,每一步都踩过坑、反复验证过,照着做绝对能跑通!手把手带你搞定网关搭建、安全配置,再无缝对接主流大模型,一站式解决私有化部署所有难题。
|
3月前
|
存储 缓存 自然语言处理
身份证二要素实名认证接口|姓名 + 身份证号一致性核验方案,快速完成业务实名核验接入
本文以云市场身份证二要素实名认证接口为对象,介绍姓名与身份证号一致性核验的完整接入方案:接口参数设计与两种鉴权方式(APPCODE 简单认证、AppKey/AppSecret 签名认证)、多语言调用示例、返回结构解析与业务错误码排查(0 匹配、1 不匹配、2 无此号码、12 号码不合法、101/103 频控),以及前置校验、同证件 60 秒冷却与 24 小时级频控、敏感信息脱敏存储等工程实践要点,适合需要在注册、开卡、信贷、政务办事等流程中落地实名核验环节的开发者参考。
1313 0
身份证二要素实名认证接口|姓名 + 身份证号一致性核验方案,快速完成业务实名核验接入
|
4月前
|
数据采集 人工智能 监控
从SEO到GEO:B2B出海企业AI认知工程的12步闭环架构与实践
基于B2B外贸出海实践,见增出海提出一套可落地的GEO技术实施框架与12步闭环架构,涵盖内容结构化(Schema.org/JSON-LD)、多信源矩阵分发、AI爬虫策略、客户信号追踪及销售触达闭环。重点探讨GEO如何同时服务Inbound(海外买家主动验证)与Outbound(基于预热信号的精准触达)两条路径,避免"做了GEO就等客上门"的常见误区。适合技术团队、架构师及出海企业CTO参考。
432 1
从SEO到GEO:B2B出海企业AI认知工程的12步闭环架构与实践
|
3月前
|
人工智能 安全 IDE
自主编码智能体上手|Qoder CN v1.4.1 深度实战,本地环境搭建、多文件工程开发与企业私有化部署
Qoder CN v1.4.1最大的价值,是把AI编码从“代码片段生成”升级为完整Agent式工程任务执行。借助Quest任务引擎、RepoWiki记忆知识库、MCP工具扩展、Hooks安全机制,开发者只需要描述业务需求,智能体自主完成需求拆解、多文件修改、命令执行、测试验证完整链路。同时兼容CLI、IDE、插件多种形态,深度对接百炼平台各类订阅方案,既可以满足个人开发者提升开发效率,也具备完整权限管控、安全拦截、团队知识库能力,支撑企业规模化落地AI研发。
599 0
|
8月前
|
JavaScript 前端开发 搜索推荐
前端组件库Element UI知识点大全(一)
教程来源 https://tmywi.cn/category/shishang.html Element UI是饿了么团队于2016年推出的Vue 2桌面端UI组件库,提供丰富组件、统一设计规范与24列栅格系统,显著提升中后台开发效率。GitHub超4万Star,广泛应用于国内管理系统,虽Vue 3时代有Element Plus替代,但其设计理念仍深刻影响生态。
|
5月前
|
人工智能 缓存 自然语言处理
阿里云百炼Token Plan新增个人版:39元1个月,个人版和团队版有啥区别?选哪个?
阿里云百炼Token Plan新增个人版,最低39元/月,含Lite/Standard/Pro三档;企业版分标准/高级/尊享席位,最低150元/席位/月。统一按Credits计费,支持Qwen3.8-Max-preview等多模态模型及主流AI工具,夜间调用低至2折。在阿里云百炼官网:https://t.aliyun.com/U/fPVHqY 免费领取千万Tokens
673 0
|
敏捷开发 SQL 运维
运维进度看板工具全景攻略:如何通过工具实现任务、责任和协作的完美结合
运维进度看板工具通过可视化任务流程,提升运维团队协作效率与透明度,解决任务无人跟进、信息碎片化、责任不清等问题,助力任务高效流转与项目有序推进。
|
12月前
|
算法 搜索推荐 定位技术
《独立游戏社区支持的生态构建与共创赋能指南》
本文聚焦独立游戏项目如何依托自有网站构建高粘性社区支持生态,指出网站并非传统展示窗口,而是连接开发者与玩家的价值共生枢纽。文章结合实践路径,提出需打破单向信息输出模式,通过场景化互动设计、“研发温度+玩家价值”双轨内容体系、分层参与机制,让玩家从体验者转变为共建者。同时强调透明化反馈处理与常态化互动的核心作用,主张搭建线上线下联动的立体生态,整合社区资源,最终实现开发者与玩家的价值共生,为缺乏大厂资源的独立游戏项目,提供破圈突围的切实可行路径。
588 10
|
JSON JavaScript 定位技术
Echarts 绘制地图(中国、省市、区县),保姆级教程!
Echarts 绘制地图(中国、省市、区县),保姆级教程!
30113 154
|
安全 搜索推荐 网络安全
HTTPS与HTTP:区别及安全性对比
HTTP和HTTPS是现代网络通信中的两种重要协议。HTTP为明文传输,简单但不安全;HTTPS基于HTTP并通过SSL/TLS加密,确保数据安全性和完整性,防止劫持和篡改。HTTPS还提供身份验证,保护用户隐私并防止中间人攻击。尽管HTTPS有额外的性能开销和配置成本,但在涉及敏感信息的场景中,如在线支付和用户登录,其安全性优势至关重要。搜索引擎也更青睐HTTPS网站,有助于提升SEO排名。综上,HTTPS已成为大多数网站的必然选择,以保障用户数据安全和合规性。
4138 1