Opentopia Directory Encyclopedia Tools

Projection (relational algebra)

Encyclopedia : P : PR : PRO : Projection (relational algebra)



 

In relational algebra, a projection is a unary operation written as [\pi_( R )] where [a_1,...,a_n] is a set of attribute names. The result of such projection is defined as the set that is obtained when all tuples in [R] are restricted to the set [\].

Projection is relational algebra's counterpart of existential quantification in predicate logic. The attributes not included correspond to existentially quantified variables in the predicate whose extension the operand relation represents. The example below illustrates this point.

Because of the correspondence with existential quantification, some authorities prefer to define projection in terms of the excluded attributes. In a computer language it is of course possible to provide notations for both, and that was done in ISBL and several languages that have taken their cue from ISBL.

Explanation

For an example, consider the relations depicted in the following two tables which are the relation [Person] and its projection on (some say, over) the attributes [Age] and [Weight]:

[Person] [\pi_(Person)]

! style="border: 1px solid black" width="34%" | Name
! style="border: 1px solid black" width="33%" | Age
! style="border: 1px solid black" width="33%" | Weight

| style="border: 1px solid black" | Harry
| style="border: 1px solid black" | 34
| style="border: 1px solid black" | 80

| style="border: 1px solid black" | Sally
| style="border: 1px solid black" | 28
| style="border: 1px solid black" | 64

| style="border: 1px solid black" | George
| style="border: 1px solid black" | 29
| style="border: 1px solid black" | 70

| style="border: 1px solid black" | Helena
| style="border: 1px solid black" | 54
| style="border: 1px solid black" | 54

| style="border: 1px solid black" | Peter
| style="border: 1px solid black" | 34
| style="border: 1px solid black" | 80

! style="border: 1px solid black" width="50%" | Age
! style="border: 1px solid black" width="50%" | Weight

| style="border: 1px solid black" | 34
| style="border: 1px solid black" | 80

| style="border: 1px solid black" | 28
| style="border: 1px solid black" | 64

| style="border: 1px solid black" | 29
| style="border: 1px solid black" | 70

| style="border: 1px solid black" | 54
| style="border: 1px solid black" | 54

Suppose the predicate of Person is "Name is age years old and weighs weight." Then the given projection represents the predicate, "There exists Name such that Name is age years old and weighs weight."

Note that Harry and Peter have the same age and weight, but since the result is a relation, and therefore a set, this combination only appears once in the result.

More formally the semantics of projection are defined as follows:

[\pi_( R ) = \]
where [t[a_1,...,a_n]] is the restriction of the tuple [t] to the set [\] so that

[t[a_1,...,a_n] = \]
The result of a projection [\pi_( R )] is defined only if [\] is a subset of the header of [R].

It is interesting to note that projection over no attributes at all is possible, yielding a relation of degree zero. In this case the cardinality of the result is zero if the operand is empty, otherwise one. The two relations of degree zero are the only ones that cannot be depicted as tables.

In SQL, a projection can be simulated by using the keyword DISTINCT in the SELECT clause of a table expression (query), provided that at least one column is to be included in the result (SQL doesn't recognize relations of degree zero).

 


From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.


Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: