Soft Test-Architect-Chapter III-Database system fourth section relational algebra (reading notes) __ Reading notes

Source: Internet
Author: User
Copyright Notice

The architecture Architect's tutorial, "The 4th edition" of the architect's exam, is the author of the "School of soft test for Greek games". Complete the relevant reading notes for later self-examination, only for personal learning and use, not for any commercial purposes.

Copyright Notice Fourth section relationship algebra and differential Cartesian product projection theta Connection apart

fourth section relational algebra

The basic operations of relational algebra include the sum, intersection, difference, Cartesian product, selection, projection, connection and division operations. and

Calculates the set of two relations in the set theory, which gives the relationship R and S (the two have the same number/column), and the R∪s tuple includes the set of R and s all tuples, in the form defined as follows:
R∪s={t| Rμt∉s} r∪s = {T | Rμt∉s} R \cup S = \{t| R \mu t \notin s\}

T in the formula is a tuple variable (the same below). Apparently, R∪s=s∪r. Poor

A set that computes the difference between two relationships, that is, the relationship R and S (the two have the same number of bytes/columns), and the R-s tuple includes a set of tuples in R that are not in S, in the form defined below:

R−s={t|t∈r∧t∉s} r−s = {T | t∈r∧t∉s} r-s = \{t | t \in R \wedge t \notin s\}
Obviously, R∩s = R (r-s) and r∩s = S (s-r) are established.

Cartesian product

To compute the Cartesian product of two relationships, so that R is a relationship with an M, and S is a relationship with n-ary, then RxS is a set of tuples of M+n, whose first m elements come from a tuple of R, and then n elements from a tuple of S. The form is defined as follows:

Rxs={t|t=<tr,ts>∧tr∈r∧ts∈s} RxS = {T | t =< t R, t S >∧t r∈r∧t s∈s} R \times S = \{T | t = \WEDG E t_r \in R \wedge t_s \in s\}
If R has a U-tuple and S has a V-tuple, then RxS has UXV tuples. For example, there is a relationship between R and S as shown in table 3-1 and table 3-2.

The result of the Cartesian product operation between R and S is 4+2=6 column, and the number of tuples is 3*2=6. As shown in table 3-3.

projection

Extracts the specified property (column) from a relationship. So that R is a relationship that contains property A, the
PA (R) ={t[a]|t∈r} P A (r) = {T [A] | t∈r} p_a (r) =\{t[a]|t\in R\}
For example, if you do a projection operation on table 3-1 relationship R, p1,2 (R), the result is shown in table 3-4.

Note: the numbers involved in relational algebra operations represent the column numbers, and the p1,2 (R) operation is a projection of columns 1th and 2nd.

Where F represents a selection condition, is a logical expression (logical operator + arithmetic expression). A select operation is an operation from the perspective of a tuple (row). Theta Connection

Theta joins a tuple that satisfies a certain condition from the selection of attributes in the Cartesian product of two relationships:

Where A and B are respectively equal and comparable in the number of tuples on R and S. The connection of θ to "=", called an equivalent connection, is recorded as:

If the component to be compared in two relationships must be of the same attribute group, and if the duplicate attribute is removed in the result, it is called a natural connection and is written as:

For example, for table 3-1 relationship R and table 3-2 relationship S do natural join operations. The result set is shown in table 3-6.

except

With relation R (x,y) and relation S (z), Y and z have the same number of attributes, and the corresponding attributes are derived from the same domain. The quotient relationship R (x,y) ÷s (z) is a subset of relation R that is projected on the attribute X, and the Cartesian product of the subset and S (z) must be included in R (X,y), which is recorded as R÷s, and its calculated formula is:

For example, the relationship between table 3-1 R and table 3-2 of the relationship S do division operations.

The solution process is: First, the X,y,z attribute collection is determined by defining the requirements in addition to the operation. Y is the set of attributes in relationship R, Z is the set of all attributes in S, that is, z={u3,u4}, because of y=z, so Y={u3,u4}, X={U1,U2}. That is, the r÷s result set contains the attributes U1 and U2, and then the U1, U2 (Total <a,b>, <c,a> two tuples) of the relationship R and the relationship S as Cartesian product operations, as shown in table 3-7.

By checking table 3-7, the Cartesian product of the tuple <a,b> and S (z) can be found to be contained in R (X,y), whereas the Cartesian product of the tuple <c,a> and S (z) has a tuple that is not contained in R (X,y), so only tuples are in the result set <a,b >.

Learning slag. This did not understand, read down first, and so the first time after sweeping the book again. Headache...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.