请参阅此处所有主题的最后一分钟笔记。
我们将以总结的形式讨论对 GATE 考试有用的重要关键点。有关详细信息,您可以参考这个。
ER 图: ER 图中最常见的问题是给定 ER 图所需的最少表格数。通常,使用以下标准:
Cardinality | Minimum No. of tables |
1:1 cardinality with partial participation of both entities | 2 |
1:1 cardinality with total participation of atleast 1 entity | 1 |
1:n cardinality | 2 |
m:n cardinality | 3 |
注意:这是一般观察。特殊情况需要注意。如果关系的属性不能移动到任何实体端,我们可能需要额外的表。
关系的键:关系中有各种类型的键,它们是:
- 候选键:可以唯一确定元组的最小属性集。一个关系的候选键可以有 1 个以上,其真子集不能唯一确定元组,也不能为 NULL。
- 超级键:可以唯一确定元组的属性集。候选键始终是超级键,反之亦然。
- 主键和备用键:在各种候选键中,一个键为主键,其他键为备用键。
- 外键:外键是表中的一组属性,用于引用同一表或其他表的主键或备用键。
范式
- 第一范式:如果关系不包含任何多值或复合属性,则该关系为第一范式。
- 第二范式:如果关系不包含任何部分依赖,则关系为第二范式。如果候选键的任何适当子集确定非主要(不是候选键的一部分)属性,则依赖称为部分依赖。
- 第三范式:如果关系不包含任何传递依赖,则该关系是第三范式。对于处于第三范式的关系,FD 的 LHS 应该是超级键,或者 RHS 应该是主要属性。
- Boyce-Codd 范式:关系在 博伊斯-科德 如果每个 FD 的 LHS 是超级键,则为范式。范式之间的关系可以表示为: 1NF ⊃ 2NF ⊃ 3NF ⊃ BCNF
关系代数:具有基本和扩展运算符的过程语言。
Basic Operator | Semantic |
σ(Selection) | Select rows based on given condition |
∏(Projection) | Project some columns |
X (Cross Product) | Cross product of relations, returns m*n rows where m and n are number of rows in R1 and R2 respectively. |
U (Union) | Return those tuples which are either in R1 or in R2. Max no. of rows returned = m+n andMin no. of rows returned = max(m,n) |
−(Minus) | R1-R2 returns those tuples which are in R1 but not in R2. Max no. of rows returned = m and Min no. of rows returned = m-n |
ρ(Rename) | Renaming a relation to other relation. |
Extended Operator | Semantic |
∩ (Intersection) | Returns those tuples which are in both R1 and R2. Max no. of rows returned = min(m,n) and Min no. of rows returned = 0 |
⋈c(Conditional Join) |
Selection from two or more tables based on some condition (Cross product followed by selection) |
⋈(Equi Join) |
It is a special case of conditional join when only equality condition is applied between attributes. |
⋈(Natural Join) |
In natural join, equality condition on common attributes hold and duplicate attributes are removed by default. Note: Natural Join is equivalent to cross product if two relations have no attribute in common and natural join of a relation R with itself will return R only. |
⟕(Left Outer Join) |
When applying join on two relations R and S, some tuples of R or S does not appear in result set which does not satisfy the join conditions. But Left Outer Joins gives all tuples of R in the result set. The tuples of R which do not satisfy join condition will have values as NULL for attributes of S. |
⟖(Right Outer Join) |
When applying join on two relations R and S, some tuples of R or S does not appear in result set which does not satisfy the join conditions. But Right Outer Joins gives all tuples of S in the result set. The tuples of S which do not satisfy join condition will have values as NULL for attributes of R. |
⟗(Full Outer Join) |
When applying join on two relations R and S, some tuples of R or S does not appear in result set which does not satisfy the join conditions. But Full Outer Joins gives all tuples of S and all tuples of R in the result set. The tuples of S which do not satisfy join condition will have values as NULL for attributes of R and vice versa. |
/(Division Operator) |
Division operator A/B will return those tuples in A which is associated with every tuple of B.Note:Attributes of B should be proper subset of attributes of A. The attributes in A/B will be Attributes of A- Attribute of B. |
如何解决 GATE 的关系代数问题 – SET 1
如何解决 GATE 的关系代数问题 – SET 2
SQL :与关系代数相反,SQL 是一种非过程语言。
Operator | Meaning |
Select | Selects columns from a relation or set of relations.Note: As opposed to Relational Algebra, it may give duplicate tuples for repeated value of an attribute. |
From | From is used to give input as relation or set of relations from which data needs to be selected. |
where | Where is used to give condition to be used to filter tuples |
EXISTS | EXISTS is used to check whether the result of a correlated nested query is empty (contains no tuples) or not. |
Group By | Group By is used to group the tuples based on some attribute or set of attributes like counting the no. of students group by department. |
Order By | Order By is used to sort the fetched data in either ascending or descending according to one or more columns. |
Aggregate functions | Find the aggregated value of an attribute. Used mostly with group by. e.g.; count, sum, min max. select count(*) from student group by dept_idNote: we can select only those columns which are part of group by. |
Nested Queries | When one query is a part of other query. Solving nested queries questions can be learnt in https://www.geeksforgeeks.org/nested-queries-in-sql/ |
Conflict serializable 和 Conflict Equivalent :如果冲突等同于串行调度,则调度是冲突可序列化的。
检查冲突可串行化
要检查时间表是否冲突串行化与否,找到所有冲突操作对S内的调度的和绘制优先级图(对于所有的冲突的操作一对,在T的边缘i到T J,如果冲突的对中的一个操作是从T I和其他来自 T j并且 T i 的操作发生在调度中的T j之前)。如果图不包含循环,则调度是冲突可序列化的,否则它不是冲突可序列化的。
如果可以通过交换非冲突操作将一个调度转换为另一个调度,则称调度为冲突等价的。
注意:两阶段锁定协议会产生冲突的可序列化调度,但可能会遇到死锁。另一方面,基于时间戳的协议没有死锁,但会产生冲突的可序列化调度。
视图可序列化和视图等效:如果所有对象的所有条件都满足,则两个调度 S1 和 S2 被称为视图等效:
-
如果S1 中的事务T i 读取对象 X 的初始值,那么在 S2 中, T i 也必须读取 X 的初始值。
-
如果S1 中的事务T i 读取了事务T j 在 S1 中为对象 X 写入的值,则在 S2 中也应该这样做。
-
如果在S1 中的事务T i 为最终交易将该值写入一个对象X,在S2中也,T I 必须写X的最终值
如果一个调度等同于任何串行调度的视图,则该调度是视图可序列化的。
不可恢复的时间表: 对于事务对< T i , T j >,如果T j 正在读取Ti 更新的值并且Tj 在Ti 提交之前提交,则调度将不可恢复。
可恢复的时间表: 对于事务对< T i , T j >,如果T j 正在读取Ti 更新的值并且Tj 在Ti 提交后提交,则调度将是可恢复的。
无级联可恢复计划: 对于事务对< T i , T j >,如果Ti 更新的值只有在T i 提交后才被Tj 读取,则调度将是无级联可恢复的。
Strict Recoverable: 对于< T i , T j > 的事务对,如果Ti更新的值只有在T i 提交后才被Tj读或写,则调度是严格可恢复的。它们之间的关系可以表示为:
严格⊂ Cascadeless Recoverable ⊂ 可恢复⊂ 所有计划
文件结构
主索引 ::主索引是一个有序文件,具有两个字段的固定长度的记录。第一个字段与数据文件的主键相同,第二个字段是指向数据块的指针,其中键可用。
使用 index = log 2 Bi + 1的平均块访问数,其中 Bi = 索引块数。集群索引:集群索引是在数据文件上创建的,这些文件的记录在非键字段(称为集群字段)上物理排序。二级索引:二级索引提供了访问已存在一级访问的文件的二级方法。
Number of index entries = Number of records
B 树
在每一层,我们都有键和数据指针,数据指针指向块或记录。
B树的特性:
B 树的根可以有2和P之间的孩子,其中 P 是树的顺序。
树的顺序——一个节点可以拥有的最大子节点数。
内部节点可以在⌈ P/2 ⌉和P之间有子节点
内部节点可以在⌈ P/2 ⌉ – 1和P-1之间有键
B+树
在B+树中,叶子和非叶子的结构是不同的,所以它们的顺序是。与叶节点相比,非叶节点的顺序会更高。
在 B+ 树中搜索时间会更少,因为它在非叶中没有记录指针,因此深度会减少。
本文由 Sonal Tuteja 提供。