Definition
Relational Algebra
Relational algebra is a theory that uses algebraic structure for modeling data and defining queries on it with well founded semantics. It was introduced by Edgar Frank Codd.
Domain
A domain is a set of possible values for an attribute.
Relation
Definition
Link to originalRelation (Relational Algebra)
Let be domains. A relation is a set of tuples based on the Cartesian product of multiple, possibly identical, domains.
Example:
Relation Schema
Definition
Link to originalSchema (Relational Algebra)
Arity
Arity
The number of attributes of a relation is called arity.
Attribute
Operations
Definition
Link to originalSelection (Relational Algebra)
Projection
Definition
Link to originalProjection (Relational Algebra)
The projection operation selects a subset of attribute from a relation and maps it to a new relation containing only those attributes, i.e.
Where is a new tuple containing only the values from the attribute specified in the list for a given tuple . Since the resulting relation is a set, any duplicate tuple that arise from this operation are automatically eliminated.
Note that there’s also the possibility for extended projection, meaning specifying expressions instead of attributes, i.e.:
Rename
Definition
Link to originalRename (Relational Algebra)
The rename operation, denoted by , modifies the schema of a relation without altering the data within its tuples. It produces a new relation with either a new name for the relation itself or new names for its attributes. It is used in two primary forms:
Renaming a Relation
The expression renames the relation to . The new relation has the identical schema and contains the exact same set of tuples as .Renaming Attributes
The expression produces a new relation where the attribute from is renamed to . This can be extended to rename multiple attributes at once, e.g., .The values and the number of tuples remain unchanged, only the attribute names in the schema are modified.
Grouping and Aggregation
Definition
Link to originalGrouping and Aggregation (Relational Algebra)
The grouping and aggregation operation, denoted by , is an operator that first partitions tuples of a relation into groups and then computes a single or multiple summary value for each group using an aggregate function.
This process involves two main steps:
- Grouping: Tuples that have the same values for all attributes in a specified grouping list are placed into the same group.
- Aggregation: An aggregate function (like
SUM
,COUNT
,AVG
,MIN
,MAX
) is applied to an attribute of the tuples within each group, producing a single value per group.where:
- is the list of attributes to group by
- is the aggregate function to be applied to each group. This also defines the new attribute for the aggregate value in the result schema (e.g., )
- is the input relation
The resulting relation consists of the grouping attributes in and the new attribute(s) generated by the aggregate function(s) in .
Union
Definition
Link to originalUnion (Relational Algebra)
The union operation between two union compatible relations is the set of all tuples contained by or , i.e.
Intersection
Definition
Link to originalIntersection (Relational Algebra)
The intersection operation between two union compatible relations is the set of all tuples contained by both and , i.e.
Difference
Definition
Link to originalDifference (Relational Algebra)
The difference operation between two union compatible relations is the set of all tuples that are in but not in , i.e.
Join
Definition
Link to originalJoin (Relational Algebra)
Joins are a way to associate two relations and based on certain conditions.
Division
Definition
Link to originalRelational Division (Relational Algebra)
The relational division operation, denoted by , is typically used to answer queries that involve the phrase “for all”. It finds all tuples in one relation that are associated with every single tuple from another relation .
The division operation can be expressed using projection, difference, and the Cartesian Product:
Joins
Commutativity: due to different output schemas.
Theta Join
Definition
Link to originalTheta Join (Relational Algebra)
Natural Join
Definition
Link to originalNatural Join (Relational Algebra)
The natural join combines two relations via common attributes (same names and domains) by combining only tuples with the same values for common attributes.
Given two relations and , the natural join can be expressed using projection, selection and the Cartesian Product:
Outer Joins
Definition
Link to originalOuter Join
Left Outer Join
Definition
Link to originalLeft Outer Join
Right Outer Join
Definition
Link to originalRight Outer Join (Relational Algebra)
Full Outer Join
Definition
Link to originalFull Outer Join (Relational Algebra)
Semi Joins
Definition
Link to originalSemi Join (Relational Algebra)
Left Semi Join
Definition
Link to originalLeft Semi Join (Relational Algebra)
Right Semi Join
Definition
Link to originalRight Semi Join (Relational Algebra)