Tuesday 20 February 2024

Projection Operator in Relational Algebra

 

Projection Operator-

 

  • Projection Operator (π) is a unary operator in relational algebra that performs a projection operation.
  • It displays the columns of a relation or table based on the specified attributes.
  • It is a fundamental / Basic operator
  • It is a unary operator

Syntax-

 

π<attribute list>(R)

 

Example-

 

Consider the following Student relation-

IDNameSubjectAge
100AshishMaths19
200RahulScience20
300NainaPhysics20
400SameerChemistry21

Student


Result for Query πName, Age(Student)-

 

NameAge
Ashish19
Rahul20
Naina20
Sameer21


Result for Query πID , Name(Student)-

IDName
100Ashish
200Rahul
300Naina
400Sameer

 

Important Points-

 

Point-01:

 

  • The degree of output relation (number of columns present) is equal to the number of attributes mentioned in the attribute list.

Point-02:

 

  • Projection operator automatically removes all the duplicates while projecting the output relation.
  • So, cardinality of the original relation and output relation may or may not be same.
  • If there are no duplicates in the original relation, then the cardinality will remain same otherwise it will surely reduce.

 

Point-03:

 

  • If attribute list is a super key on relation R, then we will always get the same number of tuples in the output relation.
  • This is because then there will be no duplicates to filter.

Point-04:

 

  • Projection operator does not obey commutative property i.e.

π <list2> (π <list1> (R)) ≠ π <list1> (π <list2> (R))


Point-05:

 

  • Selection Operator performs horizontal partitioning of the relation.
  • Projection operator performs vertical partitioning of the relation.

 

Point-06:

 

  • There is only one difference between projection operator of relational algebra and SELECT operation of SQL.
  • Projection operator does not allow duplicates while SELECT operation allows duplicates.
  • To avoid duplicates in SQL, we use “distinct” keyword and write SELECT distinct.
  • Thus, projection operator of relational algebra is equivalent to SELECT operation of SQL.

















No comments:

Post a Comment