0% found this document useful (0 votes)
92 views

Practice 1

This document contains the instructions for Problem Set #1, which involves writing queries over sample databases using different query languages. The first section describes a database of drinkers, bars, and beers and provides sample queries to write in different languages. The second section describes a movie database and provides additional sample queries. The third section asks to prove or disprove properties of relational algebra operations. The fourth section describes rewriting a relational algebra query for more efficient evaluation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Practice 1

This document contains the instructions for Problem Set #1, which involves writing queries over sample databases using different query languages. The first section describes a database of drinkers, bars, and beers and provides sample queries to write in different languages. The second section describes a movie database and provides additional sample queries. The third section asks to prove or disprove properties of relational algebra operations. The fourth section describes rewriting a relational algebra query for more efficient evaluation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE 132A

Problem Set # 1

Practice Problems on Queries

1. The beer drinkers database consists of the following three relations frequents: drinker, bar serves: bar, beer likes: drinker, beer The rst indicates the bars each drinker frequents, the second tells what beers each bar serves, and the last indicates which beers each drinker likes to drink. Express the following queries in (i) tuple calculus (ii) domain calculus (iii) relational algebra (iv) SQL and (v) QBE: (a) List the bars that serve a beer that Joe likes. (b) List the drinkers who frequent at least one bar that serves a beer they like. (c) List the drinkers who frequent only bars that serve some beer that they like. (Assume each drinker likes at least one beer and frequents at least one bar.) (d) List the drinkers who frequent no bar that serves a beer that they like. 2. Consider the database consisting of one relation: movie: title, director, actor. Express the following queries in (i) domain calculus, (ii) relational algebra, (iii) QBE, and (iv) SQL. (a) List the actors cast in at least one movie by Kurosawa. (b) List the actors cast in every movie by Kurosawa. (c) List the actors cast only in movies by Kurosawa. (d) List all pairs of actors who act together in at least one movie. 1

(e) List the directors such that every actor is cast in one of his/her movies. (Assume that a movie is uniquely identied by its title.) 3. Let R and S be relations with attributes AB. Prove or disprove the following: (a) A (R S) = A (R) A (S) (b) A (R S) = A (R) A (S) (c) A (R S) = A (R) A (S) 4. Consider the movie database consisting of two relations movie: title, director, actor schedule: title, theater Consider the relational algebra query: director [theater=Hillcrest (movie 1 schedule)] (nd the directors of all movies playing elsewhere than Hillcrest). How should a query optimizer rewrite this query to make its evaluation more ecient? Explain why the rewritten query is better.

You might also like