Tuple calculus and the relational operators


Write for a long time, do not know what's the use, good cumbersome and do not know these things can be used in any place, what scene.


1. Relational Operators

The basic operation of the main and relational algebra, intersection, difference, Cartesian product, selection, projection, connection and division.
(1) and. Two theoretically calculated and set in the relationship set, i.e., given the relationship between R and S (they have the same element / the number of columns), R∪S tuples comprises a set of R and S of all tuples, the form is defined as follows:
Here Insert Picture Description
where t is a tuple variable (below). Obviously, R∪S = S∪R.

(2) difference. Calculating the difference between the two relationships set, i.e., given the relationship between R and S (they have the same element / the number of columns), RS tuple packet
comprises R has the set of tuples S is not in the form defined as follows:
Here Insert Picture Description
popular point that is part of it belongs to the element of S R.

In view of this difference computing application scenarios, for example, on two stocks combined, a combination comprising a "donkey-hide gelatin", "Fuling mustard", "Tong Ren Tang."
And the other portfolio includes only "donkey-hide gelatin", "Fuling mustard." That's the difference between these two is the "Tongrentang"

(3) cross. Computing the intersection of two theoretical relationship set, i.e., given the relationship between R and S (they have the same element / the number of columns), R∩S set of tuples comprises tuples of the same R and S, forms are defined as follows:
Here Insert Picture Description
Obviously, R∩S = R- (RS) and R∩S = S- (SR) was founded.

(4) Cartesian product. Calculation of the relationship between two Cartesian product, let R be a relationship m-ary, S is the n-element relationship R × S is the set of tuples m + n elements, from which a first m elements of R tuple, then n elements from a tuple of S. Form is defined as follows:

Here Insert Picture Description
If R has tuples u, S v tuples have, have the R × S × u v tuples.

Remember Cartesian product number is the product of both can, corresponding to permutations and combinations of both.

(5) a projection. Extracting specified attributes (columns) from a relationship. Let R be a relation attribute A is included,

Here Insert Picture Description

(6) θ is connected. θ satisfies a certain condition is connected between the select attribute tuples from the Cartesian product of the two relations, denoted by:
Here Insert Picture Description

Wherein A and B are equal and set properties comparable to the number of R and S Lantern. θ is the "=" connections, called equivalent connection, referred to as:
Here Insert Picture Description

If the two components are compared must be the same relationships set of attributes, and the result will be to remove the duplicate attribute, it is called the natural connection, denoted by:
Here Insert Picture Description
[theta] is connected Cartesian product processing, although I do not know in the end is used to do.

Second, Ganso operation

Tuple calculus, simply referred to as a tuple calculus expressions tuple expression , which is a general form {t | P (t)} , where, t is a tuple variable
volume element represents a fixed number of tuples; P is the formula, in mathematical logic predicates also referred to, i.e. in the condition table computer language
expression. {t | P (t)} represents the set of all tuples t satisfies the formula of P.

Tuple expression, by the atomic formula composition formula, there are two forms atomic formula:
(. 1) R (S), where R is the relation name, s is a tuple variable. The implication is that "s is a tuple of the relation R."
(2) s [i] θu [j], where s and u is a tuple variable, θ is the arithmetic comparison operator, s [i] and u [j] are respectively the i th component of s, and u j a component. Atomic formula s [i] θu [j] represents "operation between satisfies θ i th component of s-tuples in tuple u j-th component." For example, "t [2] <u [3]" means the second component is less than t-tuple of tuples u, the third component. A simplified form of this equation atoms is s [i] θa or aθu [j], where a is a constant. For example, "t [4] = 3 " represents the fourth component equal to t 3.

In a formula, if the variable is not the tuple with the existential quantifier "" or universal quantifier "" and other symbols are as defined, then referred to as a tuple consisting of a variable, otherwise known as a variable constraint tuples. Recursively defined using the following formula.

(1) Each atom is a formula in which variable tuple is a free variable.
(2) If P1 and P2 are formulas, then, P1, P1∨P2, P1∧P2 → P1 and P2 are formulas.
(3) If P1 is the formula, then (S) (P1) and (S) (P1) are also formulas.
(4) Equation various operators descending order of priority θ, and,, ∧ and ∨, →. Formula can also be the outer brackets, to change the priority order.
(5) composed of the above formula can only four forms, in addition to not constituting the formula.

In Formula tuple calculus, there are the following four equivalent conversion rule:
(. 1) is equivalent to P1∧P2 (P1∨ P2).
(2) P1∨P2 equivalent (P1∧ P2).
(3) (s) (P1 (s)) equivalent (s) (P1 (s) ); (s) (P1 (s)) equivalent (s) (P1 (s) ).
(4) P1 → P2 is equivalent to P1∨P2.
Relational algebra expression can be converted tuple expression, e.g., R∪S available {t | R (t) ∨S (t)} represents, RS is available {t | R (t) ∧S (t)} represents

Read the above so many words, fully understand what Ganso calculus stuff, ha ha ha.

Test Exercises

Questions 1
If the relationship R (A, B, C, D) for π1.3 (R) operation, the relationship between arithmetic and __B__ equivalent, expressed __B__.
A. πA = 1, C = 3 ( R) B. πA = 1∧C = 3 (R) C. πA, C (R) D. πA = 1∨C = 3 (R)

A. Property values A and C are equal to 1 and 3 is the result tuple set
B. Property values A and C are equal to 1 and sets the result as two 3
C. A = R relationship of projection operator 1, C = 3 is
D. R is projected on the relationship calculation attribute A and C

Questions 2
If the relationship R, S shown in Figure 5-3, the number of columns and the number of attributes of the tuples R and S are natural join __B__;
π1,4 (sigma3. 6 = (R × S)) B .
FIG relation R 5-3 and S
(. 3) A. 4 and 3 B. 4 and 6 C. 6 and 3 D. 6 and 6
(. 4) A. πA, D (σC = D ( R × S)) B. πA, the RD (σS.C the RD = (R & lt × S))
C. πA, RD (σR.C = SD ( R × S)) D. πR.A, RD (σS.C = SD ( R × S))
Here Insert Picture Description

Published 47 original articles · won praise 3 · Views 5420

Guess you like

Origin blog.csdn.net/weixin_43221207/article/details/102484054