HOME

TheInfoList



OR:

In
relational algebra In database theory, relational algebra is a theory that uses algebraic structures for modeling data and defining queries on it with well founded semantics (computer science), semantics. The theory was introduced by Edgar F. Codd. The main applica ...
, a projection is a unary operation written as \Pi_( R ), where R is a relation and a_1,...,a_n are attribute names. Its result is defined as the set obtained when the components of the tuples in R are restricted to the set \ – it ''discards'' (or ''excludes'') the other attributes. In practical terms, if a relation is thought of as a table, then projection can be thought of as picking a subset of its columns. For example, if the attributes are (name, age), then projection of the relation onto attribute list (age) yields – we have discarded the names, and only know what ages are present. Projections may also modify attribute values. For example, if R has attributes a, b, c, where the values of b are numbers, then \Pi_( R ) is like R, but with all b-values halved.http://www.csee.umbc.edu/~pmundur/courses/CMSC661-02/rel-alg.pdf ''See Problem 3.8.B on page 3''


Related concepts

The closely related concept in
set theory Set theory is the branch of mathematical logic that studies Set (mathematics), sets, which can be informally described as collections of objects. Although objects of any kind can be collected into a set, set theory – as a branch of mathema ...
(see: projection (set theory)) differs from that of
relational algebra In database theory, relational algebra is a theory that uses algebraic structures for modeling data and defining queries on it with well founded semantics (computer science), semantics. The theory was introduced by Edgar F. Codd. The main applica ...
in that, in set theory, one projects onto ordered components, not onto attributes. For instance, projecting (3,7) onto the second component yields 7. Projection is relational algebra's counterpart of
existential quantification Existentialism is a family of philosophy, philosophical views and inquiry that explore the human individual's struggle to lead an Authenticity (philosophy), authentic life despite the apparent Absurdity#The Absurd, absurdity or incomprehensibili ...
in
predicate logic First-order logic, also called predicate logic, predicate calculus, or quantificational logic, is a collection of formal systems used in mathematics, philosophy, linguistics, and computer science. First-order logic uses quantified variables ove ...
. 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 A computer language is a formal language used to communicate with a computer. Types of computer languages include: * Software construction#Construction languages, Construction language – all forms of communication by which a human can Comput ...
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. A nearly identical concept occurs in the category of monoids, called a string projection, which consists of removing all of the letters in the string that do not belong to a given
alphabet An alphabet is a standard set of letter (alphabet), letters written to represent particular sounds in a spoken language. Specifically, letters largely correspond to phonemes as the smallest sound segments that can distinguish one word from a ...
. When implemented in SQL standard the "default projection" returns a multiset instead of a set, and the projection is obtained by the addition of the DISTINCT keyword to eliminate duplicate data.


Example

For an example, consider the relations depicted in the following two tables which are the relation and its projection on (some say "over") the attributes and : 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.


Formal definition

More formally the semantics of projection are defined as follows: : \Pi_( R ) = \, where t _1,...,a_n/math> is the restriction of the tuple t to the set \ so that : t _1,...,a_n= \, where (a', v) is an attribute value, a' is an attribute name, and v is an element of that attribute's domain — see Relation (database). The result of a projection \Pi_( R ) is defined only if \ is a
subset In mathematics, a Set (mathematics), set ''A'' is a subset of a set ''B'' if all Element (mathematics), elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they a ...
of the header of R. Projection over no attributes at all is possible, yielding a relation of degree zero. In this case the
cardinality The thumb is the first digit of the hand, next to the index finger. When a person is standing in the medical anatomical position (where the palm is facing to the front), the thumb is the outermost digit. The Medical Latin English noun for thum ...
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.


See also

* Projection (set theory)


References

{{DEFAULTSORT:Projection (Relational Algebra) Relational algebra ru:Алгебра Кодда#Проекция