SlideShare a Scribd company logo
1 of 29
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

What's hot (20)

STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Relational model
Relational modelRelational model
Relational model
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Join
JoinJoin
Join
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
 
Normal forms
Normal formsNormal forms
Normal forms
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
Normalization PRESENTATION
Normalization PRESENTATIONNormalization PRESENTATION
Normalization PRESENTATION
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
Sql operator
Sql operatorSql operator
Sql operator
 

Similar to Relational algebra

Project Management System
Project Management SystemProject Management System
Project Management SystemDivyen Patel
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
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 AnalysisFerdin Joe John Joseph PhD
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operationNikhil Pandit
 
Fp304 DATABASE SYSTEM JUNE 2012
Fp304   DATABASE SYSTEM JUNE 2012Fp304   DATABASE SYSTEM JUNE 2012
Fp304 DATABASE SYSTEM JUNE 2012Syahriha 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
 
It110 assignment-1 answer key
It110 assignment-1 answer keyIt110 assignment-1 answer key
It110 assignment-1 answer keyJVM_
 
Recommending job ads to people
Recommending job ads to peopleRecommending job ads to people
Recommending job ads to peopleFabian Abel
 

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
 
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
 
Recommending job ads to people
Recommending job ads to peopleRecommending job ads to people
Recommending job ads to people
 

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

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

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