Relational Algebra: Set Operations and Cartesian Product - Prof. Yicheng Tu, Study notes of Deductive Database Systems

The fundamental set operations and cartesian product in relational algebra. It covers the concepts of rename operation, union, set-intersection, set difference, and cartesian product. Each operation is defined, and their features and conditions for validity are discussed. The document also includes examples and assumptions for each operation.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-45n
koofers-user-45n 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Rename Operation (9/9)
Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
Allows us to refer to a relation by more than one name.
Example:
ρ
x
(E)
returns the expression E under the name X
If a relational-algebra expression E has arity n, then
returns the result of expression E under the name X, and with the
attributes renamed to A
1
, A
2
, …., A
n
.
Union
Notation: r s
Defined as:
r s = {t | t r or t s}
For r s to be valid. (type compatibility)
1. r, s must have the same arity (same number of attributes)
2. The attribute domains must be compatible (example: 2
nd
column
of r deals with the same type of values as does the 2
nd
column of s)
Example: to find all customers with either an account or a loan
customer_name
(depositor)
customer_name
(borrower)
Key constraints can be violated when the union is processed if both have the same attribute as a
key before union.
)(
),...,,(
21
E
n
AAAx
ρ
pf3

Partial preview of the text

Download Relational Algebra: Set Operations and Cartesian Product - Prof. Yicheng Tu and more Study notes Deductive Database Systems in PDF only on Docsity!

Rename Operation (9/9)

  • Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
  • Allows us to refer to a relation by more than one name.
  • Example:

ρ (^) x (E)

returns the expression E under the name X

  • If a relational-algebra expression E has arity n, then

returns the result of expression E under the name X, and with the

attributes renamed to A 1 , A 2 , …., An.

Union

  • Notation: r ∪ s
  • Defined as:

r ∪ s = {t | t ∈ r or t ∈ s}

  • For r ∪ s to be valid. (type compatibility)
    1. r, s must have the same arity (same number of attributes)
    2. The attribute domains must be compatible (example: 2nd^ column of r deals with the same type of values as does the 2nd column of s)
  • Example: to find all customers with either an account or a loan

∏customer_name (depositor) ∪ ∏customer_name (borrower)

  • Key constraints can be violated when the union is processed if both have the same attribute as a key before union.

ρ x ( A 1 , A 2 ,..., An )( E )

Set-Intersection

  • Notation: r ∩ s
  • Defined as:
  • r ∩ s = { t | t ∈ r and t ∈ s }
  • Assume:

l r, s have the same arity

l attributes of r and s are compatible

  • Note: r ∩ s = r – (r – s)

Set Difference

  • Notation r – s
  • Defined as:

r – s = {t | t ∈ r and t ∉ s}

  • Set differences must be taken between compatible relations.

 r and s must have the same arity

 attribute domains of r and s must be compatible

Cartesian-Product

  • Notation r x s