Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Projection (relational algebra)

From Wikipedia, the free encyclopedia
Operation that restricts a relation to a specified set of attributes
This article is about relational algebra. For other uses of the term "projection", seeProjection (disambiguation).

Inrelational algebra, aprojection is aunary operation written asΠa1,...,an(R){\displaystyle \Pi _{a_{1},...,a_{n}}(R)}, whereR{\displaystyle R} is arelation anda1,...,an{\displaystyle a_{1},...,a_{n}} are attribute names. Its result is defined as theset obtained when the components of thetuples inR{\displaystyle R} are restricted to the set{a1,...,an}{\displaystyle \{a_{1},...,a_{n}\}} – itdiscards (orexcludes) 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, ifR{\displaystyle R} has attributesa{\displaystyle a},b{\displaystyle b},c{\displaystyle c}, where the values ofb{\displaystyle b} are numbers, thenΠa, b×0.5, c(R){\displaystyle \Pi _{a,\ b\times 0.5,\ c}(R)}is likeR{\displaystyle R}, but with allb{\displaystyle b}-values halved.[2]

Related concepts

[edit]

The closely related concept inset theory (see:projection (set theory)) differs from that ofrelational algebra in that, in set theory, one projects onto ordered components, not onto attributes. For instance, projecting(3,7){\displaystyle (3,7)} onto the second component yields 7.

Projection is relational algebra's counterpart ofexistential quantification inpredicate logic. The attributesnot included correspond to existentially quantified variables in the predicate whoseextension 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 acomputer language it is of course possible to provide notations for both, and that was done inISBL and several languages that have taken their cue from ISBL.

A nearly identical concept occurs in the category ofmonoids, called astring projection, which consists of removing all of the letters in thestring that do not belong to a givenalphabet.

When implemented inSQL standard the "default projection" returns amultiset instead of a set, and theπ projection is obtained by the addition of theDISTINCT keyword to eliminate duplicate data.

Example

[edit]

For an example, consider the relations depicted in the following two tables which are the relationPerson and its projection on (some say "over") the attributesAge andWeight:

Person{\displaystyle {\text{Person}}}ΠAge,Weight(Person){\displaystyle \Pi _{\text{Age,Weight}}({\text{Person}})}
NameAgeWeight
Harry34180
Sally28164
George28170
Helena54154
Peter34180
AgeWeight
34180
28164
28170
54154

Suppose the predicate of Person is "Name isage years old and weighsweight." Then the given projection represents the predicate, "There existsName such thatName isage years old and weighsweight."

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:

Πa1,...,an(R)={ t[a1,...,an]: tR },{\displaystyle \Pi _{a_{1},...,a_{n}}(R)=\{\ t[a_{1},...,a_{n}]:\ t\in R\ \},}

wheret[a1,...,an]{\displaystyle t[a_{1},...,a_{n}]} is therestriction of the tuplet{\displaystyle t} to the set{a1,...,an}{\displaystyle \{a_{1},...,a_{n}\}} 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}\}\},}

where(a,v){\displaystyle (a',v)} is an attribute value,a{\displaystyle a'} is an attribute name, andv{\displaystyle v} is an element of that attribute's domain — seeRelation (database).

The result of a projectionΠa1,...,an(R){\displaystyle \Pi _{a_{1},...,a_{n}}(R)} is defined only if{a1,...,an}{\displaystyle \{a_{1},...,a_{n}\}} is asubset of theheader ofR{\displaystyle R}.

Projection over no attributes at all is possible, yielding arelation of degree zero. In this case thecardinality 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. Retrieved2014-07-28.
  2. ^http://www.csee.umbc.edu/~pmundur/courses/CMSC661-02/rel-alg.pdfSee Problem 3.8.B on page 3
Retrieved from "https://en.wikipedia.org/w/index.php?title=Projection_(relational_algebra)&oldid=1282416718"
Category:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp