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 In mathematics, a unary operation is an operation with only one operand, i.e. a single input. This is in contrast to ''binary operations'', which use two operands. An example is any function , where is a set; the function is a unary operation ...
written as \Pi_( R ), where R is a
relation Relation or relations may refer to: General uses * International relations, the study of interconnection of politics, economics, and law on a global level * Interpersonal relationship, association or acquaintance between two or more people * ...
and a_1,...,a_n are attribute names. Its result is defined as the
set Set, The Set, SET or SETS may refer to: Science, technology, and mathematics Mathematics *Set (mathematics), a collection of elements *Category of sets, the category whose objects and morphisms are sets and total functions, respectively Electro ...
obtained when the components of the
tuples In mathematics, a tuple is a finite sequence or ''ordered list'' of numbers or, more generally, mathematical objects, which are called the ''elements'' of the tuple. An -tuple is a tuple of elements, where is a non-negative integer. There is on ...
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) In set theory, a projection is one of two closely related types of functions or operations, namely: * A set-theoretic operation typified by the jth projection map, written \mathrm_j, that takes an element \vec = (x_1,\ \dots,\ x_j,\ \dots,\ x_k) ...
) 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
monoid In abstract algebra, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being . Monoids are semigroups with identity ...
s, called a string projection, which consists of removing all of the letters in the
string String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, entertainment, and media Films * ''Strings'' (1991 film), a Canadian anim ...
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 Structured Query Language (SQL) (pronounced ''S-Q-L''; or alternatively as "sequel") is a domain-specific language used to manage data, especially in a relational database management system (RDBMS). It is particularly useful in handling s ...
standard the "default projection" returns a
multiset In mathematics, a multiset (or bag, or mset) is a modification of the concept of a set that, unlike a set, allows for multiple instances for each of its elements. The number of instances given for each element is called the ''multiplicity'' of ...
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) In database theory, a relation, as originally defined by E. F. Codd, is a set of tuples (d1,d2,...,dn), where each element dj is a member of Dj, a data domain. Codd's original definition notwithstanding, and contrary to the usual definition in ...
. 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) In set theory, a projection is one of two closely related types of functions or operations, namely: * A set-theoretic operation typified by the jth projection map, written \mathrm_j, that takes an element \vec = (x_1,\ \dots,\ x_j,\ \dots,\ x_k) ...


References

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