SlideShare a Scribd company logo
Department of Information Technology 1Data base Technologies (ITB4201)
Introduction to Relational Algebra
Dr. C.V. Suresh Babu
Professor
Department of IT
Hindustan Institute of Science & Technology
Department of Information Technology 2Data base Technologies (ITB4201)
Discussion Topics
• DBMS Architecture
• Relational Algebra
• Union and Differences
• Selectin
• Projection
• Cartesian Product
• Renaming
• Join
• Limitations of Relational Algebra
• Quiz
Department of Information Technology 3Data base Technologies (ITB4201)
DBMS Architecture
How does a SQL engine work ?
• SQL query  relational
algebra plan
• Relational algebra plan 
Optimized plan
• Execute each operator of the
plan
Query Optimization
and Execution
Relational Operators
Files and Access Methods
Buffer Management
Disk Space Management
DB
PracticeTheory
Relational Algebra
Relational Model
Relational Calculus
Department of Information Technology 4Data base Technologies (ITB4201)
Review – Why do we need Query Languages anyway?
• Two key advantages
– Less work for user asking query
– More opportunities for optimization
• Relational Algebra
– Theoretical foundation for SQL
– Higher level than programming language
• but still must specify steps to get desired result
• Relational Calculus
– Formal foundation for Query-by-Example
– A first-order logic description of desired result
– Only specify desired result, not how to get it
Department of Information Technology 5Data base Technologies (ITB4201)
Relational Algebra
• Formalism for creating new relations from existing ones
• Its place in the big picture:
Declartive
query
language
Algebra Implementation
SQL,
relational calculus
Relational algebra
Relational bag algebra
Department of Information Technology 6Data base Technologies (ITB4201)
Relational Algebra
• Five operators:
– Union: 
– Difference: -
– Selection: s
– Projection: P
– Cartesian Product: 
• Derived or auxiliary operators:
– Intersection, complement
– Joins (natural,equi-join, theta join, semi-join)
– Renaming: r
Department of Information Technology 7Data base Technologies (ITB4201)
1. Union and 2. Difference
• R1  R2
• Example:
– ActiveEmployees  RetiredEmployees
• R1 – R2
• Example:
– AllEmployees -- RetiredEmployees
Department of Information Technology 8Data base Technologies (ITB4201)
What about Intersection ?
• It is a derived operator
• R1  R2 = R1 – (R1 – R2)
• Also expressed as a join
• Example
– UnionizedEmployees  RetiredEmployees
Department of Information Technology 9Data base Technologies (ITB4201)
3. Selection
• Returns all tuples which satisfy a condition
• Notation: sc(R)
• Examples
– sSalary > 40000 (Employee)
– sname = “Smith” (Employee)
• The condition c can be =, <, , >, , <>
Department of Information Technology 10Data base Technologies (ITB4201)
sSalary > 40000 (Employee)
SSN Name Salary
1234545 John 200000
5423341 Smith 600000
4352342 Fred 500000
SSN Name Salary
5423341 Smith 600000
4352342 Fred 500000
Department of Information Technology 11Data base Technologies (ITB4201)
4. Projection
• Eliminates columns, then removes duplicates
• Notation: P A1,…,An (R)
• Example: project social-security number and names:
– P SSN, Name (Employee)
– Output schema: Answer(SSN, Name)
Department of Information Technology 12Data base Technologies (ITB4201)
P Name,Salary (Employee)
SSN Name Salary
1234545 John 200000
5423341 John 600000
4352342 John 200000
Name Salary
John 20000
John 60000
Department of Information Technology 13Data base Technologies (ITB4201)
5. Cartesian Product
• Each tuple in R1 with each tuple in R2
• Notation: R1  R2
• Example:
– Employee  Dependents
• Very rare in practice; mainly used to express joins
Department of Information Technology 14Data base Technologies (ITB4201)
Cartesian Product Example
Employee
Name SSN
John 999999999
Tony 777777777
Dependents
EmployeeSSN Dname
999999999 Emily
777777777 Joe
Employee x Dependents
Name SSN EmployeeSSN Dname
John 999999999 999999999 Emily
John 999999999 777777777 Joe
Tony 777777777 999999999 Emily
Tony 777777777 777777777 Joe
Department of Information Technology 15Data base Technologies (ITB4201)
Renaming
• Changes the schema, not the instance
• Notation: r B1,…,Bn (R)
• Example:
– rLastName, SocSocNo (Employee)
– Output schema:
Answer(LastName, SocSocNo)
Department of Information Technology 16Data base Technologies (ITB4201)
Renaming Example
Employee
Name SSN
John 999999999
Tony 777777777
LastName SocSocNo
John 999999999
Tony 777777777
rLastName, SocSocNo (Employee)
Department of Information Technology 17Data base Technologies (ITB4201)
Natural Join
• Notation: R1 || R2
• Meaning: R1 || R2 = PA(sC(R1  R2))
• Where:
– The selection sC checks equality of all common attributes
– The projection eliminates the duplicate common attributes
Department of Information Technology 18Data base Technologies (ITB4201)
Natural Join Example
Employee
Name SSN
John 999999999
Tony 777777777
Dependents
SSN Dname
999999999 Emily
777777777 Joe
Name SSN Dname
John 999999999 Emily
Tony 777777777 Joe
Employee Dependents =
PName, SSN, Dname(s SSN=SSN2(Employee x rSSN2, Dname(Dependents))
Department of Information Technology 19Data base Technologies (ITB4201)
Natural Join
• R= S=
• R || S=
A B
X Y
X Z
Y Z
Z V
B C
Z U
V W
Z V
A B C
X Z U
X Z V
Y Z U
Y Z V
Z V W
Department of Information Technology 20Data base Technologies (ITB4201)
Natural Join
• Given the schemas R(A, B, C, D), S(A, C, E), what is the
schema of R || S ?
• Given R(A, B, C), S(D, E), what is R || S ?
• Given R(A, B), S(A, B), what is R || S ?
Department of Information Technology 21Data base Technologies (ITB4201)
Theta Join
• A join that involves a predicate
• R1 || q R2 = s q (R1  R2)
• Here q can be any condition
Department of Information Technology 22Data base Technologies (ITB4201)
Eq-join
• A theta join where q is an equality
• R1 || A=B R2 = s A=B (R1  R2)
• Example:
– Employee || SSN=SSN Dependents
• Most useful join in practice
Department of Information Technology 23Data base Technologies (ITB4201)
Semijoin
• R | S = P A1,…,An (R || S)
• Where A1, …, An are the attributes in R
• Example:
– Employee | Dependents
Department of Information Technology 24Data base Technologies (ITB4201)
Semijoins in Distributed Databases
• Semijoins are used in distributed databases
SSN Name
. . . . . .
SSN Dname Age
. . . . . .
Employee
Dependents
network
Employee | ssn=ssn (s age>71 (Dependents))
T = P SSN s age>71 (Dependents)
R = Employee |T
Answer = R ||Dependents
Department of Information Technology 25Data base Technologies (ITB4201)
Complex RA Expressions
Person Purchase Person Product
sname=fred sname=gizmo
P pidP ssn
seller-ssn=ssn
pid=pid
buyer-ssn=ssn
P name
Department of Information Technology 26Data base Technologies (ITB4201)
Operations on Bags
A bag = a set with repeated elements
All operations need to be defined carefully on bags
• {a,b,b,c}{a,b,b,b,e,f,f}={a,a,b,b,b,b,b,c,e,f,f}
• {a,b,b,b,c,c} – {b,c,c,c,d} = {a,b,b,d}
• sC(R): preserve the number of occurrences
• PA(R): no duplicate elimination
• Cartesian product, join: no duplicate elimination
Important ! Relational Engines work on bags, not sets !
Reading assignment: 5.3 – 5.4
Department of Information Technology 27Data base Technologies (ITB4201)
Finally: RA has Limitations !
• Cannot compute “transitive closure”
• Find all direct and indirect relatives of Fred
• Cannot express in RA !!! Need to write program
Name1 Name2 Relationship
Fred Mary Father
Mary Joe Cousin
Mary Bill Spouse
Nancy Lou Sister
Department of Information Technology 28Data base Technologies (ITB4201)
Test Yourself
1. Which of the following is not a valid binary operation in the Relational Algebra?
a) Project
b) Union
c) Set difference
d) Cartesian product
2. The operation of a relation x, produces y, such that y contains only selected attributes of x. Such a operation is:?
a) Projection
b) Intersection
c) Union
d) Difference
3. Which of the following is not a valid unary operation in the relational algebra?
a) select
b) min
c) project
d) rename
4. Which clause from the following corresponds to the project operation of the relational algebra?
a) from
b) select
c) where
d) none of these
5. The intersect operation:
a) automatically eliminates duplicates
b) automatically eliminates duplicates. If we provide all clause with intersect
c) never eliminates duplicates
d) none of these
Department of Information Technology 29Data base Technologies (ITB4201)
Answers
1. Which of the following is not a valid binary operation in the Relational Algebra?
a) Project
b) Union
c) Set difference
d) Cartesian product
2. The operation of a relation x, produces y, such that y contains only selected attributes of x. Such a operation is:?
a) Projection
b) Intersection
c) Union
d) Difference
3. Which of the following is not a valid unary operation in the relational algebra?
a) select
b) min
c) project
d) rename
4. Which clause from the following corresponds to the project operation of the relational algebra?
a) from
b) select
c) where
d) none of these
5. The intersect operation:
a) automatically eliminates duplicates
b) automatically eliminates duplicates. If we provide all clause with intersect
c) never eliminates duplicates
d) none of these

More Related Content

What's hot

SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
database Normalization
database Normalizationdatabase Normalization
database Normalization
Harsiddhi Thakkar
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
Decomposition methods in DBMS
Decomposition methods in DBMSDecomposition methods in DBMS
Decomposition methods in DBMS
soniyagoyal3
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
Smriti Jain
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
koolkampus
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
Vishal Anand
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
Chirag vasava
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
Oum Saokosal
 
Normal forms
Normal formsNormal forms
Normal forms
Samuel Igbanogu
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Relational model
Relational modelRelational model
Relational model
Dabbal Singh Mahara
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
Dashani Rajapaksha
 
Functional dependencies in Database Management System
Functional dependencies in Database Management SystemFunctional dependencies in Database Management System
Functional dependencies in Database Management System
Kevin Jadiya
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalization
daxesh chauhan
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Vigneshwaran Sankaran
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
 
SQL Views
SQL ViewsSQL Views
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
koolkampus
 

What's hot (20)

SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
database Normalization
database Normalizationdatabase Normalization
database Normalization
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 
Decomposition methods in DBMS
Decomposition methods in DBMSDecomposition methods in DBMS
Decomposition methods in DBMS
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
Normal forms
Normal formsNormal forms
Normal forms
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Relational model
Relational modelRelational model
Relational model
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
Functional dependencies in Database Management System
Functional dependencies in Database Management SystemFunctional dependencies in Database Management System
Functional dependencies in Database Management System
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalization
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
 

Similar to Relational algebra

Relational Calculus
Relational CalculusRelational Calculus
Relational Calculus
Dr. C.V. Suresh Babu
 
Relational database design
Relational database designRelational database design
Relational database design
Dr. C.V. Suresh Babu
 
SQL
SQL SQL
Cocomo
CocomoCocomo
Cocomo
Yunis Lone
 
Cocomo models
Cocomo modelsCocomo models
Cocomo models
minhasmushtaqbhatti
 
Normalization
NormalizationNormalization
Normalization
Dr. C.V. Suresh Babu
 
Project Management System
Project Management SystemProject Management System
Project Management System
Divyen Patel
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
Pyingkodi Maran
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
Mary Margarat
 
UNIT 2 relational algebra and Structured Query Language
UNIT 2 relational algebra and Structured Query LanguageUNIT 2 relational algebra and Structured Query Language
UNIT 2 relational algebra and Structured Query Language
Bhakti Pawar
 
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm AnalysisData Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Ferdin Joe John Joseph PhD
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
Nikhil Pandit
 
Data models
Data modelsData models
Fp304 DATABASE SYSTEM JUNE 2012
Fp304   DATABASE SYSTEM JUNE 2012Fp304   DATABASE SYSTEM JUNE 2012
Fp304 DATABASE SYSTEM JUNE 2012
Syahriha Ruslan
 
How Do Gain and Discount Functions Affect the Correlation between DCG and Use...
How Do Gain and Discount Functions Affect the Correlation between DCG and Use...How Do Gain and Discount Functions Affect the Correlation between DCG and Use...
How Do Gain and Discount Functions Affect the Correlation between DCG and Use...
Julián Urbano
 
IRJET- Implementation of Radix-16 and Binary 64 Division VLSI Realization...
IRJET-  	  Implementation of Radix-16 and Binary 64 Division VLSI Realization...IRJET-  	  Implementation of Radix-16 and Binary 64 Division VLSI Realization...
IRJET- Implementation of Radix-16 and Binary 64 Division VLSI Realization...
IRJET Journal
 
DDL,DML,1stNF
DDL,DML,1stNFDDL,DML,1stNF
DDL,DML,1stNF
Bala Ganesh
 
IT Skills Analysis
IT Skills AnalysisIT Skills Analysis
IT Skills Analysis
Habet Madoyan
 
It110 assignment-1 answer key
It110 assignment-1 answer keyIt110 assignment-1 answer key
It110 assignment-1 answer key
JVM_
 
sfdfds
sfdfdssfdfds
sfdfds
Bala Ganesh
 

Similar to Relational algebra (20)

Relational Calculus
Relational CalculusRelational Calculus
Relational Calculus
 
Relational database design
Relational database designRelational database design
Relational database design
 
SQL
SQL SQL
SQL
 
Cocomo
CocomoCocomo
Cocomo
 
Cocomo models
Cocomo modelsCocomo models
Cocomo models
 
Normalization
NormalizationNormalization
Normalization
 
Project Management System
Project Management SystemProject Management System
Project Management System
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
UNIT 2 relational algebra and Structured Query Language
UNIT 2 relational algebra and Structured Query LanguageUNIT 2 relational algebra and Structured Query Language
UNIT 2 relational algebra and Structured Query Language
 
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm AnalysisData Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm Analysis
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
 
Data models
Data modelsData models
Data models
 
Fp304 DATABASE SYSTEM JUNE 2012
Fp304   DATABASE SYSTEM JUNE 2012Fp304   DATABASE SYSTEM JUNE 2012
Fp304 DATABASE SYSTEM JUNE 2012
 
How Do Gain and Discount Functions Affect the Correlation between DCG and Use...
How Do Gain and Discount Functions Affect the Correlation between DCG and Use...How Do Gain and Discount Functions Affect the Correlation between DCG and Use...
How Do Gain and Discount Functions Affect the Correlation between DCG and Use...
 
IRJET- Implementation of Radix-16 and Binary 64 Division VLSI Realization...
IRJET-  	  Implementation of Radix-16 and Binary 64 Division VLSI Realization...IRJET-  	  Implementation of Radix-16 and Binary 64 Division VLSI Realization...
IRJET- Implementation of Radix-16 and Binary 64 Division VLSI Realization...
 
DDL,DML,1stNF
DDL,DML,1stNFDDL,DML,1stNF
DDL,DML,1stNF
 
IT Skills Analysis
IT Skills AnalysisIT Skills Analysis
IT Skills Analysis
 
It110 assignment-1 answer key
It110 assignment-1 answer keyIt110 assignment-1 answer key
It110 assignment-1 answer key
 
sfdfds
sfdfdssfdfds
sfdfds
 

More from Dr. C.V. Suresh Babu

Data analytics with R
Data analytics with RData analytics with R
Data analytics with R
Dr. C.V. Suresh Babu
 
Association rules
Association rulesAssociation rules
Association rules
Dr. C.V. Suresh Babu
 
Clustering
ClusteringClustering
Classification
ClassificationClassification
Classification
Dr. C.V. Suresh Babu
 
Blue property assumptions.
Blue property assumptions.Blue property assumptions.
Blue property assumptions.
Dr. C.V. Suresh Babu
 
Introduction to regression
Introduction to regressionIntroduction to regression
Introduction to regression
Dr. C.V. Suresh Babu
 
DART
DARTDART
Mycin
MycinMycin
Expert systems
Expert systemsExpert systems
Expert systems
Dr. C.V. Suresh Babu
 
Dempster shafer theory
Dempster shafer theoryDempster shafer theory
Dempster shafer theory
Dr. C.V. Suresh Babu
 
Bayes network
Bayes networkBayes network
Bayes network
Dr. C.V. Suresh Babu
 
Bayes' theorem
Bayes' theoremBayes' theorem
Bayes' theorem
Dr. C.V. Suresh Babu
 
Knowledge based agents
Knowledge based agentsKnowledge based agents
Knowledge based agents
Dr. C.V. Suresh Babu
 
Rule based system
Rule based systemRule based system
Rule based system
Dr. C.V. Suresh Babu
 
Formal Logic in AI
Formal Logic in AIFormal Logic in AI
Formal Logic in AI
Dr. C.V. Suresh Babu
 
Production based system
Production based systemProduction based system
Production based system
Dr. C.V. Suresh Babu
 
Game playing in AI
Game playing in AIGame playing in AI
Game playing in AI
Dr. C.V. Suresh Babu
 
Diagnosis test of diabetics and hypertension by AI
Diagnosis test of diabetics and hypertension by AIDiagnosis test of diabetics and hypertension by AI
Diagnosis test of diabetics and hypertension by AI
Dr. C.V. Suresh Babu
 
A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”
Dr. C.V. Suresh Babu
 
A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”
Dr. C.V. Suresh Babu
 

More from Dr. C.V. Suresh Babu (20)

Data analytics with R
Data analytics with RData analytics with R
Data analytics with R
 
Association rules
Association rulesAssociation rules
Association rules
 
Clustering
ClusteringClustering
Clustering
 
Classification
ClassificationClassification
Classification
 
Blue property assumptions.
Blue property assumptions.Blue property assumptions.
Blue property assumptions.
 
Introduction to regression
Introduction to regressionIntroduction to regression
Introduction to regression
 
DART
DARTDART
DART
 
Mycin
MycinMycin
Mycin
 
Expert systems
Expert systemsExpert systems
Expert systems
 
Dempster shafer theory
Dempster shafer theoryDempster shafer theory
Dempster shafer theory
 
Bayes network
Bayes networkBayes network
Bayes network
 
Bayes' theorem
Bayes' theoremBayes' theorem
Bayes' theorem
 
Knowledge based agents
Knowledge based agentsKnowledge based agents
Knowledge based agents
 
Rule based system
Rule based systemRule based system
Rule based system
 
Formal Logic in AI
Formal Logic in AIFormal Logic in AI
Formal Logic in AI
 
Production based system
Production based systemProduction based system
Production based system
 
Game playing in AI
Game playing in AIGame playing in AI
Game playing in AI
 
Diagnosis test of diabetics and hypertension by AI
Diagnosis test of diabetics and hypertension by AIDiagnosis test of diabetics and hypertension by AI
Diagnosis test of diabetics and hypertension by AI
 
A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”
 
A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”
 

Recently uploaded

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

Relational algebra

  • 1. Department of Information Technology 1Data base Technologies (ITB4201) Introduction to Relational Algebra Dr. C.V. Suresh Babu Professor Department of IT Hindustan Institute of Science & Technology
  • 2. Department of Information Technology 2Data base Technologies (ITB4201) Discussion Topics • DBMS Architecture • Relational Algebra • Union and Differences • Selectin • Projection • Cartesian Product • Renaming • Join • Limitations of Relational Algebra • Quiz
  • 3. Department of Information Technology 3Data base Technologies (ITB4201) DBMS Architecture How does a SQL engine work ? • SQL query  relational algebra plan • Relational algebra plan  Optimized plan • Execute each operator of the plan Query Optimization and Execution Relational Operators Files and Access Methods Buffer Management Disk Space Management DB PracticeTheory Relational Algebra Relational Model Relational Calculus
  • 4. Department of Information Technology 4Data base Technologies (ITB4201) Review – Why do we need Query Languages anyway? • Two key advantages – Less work for user asking query – More opportunities for optimization • Relational Algebra – Theoretical foundation for SQL – Higher level than programming language • but still must specify steps to get desired result • Relational Calculus – Formal foundation for Query-by-Example – A first-order logic description of desired result – Only specify desired result, not how to get it
  • 5. Department of Information Technology 5Data base Technologies (ITB4201) Relational Algebra • Formalism for creating new relations from existing ones • Its place in the big picture: Declartive query language Algebra Implementation SQL, relational calculus Relational algebra Relational bag algebra
  • 6. Department of Information Technology 6Data base Technologies (ITB4201) Relational Algebra • Five operators: – Union:  – Difference: - – Selection: s – Projection: P – Cartesian Product:  • Derived or auxiliary operators: – Intersection, complement – Joins (natural,equi-join, theta join, semi-join) – Renaming: r
  • 7. Department of Information Technology 7Data base Technologies (ITB4201) 1. Union and 2. Difference • R1  R2 • Example: – ActiveEmployees  RetiredEmployees • R1 – R2 • Example: – AllEmployees -- RetiredEmployees
  • 8. Department of Information Technology 8Data base Technologies (ITB4201) What about Intersection ? • It is a derived operator • R1  R2 = R1 – (R1 – R2) • Also expressed as a join • Example – UnionizedEmployees  RetiredEmployees
  • 9. Department of Information Technology 9Data base Technologies (ITB4201) 3. Selection • Returns all tuples which satisfy a condition • Notation: sc(R) • Examples – sSalary > 40000 (Employee) – sname = “Smith” (Employee) • The condition c can be =, <, , >, , <>
  • 10. Department of Information Technology 10Data base Technologies (ITB4201) sSalary > 40000 (Employee) SSN Name Salary 1234545 John 200000 5423341 Smith 600000 4352342 Fred 500000 SSN Name Salary 5423341 Smith 600000 4352342 Fred 500000
  • 11. Department of Information Technology 11Data base Technologies (ITB4201) 4. Projection • Eliminates columns, then removes duplicates • Notation: P A1,…,An (R) • Example: project social-security number and names: – P SSN, Name (Employee) – Output schema: Answer(SSN, Name)
  • 12. Department of Information Technology 12Data base Technologies (ITB4201) P Name,Salary (Employee) SSN Name Salary 1234545 John 200000 5423341 John 600000 4352342 John 200000 Name Salary John 20000 John 60000
  • 13. Department of Information Technology 13Data base Technologies (ITB4201) 5. Cartesian Product • Each tuple in R1 with each tuple in R2 • Notation: R1  R2 • Example: – Employee  Dependents • Very rare in practice; mainly used to express joins
  • 14. Department of Information Technology 14Data base Technologies (ITB4201) Cartesian Product Example Employee Name SSN John 999999999 Tony 777777777 Dependents EmployeeSSN Dname 999999999 Emily 777777777 Joe Employee x Dependents Name SSN EmployeeSSN Dname John 999999999 999999999 Emily John 999999999 777777777 Joe Tony 777777777 999999999 Emily Tony 777777777 777777777 Joe
  • 15. Department of Information Technology 15Data base Technologies (ITB4201) Renaming • Changes the schema, not the instance • Notation: r B1,…,Bn (R) • Example: – rLastName, SocSocNo (Employee) – Output schema: Answer(LastName, SocSocNo)
  • 16. Department of Information Technology 16Data base Technologies (ITB4201) Renaming Example Employee Name SSN John 999999999 Tony 777777777 LastName SocSocNo John 999999999 Tony 777777777 rLastName, SocSocNo (Employee)
  • 17. Department of Information Technology 17Data base Technologies (ITB4201) Natural Join • Notation: R1 || R2 • Meaning: R1 || R2 = PA(sC(R1  R2)) • Where: – The selection sC checks equality of all common attributes – The projection eliminates the duplicate common attributes
  • 18. Department of Information Technology 18Data base Technologies (ITB4201) Natural Join Example Employee Name SSN John 999999999 Tony 777777777 Dependents SSN Dname 999999999 Emily 777777777 Joe Name SSN Dname John 999999999 Emily Tony 777777777 Joe Employee Dependents = PName, SSN, Dname(s SSN=SSN2(Employee x rSSN2, Dname(Dependents))
  • 19. Department of Information Technology 19Data base Technologies (ITB4201) Natural Join • R= S= • R || S= A B X Y X Z Y Z Z V B C Z U V W Z V A B C X Z U X Z V Y Z U Y Z V Z V W
  • 20. Department of Information Technology 20Data base Technologies (ITB4201) Natural Join • Given the schemas R(A, B, C, D), S(A, C, E), what is the schema of R || S ? • Given R(A, B, C), S(D, E), what is R || S ? • Given R(A, B), S(A, B), what is R || S ?
  • 21. Department of Information Technology 21Data base Technologies (ITB4201) Theta Join • A join that involves a predicate • R1 || q R2 = s q (R1  R2) • Here q can be any condition
  • 22. Department of Information Technology 22Data base Technologies (ITB4201) Eq-join • A theta join where q is an equality • R1 || A=B R2 = s A=B (R1  R2) • Example: – Employee || SSN=SSN Dependents • Most useful join in practice
  • 23. Department of Information Technology 23Data base Technologies (ITB4201) Semijoin • R | S = P A1,…,An (R || S) • Where A1, …, An are the attributes in R • Example: – Employee | Dependents
  • 24. Department of Information Technology 24Data base Technologies (ITB4201) Semijoins in Distributed Databases • Semijoins are used in distributed databases SSN Name . . . . . . SSN Dname Age . . . . . . Employee Dependents network Employee | ssn=ssn (s age>71 (Dependents)) T = P SSN s age>71 (Dependents) R = Employee |T Answer = R ||Dependents
  • 25. Department of Information Technology 25Data base Technologies (ITB4201) Complex RA Expressions Person Purchase Person Product sname=fred sname=gizmo P pidP ssn seller-ssn=ssn pid=pid buyer-ssn=ssn P name
  • 26. Department of Information Technology 26Data base Technologies (ITB4201) Operations on Bags A bag = a set with repeated elements All operations need to be defined carefully on bags • {a,b,b,c}{a,b,b,b,e,f,f}={a,a,b,b,b,b,b,c,e,f,f} • {a,b,b,b,c,c} – {b,c,c,c,d} = {a,b,b,d} • sC(R): preserve the number of occurrences • PA(R): no duplicate elimination • Cartesian product, join: no duplicate elimination Important ! Relational Engines work on bags, not sets ! Reading assignment: 5.3 – 5.4
  • 27. Department of Information Technology 27Data base Technologies (ITB4201) Finally: RA has Limitations ! • Cannot compute “transitive closure” • Find all direct and indirect relatives of Fred • Cannot express in RA !!! Need to write program Name1 Name2 Relationship Fred Mary Father Mary Joe Cousin Mary Bill Spouse Nancy Lou Sister
  • 28. Department of Information Technology 28Data base Technologies (ITB4201) Test Yourself 1. Which of the following is not a valid binary operation in the Relational Algebra? a) Project b) Union c) Set difference d) Cartesian product 2. The operation of a relation x, produces y, such that y contains only selected attributes of x. Such a operation is:? a) Projection b) Intersection c) Union d) Difference 3. Which of the following is not a valid unary operation in the relational algebra? a) select b) min c) project d) rename 4. Which clause from the following corresponds to the project operation of the relational algebra? a) from b) select c) where d) none of these 5. The intersect operation: a) automatically eliminates duplicates b) automatically eliminates duplicates. If we provide all clause with intersect c) never eliminates duplicates d) none of these
  • 29. Department of Information Technology 29Data base Technologies (ITB4201) Answers 1. Which of the following is not a valid binary operation in the Relational Algebra? a) Project b) Union c) Set difference d) Cartesian product 2. The operation of a relation x, produces y, such that y contains only selected attributes of x. Such a operation is:? a) Projection b) Intersection c) Union d) Difference 3. Which of the following is not a valid unary operation in the relational algebra? a) select b) min c) project d) rename 4. Which clause from the following corresponds to the project operation of the relational algebra? a) from b) select c) where d) none of these 5. The intersect operation: a) automatically eliminates duplicates b) automatically eliminates duplicates. If we provide all clause with intersect c) never eliminates duplicates d) none of these