Sunday, July 19, 2009

Relational Algebra Introduction

Relational Query Languages

Query languages: Allow manipulation and retrieval of data from a database.
- Relational model supports simple, powerful QLs:
• Strong formal foundation based on logic.
• Allows for much optimization.
- Query Languages != programming languages!
• QLs not intended to be used for complex calculations.
• QLs support easy, efficient access to large data sets.

Formal Relational Query Languages

Two mathematical Query Languages form the basis for “real” languages (e.g. SQL), and for implementation:

Relational Algebra: More operational, very useful for
representing execution plans.
Relational Calculus: Lets users describe what they
want, rather than how to compute it. (Non-procedural,declarative.)

Note: Understanding Algebra & Calculus is key to
understanding SQL, query processing!


A query is applied to relation instances, and the
result of a query is also a relation instance.
• Schemas of input relations for a query are fixed (but
query will run over any legal instance)
• The schema for the result of a given query is also
fixed. It is determined by the definitions of the query
language constructs.

Relational Algebra: 5 Basic Operations

- Selection ( ): Selects a subset of rows from relation

- Projection ( ): Retains only wanted columns from relation
Cross-product ( ): Allows us to combine two relations.

- Set-difference ( — ): Tuples in r1, but not in r2.

- Union ( ): Tuples in r1 or in r2.

1 comment:

  1. loved the way you explained things. Much better many here