SlideShare a Scribd company logo
RELATIONAL ALGEBRA
AND TUPLE RELATIONAL
CALCULUS
9/27/2020 1
Relational Algebra
• Procedural Query Languages.
• Operation to be performed on exciting
relation to derive the result relation.
• Unary operation.
– Select
– Project
– Rename
• Binary operation.
– Cartesian product
– Union
– Set difference
• Additional Operation
– Intersection
– Join
– Division
– Assignment
9/27/2020 3
9/27/2020 4
9/27/2020 5
9/27/2020 6
9/27/2020 7
9/27/2020 8
9/27/2020 9
9/27/2020 10
9/27/2020 11
9/27/2020 12
9/27/2020 13
9/27/2020 14
9/27/2020 15
9/27/2020 16
9/27/2020 17
9/27/2020 18
9/27/2020 19
9/27/2020 20
9/27/2020 21
9/27/2020 22
Division Operation (Cont.)
 Property
 Let q – r  s
 Then q is the largest relation satisfying q x s  r
 Definition in terms of the basic algebra operation
Let r(R) and s(S) be relations, and let S  R
r  s = R-S (r) –R-S ( (R-S (r) x s) – R-S,S(r))
To see why
 R-S,S(r) simply reorders attributes of r
 R-S(R-S (r) x s) – R-S,S(r)) gives those tuples t in
R-S (r) such that for some tuple u  s, tu  r.
9/27/2020 23
Division Operation – Example
Relations r, s: B
1
2
A B











1
2
3
1
1
1
3
4
6
1
2
r  s:
A


r
s
9/27/2020 24
Another Division Example
A B








a
a
a
a
a
a
a
a
C D








a
a
b
a
b
a
b
b
E
1
1
1
1
3
1
1
1
Relations r, s:
r  s:
D
a
b
E
1
1
A B


a
a
C


r
s
9/27/2020 25
Assignment Operation
 The assignment operation () provides a convenient way to express
complex queries.
 Write query as a sequential program consisting of
 a series of assignments
 followed by an expression whose value is displayed as a result
of the query.
 Assignment must always be made to a temporary relation variable.
 Example: Write r  s as
temp1  R-S (r)
temp2  R-S ((temp1 x s) – R-S,S (r))
result = temp1 – temp2
 The result to the right of the  is assigned to the relation variable on
the left of the .
 May use variable in subsequent expressions.
9/27/2020 26
Extended Relational-Algebra-
Operations
 Generalized Projection
 Outer Join
 Aggregate Functions
9/27/2020 27
Generalized Projection
 Extends the projection operation by allowing
arithmetic functions to be used in the projection
list.
 F1, F2, …, Fn(E)
 E is any relational-algebra expression
 Each of F1, F2, …, Fn are are arithmetic
expressions involving constants and attributes
in the schema of E.
 Given relation credit-info(customer-name,
limit, credit-balance), find how much more
each person can spend:
customer-name, limit – credit-balance (credit-info)
9/27/2020 28
Aggregate Functions and Operations
 Aggregation function takes a collection of values and
returns a single value as a result.
avg: average value
min: minimum value
max: maximum value
sum: sum of values
count: number of values
 Aggregate operation in relational algebra
G1, G2, …, Gn g F1( A1), F2( A2),…, Fn( An) (E)
 E is any relational-algebra expression
 G1, G2 …, Gn is a list of attributes on which to group
(can be empty)
 Each Fi is an aggregate function
 Each Ai is an attribute name
9/27/2020 29
Aggregate Operation –
Example
 Relation r: A B








C
7
7
3
10
g sum(c) (r) sum-C
27
9/27/2020 30
Aggregate Operation –
Example
 Relation account grouped by
branch-name:
branch-name g sum(balance) (account)
branch-name account-number balance
Perryridge
Perryridge
Brighton
Brighton
Redwood
A-102
A-201
A-217
A-215
A-222
400
900
750
750
700
branch-name balance
Perryridge
Brighton
Redwood
1300
1500
700
9/27/2020 31
Aggregate Functions (Cont.)
 Result of aggregation does not have a
name
 Can use rename operation to give it a
name
 For convenience, we permit renaming
as part of aggregate operation
branch-name g sum(balance) as sum-balance (account)
9/27/2020 32
Outer Join
 An extension of the join operation that avoids loss of
information.
 Computes the join and then adds tuples form one
relation that does not match tuples in the other
relation to the result of the join.
 Uses null values:
 null signifies that the value is unknown or does
not exist
 All comparisons involving null are (roughly
speaking) false by definition.
 Will study precise meaning of comparisons
with nulls later
9/27/2020 33
Outer Join – Example
 Relation loan
 Relation borrower
customer-name loan-number
Jones
Smith
Hayes
L-170
L-230
L-155
3000
4000
1700
loan-number amount
L-170
L-230
L-260
branch-name
Downtown
Redwood
Perryridge
9/27/2020 34
Outer Join – Example
 Inner Join
loan Borrower
loan-number amount
L-170
L-230
3000
4000
customer-name
Jones
Smith
branch-name
Downtown
Redwood
Jones
Smith
null
loan-number amount
L-170
L-230
L-260
3000
4000
1700
customer-namebranch-name
Downtown
Redwood
Perryridge
 Left Outer Join
loan Borrower
loan Borrower
9/27/2020 35
Outer Join – Example
 Right Outer Join
loan borrower
loan borrower
 Full Outer Join
loan-number amount
L-170
L-230
L-155
3000
4000
null
customer-name
Jones
Smith
Hayes
branch-name
Downtown
Redwood
null
loan-number amount
L-170
L-230
L-260
L-155
3000
4000
1700
null
customer-name
Jones
Smith
null
Hayes
branch-name
Downtown
Redwood
Perryridge
null
loan borrower
9/27/2020 36
Tuple Relational Calculus
 A nonprocedural query language, where each query
is of the form
{t | P (t) }
 It is the set of all tuples t such that
predicate P is true for t
 t is a tuple variable, t[A] denotes the value of tuple t
on attribute A
 t  r denotes that tuple t is in relation r
 P is a formula similar to that of the
predicate calculus
9/27/2020 37
Predicate Calculus Formula
1. Set of attributes and constants
2. Set of comparison operators: (e.g., , , , , , )
3. Set of connectives: and (), or (v)‚ not ()
4. Implication (): x  y, if x is true, then y is true
5. Set of quantifiers:
  t  r (Q(t))  ”there exists” a tuple in t in relation r
such that predicate Q(t) is true
 t r (Q(t)) Q is true “for all” tuples t in relation r
s[x] Ѳ u[y] : s, u are tuple variables. x,y are attributes
and Ѳ is comparison operator.
s[x] Ѳ c , where c is a constant.
9/27/2020 38
Banking Example
 branch (branch-name, branch-city, assets)
 customer (customer-name, customer-
street, customer-city)
 account (account-number, branch-name,
balance)
 loan (loan-number, branch-name, amount)
 depositor (customer-name, account-
number)
 borrower (customer-name, loan-number)
Example Queries
 Find all the tuples in loan
relation
 {t | t  loan}
 Find those tuples for which
loans of greater than 1200
 {t | t  loan  t [amount]  1200}
9/27/2020 39
9/27/2020 40
Example Queries
Find the loan number for each loan of an amount greater
than $1200
The set of all tuples t such that there exists a tuple s in relation
loan for which the values t and s for the loan-number attributes
are equal and the value of s for the amount attribute is greater
than $1200
Notice that a relation on schema [loan-number] is implicitly
defined by the query
{t |  s loan (t[loan-number] = s[loan-number]  s [amount]  1200)}
9/27/2020 41
Example Queries
 Find the names of all customers having a loan, an
account, or both at the bank
{t | s  borrower( t[customer-name] = s[customer-name])
 u  depositor( t[customer-name] = u[customer-name])
 Find the names of all customers who have a loan and
an account at the bank
{t | s  borrower( t[customer-name] = s[customer-name])
 u  depositor( t[customer-name] = u[customer-name])
9/27/2020 42
Safety of Expressions
 It is possible to write tuple calculus expressions that
generate infinite relations.
 For example, {t |  t r} results in an infinite relation if
the domain of any attribute of relation r is infinite
 To guard against the problem, we restrict the set of
allowable expressions to safe expressions.
 An expression {t | P(t)} in the tuple relational calculus is
safe if every component of t appears in one of the
relations, tuples, or constants that appear in P
 NOTE: this is more than just a syntax condition.
 E.g. { t | t[A]=5  true } is not safe --- it defines
an infinite set with attribute values that do not
appear in any relation or tuples or constants in P.
9/27/2020 43
Null Values
 It is possible for tuples to have a null value, denoted by null, for
some of their attributes
 null signifies an unknown value or that a value does not exist.
 The result of any arithmetic expression involving null is null.
 Aggregate functions simply ignore null values
 Is an arbitrary decision. Could have returned null as result
instead.
 We follow the semantics of SQL in its handling of null
values
 For duplicate elimination and grouping, null is treated like any
other value, and two nulls are assumed to be the same
 Alternative: assume each null is different from each other
 Both are arbitrary decisions, so we simply follow SQL
9/27/2020 44
Null Values
 Comparisons with null values return the special truth value
unknown
 If false was used instead of unknown, then not (A < 5)
would not be equivalent to A >= 5
 Three-valued logic using the truth value unknown:
 OR: (unknown or true) = true,
(unknown or false) = unknown
(unknown or unknown) = unknown
 AND: (true and unknown) = unknown,
(false and unknown) = false,
(unknown and unknown) = unknown
 NOT: (not unknown) = unknown
 In SQL “P is unknown” evaluates to true if predicate P
evaluates to unknown
 Result of select predicate is treated as false if it evaluates to
unknown

More Related Content

PPTX
The Relational Database Model
PPTX
Database constraints
PPTX
Aggregate function
PPT
Relational algebra-and-relational-calculus
PPT
Entity Relationship Diagram
PPTX
Bit manipulation
PPTX
Cookie & Session In ASP.NET
PDF
DDL oracle - base de datos
The Relational Database Model
Database constraints
Aggregate function
Relational algebra-and-relational-calculus
Entity Relationship Diagram
Bit manipulation
Cookie & Session In ASP.NET
DDL oracle - base de datos

What's hot (20)

PPTX
Toolbar
PPTX
DATABASE CONSTRAINTS
PPTX
Data Manipulation Language (DML).pptx
PPT
4. SQL in DBMS
PPTX
The scrollbars controls
PPT
DDL - Lenguaje de definición de datos
PDF
Data manipulation language
PPT
DBMS Unit 2 ppt.ppt
PPT
stack and queue array implementation in java.
PPTX
K way merging advanced data structures materials
PPTX
class and objects
PPT
vb.net Constructor and destructor
PPTX
Relational algebra ppt
PPT
Capitulo 1 Base de Datos
PPTX
Architecture of dbms(lecture 3)
PPT
JavaScript Objects
PPT
Aggregate functions
PPTX
Sql(structured query language)
PPT
Entity relationship modelling
PPTX
Group By, Having Clause and Order By clause
Toolbar
DATABASE CONSTRAINTS
Data Manipulation Language (DML).pptx
4. SQL in DBMS
The scrollbars controls
DDL - Lenguaje de definición de datos
Data manipulation language
DBMS Unit 2 ppt.ppt
stack and queue array implementation in java.
K way merging advanced data structures materials
class and objects
vb.net Constructor and destructor
Relational algebra ppt
Capitulo 1 Base de Datos
Architecture of dbms(lecture 3)
JavaScript Objects
Aggregate functions
Sql(structured query language)
Entity relationship modelling
Group By, Having Clause and Order By clause
Ad

Similar to relational algebra Tuple Relational Calculus - database management system (20)

PPTX
UNIT-2 Relation algebra&RelationalCalculus.pptx
PDF
RelationalAlgebra-RelationalCalculus-SQL.pdf
PPT
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
PDF
Cs501 rel algebra
PPT
Formal- Relational- Query- Languages.ppt
PPT
Formal-Relational-Query-Languages.ppt for education
PDF
Relational Algebra & Calculus
PDF
Database systems-Formal relational query languages
PPT
Relational algebra operations
PPT
Chapter6
PDF
Dbms module ii
PPTX
Relational Model,relational calulus.pptx
PDF
Unit-II DBMS presentation for students.pdf
PPTX
Relation model part 1
PPTX
Relational Algebra.Pptxjejejjdjdh jsjsjd
PPTX
Slide For Database Management System Relational Model.pptx
DOCX
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
PPTX
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
PPTX
Relational Algebra in Database Systems.pptx
UNIT-2 Relation algebra&RelationalCalculus.pptx
RelationalAlgebra-RelationalCalculus-SQL.pdf
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
Cs501 rel algebra
Formal- Relational- Query- Languages.ppt
Formal-Relational-Query-Languages.ppt for education
Relational Algebra & Calculus
Database systems-Formal relational query languages
Relational algebra operations
Chapter6
Dbms module ii
Relational Model,relational calulus.pptx
Unit-II DBMS presentation for students.pdf
Relation model part 1
Relational Algebra.Pptxjejejjdjdh jsjsjd
Slide For Database Management System Relational Model.pptx
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
Relational Algebra in Database Systems.pptx
Ad

More from Surya Swaroop (20)

PDF
Pie chart - qualitative aptitude
PPTX
Simplification and data interpretation table
PPTX
Quantitative aptitude table data interpretation
PDF
Environmental engineering text book
PPT
Development of surfaces
PPT
Elasticity
PDF
Design and Drawing of Steel Structures
PDF
Design & Drawing of Steel Structures
PDF
design drawing of steel structures
PDF
design-and-drawing Steel structures
PDF
design drawing steel structures
PDF
Integration material
PDF
Probability
PDF
Other transform dip
PPT
deadlock and locking - dbms
PPT
transaction management, concept & State
PPT
relational database
PPT
er question dbms
PPT
dbms er model
PPT
data base
Pie chart - qualitative aptitude
Simplification and data interpretation table
Quantitative aptitude table data interpretation
Environmental engineering text book
Development of surfaces
Elasticity
Design and Drawing of Steel Structures
Design & Drawing of Steel Structures
design drawing of steel structures
design-and-drawing Steel structures
design drawing steel structures
Integration material
Probability
Other transform dip
deadlock and locking - dbms
transaction management, concept & State
relational database
er question dbms
dbms er model
data base

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Institutional Correction lecture only . . .
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Computing-Curriculum for Schools in Ghana
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
Basic Mud Logging Guide for educational purpose
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Complications of Minimal Access Surgery at WLH
Institutional Correction lecture only . . .
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial disease of the cardiovascular and lymphatic systems
Microbial diseases, their pathogenesis and prophylaxis
Computing-Curriculum for Schools in Ghana
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pre independence Education in Inndia.pdf
VCE English Exam - Section C Student Revision Booklet
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Insiders guide to clinical Medicine.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
human mycosis Human fungal infections are called human mycosis..pptx

relational algebra Tuple Relational Calculus - database management system

  • 1. RELATIONAL ALGEBRA AND TUPLE RELATIONAL CALCULUS 9/27/2020 1
  • 2. Relational Algebra • Procedural Query Languages. • Operation to be performed on exciting relation to derive the result relation. • Unary operation. – Select – Project – Rename • Binary operation. – Cartesian product – Union – Set difference • Additional Operation – Intersection – Join – Division – Assignment
  • 22. 9/27/2020 22 Division Operation (Cont.)  Property  Let q – r  s  Then q is the largest relation satisfying q x s  r  Definition in terms of the basic algebra operation Let r(R) and s(S) be relations, and let S  R r  s = R-S (r) –R-S ( (R-S (r) x s) – R-S,S(r)) To see why  R-S,S(r) simply reorders attributes of r  R-S(R-S (r) x s) – R-S,S(r)) gives those tuples t in R-S (r) such that for some tuple u  s, tu  r.
  • 23. 9/27/2020 23 Division Operation – Example Relations r, s: B 1 2 A B            1 2 3 1 1 1 3 4 6 1 2 r  s: A   r s
  • 24. 9/27/2020 24 Another Division Example A B         a a a a a a a a C D         a a b a b a b b E 1 1 1 1 3 1 1 1 Relations r, s: r  s: D a b E 1 1 A B   a a C   r s
  • 25. 9/27/2020 25 Assignment Operation  The assignment operation () provides a convenient way to express complex queries.  Write query as a sequential program consisting of  a series of assignments  followed by an expression whose value is displayed as a result of the query.  Assignment must always be made to a temporary relation variable.  Example: Write r  s as temp1  R-S (r) temp2  R-S ((temp1 x s) – R-S,S (r)) result = temp1 – temp2  The result to the right of the  is assigned to the relation variable on the left of the .  May use variable in subsequent expressions.
  • 26. 9/27/2020 26 Extended Relational-Algebra- Operations  Generalized Projection  Outer Join  Aggregate Functions
  • 27. 9/27/2020 27 Generalized Projection  Extends the projection operation by allowing arithmetic functions to be used in the projection list.  F1, F2, …, Fn(E)  E is any relational-algebra expression  Each of F1, F2, …, Fn are are arithmetic expressions involving constants and attributes in the schema of E.  Given relation credit-info(customer-name, limit, credit-balance), find how much more each person can spend: customer-name, limit – credit-balance (credit-info)
  • 28. 9/27/2020 28 Aggregate Functions and Operations  Aggregation function takes a collection of values and returns a single value as a result. avg: average value min: minimum value max: maximum value sum: sum of values count: number of values  Aggregate operation in relational algebra G1, G2, …, Gn g F1( A1), F2( A2),…, Fn( An) (E)  E is any relational-algebra expression  G1, G2 …, Gn is a list of attributes on which to group (can be empty)  Each Fi is an aggregate function  Each Ai is an attribute name
  • 29. 9/27/2020 29 Aggregate Operation – Example  Relation r: A B         C 7 7 3 10 g sum(c) (r) sum-C 27
  • 30. 9/27/2020 30 Aggregate Operation – Example  Relation account grouped by branch-name: branch-name g sum(balance) (account) branch-name account-number balance Perryridge Perryridge Brighton Brighton Redwood A-102 A-201 A-217 A-215 A-222 400 900 750 750 700 branch-name balance Perryridge Brighton Redwood 1300 1500 700
  • 31. 9/27/2020 31 Aggregate Functions (Cont.)  Result of aggregation does not have a name  Can use rename operation to give it a name  For convenience, we permit renaming as part of aggregate operation branch-name g sum(balance) as sum-balance (account)
  • 32. 9/27/2020 32 Outer Join  An extension of the join operation that avoids loss of information.  Computes the join and then adds tuples form one relation that does not match tuples in the other relation to the result of the join.  Uses null values:  null signifies that the value is unknown or does not exist  All comparisons involving null are (roughly speaking) false by definition.  Will study precise meaning of comparisons with nulls later
  • 33. 9/27/2020 33 Outer Join – Example  Relation loan  Relation borrower customer-name loan-number Jones Smith Hayes L-170 L-230 L-155 3000 4000 1700 loan-number amount L-170 L-230 L-260 branch-name Downtown Redwood Perryridge
  • 34. 9/27/2020 34 Outer Join – Example  Inner Join loan Borrower loan-number amount L-170 L-230 3000 4000 customer-name Jones Smith branch-name Downtown Redwood Jones Smith null loan-number amount L-170 L-230 L-260 3000 4000 1700 customer-namebranch-name Downtown Redwood Perryridge  Left Outer Join loan Borrower loan Borrower
  • 35. 9/27/2020 35 Outer Join – Example  Right Outer Join loan borrower loan borrower  Full Outer Join loan-number amount L-170 L-230 L-155 3000 4000 null customer-name Jones Smith Hayes branch-name Downtown Redwood null loan-number amount L-170 L-230 L-260 L-155 3000 4000 1700 null customer-name Jones Smith null Hayes branch-name Downtown Redwood Perryridge null loan borrower
  • 36. 9/27/2020 36 Tuple Relational Calculus  A nonprocedural query language, where each query is of the form {t | P (t) }  It is the set of all tuples t such that predicate P is true for t  t is a tuple variable, t[A] denotes the value of tuple t on attribute A  t  r denotes that tuple t is in relation r  P is a formula similar to that of the predicate calculus
  • 37. 9/27/2020 37 Predicate Calculus Formula 1. Set of attributes and constants 2. Set of comparison operators: (e.g., , , , , , ) 3. Set of connectives: and (), or (v)‚ not () 4. Implication (): x  y, if x is true, then y is true 5. Set of quantifiers:   t  r (Q(t))  ”there exists” a tuple in t in relation r such that predicate Q(t) is true  t r (Q(t)) Q is true “for all” tuples t in relation r s[x] Ѳ u[y] : s, u are tuple variables. x,y are attributes and Ѳ is comparison operator. s[x] Ѳ c , where c is a constant.
  • 38. 9/27/2020 38 Banking Example  branch (branch-name, branch-city, assets)  customer (customer-name, customer- street, customer-city)  account (account-number, branch-name, balance)  loan (loan-number, branch-name, amount)  depositor (customer-name, account- number)  borrower (customer-name, loan-number)
  • 39. Example Queries  Find all the tuples in loan relation  {t | t  loan}  Find those tuples for which loans of greater than 1200  {t | t  loan  t [amount]  1200} 9/27/2020 39
  • 40. 9/27/2020 40 Example Queries Find the loan number for each loan of an amount greater than $1200 The set of all tuples t such that there exists a tuple s in relation loan for which the values t and s for the loan-number attributes are equal and the value of s for the amount attribute is greater than $1200 Notice that a relation on schema [loan-number] is implicitly defined by the query {t |  s loan (t[loan-number] = s[loan-number]  s [amount]  1200)}
  • 41. 9/27/2020 41 Example Queries  Find the names of all customers having a loan, an account, or both at the bank {t | s  borrower( t[customer-name] = s[customer-name])  u  depositor( t[customer-name] = u[customer-name])  Find the names of all customers who have a loan and an account at the bank {t | s  borrower( t[customer-name] = s[customer-name])  u  depositor( t[customer-name] = u[customer-name])
  • 42. 9/27/2020 42 Safety of Expressions  It is possible to write tuple calculus expressions that generate infinite relations.  For example, {t |  t r} results in an infinite relation if the domain of any attribute of relation r is infinite  To guard against the problem, we restrict the set of allowable expressions to safe expressions.  An expression {t | P(t)} in the tuple relational calculus is safe if every component of t appears in one of the relations, tuples, or constants that appear in P  NOTE: this is more than just a syntax condition.  E.g. { t | t[A]=5  true } is not safe --- it defines an infinite set with attribute values that do not appear in any relation or tuples or constants in P.
  • 43. 9/27/2020 43 Null Values  It is possible for tuples to have a null value, denoted by null, for some of their attributes  null signifies an unknown value or that a value does not exist.  The result of any arithmetic expression involving null is null.  Aggregate functions simply ignore null values  Is an arbitrary decision. Could have returned null as result instead.  We follow the semantics of SQL in its handling of null values  For duplicate elimination and grouping, null is treated like any other value, and two nulls are assumed to be the same  Alternative: assume each null is different from each other  Both are arbitrary decisions, so we simply follow SQL
  • 44. 9/27/2020 44 Null Values  Comparisons with null values return the special truth value unknown  If false was used instead of unknown, then not (A < 5) would not be equivalent to A >= 5  Three-valued logic using the truth value unknown:  OR: (unknown or true) = true, (unknown or false) = unknown (unknown or unknown) = unknown  AND: (true and unknown) = unknown, (false and unknown) = false, (unknown and unknown) = unknown  NOT: (not unknown) = unknown  In SQL “P is unknown” evaluates to true if predicate P evaluates to unknown  Result of select predicate is treated as false if it evaluates to unknown