数据库原理 英文课件chapter4- Relational Algebra.ppt
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
6
Operators
运算符
集合
运算符
专门的
关系
运算符
含义
并 差 交 广义笛卡尔积
选择 投影 连接
除
运算符
比较
>
运算符
>=
<
<=
=
逻辑
运算符
含义
大于 大于等于
小于 小于等于
等于 不等于
非 与 或
7
Set Operators
R U S: union, the set of elements that are in R or S or both. RS: intersection, the set of elements that are in both R and S. R - S: difference, the set of elements that are in R but no in S. Required
Called natural join.
3
What is Relational Algebra?
An algebra whose operands are relations or variables that represent relations. Operators are designed to do the most common things that we need to do with relations in a database.
Example title, year, length (Movie)
10
Selection
C (R)
C is a condition (as in “if” statements) that refers to attributes of R. The result is a new relation with a subset of R’s tuples that satisfy C.
12
RS
AB
a1
b1
a1
b1
a1
b1
a1
b2
a1
b2
a1
b2
a2
b2
a2
b2
a2
b2
R
S
A
B
C
A
BC
a1
b1
c1
a1
b2
c2
a1
b2
c2
a1
b3
c2
a2
b2
c1
a2
b2
c1
C A BC
c1
a1
b2 c2
c1
a1
b3 c2
c1
a2
b2 c1
c2
a1
b2 c2
c2
a1
b3 c2
c2
a2
b2 c1
c1
a1
R and S must have schema with identical set of attributes, and Before calculation, the columns of R and S must be ordered.
8
RS
AB
C
a1 b1 c1
R
A
B
a1
b1
a1
b2
a2
The result is an algebra that can be used as a query language for relations.
4
What we will learn…
Core (or traditionally) relational algebra
5
Core Relational Algebra
b2
a1 b2 c2
a2 b2 c1
a1 b3 c2
R-S
A
B
C
a1 b1
c1
S
C
A
c1
a1
c2
a1
c1
a2
BC
b2
c2
b3
c2
b2
c1
RS
A
B
C
a1 b2 c2 a2 b2 c1
9
Projection
L (R)
L is a list of attributes from the schema of R. The result is a new relation that has only some of R’s columns. Eliminate duplicate tuples, if any.
Example
lentgh>=100 AND studioName = ‘Fox’ (Movie)
11
Cartesian Product
or just product R S
Pair each tuple t1 of R with each tuple t2 of S. Result: a new relation with new tuples, each of them concatenation a pair of t1t2, the attributes of R and S are in ordered. But beware attribute A of the same name in R and S: use R.A and S.A.
Union, intersection, and difference.
Usual set operations, but require both operands have the same relation schema.
Selection: picking certain rown columns. Products and joins: compositions of relations.
Database Principles
1
Chapter 4 Relational Algebra
Operators Expression Trees
2
What is an “Algebra”
Mathematical system consisting of:
Operands --- variables or values from which new values can be constructed. Operators --- symbols denoting procedures that construct new values from given values.
b2 c2
c1
a1
b3 c2
13
c1
a2
b2 c1
Natural Join
A frequent type of join connects two relations by:
Equating attributes of the same name, and
Projecting out one copy of each pair of equated attributes.
Operators
运算符
集合
运算符
专门的
关系
运算符
含义
并 差 交 广义笛卡尔积
选择 投影 连接
除
运算符
比较
>
运算符
>=
<
<=
=
逻辑
运算符
含义
大于 大于等于
小于 小于等于
等于 不等于
非 与 或
7
Set Operators
R U S: union, the set of elements that are in R or S or both. RS: intersection, the set of elements that are in both R and S. R - S: difference, the set of elements that are in R but no in S. Required
Called natural join.
3
What is Relational Algebra?
An algebra whose operands are relations or variables that represent relations. Operators are designed to do the most common things that we need to do with relations in a database.
Example title, year, length (Movie)
10
Selection
C (R)
C is a condition (as in “if” statements) that refers to attributes of R. The result is a new relation with a subset of R’s tuples that satisfy C.
12
RS
AB
a1
b1
a1
b1
a1
b1
a1
b2
a1
b2
a1
b2
a2
b2
a2
b2
a2
b2
R
S
A
B
C
A
BC
a1
b1
c1
a1
b2
c2
a1
b2
c2
a1
b3
c2
a2
b2
c1
a2
b2
c1
C A BC
c1
a1
b2 c2
c1
a1
b3 c2
c1
a2
b2 c1
c2
a1
b2 c2
c2
a1
b3 c2
c2
a2
b2 c1
c1
a1
R and S must have schema with identical set of attributes, and Before calculation, the columns of R and S must be ordered.
8
RS
AB
C
a1 b1 c1
R
A
B
a1
b1
a1
b2
a2
The result is an algebra that can be used as a query language for relations.
4
What we will learn…
Core (or traditionally) relational algebra
5
Core Relational Algebra
b2
a1 b2 c2
a2 b2 c1
a1 b3 c2
R-S
A
B
C
a1 b1
c1
S
C
A
c1
a1
c2
a1
c1
a2
BC
b2
c2
b3
c2
b2
c1
RS
A
B
C
a1 b2 c2 a2 b2 c1
9
Projection
L (R)
L is a list of attributes from the schema of R. The result is a new relation that has only some of R’s columns. Eliminate duplicate tuples, if any.
Example
lentgh>=100 AND studioName = ‘Fox’ (Movie)
11
Cartesian Product
or just product R S
Pair each tuple t1 of R with each tuple t2 of S. Result: a new relation with new tuples, each of them concatenation a pair of t1t2, the attributes of R and S are in ordered. But beware attribute A of the same name in R and S: use R.A and S.A.
Union, intersection, and difference.
Usual set operations, but require both operands have the same relation schema.
Selection: picking certain rown columns. Products and joins: compositions of relations.
Database Principles
1
Chapter 4 Relational Algebra
Operators Expression Trees
2
What is an “Algebra”
Mathematical system consisting of:
Operands --- variables or values from which new values can be constructed. Operators --- symbols denoting procedures that construct new values from given values.
b2 c2
c1
a1
b3 c2
13
c1
a2
b2 c1
Natural Join
A frequent type of join connects two relations by:
Equating attributes of the same name, and
Projecting out one copy of each pair of equated attributes.