But beware attributeAof the same name inrands: user.Aands.Aarity(r×s)= arity(r) + arity(s)43 / 98

Cartesian-Product Operation - ExampleRelationsr,sr×s44 / 98

Composition of OperationsCan build expressions using multiple operationsExample:σA=C(r×s)r×sσA=C(r×s)45 / 98

Cartesian-Product Operation - ExampleThe Cartesian product of the relationsinstructorandteachesiswritten as:instructor×teachesWe construct a tuple of the result out of each possible pair of tuples: onefrom theinstructorrelation and one from theteachesrelation (seenext slide)Since theinstructor IDappears in both relations, we distinguish betweenthese attributes by attaching to the attribute the name of the relationfrom which the attribute originally came.instructor.IDteaches.ID46 / 98

Cartesian-Product Operation - ExampleRelation:instructorRelation:teaches47 / 98

instructor×teaches48 / 98

NoteTheCartesian-Productinstructor×teachesassociates every tuple ofinstructorwith every tuple ofteaches.Most of the resulting rows have information about instructors who didNOT teach a particular courseTo get only those tuples of “instructor×teaches” that pertain toinstructors and the courses that they taught, we write:σinstructor.id = teaches.id(instructor×teaches)We get only those tuples of “instructor×teaches” that pertain toinstructors and the courses that they taught.The result of this expression, shown in the next slide49 / 98

Note (Cont.)The table corresponding to:σinstructor.id = teaches.id(instructor×teaches)50 / 98

Rename OperationThe results of relational-algebra expressions do not have a name that wecan use to refer to them.Therenameoperator,ρ, is provided for that purposeAllow us to name and therefore to refer to the result of relational algebraexpressionAllow us to refer to a relation by more than one name (e.g., if the samerelation is used twice in a relational algebra expression)The expression:ρx(E)returns the result of expressionEunder the namex(change the name ofrelation)Another form of the rename operation:Assume a relational algebra expressionE(which is a relation) hasarityn, thenρx(A1,A2,...,An)(E)returns the result of expressionEunder the namex, and with the attributenamesA1,A2,...,An(rename both the relation and the columns)51 / 98

Example QueryRelation:instructorFind the highest salary in the universityStep 1:find instructor salaries that are less than some other instructor salary (i.e.not maximum) by computing first a temporary relation consisting of thosesalaries that are not the largesusing a copy ofinstructorunder a new namedπinstructor.salaryσinstructor.salary<d.salary(instructor×ρd(instructor))Step 2:Find the largest salaryπsalary(instructor)-πinstructor.salaryσinstructor.salary<d.salary(instructor×ρd(instructor))52 / 98

Additional OperationsWe define additional operations that do not add any expressive power tothe relational algebra, but that simplify common queries.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 98 pages?

Upload your study docs or become a

Course Hero member to access this document