数据库应用的自动迁移与包装及实体关系模型聚类方法
数据库应用的自动迁移与包装
在数据库操作中,模式转换是实现数据互操作性的关键环节。下面将详细介绍数据库应用的自动迁移与包装相关内容。
模式转换基础
模式转换存在一些基本操作,如
delEntity
操作,示例如下:
delEntity(s2,s2a,[dept,Y],[],[],[att,person,dname, ,Y]).
步骤 5 - 8 作为复合转换,实现了属性和实体类之间的等价转换。
模式转换示例
- 从 s2 到 s1 的转换
addEntity(s2a,s2,[dept,Y],[],[],[att,person,dname, ,Y]),
addAttribute(s2b,s2a,[dept,dname,X,Y],[[1,1],[1,1]],
[],[implies,[att,dept,dname,X,Y],[eq,X,Y]],
[att,person,dname,X,Y]),
addRelationship(s2c,s2b,[person,worksin,dept,X,Y],
[[1,1],[1,n]],[],[],[att,person,dname,X,Y]),
delAttribute(s4,s2c,[person,dname,X,Y],[[1,1],[1,n]],[],[],
[rel,person,worksin,dept,X,Y]),
addAttribute(s1c,s4,[person,sex,EV,AV],[[1,1],[1,n]],[],[],
[or,[and,[ent,male,EV],[eq,AV,m]],
[and,[ent,female,EV],[eq,AV,f]]]),
delGeneralisation(s1b,s1c,[total,person,[male,female]],
[implies,[att,person,sex, ,AV],[or,[eq,AV,m],[eq,AV,f]]]),
delEntity(s1a,s1b,[female,EV],[],[],[att,person,sex,EV,f]),
delEntity(s1,s1a,[male,EV],[],[],[att,person,sex,EV,m]).
-
数据迁移
数据迁移涉及不同模式之间数据的转换,以下是两个示例:-
从 s1 到 s2 的数据迁移
| s2 | s1 | Step |
| ---- | ---- | ---- |
| [ent,person,X] | [ent,person,X] | - |
| [att,person,id,X,Y] | [att,person,id,X,Y] | - |
| [att,person,name,X,Y] | [att,person,name,X,Y] | - |
| [att,person,dname,X,Y] | [rel,person,worksin,dept,X,Y] | 5 |
| [ent,male,X] | [att,person,sex,EV,m] | 1 |
| [ent,female,X] | [att,person,sex,EV,f] | 2 | -
从 s2 到 s1 的数据迁移
| s1 | s2 | Step |
| ---- | ---- | ---- |
| [ent,person,X] | [ent,person,X] | - |
| [att,person,id,X,Y] | [att,person,id,X,Y] | - |
| [att,person,name,X,Y] | [att,person,name,X,Y] | - |
| [att,person,sex,X,Y] | [or,[and,[ent,male,X],[eq,Y,m]],[and,[ent,female,X],[eq,Y,f]]] | 13 |
| [rel,person,worksin,dept] | [att,person,dname,X,Y] | 11 |
| [ent,dept,Y] | [att,person,dname, ,Y] | 9 |
| [att,dept,dname,X,Y] | [att,person,dname,X,Y] | 10 |
-
从 s1 到 s2 的数据迁移
查询和更新翻译
由于工具支持双向转换,查询和更新的迁移与翻译没有区别。对于 s1 上的任何查询,可使用从 s2 到 s1 数据迁移表将 s1 的构造转换为 s2 的构造,从而得到 s2 上的查询;反之亦然。
-
查询翻译示例
查询“Find the ids of all females that work in Computing.”的翻译过程如下:
Query on s1
Step Query on s2
[and,
-
[and,
[att,person,sex,Id,f],
13
[or,[and,[ent,male,Id],[eq,f,m]],
[and,[ent,female,Id],[eq,f,f]]],
[rel,person,worksin,
11
[att,person,dname,Id,maths]]
dept,Id,computing]]
-
更新翻译示例
插入操作的翻译,如在 s2 中插入一个 id 为 1000,名字为 ‘Peter’ 的男性人员,可转换为在 s1 中插入一个 id 为 1000,名字为 ‘Peter’ 且性别为 m 的人员:
Insert into s2
Step Insert into s1
[and,
-
[and,
[ent,person,1000],
-
[ent,person,1000],
[and,
-
[and,
[ent,male,1000],
1
[att,person,sex,1000,m],
[att,person,name,
-
[att,person,name,
1000,’Peter’]]]
-
1000,’Peter’]]]
非等价模式之间的转换
更高层次的转换,如
extendEntity
、
contractEntity
等,可基于低级的扩展和收缩操作来定义。
-
从 s3 到 s4 的转换示例
expandAttribute(s5,s3,[person,name, , ]).
contractAttribute(s5a,s5,[degree,code, , ]),
contractAttribute(s5b,s5a,[degree,title, , ]),
contractRelationship(s3c,s3b,[degree,runby,dept, , ]),
contractEntity(s4,s5c,[degree, ]),
- 从 s4 到 s3 的转换示例
expandEntity(s4,s5c,[degree, ]),
expandRelationship(s5c,s3b,[degree,runby,dept, , ]),
expandAttribute(s5b,s5a,[degree,title, , ]),
expandAttribute(s5a,s5,[degree,code, , ]),
contractAttribute(s5,s3,[person,name, , ]).
全局模式和查询
在某些情况下,存在一个联邦模式 s5,它包含了 s1、s2 和 s3 三个源模式的信息。对于全局查询,需要将其分解到各个源模式上进行处理。
-
查询分解示例
查询“Find the names and ids of the persons and the dname of departments which are all involved with the degree programme with code=‘G500’.”的分解过程如下:
Query on s5
Step Query on s1
[and,
-
[and,
[att,person,name,Id,Name],
-
[att,person,name,Id,Name],
[and,
-
[and,
[rel,person,worksin,
-
[rel,person,worksin,
dept,Id,DName],
dept,Id,DName],
[rel,degree,runby,
20
[void]
dept,’G500’,DName]]]
]]
Query on s5
Step Query on s2
[and,
-
[and,
[att,person,name,Id,Name],
-
[att,person,name,Id,Name],
[and,
-
[and,
[rel,person,worksin
11
[att,person,
dept,Id,DName],
dname,Id,DName],
[rel,degree,runby
20
[void]
dept,’G500’,DName]]]
]]
Query on s5
Step Query on s3
[and,
-
[and,
[att,person,name,Id,Name],
26
[void],
[and,
-
[and,
[rel,person,
-
[rel,person,
worksin,dept,Id,DName],
-
worksin,dept,Id,DName],
[rel,degree,runby,
-
[rel,degree,runby,
dept,’G500’,DName]]]
-
dept,’G500’,DName]]]
全局查询计划如下:
Query on s5
Global Query Plan
[and,
[and,
[att,person,name,
[plan,
Id,Name],
[ask,s1,[att,person,name,Id,Name]],
[ask,s2,[att,person,name,Id,Name]]
],
[and,
[and,
[rel,person,worksin,
[plan,
dept,Id,DName],
[ask,s1,
[rel,person,worksin,dept,Id,DName]],
[ask,s2,
[att,person,dname,Id,DName]],
[ask,s3,
[rel,person,worksin,dept,Id,DName]]
],
[rel,degree,runby,
[ask,s3,[rel,degree,runby,
dept,’G500’,DName]
dept,’G500’,DName]]
]]
]]
实体关系模型聚类方法
在处理大型数据模型时,为了提高用户理解和简化文档维护,需要对数据模型进行聚类。
研究背景
数据模型聚类的目的是将大型数据模型分解为易于管理的层次结构。此前有基于街道目录组织的方法来表示大型数据模型,即 Levelled Data Model,它包含以下组件:
- 上下文数据模型(Context Data Model):提供模型的概述以及如何划分为主题区域,类似于街道目录中的关键地图。
- 主题区域数据模型(Subject Area Data Models):详细展示数据模型的一个子集(主题区域),使用修改后的实体关系图表示,类似于街道目录中的详细地图,使用外部实体表示与其他主题区域的关系。
- 索引:用于帮助定位每个主题区域内的单个对象(实体、关系和属性),类似于街道和地点索引。
研究目标
一个全面的分解方法应具备以下两个能力:
- 评估分解的质量并在不同方案中进行选择。
- 规定如何生成“良好”或最优的分解。
以往研究方法对比
| 方法 | 分解原则 | 过程类型 | 聚类级别 |
|---|---|---|---|
| Martin, 1983 | 功能依赖(Level 1)、关联强度(Level 2) | 手动 | 两个 |
| Feldman and Miller, 1986 | 功能依赖(Level 1)、主观判断(Level 2) | 手动 | 两个 |
| Teory, Wie, Bolton and Koenig, 1989 | 功能区域、主导实体、内聚级别 | 手动 | 两个 |
| Batini, Ceri and Navathe, 1992 | 耦合、内聚、模式平衡、概念平衡 | 无 | 无限制 |
| Francalanci and Percini, 1994 | 接近度(语法内聚)、亲和度(语义内聚)、平衡 | 自动 | 一个 |
| Akoka and Comyn - Wattiau, 1996 | 语义距离 | 自动 | 一个 |
数据库应用的自动迁移与包装及实体关系模型聚类方法
实体关系模型聚类方法(续)
聚类原则与方法
为了实现数据模型的有效聚类,需要定义一套“好”的分解原则,这些原则可用于评估分解质量和选择最优方案。基于这些原则,可采用以下两种方法进行聚类:
- 手动聚类 :由人类专家依据原则进行操作,以产生相对最优的聚类结果。虽然手动操作可能较为耗时,但专家可以根据实际情况灵活调整,充分考虑数据模型的特点和业务需求。
- 遗传算法自动聚类 :通过遗传算法自动寻找最优分解。遗传算法是一种基于生物进化原理的优化算法,它模拟自然选择和遗传机制,通过不断迭代和进化,找到最优的聚类方案。这种方法具有高效性和准确性,能够在复杂的数据模型中快速找到最优解。
以下是一个简单的 mermaid 流程图,展示了实体关系模型聚类的基本流程:
graph LR
A[定义分解原则] --> B[选择聚类方法]
B --> C{手动聚类?}
C -- 是 --> D[人类专家操作]
C -- 否 --> E[使用遗传算法]
D --> F[生成聚类结果]
E --> F
实际应用与未来展望
实际应用场景
上述数据库应用的自动迁移与包装以及实体关系模型聚类方法在实际数据库操作中有广泛的应用场景。
- 数据库集成 :在多个数据库进行集成时,不同数据库的模式可能存在差异。通过模式转换和数据迁移,可以将不同模式的数据整合到一个统一的环境中,实现数据的互操作性。
- 数据模型优化 :对于大型数据模型,通过实体关系模型聚类方法可以将其分解为易于管理的子模型,提高用户对数据模型的理解和维护效率。
以下是一个实际应用中的操作步骤示例,展示如何进行从 s2 到 s1 的数据迁移:
1. 确定 s2 和 s1 的模式结构,明确需要迁移的数据构造。
2. 根据从 s2 到 s1 的数据迁移表,将 s2 中的数据构造转换为 s1 中的对应构造。例如,将
[att,person,dname,X,Y]
转换为
[rel,person,worksin,dept,X,Y]
(步骤 11)。
3. 执行转换操作,将转换后的数据插入到 s1 中。
未来发展方向
这两种方法在未来还有很大的发展空间,以下是两个主要的发展方向:
- 嵌入编程语言 :将基本的转换操作扩展为一种完整的编程语言,例如添加迭代构造、条件分支构造和过程等。这样可以定义更灵活的通用转换,满足不同场景的需求。
- 开发图形化工具 :以现有的原型工具为基础,开发更复杂的图形化工具。该工具可以支持图形化显示和操作模式,提供常见模式转换的预定义模板,降低用户的操作难度。
综上所述,数据库应用的自动迁移与包装以及实体关系模型聚类方法为数据库操作和数据模型管理提供了有效的解决方案。通过不断发展和完善这些方法,可以更好地应对日益复杂的数据库环境和数据管理需求。
2385

被折叠的 条评论
为什么被折叠?



