SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
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

More Related Content

PPT
15. Transactions in DBMS
PPTX
B and B+ tree
PPT
Data Structures- Part5 recursion
PPTX
8 queens problem using back tracking
PPTX
serializability in dbms
PPTX
Validation based protocol
PPTX
Relational Algebra,Types of join
15. Transactions in DBMS
B and B+ tree
Data Structures- Part5 recursion
8 queens problem using back tracking
serializability in dbms
Validation based protocol
Relational Algebra,Types of join

What's hot (20)

PPT
11. Storage and File Structure in DBMS
PPTX
Basic Computer Organization and Design
PDF
Relational algebra in dbms
PPT
13. Query Processing in DBMS
PPTX
Normal forms
PPTX
Two-way Deterministic Finite Automata
PPT
Abstract data types
PPTX
RECURSIVE DESCENT PARSING
PPTX
Concurrency Control in Distributed Database.
PPTX
Means End Analysis (MEA) in Artificial.pptx
PPT
Computer Organization and Architecture.
PPTX
SQL, Embedded SQL, Dynamic SQL and SQLJ
PPTX
Relational algebra ppt
PPTX
1.10. pumping lemma for regular sets
PPTX
Cost estimation for Query Optimization
PPT
Indexing and Hashing
PPT
Query optimization and processing for advanced database systems
PPT
Codd's rules
PPTX
Graph coloring using backtracking
11. Storage and File Structure in DBMS
Basic Computer Organization and Design
Relational algebra in dbms
13. Query Processing in DBMS
Normal forms
Two-way Deterministic Finite Automata
Abstract data types
RECURSIVE DESCENT PARSING
Concurrency Control in Distributed Database.
Means End Analysis (MEA) in Artificial.pptx
Computer Organization and Architecture.
SQL, Embedded SQL, Dynamic SQL and SQLJ
Relational algebra ppt
1.10. pumping lemma for regular sets
Cost estimation for Query Optimization
Indexing and Hashing
Query optimization and processing for advanced database systems
Codd's rules
Graph coloring using backtracking
Ad

Similar to Additional Relational Algebra Operations (20)

PPTX
Operators
PDF
Java basic operators
PDF
Java basic operators
PDF
C++ Expressions Notes
PPTX
Operators In Java Part - 8
PPTX
Operators in C & C++ Language
PPT
Operator & Expression in c++
PDF
Constructor and destructors
PPTX
Operators and it's type
PDF
The aggregate function - from sequential and parallel folds to parallel aggre...
PDF
Programming C Part 02
PPTX
Python notes for students to develop and learn
PPTX
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
PPTX
5th chapter Relational algebra.pptx
PPTX
Python operators part2
PPT
ch14.ppt
PPTX
C Operators
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
PPT
C Sharp Jn (2)
PPT
C Sharp Jn (2)
Operators
Java basic operators
Java basic operators
C++ Expressions Notes
Operators In Java Part - 8
Operators in C & C++ Language
Operator & Expression in c++
Constructor and destructors
Operators and it's type
The aggregate function - from sequential and parallel folds to parallel aggre...
Programming C Part 02
Python notes for students to develop and learn
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
5th chapter Relational algebra.pptx
Python operators part2
ch14.ppt
C Operators
Lecture 2 C++ | Variable Scope, Operators in c++
C Sharp Jn (2)
C Sharp Jn (2)
Ad

More from A. S. M. Shafi (20)

DOCX
Data Warehouse Schema (Star, Snowflake).docx
PDF
Correlation Analysis in Machine Learning.pdf
PDF
Naive Bayes and Decision Tree Algorithm.pdf
PDF
Frequent Pattern Growth Mining Algorithm.pdf
PDF
Direct Hashing and Pruning Algorithm in Data MIning.pdf
PDF
Association Rule Mining with Apriori Algorithm.pdf
PDF
HITS Algorithm in Data and Web MIning.pdf
PDF
Page Rank Algorithm in Data Mining and Web Application.pdf
PDF
K Nearest Neighbor Classifier in Machine Learning.pdf
PDF
K Means Clustering Algorithm in Machine Learning.pdf
PDF
2D Transformation in Computer Graphics
PDF
3D Transformation in Computer Graphics
PDF
Projection
PDF
2D Transformation
PDF
Line drawing algorithm
PDF
Fragmentation
PDF
File organization
PDF
Bankers algorithm
PDF
RR and priority scheduling
PDF
Fcfs and sjf
Data Warehouse Schema (Star, Snowflake).docx
Correlation Analysis in Machine Learning.pdf
Naive Bayes and Decision Tree Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdf
Association Rule Mining with Apriori Algorithm.pdf
HITS Algorithm in Data and Web MIning.pdf
Page Rank Algorithm in Data Mining and Web Application.pdf
K Nearest Neighbor Classifier in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdf
2D Transformation in Computer Graphics
3D Transformation in Computer Graphics
Projection
2D Transformation
Line drawing algorithm
Fragmentation
File organization
Bankers algorithm
RR and priority scheduling
Fcfs and sjf

Recently uploaded (20)

PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
composite construction of structures.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Construction Project Organization Group 2.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
PPT on Performance Review to get promotions
CH1 Production IntroductoryConcepts.pptx
UNIT 4 Total Quality Management .pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Geodesy 1.pptx...............................................
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mechanical Engineering MATERIALS Selection
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Embodied AI: Ushering in the Next Era of Intelligent Systems
CYBER-CRIMES AND SECURITY A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
composite construction of structures.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Construction Project Organization Group 2.pptx
R24 SURVEYING LAB MANUAL for civil enggi
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT on Performance Review to get promotions

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