SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
Additional Relational-Algebra Operations
The fundamental operations of the relational algebra are sufficient to express any relational-algebra query.
However, if we restrict ourselves to just the fundamental operations, certain common queries are lengthy
to express. Therefore, we define additional operations that do not add any power to the algebra, but simplify
common queries.
 set-intersection (binary)
 natural join (binary)
 division (binary)
 assignment (unary)
Figure 1. The loan relation. Figure: The depositor relation.
Figure 2. The borrower relation.
The Set-Intersection Operation
The first additional-relational algebra operation that we shall define is set intersection (∩). Suppose that
we wish to find all customers who have both a loan and an account. Using set intersection, we can write
Figure 3. Customers with both an account and a loan at the bank.
The Natural-Join Operation
 It is often desirable to simplify certain queries that require Cartesian product operation. Natural join
operation helps in this regard.
 The natural join is a binary operation that allows us to combine certain selection and a Cartesian product
into one operation. It is denoted by the “join” symbol |X|.
 The natural join operation forms:
 A Cartesian product of two arguments
 Performs a selection forcing equality on those attributes that appear in both relation schemas and
finally
 Removes duplicate attributes
As an illustration, consider again the example “Find the names of all customers who have a loan at the
bank, and find the amount of the loan.” We express this query by using the natural join as follows:
Division Operator (÷)
Division operator A÷B can be applied if and only if:
 Attributes of B is proper subset of Attributes of A.
 The relation returned by division operator will have attributes = (All attributes of A – All Attributes of
B)
 The relation returned by division operator will return those tuples from relation A which are associated
to every B’s tuple.
Table 1
STUDENT_SPORTS
ROLL_NO SPORTS
1 Badminton
2 Cricket
2 Badminton
4 Badminton
Table 2
ALL_SPORTS
SPORTS
Badminton
Cricket
Consider the relation STUDENT_SPORTS and ALL_SPORTS given in Table 2 and Table 3 above.
To apply division operator as
STUDENT_SPORTS÷ ALL_SPORTS
 The operation is valid as attributes in ALL_SPORTS is a proper subset of attributes in
STUDENT_SPORTS.
 The attributes in resulting relation will have attributes {ROLL_NO,SPORTS}-{SPORTS}=ROLL_NO
 The tuples in resulting relation will have those ROLL_NO which are associated with all B’s tuple
{Badminton, Cricket}. ROLL_NO 1 and 4 are associated to Badminton only. ROLL_NO 2 is
associated to all tuples of B. So the resulting relation will be:
ROLL_NO
2
The Assignment Operation
It is convenient at times to write a relational-algebra expression by assigning parts of it to temporary relation
variables. The assignment operation, denoted by ←, works like assignment in a programming language.
Extended Relational-Algebra Operations
Generalized Projection
The generalized-projection operation extends the projection operation by allowing arithmetic functions to
be used in the projection list. The generalized projection operation has the form
ΠF1,F2,...,Fn (E)
where E is any relational-algebra expression, and each of F1, F2, . . . , Fn is an arithmetic expression
involving constants and attributes in the schema of E.
Aggregate Functions
Aggregate functions take a collection of values and return a single value as a result.
For example, the aggregate function sum takes a collection of values and returns the sum of the values.
The aggregate function avg returns the average of the values. The aggregate function count returns the
number of the elements in the collection Other common aggregate functions include min and max, which
return the minimum and maximum values in a collection
Suppose that we want to find out the total sum of salaries of all the part-time employees in the bank. The
relational-algebra expression for this query is:
There are cases where we must eliminate multiple occurrences of a value before computing an aggregate
function. If we do want to eliminate duplicates, we use the same function names as before, with the addition
of the hyphenated string “distinct” appended to the end of the function name (for example, count-distinct).
An example arises in the query “Find the number of branches appearing in the pt-works relation.” We write
this query as follows:
Suppose we want to find the total salary sum of all part-time employees at each branch of the bank
separately, rather than the sum for the entire bank.
The following expression using the aggregation operator achieves the desired result:
if we want to find the maximum salary for part-time employees at each branch, in addition to the sum of the
salaries, we write the expression
We can apply a rename operation to the result in order to give it a name. As a notational convenience,
attributes of an aggregation operation can be renamed as illustrated below:
Outer Join
Join operation is essentially a cartesian product followed by a selection criterion.
The outer-join operation is an extension of the join operation to deal with missing information.
There are actually three forms of the operation: left outer join, denoted ; right outer join, denoted
; and full outer join, denoted .
Left Outer Join(A B)
In the left outer join, operation allows keeping all tuple in the left relation. However, if there is no matching
tuple is found in right relation, then the attributes of right relation in the join result are filled with null values.
Consider the following 2 Tables
A
Num Square
2 4
3 9
4 16
A B
Num Square Cube
2 4 8
3 9 18
4 16 null
Right Outer Join: ( A B )
In the right outer join, operation allows keeping all tuple in the right relation. However, if there is no matching
tuple is found in the left relation, then the attributes of the left relation in the join result are filled with null
values.
B
Num Cube
2 8
3 18
5 75
A B
Num Cube Square
2 8 4
3 18 9
5 75 null
Full Outer Join: ( A B)
In a full outer join, all tuples from both relations are included in the result, irrespective of the matching
condition.
A B
Num Square Cube
2 4 8
3 9 18
4 16 null
5 null 75
A. S. M. Shafi
Lecturer
Department of Computer Science and Engineering
Khwaja Yunus Ali University
Enaytpur, Sirajgonj-6751, Bangladesh

Contenu connexe

Tendances

10. XML in DBMS
10. XML in DBMS10. XML in DBMS
10. XML in DBMS
koolkampus
 

Tendances (20)

I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
joins in database
 joins in database joins in database
joins in database
 
Uml class-diagram
Uml class-diagramUml class-diagram
Uml class-diagram
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Three Address code
Three Address code Three Address code
Three Address code
 
Extended relational algebra
Extended relational algebraExtended relational algebra
Extended relational algebra
 
Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
Relational model
Relational modelRelational model
Relational model
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
Array data structure
Array data structureArray data structure
Array data structure
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
10. XML in DBMS
10. XML in DBMS10. XML in DBMS
10. XML in DBMS
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Conceptual dependency
Conceptual dependencyConceptual dependency
Conceptual dependency
 
Elmasri Navathe DBMS Unit-1 ppt
Elmasri Navathe DBMS Unit-1 pptElmasri Navathe DBMS Unit-1 ppt
Elmasri Navathe DBMS Unit-1 ppt
 
Array in c++
Array in c++Array in c++
Array in c++
 

Similaire à Additional Relational Algebra Operations

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
jahanullah
 

Similaire à Additional Relational Algebra Operations (20)

Operators
OperatorsOperators
Operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
Operators In Java Part - 8
Operators In Java Part - 8Operators In Java Part - 8
Operators In Java Part - 8
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...
 
Programming C Part 02
Programming C Part 02Programming C Part 02
Programming C Part 02
 
5th chapter Relational algebra.pptx
5th chapter Relational algebra.pptx5th chapter Relational algebra.pptx
5th chapter Relational algebra.pptx
 
Python operators part2
Python operators part2Python operators part2
Python operators part2
 
ch14.ppt
ch14.pptch14.ppt
ch14.ppt
 
C Operators
C OperatorsC Operators
C Operators
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 

Plus de A. S. M. Shafi

Plus de A. S. M. Shafi (20)

2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
Projection
ProjectionProjection
Projection
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
 
Fragmentation
FragmentationFragmentation
Fragmentation
 
File organization
File organizationFile organization
File organization
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
1D Array
1D Array1D Array
1D Array
 
2D array
2D array2D array
2D array
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Queue
QueueQueue
Queue
 
Searching
SearchingSearching
Searching
 
Sorting
SortingSorting
Sorting
 
Linked list
Linked listLinked list
Linked list
 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problem
 
Quick sort
Quick sortQuick sort
Quick sort
 

Dernier

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Dernier (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 

Additional Relational Algebra Operations

  • 1. Additional Relational-Algebra Operations The fundamental operations of the relational algebra are sufficient to express any relational-algebra query. However, if we restrict ourselves to just the fundamental operations, certain common queries are lengthy to express. Therefore, we define additional operations that do not add any power to the algebra, but simplify common queries.  set-intersection (binary)  natural join (binary)  division (binary)  assignment (unary) Figure 1. The loan relation. Figure: The depositor relation. Figure 2. The borrower relation. The Set-Intersection Operation The first additional-relational algebra operation that we shall define is set intersection (∩). Suppose that we wish to find all customers who have both a loan and an account. Using set intersection, we can write Figure 3. Customers with both an account and a loan at the bank.
  • 2. The Natural-Join Operation  It is often desirable to simplify certain queries that require Cartesian product operation. Natural join operation helps in this regard.  The natural join is a binary operation that allows us to combine certain selection and a Cartesian product into one operation. It is denoted by the “join” symbol |X|.  The natural join operation forms:  A Cartesian product of two arguments  Performs a selection forcing equality on those attributes that appear in both relation schemas and finally  Removes duplicate attributes As an illustration, consider again the example “Find the names of all customers who have a loan at the bank, and find the amount of the loan.” We express this query by using the natural join as follows: Division Operator (÷) Division operator A÷B can be applied if and only if:  Attributes of B is proper subset of Attributes of A.  The relation returned by division operator will have attributes = (All attributes of A – All Attributes of B)  The relation returned by division operator will return those tuples from relation A which are associated to every B’s tuple. Table 1 STUDENT_SPORTS ROLL_NO SPORTS 1 Badminton 2 Cricket 2 Badminton 4 Badminton
  • 3. Table 2 ALL_SPORTS SPORTS Badminton Cricket Consider the relation STUDENT_SPORTS and ALL_SPORTS given in Table 2 and Table 3 above. To apply division operator as STUDENT_SPORTS÷ ALL_SPORTS  The operation is valid as attributes in ALL_SPORTS is a proper subset of attributes in STUDENT_SPORTS.  The attributes in resulting relation will have attributes {ROLL_NO,SPORTS}-{SPORTS}=ROLL_NO  The tuples in resulting relation will have those ROLL_NO which are associated with all B’s tuple {Badminton, Cricket}. ROLL_NO 1 and 4 are associated to Badminton only. ROLL_NO 2 is associated to all tuples of B. So the resulting relation will be: ROLL_NO 2 The Assignment Operation It is convenient at times to write a relational-algebra expression by assigning parts of it to temporary relation variables. The assignment operation, denoted by ←, works like assignment in a programming language. Extended Relational-Algebra Operations Generalized Projection The generalized-projection operation extends the projection operation by allowing arithmetic functions to be used in the projection list. The generalized projection operation has the form ΠF1,F2,...,Fn (E) where E is any relational-algebra expression, and each of F1, F2, . . . , Fn is an arithmetic expression involving constants and attributes in the schema of E. Aggregate Functions Aggregate functions take a collection of values and return a single value as a result. For example, the aggregate function sum takes a collection of values and returns the sum of the values. The aggregate function avg returns the average of the values. The aggregate function count returns the number of the elements in the collection Other common aggregate functions include min and max, which return the minimum and maximum values in a collection
  • 4. Suppose that we want to find out the total sum of salaries of all the part-time employees in the bank. The relational-algebra expression for this query is: There are cases where we must eliminate multiple occurrences of a value before computing an aggregate function. If we do want to eliminate duplicates, we use the same function names as before, with the addition of the hyphenated string “distinct” appended to the end of the function name (for example, count-distinct). An example arises in the query “Find the number of branches appearing in the pt-works relation.” We write this query as follows: Suppose we want to find the total salary sum of all part-time employees at each branch of the bank separately, rather than the sum for the entire bank. The following expression using the aggregation operator achieves the desired result: if we want to find the maximum salary for part-time employees at each branch, in addition to the sum of the salaries, we write the expression We can apply a rename operation to the result in order to give it a name. As a notational convenience, attributes of an aggregation operation can be renamed as illustrated below: Outer Join Join operation is essentially a cartesian product followed by a selection criterion. The outer-join operation is an extension of the join operation to deal with missing information. There are actually three forms of the operation: left outer join, denoted ; right outer join, denoted ; and full outer join, denoted .
  • 5. Left Outer Join(A B) In the left outer join, operation allows keeping all tuple in the left relation. However, if there is no matching tuple is found in right relation, then the attributes of right relation in the join result are filled with null values. Consider the following 2 Tables A Num Square 2 4 3 9 4 16 A B Num Square Cube 2 4 8 3 9 18 4 16 null Right Outer Join: ( A B ) In the right outer join, operation allows keeping all tuple in the right relation. However, if there is no matching tuple is found in the left relation, then the attributes of the left relation in the join result are filled with null values. B Num Cube 2 8 3 18 5 75
  • 6. A B Num Cube Square 2 8 4 3 18 9 5 75 null Full Outer Join: ( A B) In a full outer join, all tuples from both relations are included in the result, irrespective of the matching condition. A B Num Square Cube 2 4 8 3 9 18 4 16 null 5 null 75 A. S. M. Shafi Lecturer Department of Computer Science and Engineering Khwaja Yunus Ali University Enaytpur, Sirajgonj-6751, Bangladesh