01-11-2012, 12:34 PM
The Relational Algebra
The Relational.pdf (Size: 72.31 KB / Downloads: 20)
Relational Algebra
• One of the relational data model languages
• The others are Tuple Calculus, Domain
Calculus, SQL
• Important for query optimization
– A SQL query is transformed into a relational algebra
equivalent, optimized and executed
• A set of operations to manipulate (query and
update) a relational database
• Operations are applied onto relations
• The result is a new relation
Relational Algebra Operations
• Three types of operations:
– Relational database operations:
• select, project, and join
– Set theoretic operations:
• union, intersect, set difference, Cartesian product
– Additional relational operations:
• aggregate operations, grouping, and outer join
Join Operation
• Join operation joins two relations by merging
those tuples from two relations that satisfy some
given condition
• Theta, equi, and natural join operations
• Theta, equi, and natural join are collectively
called INNER joins
• In each of inner joins, tuples with null valued join
attributes do not appear in the result
Additional relational
operations
• Relational database and set theoretic operations are not
sufficient to perform some common database queries
• To enhance the power of relational algebra, there are some new
operations introduced:
– Aggregate functions (SUM, AVERAGE, MAX, MIN, COUNT),
– Grouping, and
– Outer join
– Generalized projection
• Aggregate functions are defined on numeric attributes and
applied on all relation tuples
• Relation is partitioned by means of grouping attribute values,
and the defined aggregate functions are computed for the tuples
of each group
• Outer join extends the join operation to cope with null values
Summary
• Relational algebra:
– Relational database operations,
– Set theoretic operations
– Additional operations
• Relational database operations
– select (chooses tuples), project (restricts tuples), join
(concatenates matching tuples)
• Set theoretic operations
– Union, Intersect, Set difference, Cartesian product
• Additional relational operations
– Aggregate functions COUNT, SUM, AVERAGE,…,
Grouping, and Outer join