SlideShare a Scribd company logo
An Introduction to Relational Algebra 
James McMurray 
PhD Student 
Department of Empirical Inference 
09/12/2014
Outline of talk 
Introduction 
What is Relational Algebra? 
Relational Algebra operators 
Core operators 
Joins 
Set operators 
Rename operator 
Conclusion 
Conclusion
What is Relational Algebra? 
I Algebra for modelling and querying data stored in relational 
databases. 
I A relational database consists of a set of named relations, 
which contain named and typed attributes, and the data 
stored in tuples. 
I A relation is a table. 
I An attribute is a column. 
I A tuple is a row. 
I Relational Algebra queries are compositional, so any query 
returns a relation, which can in turn be queried.
Database schema 
I The schema of the database is the names of the relation, 
names and types of attributes - the structure of the database. 
I Usually, the schema is
xed in advance, and the data 
instances may change with time. 
I All attributes are typed - i.e. Ints, strings, etc., the 
implementation depends on the speci
c database 
management system (DBMS). 
I In addition to typed values, there exists the null value which is 
used for missing values. 
I A key is an attribute which is unique for every tuple (usually 
an ID, or row ID), this is important for indexing the relations 
in practice. 
I Note there is a debate over where relations (tables) should 
have singular or plural names. Ruby on Rails uses plurals, 
Django uses singular names.
Example database 
DVD 
movie rating 
`Edge Of Tomorrow' 4 
`Elysium' 9 
`Gattaca' 8 
A relation DVD, with the attributes movie (String) and rating (Int). 
Store 
name movie price 
`CheapBay' `Edge Of Tomorrow' 10 
`DVD World' `Elysium' 20 
`DVD World' `Gattaca' 10 
`Prime' `Edge Of Tomorrow' 20 
`Prime' `Elysium' 15 
A relation Store, with the attributes name (String), movie (String) and price (Int)
Relational Algebra operators 
I The simplest query is just the relation name, which returns 
the relation (table). 
I Operators act on this to
lter, slice and combine the data. 
I The projection operator, [attr ], returns the relation with only 
the chosen attributes, from the relation to which it is applied. 
I The selection operator, [cond], returns a relation with only 
the tuples matching the conditions provided, from the relation 
to which it is applied. 
I Note we use ^ for AND, and _ for OR.
Example of projection and selection 
DVD 
movie rating 
`Edge Of Tomorrow' 4 
`Elysium' 9 
`Gattaca' 8 
ratingDVD = 
rating 
4 
9 
8 
rating=5DVD = 
movie rating 
`Elysium' 9 
`Gattaca' 8
Example of combination 
DVD 
Movie Rating 
`Edge Of Tomorrow' 4 
`Elysium' 9 
`Gattaca' 8 
movie (rating=5DVD) = 
movie 
`Elysium' 
`Gattaca'
Relational Algebra operators (contd.) 
I The tuple cross-product, , returns a relation with every 
combination of the tuples. 
I The natural join, ./, is the cross-product combined with the 
selection operator to match tuples according to shared 
attribute names. 
I Note any relation natural joined with itself, returns the same 
relation itself. 
I Note the natural join just syntactic sugar for combining the 
cross-product and a speci
c selection operator. 
I The Theta join, ./, is the cross-product combined with a 
general selection operator. 
I This is also just syntactic sugar, and is the standard JOIN ON 
operator in DBMSs.
Example database 
DVD 
movie rating 
`Edge Of Tomorrow' 4 
`Elysium' 9 
`Gattaca' 8 
A relation DVD, with the attributes movie (String) and rating (Int) 
Store 
name movie price 
`CheapBay' `Edge Of Tomorrow' 10 
`DVD World' `Elysium' 20 
`DVD World' `Gattaca' 10 
`Prime' `Edge Of Tomorrow' 20 
`Prime' `Elysium' 15 
A relation Store, with the attributes name (String), movie (String) and price (Int)
Example cross-product 
I The cross-product returns every possible combination of the 
tuples. 
(nameStore)  (MovieDVD) = 
name movie 
`CheapBay' `Edge Of Tomorrow' 
`CheapBay' `Elysium' 
`CheapBay' `Gattaca' 
`DVD World' `Edge Of Tomorrow' 
`DVD World' `Elysium' 
`DVD World' `Gattaca' 
`Prime' `Edge Of Tomorrow' 
`Prime' `Elysium' 
`Prime' `Gattaca'
Example join 
I The natural join combines the tuples in the relations, where 
the joint attribute (movie) is equal. 
Store ./ DVD = 
name movie price rating 
`CheapBay' `Edge Of Tomorrow' 10 4 
`DVD World' `Elysium' 20 9 
`DVD World' `Gattaca' 10 8 
`Prime' `Edge Of Tomorrow' 20 4 
`Prime' `Elysium' 15 9
Relational Algebra operators (contd.) 
I The union operator, [, concatenates/stacks the tuples. 
I The dierence operator, , subtracts the second set of tuples 
from the
rst . 
I i.e. A  B returns tuples in A but not in B. 
I The intersection operator, , returns the tuples present in 
both sets. 
I Note the intersection operator is just syntactic sugar, we can 
always write: 
A  B = A  (A  B)
Example dierence 
I We want to
Ad

More Related Content

Viewers also liked (18)

Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Beat Signer
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
shynajain
 
DBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READDBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READ
amitp26
 
Database Lecture Notes
Database Lecture NotesDatabase Lecture Notes
Database Lecture Notes
FellowBuddy.com
 
Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)
Vidyasagar Mundroy
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
Vaibhav Kathuria
 
TRIGGERS
TRIGGERSTRIGGERS
TRIGGERS
demoiselle
 
Trigger
TriggerTrigger
Trigger
VForce Infotech
 
Relational Algebra and MapReduce
Relational Algebra and MapReduceRelational Algebra and MapReduce
Relational Algebra and MapReduce
Pietro Michiardi
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
pitchaiah yechuri
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
Hammad Rasheed
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
emailharmeet
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
yourbookworldanil
 
Sql ppt
Sql pptSql ppt
Sql ppt
Anuja Lad
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
Ram Sagar Mourya
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Beat Signer
 
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Beat Signer
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
shynajain
 
DBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READDBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READ
amitp26
 
Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)
Vidyasagar Mundroy
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
Vaibhav Kathuria
 
Relational Algebra and MapReduce
Relational Algebra and MapReduceRelational Algebra and MapReduce
Relational Algebra and MapReduce
Pietro Michiardi
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
emailharmeet
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
yourbookworldanil
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
Ram Sagar Mourya
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Beat Signer
 

Similar to Introduction to Relational Algebra (20)

lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
BALAMURUGANK63
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
ImXaib
 
Windy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4jWindy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4j
Max De Marzi
 
SQL PPT.ppt
SQL PPT.pptSQL PPT.ppt
SQL PPT.ppt
hemamalinikrishnan2
 
Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...
Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...
Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...
Chris Grabosky
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
koolkampus
 
Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)
Michal Bachman
 
Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)
GraphAware
 
Joint Repairs for Web Wrappers
Joint Repairs for Web WrappersJoint Repairs for Web Wrappers
Joint Repairs for Web Wrappers
Giorgio Orsi
 
04a-compare Object orienting programming.ppt
04a-compare Object orienting programming.ppt04a-compare Object orienting programming.ppt
04a-compare Object orienting programming.ppt
GESISLAMIAPATTOKI
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
VimalSangar1
 
04a-compare in java operator collection.ppt
04a-compare in java operator collection.ppt04a-compare in java operator collection.ppt
04a-compare in java operator collection.ppt
22ad0301
 
Sql server select queries ppt 18
Sql server select queries ppt 18Sql server select queries ppt 18
Sql server select queries ppt 18
Vibrant Technologies & Computers
 
04 Introduction to SQ(Structural Query Language)L.ppt
04 Introduction to SQ(Structural Query Language)L.ppt04 Introduction to SQ(Structural Query Language)L.ppt
04 Introduction to SQ(Structural Query Language)L.ppt
ShishirOyshi20143346
 
R markup code to create Regression Model
R markup code to create Regression ModelR markup code to create Regression Model
R markup code to create Regression Model
Mohit Rajput
 
08 Functions
08 Functions08 Functions
08 Functions
Hadley Wickham
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
"FENG "GEORGE"" YU
 
lecture04_movie_discussion.pdf
lecture04_movie_discussion.pdflecture04_movie_discussion.pdf
lecture04_movie_discussion.pdf
KRISLAM4
 
16 recommender systems
16 recommender systems16 recommender systems
16 recommender systems
TanmayVijay1
 
Chapter3
Chapter3Chapter3
Chapter3
Subhadip Pal
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
ImXaib
 
Windy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4jWindy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4j
Max De Marzi
 
Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...
Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...
Microsoft cloud workshop - automated cloud service for MongoDB on Microsoft A...
Chris Grabosky
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
koolkampus
 
Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)
Michal Bachman
 
Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)Recommendations with Neo4j (FOSDEM 2015)
Recommendations with Neo4j (FOSDEM 2015)
GraphAware
 
Joint Repairs for Web Wrappers
Joint Repairs for Web WrappersJoint Repairs for Web Wrappers
Joint Repairs for Web Wrappers
Giorgio Orsi
 
04a-compare Object orienting programming.ppt
04a-compare Object orienting programming.ppt04a-compare Object orienting programming.ppt
04a-compare Object orienting programming.ppt
GESISLAMIAPATTOKI
 
04a-compare in java operator collection.ppt
04a-compare in java operator collection.ppt04a-compare in java operator collection.ppt
04a-compare in java operator collection.ppt
22ad0301
 
04 Introduction to SQ(Structural Query Language)L.ppt
04 Introduction to SQ(Structural Query Language)L.ppt04 Introduction to SQ(Structural Query Language)L.ppt
04 Introduction to SQ(Structural Query Language)L.ppt
ShishirOyshi20143346
 
R markup code to create Regression Model
R markup code to create Regression ModelR markup code to create Regression Model
R markup code to create Regression Model
Mohit Rajput
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
"FENG "GEORGE"" YU
 
lecture04_movie_discussion.pdf
lecture04_movie_discussion.pdflecture04_movie_discussion.pdf
lecture04_movie_discussion.pdf
KRISLAM4
 
16 recommender systems
16 recommender systems16 recommender systems
16 recommender systems
TanmayVijay1
 
Ad

Recently uploaded (20)

AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Ad

Introduction to Relational Algebra

  • 1. An Introduction to Relational Algebra James McMurray PhD Student Department of Empirical Inference 09/12/2014
  • 2. Outline of talk Introduction What is Relational Algebra? Relational Algebra operators Core operators Joins Set operators Rename operator Conclusion Conclusion
  • 3. What is Relational Algebra? I Algebra for modelling and querying data stored in relational databases. I A relational database consists of a set of named relations, which contain named and typed attributes, and the data stored in tuples. I A relation is a table. I An attribute is a column. I A tuple is a row. I Relational Algebra queries are compositional, so any query returns a relation, which can in turn be queried.
  • 4. Database schema I The schema of the database is the names of the relation, names and types of attributes - the structure of the database. I Usually, the schema is
  • 5. xed in advance, and the data instances may change with time. I All attributes are typed - i.e. Ints, strings, etc., the implementation depends on the speci
  • 6. c database management system (DBMS). I In addition to typed values, there exists the null value which is used for missing values. I A key is an attribute which is unique for every tuple (usually an ID, or row ID), this is important for indexing the relations in practice. I Note there is a debate over where relations (tables) should have singular or plural names. Ruby on Rails uses plurals, Django uses singular names.
  • 7. Example database DVD movie rating `Edge Of Tomorrow' 4 `Elysium' 9 `Gattaca' 8 A relation DVD, with the attributes movie (String) and rating (Int). Store name movie price `CheapBay' `Edge Of Tomorrow' 10 `DVD World' `Elysium' 20 `DVD World' `Gattaca' 10 `Prime' `Edge Of Tomorrow' 20 `Prime' `Elysium' 15 A relation Store, with the attributes name (String), movie (String) and price (Int)
  • 8. Relational Algebra operators I The simplest query is just the relation name, which returns the relation (table). I Operators act on this to
  • 9. lter, slice and combine the data. I The projection operator, [attr ], returns the relation with only the chosen attributes, from the relation to which it is applied. I The selection operator, [cond], returns a relation with only the tuples matching the conditions provided, from the relation to which it is applied. I Note we use ^ for AND, and _ for OR.
  • 10. Example of projection and selection DVD movie rating `Edge Of Tomorrow' 4 `Elysium' 9 `Gattaca' 8 ratingDVD = rating 4 9 8 rating=5DVD = movie rating `Elysium' 9 `Gattaca' 8
  • 11. Example of combination DVD Movie Rating `Edge Of Tomorrow' 4 `Elysium' 9 `Gattaca' 8 movie (rating=5DVD) = movie `Elysium' `Gattaca'
  • 12. Relational Algebra operators (contd.) I The tuple cross-product, , returns a relation with every combination of the tuples. I The natural join, ./, is the cross-product combined with the selection operator to match tuples according to shared attribute names. I Note any relation natural joined with itself, returns the same relation itself. I Note the natural join just syntactic sugar for combining the cross-product and a speci
  • 13. c selection operator. I The Theta join, ./, is the cross-product combined with a general selection operator. I This is also just syntactic sugar, and is the standard JOIN ON operator in DBMSs.
  • 14. Example database DVD movie rating `Edge Of Tomorrow' 4 `Elysium' 9 `Gattaca' 8 A relation DVD, with the attributes movie (String) and rating (Int) Store name movie price `CheapBay' `Edge Of Tomorrow' 10 `DVD World' `Elysium' 20 `DVD World' `Gattaca' 10 `Prime' `Edge Of Tomorrow' 20 `Prime' `Elysium' 15 A relation Store, with the attributes name (String), movie (String) and price (Int)
  • 15. Example cross-product I The cross-product returns every possible combination of the tuples. (nameStore) (MovieDVD) = name movie `CheapBay' `Edge Of Tomorrow' `CheapBay' `Elysium' `CheapBay' `Gattaca' `DVD World' `Edge Of Tomorrow' `DVD World' `Elysium' `DVD World' `Gattaca' `Prime' `Edge Of Tomorrow' `Prime' `Elysium' `Prime' `Gattaca'
  • 16. Example join I The natural join combines the tuples in the relations, where the joint attribute (movie) is equal. Store ./ DVD = name movie price rating `CheapBay' `Edge Of Tomorrow' 10 4 `DVD World' `Elysium' 20 9 `DVD World' `Gattaca' 10 8 `Prime' `Edge Of Tomorrow' 20 4 `Prime' `Elysium' 15 9
  • 17. Relational Algebra operators (contd.) I The union operator, [, concatenates/stacks the tuples. I The dierence operator, , subtracts the second set of tuples from the
  • 18. rst . I i.e. A B returns tuples in A but not in B. I The intersection operator, , returns the tuples present in both sets. I Note the intersection operator is just syntactic sugar, we can always write: A B = A (A B)
  • 19. Example dierence I We want to
  • 20. nd all stores which only sell movies for less than 12 dollars. I We can do this by
  • 21. nding all stores which sell any movie for 12 dollars or more, and then subtracting this from the set of all stores. (nameStore) (name(price=12Store)) = name `CheapBay'
  • 22. Relational Algebra operators (contd.) I The rename operator, [newnames], returns the relation with the attributes assigned to the new names. I This is not just syntactic sugar. I Technically we need attribute names to be the same to carry out the natural join. I More importantly, it is necessary for disambiguation in self-joins. newname ratingDVD = newname 4 9 8
  • 23. Self-join example I We want to
  • 24. nd every distinct pair of names of movies which have been rated - i.e. (`Edge Of Tomorrow', `Elysium') I In order to do this we have to use a self-join, and the rename operator is critical (also note the importance of the greater than condition): moviemovie2 ((movieDVD) (movie2 movieDVD)) = movie movie2 `Edge Of Tomorrow' `Elysium' `Edge Of Tomorrow' `Gattaca' `Elysium' `Gattaca'
  • 25. More complicated example I We want to
  • 26. nd the maximum rating of all
  • 27. lms sold by Prime. I The trick we use is to
  • 28. nd the set of ratings which are ever less than another rating (via a self-join), and then subtract this from the set of all ratings of
  • 29. lms sold by Prime (denoted by PrimeRatings). PrimeRatings := rating ((name=`prime'Store) ./ DVD) Result := PrimeRatings rating ratingrating2( PrimeRatings rating2PrimeRatings ) = rating 9
  • 30. Even harder example I We want to
  • 31. nd the names of all the stores which sell ALL of the
  • 32. lms which have ratings higher than 7. I Trick is to calculate all possible, relevant store-movie tuples, then calculate the could have been tuples which were not observed, then
  • 33. nd which stores these were present for, and subtract this from all the stores. I This is Relational Division. GoodMovie := movie rating7DVD Result :=nameStore name(((nameStore) GoodMovie) name,movieStore) = name `DVD World'
  • 35. nes an algebra for querying relational databases. I Operators may seem simple but queries can become complicated. I Many other common extensions have been omitted here, such as the semijoin, antijoin and relational division - these are all syntactic sugar. I In practice we do not query relational databases with relational algebra directly, but with a query language based upon it. I The most popular is SQL, the Structured Query Language. I Though there is a Relational Algebra interpeter called RA for SQLite (used for these examples). Questions?