HOME

TheInfoList



OR:

In
relational algebra In database theory, relational algebra is a theory that uses algebraic structures with a well-founded semantics for modeling data, and defining queries on it. The theory was introduced by Edgar F. Codd. The main application of relational algebr ...
, a projection is a
unary operation In mathematics, an 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 o ...
written as \Pi_( R ), where R is a relation 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 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 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 mathematics, is mostly concern ...
(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 ''j''th projection map, written \mathrm_, that takes an element \vec = (x_1,\ \ldots,\ x_j,\ \ldots,\ x ...
) differs from that of
relational algebra In database theory, relational algebra is a theory that uses algebraic structures with a well-founded semantics for modeling data, and defining queries on it. The theory was introduced by Edgar F. Codd. The main application of relational algebr ...
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 In predicate logic, an existential quantification is a type of quantifier, a logical constant which is interpreted as "there exists", "there is at least one", or "for some". It is usually denoted by the logical operator symbol ∃, which, ...
in
predicate logic First-order logic—also known as predicate logic, quantificational logic, and first-order predicate calculus—is a collection of formal systems used in mathematics, philosophy, linguistics, and computer science. First-order logic uses quantifie ...
. The attributes ''not'' included correspond to existentially quantified variables in the predicate whose
extension Extension, extend or extended may refer to: Mathematics Logic or set theory * Axiom of extensionality * Extensible cardinal * Extension (model theory) * Extension (predicate logic), the set of tuples of values that satisfy the predicate * Ext ...
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 ISBL (Information Systems Base Language) is the relational algebra notation that was invented for PRTV, one of the earliest database management systems to implement E.F. Codd's relational model The relational model (RM) is an approach to manag ...
and several languages that have taken their cue from ISBL. A nearly identical concept occurs in the category of
monoid In abstract algebra, a branch of mathematics, 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 0. Monoid ...
s, 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 standardized set of basic written graphemes (called letters) that represent the phonemes of certain spoken languages. Not all writing systems represent language in this way; in a syllabary, each character represents a syllab ...
. When implemented in SQL 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 that e ...
instead 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. More formally the semantics of projection are defined as follows: : \Pi_( R ) = \, where t _1,...,a_n/math> is the
restriction Restriction, restrict or restrictor may refer to: Science and technology * restrict, a keyword in the C programming language used in pointer declarations * Restriction enzyme, a type of enzyme that cleaves genetic material Mathematics and logi ...
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 usua ...
. The result of a projection \Pi_( R ) is defined only if \ is a
subset In mathematics, set ''A'' is a subset of a set ''B'' if all 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 are unequal, then ''A'' is a proper subset of ...
of the header of R. 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.


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 ''j''th projection map, written \mathrm_, that takes an element \vec = (x_1,\ \ldots,\ x_j,\ \ldots,\ x ...


References

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