Extending the Relational Algebra and Datalog




CS157a

Chris Pollett

Oct 25, 2023

Outline

Introduction

Extended Operators of Relational Algebra

Duplicate Elimination and Aggregation operators

Grouping

Extending the Projection Operator

The Sorting Operator and Outer Joins

In-Class Exercise

Give the relational algebra for the following queries. Assume we have relations Employee(eid, fname, lname, address, birth_date, salary), WorksOn(emp_id, proj_id, hours), and Project(pid, proj_name, manager_id).

  1. Return the table LastNameAddress(lname, address) of the distinct (last_name, address) pairs sorted descending by last_name.
  2. Return the average age as avg_age and average salary as avg_sal of employees. Assume we have a built-in function time() that gives the current time and that time() - birth_date returns a time in a format that can be averaged.
  3. Return a table MostTimeConsuming(fname, lname, pname, hours), the names of employees and the names of the projects they spend the most hours on. If an employee doesn't work on any projects, they should still be output but with nulls for the last two columns.

Post your solutions to the Oct 25 In-Class Exercise Thread.

Datalog

Predicates and Atoms

Arithmetic Atoms

Datalog Rules and Queries

Meaning of Datalog Rules

Extensional and Intensional Predicates

Datalog Applied to Bags

Relational Algebra and Datalog