fbpx
Wikipedia

Projection (relational algebra)

In relational algebra, a projection is a unary operation written as , where is a relation and are attribute names. Its result is defined as the set obtained when the components of the tuples in are restricted to the set – it discards (or excludes) the other attributes.[1]

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 {(Alice, 5), (Bob, 8)} onto attribute list (age) yields {5,8} – we have discarded the names, and only know what ages are present.

Projections may also modify attribute values. For example, if has attributes , , , where the values of are numbers, then is like , but with all -values halved.[2]

Related concepts edit

The closely related concept in set theory (see: projection (set theory)) differs from that of relational algebra in that, in set theory, one projects onto ordered components, not onto attributes. For instance, projecting   onto the second component yields 7.

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.

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.

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 edit

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:

   
Name Age Weight
Harry 34 180
Sally 28 164
George 28 170
Helena 54 154
Peter 34 180
Age Weight
34 180
28 164
28 170
54 154

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 edit

More formally the semantics of projection are defined as follows:

 

where   is the restriction of the tuple   to the set   so that

 

where   is an attribute value,   is an attribute name, and   is an element of that attribute's domain — see Relation (database).

The result of a projection   is defined only if   is a subset of the header of  .

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 edit

References edit

  1. ^ "Relational Algebra". cs.rochester.edu. Retrieved 2014-07-28.
  2. ^ http://www.csee.umbc.edu/~pmundur/courses/CMSC661-02/rel-alg.pdf See Problem 3.8.B on page 3

projection, relational, algebra, this, article, about, relational, algebra, other, uses, term, projection, projection, disambiguation, relational, algebra, projection, unary, operation, written, Πa1, displaystyle, where, displaystyle, relation, displaystyle, a. This article is about relational algebra For other uses of the term projection see Projection disambiguation In relational algebra a projection is a unary operation written as Pa1 an R displaystyle Pi a 1 a n R where R displaystyle R is a relation and a1 an displaystyle a 1 a n are attribute names Its result is defined as the set obtained when the components of the tuples in R displaystyle R are restricted to the set a1 an displaystyle a 1 a n it discards or excludes the other attributes 1 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 Alice 5 Bob 8 onto attribute list age yields 5 8 we have discarded the names and only know what ages are present Projections may also modify attribute values For example if R displaystyle R has attributes a displaystyle a b displaystyle b c displaystyle c where the values of b displaystyle b are numbers then Pa b 0 5 c R displaystyle Pi a b 0 5 c R is like R displaystyle R but with all b displaystyle b values halved 2 Contents 1 Related concepts 2 Example 3 Formal definition 4 See also 5 ReferencesRelated concepts editThe closely related concept in set theory see projection set theory differs from that of relational algebra in that in set theory one projects onto ordered components not onto attributes For instance projecting 3 7 displaystyle 3 7 nbsp onto the second component yields 7 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 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 When implemented in SQL standard the default projection returns a multiset instead of a set and the p projection is obtained by the addition of the DISTINCT keyword to eliminate duplicate data Example editFor 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 displaystyle text Person nbsp PAge Weight Person displaystyle Pi text Age Weight text Person nbsp Name Age WeightHarry 34 180Sally 28 164George 28 170Helena 54 154Peter 34 180 Age Weight34 18028 16428 17054 154Suppose 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 editMore formally the semantics of projection are defined as follows Pa1 an R t a1 an t R displaystyle Pi a 1 a n R t a 1 a n t in R nbsp where t a1 an displaystyle t a 1 a n nbsp is the restriction of the tuple t displaystyle t nbsp to the set a1 an displaystyle a 1 a n nbsp so that t a1 an a v a v t a a1 an displaystyle t a 1 a n a v a v in t a in a 1 a n nbsp where a v displaystyle a v nbsp is an attribute value a displaystyle a nbsp is an attribute name and v displaystyle v nbsp is an element of that attribute s domain see Relation database The result of a projection Pa1 an R displaystyle Pi a 1 a n R nbsp is defined only if a1 an displaystyle a 1 a n nbsp is a subset of the header of R displaystyle R nbsp 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 editProjection set theory References edit Relational Algebra cs rochester edu Retrieved 2014 07 28 http www csee umbc edu pmundur courses CMSC661 02 rel alg pdf See Problem 3 8 B on page 3 Retrieved from https en wikipedia org w index php title Projection relational algebra amp oldid 1172516982, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.